| 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.entity.EntitySpawnReason;
|
| 8 | import net.minecraft.world.entity.EntityTypes;
|
| 9 | import net.minecraft.world.entity.animal.feline.Cat;
|
| 10 | import net.minecraft.world.entity.monster.Witch;
|
| 11 | import net.minecraft.world.level.ChunkPos;
|
| 12 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 13 | import net.minecraft.world.level.StructureManager;
|
| 14 | import net.minecraft.world.level.WorldGenLevel;
|
| 15 | import net.minecraft.world.level.block.Blocks;
|
| 16 | import net.minecraft.world.level.block.StairBlock;
|
| 17 | import net.minecraft.world.level.block.state.BlockState;
|
| 18 | import net.minecraft.world.level.block.state.properties.StairsShape;
|
| 19 | import net.minecraft.world.level.chunk.ChunkGenerator;
|
| 20 | import net.minecraft.world.level.levelgen.structure.BoundingBox;
|
| 21 | import net.minecraft.world.level.levelgen.structure.ScatteredFeaturePiece;
|
| 22 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceSerializationContext;
|
| 23 | import net.minecraft.world.level.levelgen.structure.pieces.StructurePieceType;
|
| 24 |
|
| 25 | public class SwampHutPiece extends ScatteredFeaturePiece {
|
| 26 | private boolean spawnedWitch;
|
| 27 | private boolean spawnedCat;
|
| 28 |
|
| 29 | public SwampHutPiece(final RandomSource random, final int west, final int north) {
|
| 30 | super(StructurePieceType.SWAMPLAND_HUT, west, 64, north, 7, 7, 9, getRandomHorizontalDirection(random));
|
| 31 | }
|
| 32 |
|
| 33 | public SwampHutPiece(final CompoundTag tag) {
|
| 34 | super(StructurePieceType.SWAMPLAND_HUT, tag);
|
| 35 | this.spawnedWitch = tag.getBooleanOr("Witch", false);
|
| 36 | this.spawnedCat = tag.getBooleanOr("Cat", false);
|
| 37 | }
|
| 38 |
|
| 39 | @Override
|
| 40 | protected void addAdditionalSaveData(final StructurePieceSerializationContext context, final CompoundTag tag) {
|
| 41 | super.addAdditionalSaveData(context, tag);
|
| 42 | tag.putBoolean("Witch", this.spawnedWitch);
|
| 43 | tag.putBoolean("Cat", this.spawnedCat);
|
| 44 | }
|
| 45 |
|
| 46 | @Override
|
| 47 | public void postProcess(
|
| 48 | final WorldGenLevel level,
|
| 49 | final StructureManager structureManager,
|
| 50 | final ChunkGenerator generator,
|
| 51 | final RandomSource random,
|
| 52 | final BoundingBox chunkBB,
|
| 53 | final ChunkPos chunkPos,
|
| 54 | final BlockPos referencePos
|
| 55 | ) {
|
| 56 | if (this.updateAverageGroundHeight(level, chunkBB, 0)) {
|
| 57 | this.generateBox(level, chunkBB, 1, 1, 1, 5, 1, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
|
| 58 | this.generateBox(level, chunkBB, 1, 4, 2, 5, 4, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
|
| 59 | this.generateBox(level, chunkBB, 2, 1, 0, 4, 1, 0, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
|
| 60 | this.generateBox(level, chunkBB, 2, 2, 2, 3, 3, 2, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
|
| 61 | this.generateBox(level, chunkBB, 1, 2, 3, 1, 3, 6, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
|
| 62 | this.generateBox(level, chunkBB, 5, 2, 3, 5, 3, 6, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
|
| 63 | this.generateBox(level, chunkBB, 2, 2, 7, 4, 3, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
|
| 64 | this.generateBox(level, chunkBB, 1, 0, 2, 1, 3, 2, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
|
| 65 | this.generateBox(level, chunkBB, 5, 0, 2, 5, 3, 2, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
|
| 66 | this.generateBox(level, chunkBB, 1, 0, 7, 1, 3, 7, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
|
| 67 | this.generateBox(level, chunkBB, 5, 0, 7, 5, 3, 7, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
|
| 68 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState(), 2, 3, 2, chunkBB);
|
| 69 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState(), 3, 3, 7, chunkBB);
|
| 70 | this.placeBlock(level, Blocks.AIR.defaultBlockState(), 1, 3, 4, chunkBB);
|
| 71 | this.placeBlock(level, Blocks.AIR.defaultBlockState(), 5, 3, 4, chunkBB);
|
| 72 | this.placeBlock(level, Blocks.AIR.defaultBlockState(), 5, 3, 5, chunkBB);
|
| 73 | this.placeBlock(level, Blocks.POTTED_RED_MUSHROOM.defaultBlockState(), 1, 3, 5, chunkBB);
|
| 74 | this.placeBlock(level, Blocks.CRAFTING_TABLE.defaultBlockState(), 3, 2, 6, chunkBB);
|
| 75 | this.placeBlock(level, Blocks.CAULDRON.defaultBlockState(), 4, 2, 6, chunkBB);
|
| 76 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState(), 1, 2, 1, chunkBB);
|
| 77 | this.placeBlock(level, Blocks.OAK_FENCE.defaultBlockState(), 5, 2, 1, chunkBB);
|
| 78 | BlockState northStairs = Blocks.SPRUCE_STAIRS.defaultBlockState().setValue(StairBlock.FACING, Direction.NORTH);
|
| 79 | BlockState eastStairs = Blocks.SPRUCE_STAIRS.defaultBlockState().setValue(StairBlock.FACING, Direction.EAST);
|
| 80 | BlockState westStairs = Blocks.SPRUCE_STAIRS.defaultBlockState().setValue(StairBlock.FACING, Direction.WEST);
|
| 81 | BlockState southStairs = Blocks.SPRUCE_STAIRS.defaultBlockState().setValue(StairBlock.FACING, Direction.SOUTH);
|
| 82 | this.generateBox(level, chunkBB, 0, 4, 1, 6, 4, 1, northStairs, northStairs, false);
|
| 83 | this.generateBox(level, chunkBB, 0, 4, 2, 0, 4, 7, eastStairs, eastStairs, false);
|
| 84 | this.generateBox(level, chunkBB, 6, 4, 2, 6, 4, 7, westStairs, westStairs, false);
|
| 85 | this.generateBox(level, chunkBB, 0, 4, 8, 6, 4, 8, southStairs, southStairs, false);
|
| 86 | this.placeBlock(level, northStairs.setValue(StairBlock.SHAPE, StairsShape.OUTER_RIGHT), 0, 4, 1, chunkBB);
|
| 87 | this.placeBlock(level, northStairs.setValue(StairBlock.SHAPE, StairsShape.OUTER_LEFT), 6, 4, 1, chunkBB);
|
| 88 | this.placeBlock(level, southStairs.setValue(StairBlock.SHAPE, StairsShape.OUTER_LEFT), 0, 4, 8, chunkBB);
|
| 89 | this.placeBlock(level, southStairs.setValue(StairBlock.SHAPE, StairsShape.OUTER_RIGHT), 6, 4, 8, chunkBB);
|
| 90 |
|
| 91 | for (int z = 2; z <= 7; z += 5) {
|
| 92 | for (int x = 1; x <= 5; x += 4) {
|
| 93 | this.fillColumnDown(level, Blocks.OAK_LOG.defaultBlockState(), x, -1, z, chunkBB);
|
| 94 | }
|
| 95 | }
|
| 96 |
|
| 97 | if (!this.spawnedWitch) {
|
| 98 | BlockPos pos = this.getWorldPos(2, 2, 5);
|
| 99 | if (chunkBB.isInside(pos)) {
|
| 100 | this.spawnedWitch = true;
|
| 101 | Witch witch = EntityTypes.WITCH.create(level.getLevel(), EntitySpawnReason.STRUCTURE);
|
| 102 | if (witch != null) {
|
| 103 | witch.setPersistenceRequired();
|
| 104 | witch.snapTo(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0.0F, 0.0F);
|
| 105 | witch.finalizeSpawn(level, level.getCurrentDifficultyAt(pos), EntitySpawnReason.STRUCTURE, null);
|
| 106 | level.addFreshEntityWithPassengers(witch);
|
| 107 | }
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | this.spawnCat(level, chunkBB);
|
| 112 | }
|
| 113 | }
|
| 114 |
|
| 115 | private void spawnCat(final ServerLevelAccessor level, final BoundingBox chunkBB) {
|
| 116 | if (!this.spawnedCat) {
|
| 117 | BlockPos pos = this.getWorldPos(2, 2, 5);
|
| 118 | if (chunkBB.isInside(pos)) {
|
| 119 | this.spawnedCat = true;
|
| 120 | Cat cat = EntityTypes.CAT.create(level.getLevel(), EntitySpawnReason.STRUCTURE);
|
| 121 | if (cat != null) {
|
| 122 | cat.setPersistenceRequired();
|
| 123 | cat.snapTo(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0.0F, 0.0F);
|
| 124 | cat.finalizeSpawn(level, level.getCurrentDifficultyAt(pos), EntitySpawnReason.STRUCTURE, null);
|
| 125 | level.addFreshEntityWithPassengers(cat);
|
| 126 | }
|
| 127 | }
|
| 128 | }
|
| 129 | }
|
| 130 | }
|
| 131 |
|