BuriedTreasurePieces .java

net.minecraft.world.level.levelgen.structure.structures.BuriedTreasurePieces (class): members: BuriedTreasurePiece. imports: StructurePiece, BoundingBox.

net.minecraft.world.level.levelgen.structure.structuresclass85 linescommon3.3 KB

API Surface (2)

void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag)
void postProcess(final WorldGenLevel level, final StructureManager structureManager, final ChunkGenerator generator, final RandomSource random, final BoundingBox chunkBB, final ChunkPos chunkPos, final BlockPos referencePos)

Full Source

BuriedTreasurePieces.java85 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.levelgen.structure.structures;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.nbt.CompoundTag;
6
import net.minecraft.util.RandomSource;
7
import net.minecraft.world.level.ChunkPos;
8
import net.minecraft.world.level.StructureManager;
9
import net.minecraft.world.level.WorldGenLevel;
10
import net.minecraft.world.level.block.Blocks;
11
import net.minecraft.world.level.block.state.BlockState;
12
import net.minecraft.world.level.chunk.ChunkGenerator;
13
import net.minecraft.world.level.levelgen.Heightmap;
14
import net.minecraft.world.level.levelgen.structure.BoundingBox;
15
import net.minecraft.world.level.levelgen.structure.StructurePiece;
16
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
17
import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
18
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
19
20
public class BuriedTreasurePieces {
21
	public static class BuriedTreasurePiece extends StructurePiece {
22
		public BuriedTreasurePiece(final BlockPos offset) {
23
			super(StructurePieceType.BURIED_TREASURE_PIECE, 0, new BoundingBox(offset));
24
		}
25
26
		public BuriedTreasurePiece(final CompoundTag tag) {
27
			super(StructurePieceType.BURIED_TREASURE_PIECE, tag);
28
		}
29
30
		@Override
31
		protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
32
		}
33
34
		@Override
35
		public void postProcess(
36
			final WorldGenLevel level,
37
			final StructureManager structureManager,
38
			final ChunkGenerator generator,
39
			final RandomSource random,
40
			final BoundingBox chunkBB,
41
			final ChunkPos chunkPos,
42
			final BlockPos referencePos
43
		) {
44
			int y = level.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, this.boundingBox.minX(), this.boundingBox.minZ());
45
			BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(this.boundingBox.minX(), y, this.boundingBox.minZ());
46
47
			while (pos.getY() > level.getMinY()) {
48
				BlockState currentState = level.getBlockState(pos);
49
				BlockState belowState = level.getBlockState(pos.below());
50
				if (belowState.is(Blocks.SANDSTONE)
51
					|| belowState.is(Blocks.STONE)
52
					|| belowState.is(Blocks.ANDESITE)
53
					|| belowState.is(Blocks.GRANITE)
54
					|| belowState.is(Blocks.DIORITE)) {
55
					BlockState softState = !currentState.isAir() && !isLiquid(currentState) ? currentState : Blocks.SAND.defaultBlockState();
56
57
					for (Direction direction : Direction.values()) {
58
						BlockPos relativePos = pos.relative(direction);
59
						BlockState relativeState = level.getBlockState(relativePos);
60
						if (relativeState.isAir() || isLiquid(relativeState)) {
61
							BlockPos belowRelativePos = relativePos.below();
62
							BlockState belowRelativeState = level.getBlockState(belowRelativePos);
63
							if ((belowRelativeState.isAir() || isLiquid(belowRelativeState)) && direction != Direction.UP) {
64
								level.setBlockAndUpdate(relativePos, belowState);
65
							} else {
66
								level.setBlockAndUpdate(relativePos, softState);
67
							}
68
						}
69
					}
70
71
					this.boundingBox = new BoundingBox(pos);
72
					this.createChest(level, chunkBB, random, pos, BuiltInLootTables.BURIED_TREASURE, null);
73
					return;
74
				}
75
76
				pos.move(0, -1, 0);
77
			}
78
		}
79
80
		private static boolean isLiquid(final BlockState blockState) {
81
			return blockState.is(Blocks.WATER) || blockState.is(Blocks.LAVA);
82
		}
83
	}
84
}
85

Decompiled Minecraft 26.3 source of BuriedTreasurePieces (net/minecraft/world/level/levelgen/structure/structures/BuriedTreasurePieces.java) with Mojang official mappings, stored verbatim on the site.