package net.minecraft.world.level.levelgen.structure;

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.monster.Witch;
import net.minecraft.core.Vec3i;
import net.minecraft.world.level.block.state.properties.StairsShape;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.levelgen.feature.StructurePieceType;
import java.util.Random;

public class SwamplandHutPiece extends ScatteredFeaturePiece {
    private boolean spawnedWitch;
    private boolean spawnedCat;
    
    public SwamplandHutPiece(final Random random, final int integer2, final int integer3) {
        super(StructurePieceType.SWAMPLAND_HUT, random, integer2, 64, integer3, 7, 7, 9);
    }
    
    public SwamplandHutPiece(final StructureManager cva, final CompoundTag le) {
        super(StructurePieceType.SWAMPLAND_HUT, le);
        this.spawnedWitch = le.getBoolean("Witch");
        this.spawnedCat = le.getBoolean("Cat");
    }
    
    @Override
    protected void addAdditionalSaveData(final CompoundTag le) {
        super.addAdditionalSaveData(le);
        le.putBoolean("Witch", this.spawnedWitch);
        le.putBoolean("Cat", this.spawnedCat);
    }
    
    @Override
    public boolean postProcess(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BoundingBox ctd, final ChunkPos bph, final BlockPos fu) {
        if (!this.updateAverageGroundHeight(bqu, ctd, 0)) {
            return false;
        }
        this.generateBox(bqu, ctd, 1, 1, 1, 5, 1, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 1, 4, 2, 5, 4, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 2, 1, 0, 4, 1, 0, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 2, 2, 2, 3, 3, 2, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 1, 2, 3, 1, 3, 6, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 5, 2, 3, 5, 3, 6, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 2, 2, 7, 4, 3, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 1, 0, 2, 1, 3, 2, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 5, 0, 2, 5, 3, 2, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 1, 0, 7, 1, 3, 7, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
        this.generateBox(bqu, ctd, 5, 0, 7, 5, 3, 7, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
        this.placeBlock(bqu, Blocks.OAK_FENCE.defaultBlockState(), 2, 3, 2, ctd);
        this.placeBlock(bqu, Blocks.OAK_FENCE.defaultBlockState(), 3, 3, 7, ctd);
        this.placeBlock(bqu, Blocks.AIR.defaultBlockState(), 1, 3, 4, ctd);
        this.placeBlock(bqu, Blocks.AIR.defaultBlockState(), 5, 3, 4, ctd);
        this.placeBlock(bqu, Blocks.AIR.defaultBlockState(), 5, 3, 5, ctd);
        this.placeBlock(bqu, Blocks.POTTED_RED_MUSHROOM.defaultBlockState(), 1, 3, 5, ctd);
        this.placeBlock(bqu, Blocks.CRAFTING_TABLE.defaultBlockState(), 3, 2, 6, ctd);
        this.placeBlock(bqu, Blocks.CAULDRON.defaultBlockState(), 4, 2, 6, ctd);
        this.placeBlock(bqu, Blocks.OAK_FENCE.defaultBlockState(), 1, 2, 1, ctd);
        this.placeBlock(bqu, Blocks.OAK_FENCE.defaultBlockState(), 5, 2, 1, ctd);
        final BlockState cfj9 = ((StateHolder<O, BlockState>)Blocks.SPRUCE_STAIRS.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)StairBlock.FACING, Direction.NORTH);
        final BlockState cfj10 = ((StateHolder<O, BlockState>)Blocks.SPRUCE_STAIRS.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)StairBlock.FACING, Direction.EAST);
        final BlockState cfj11 = ((StateHolder<O, BlockState>)Blocks.SPRUCE_STAIRS.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)StairBlock.FACING, Direction.WEST);
        final BlockState cfj12 = ((StateHolder<O, BlockState>)Blocks.SPRUCE_STAIRS.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)StairBlock.FACING, Direction.SOUTH);
        this.generateBox(bqu, ctd, 0, 4, 1, 6, 4, 1, cfj9, cfj9, false);
        this.generateBox(bqu, ctd, 0, 4, 2, 0, 4, 7, cfj10, cfj10, false);
        this.generateBox(bqu, ctd, 6, 4, 2, 6, 4, 7, cfj11, cfj11, false);
        this.generateBox(bqu, ctd, 0, 4, 8, 6, 4, 8, cfj12, cfj12, false);
        this.placeBlock(bqu, ((StateHolder<O, BlockState>)cfj9).<StairsShape, StairsShape>setValue(StairBlock.SHAPE, StairsShape.OUTER_RIGHT), 0, 4, 1, ctd);
        this.placeBlock(bqu, ((StateHolder<O, BlockState>)cfj9).<StairsShape, StairsShape>setValue(StairBlock.SHAPE, StairsShape.OUTER_LEFT), 6, 4, 1, ctd);
        this.placeBlock(bqu, ((StateHolder<O, BlockState>)cfj12).<StairsShape, StairsShape>setValue(StairBlock.SHAPE, StairsShape.OUTER_LEFT), 0, 4, 8, ctd);
        this.placeBlock(bqu, ((StateHolder<O, BlockState>)cfj12).<StairsShape, StairsShape>setValue(StairBlock.SHAPE, StairsShape.OUTER_RIGHT), 6, 4, 8, ctd);
        for (int integer13 = 2; integer13 <= 7; integer13 += 5) {
            for (int integer14 = 1; integer14 <= 5; integer14 += 4) {
                this.fillColumnDown(bqu, Blocks.OAK_LOG.defaultBlockState(), integer14, -1, integer13, ctd);
            }
        }
        if (!this.spawnedWitch) {
            final int integer13 = this.getWorldX(2, 5);
            final int integer14 = this.getWorldY(2);
            final int integer15 = this.getWorldZ(2, 5);
            if (ctd.isInside(new BlockPos(integer13, integer14, integer15))) {
                this.spawnedWitch = true;
                final Witch bcr16 = EntityType.WITCH.create(bqu.getLevel());
                bcr16.setPersistenceRequired();
                bcr16.moveTo(integer13 + 0.5, integer14, integer15 + 0.5, 0.0f, 0.0f);
                bcr16.finalizeSpawn(bqu, bqu.getCurrentDifficultyAt(new BlockPos(integer13, integer14, integer15)), MobSpawnType.STRUCTURE, null, null);
                bqu.addFreshEntity(bcr16);
            }
        }
        this.spawnCat(bqu, ctd);
        return true;
    }
    
    private void spawnCat(final LevelAccessor bqc, final BoundingBox ctd) {
        if (!this.spawnedCat) {
            final int integer4 = this.getWorldX(2, 5);
            final int integer5 = this.getWorldY(2);
            final int integer6 = this.getWorldZ(2, 5);
            if (ctd.isInside(new BlockPos(integer4, integer5, integer6))) {
                this.spawnedCat = true;
                final Cat aym7 = EntityType.CAT.create(bqc.getLevel());
                aym7.setPersistenceRequired();
                aym7.moveTo(integer4 + 0.5, integer5, integer6 + 0.5, 0.0f, 0.0f);
                aym7.finalizeSpawn(bqc, bqc.getCurrentDifficultyAt(new BlockPos(integer4, integer5, integer6)), MobSpawnType.STRUCTURE, null, null);
                bqc.addFreshEntity(aym7);
            }
        }
    }
}
