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

import net.minecraft.world.level.block.state.AbstractStateHolder;
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.core.BlockPos;
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.ChunkPos;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
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 cmo, final CompoundTag jt) {
        super(StructurePieceType.SWAMPLAND_HUT, jt);
        this.spawnedWitch = jt.getBoolean("Witch");
        this.spawnedCat = jt.getBoolean("Cat");
    }
    
    @Override
    protected void addAdditionalSaveData(final CompoundTag jt) {
        super.addAdditionalSaveData(jt);
        jt.putBoolean("Witch", this.spawnedWitch);
        jt.putBoolean("Cat", this.spawnedCat);
    }
    
    @Override
    public boolean postProcess(final LevelAccessor bjx, final ChunkGenerator<?> caa, final Random random, final BoundingBox clb, final ChunkPos bjh) {
        if (!this.updateAverageGroundHeight(bjx, clb, 0)) {
            return false;
        }
        this.generateBox(bjx, clb, 1, 1, 1, 5, 1, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bjx, clb, 1, 4, 2, 5, 4, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bjx, clb, 2, 1, 0, 4, 1, 0, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bjx, clb, 2, 2, 2, 3, 3, 2, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bjx, clb, 1, 2, 3, 1, 3, 6, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bjx, clb, 5, 2, 3, 5, 3, 6, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bjx, clb, 2, 2, 7, 4, 3, 7, Blocks.SPRUCE_PLANKS.defaultBlockState(), Blocks.SPRUCE_PLANKS.defaultBlockState(), false);
        this.generateBox(bjx, clb, 1, 0, 2, 1, 3, 2, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
        this.generateBox(bjx, clb, 5, 0, 2, 5, 3, 2, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
        this.generateBox(bjx, clb, 1, 0, 7, 1, 3, 7, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
        this.generateBox(bjx, clb, 5, 0, 7, 5, 3, 7, Blocks.OAK_LOG.defaultBlockState(), Blocks.OAK_LOG.defaultBlockState(), false);
        this.placeBlock(bjx, Blocks.OAK_FENCE.defaultBlockState(), 2, 3, 2, clb);
        this.placeBlock(bjx, Blocks.OAK_FENCE.defaultBlockState(), 3, 3, 7, clb);
        this.placeBlock(bjx, Blocks.AIR.defaultBlockState(), 1, 3, 4, clb);
        this.placeBlock(bjx, Blocks.AIR.defaultBlockState(), 5, 3, 4, clb);
        this.placeBlock(bjx, Blocks.AIR.defaultBlockState(), 5, 3, 5, clb);
        this.placeBlock(bjx, Blocks.POTTED_RED_MUSHROOM.defaultBlockState(), 1, 3, 5, clb);
        this.placeBlock(bjx, Blocks.CRAFTING_TABLE.defaultBlockState(), 3, 2, 6, clb);
        this.placeBlock(bjx, Blocks.CAULDRON.defaultBlockState(), 4, 2, 6, clb);
        this.placeBlock(bjx, Blocks.OAK_FENCE.defaultBlockState(), 1, 2, 1, clb);
        this.placeBlock(bjx, Blocks.OAK_FENCE.defaultBlockState(), 5, 2, 1, clb);
        final BlockState byj7 = ((AbstractStateHolder<O, BlockState>)Blocks.SPRUCE_STAIRS.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)StairBlock.FACING, Direction.NORTH);
        final BlockState byj8 = ((AbstractStateHolder<O, BlockState>)Blocks.SPRUCE_STAIRS.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)StairBlock.FACING, Direction.EAST);
        final BlockState byj9 = ((AbstractStateHolder<O, BlockState>)Blocks.SPRUCE_STAIRS.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)StairBlock.FACING, Direction.WEST);
        final BlockState byj10 = ((AbstractStateHolder<O, BlockState>)Blocks.SPRUCE_STAIRS.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)StairBlock.FACING, Direction.SOUTH);
        this.generateBox(bjx, clb, 0, 4, 1, 6, 4, 1, byj7, byj7, false);
        this.generateBox(bjx, clb, 0, 4, 2, 0, 4, 7, byj8, byj8, false);
        this.generateBox(bjx, clb, 6, 4, 2, 6, 4, 7, byj9, byj9, false);
        this.generateBox(bjx, clb, 0, 4, 8, 6, 4, 8, byj10, byj10, false);
        this.placeBlock(bjx, ((AbstractStateHolder<O, BlockState>)byj7).<StairsShape, StairsShape>setValue(StairBlock.SHAPE, StairsShape.OUTER_RIGHT), 0, 4, 1, clb);
        this.placeBlock(bjx, ((AbstractStateHolder<O, BlockState>)byj7).<StairsShape, StairsShape>setValue(StairBlock.SHAPE, StairsShape.OUTER_LEFT), 6, 4, 1, clb);
        this.placeBlock(bjx, ((AbstractStateHolder<O, BlockState>)byj10).<StairsShape, StairsShape>setValue(StairBlock.SHAPE, StairsShape.OUTER_LEFT), 0, 4, 8, clb);
        this.placeBlock(bjx, ((AbstractStateHolder<O, BlockState>)byj10).<StairsShape, StairsShape>setValue(StairBlock.SHAPE, StairsShape.OUTER_RIGHT), 6, 4, 8, clb);
        for (int integer11 = 2; integer11 <= 7; integer11 += 5) {
            for (int integer12 = 1; integer12 <= 5; integer12 += 4) {
                this.fillColumnDown(bjx, Blocks.OAK_LOG.defaultBlockState(), integer12, -1, integer11, clb);
            }
        }
        if (!this.spawnedWitch) {
            final int integer11 = this.getWorldX(2, 5);
            final int integer12 = this.getWorldY(2);
            final int integer13 = this.getWorldZ(2, 5);
            if (clb.isInside(new BlockPos(integer11, integer12, integer13))) {
                this.spawnedWitch = true;
                final Witch axn14 = EntityType.WITCH.create(bjx.getLevel());
                axn14.setPersistenceRequired();
                axn14.moveTo(integer11 + 0.5, integer12, integer13 + 0.5, 0.0f, 0.0f);
                axn14.finalizeSpawn(bjx, bjx.getCurrentDifficultyAt(new BlockPos(integer11, integer12, integer13)), MobSpawnType.STRUCTURE, null, null);
                bjx.addFreshEntity(axn14);
            }
        }
        this.spawnCat(bjx, clb);
        return true;
    }
    
    private void spawnCat(final LevelAccessor bjx, final BoundingBox clb) {
        if (!this.spawnedCat) {
            final int integer4 = this.getWorldX(2, 5);
            final int integer5 = this.getWorldY(2);
            final int integer6 = this.getWorldZ(2, 5);
            if (clb.isInside(new BlockPos(integer4, integer5, integer6))) {
                this.spawnedCat = true;
                final Cat ate7 = EntityType.CAT.create(bjx.getLevel());
                ate7.setPersistenceRequired();
                ate7.moveTo(integer4 + 0.5, integer5, integer6 + 0.5, 0.0f, 0.0f);
                ate7.finalizeSpawn(bjx, bjx.getCurrentDifficultyAt(new BlockPos(integer4, integer5, integer6)), MobSpawnType.STRUCTURE, null, null);
                bjx.addFreshEntity(ate7);
            }
        }
    }
}
