package micdoodle8.mods.galacticraft.planets.venus.world.gen.dungeon;
import micdoodle8.mods.galacticraft.planets.venus.VenusBlocks;
import micdoodle8.mods.galacticraft.planets.venus.blocks.BlockTier3TreasureChest;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraft.world.gen.structure.StructureBoundingBox;
import net.minecraft.world.gen.structure.StructureComponent;
import java.util.Random;
public class RoomTreasureVenus extends SizedPieceVenus
{
public RoomTreasureVenus()
{
}
public RoomTreasureVenus(DungeonConfigurationVenus configuration, Random rand, int blockPosX, int blockPosZ, EnumFacing entranceDir)
{
this(configuration, rand, blockPosX, blockPosZ, rand.nextInt(4) + 6, configuration.getRoomHeight(), rand.nextInt(4) + 6, entranceDir);
}
public RoomTreasureVenus(DungeonConfigurationVenus configuration, Random rand, int blockPosX, int blockPosZ, int sizeX, int sizeY, int sizeZ, EnumFacing entranceDir)
{
super(configuration, sizeX, sizeY, sizeZ, entranceDir.getOpposite());
this.coordBaseMode = EnumFacing.SOUTH;
int yPos = configuration.getYPosition();
this.boundingBox = new StructureBoundingBox(blockPosX, yPos, blockPosZ, blockPosX + this.sizeX, yPos + this.sizeY, blockPosZ + this.sizeZ);
}
@Override
public boolean addComponentParts(World worldIn, Random random, StructureBoundingBox boundingBox)
{
for (int i = 0; i <= this.sizeX; i++)
{
for (int j = 0; j <= this.sizeY; j++)
{
for (int k = 0; k <= this.sizeZ; k++)
{
if (i == 0 || i == this.sizeX || j == 0 || j == this.sizeY || k == 0 || k == this.sizeZ)
{
boolean placeBlock = true;
if (getDirection().getAxis() == EnumFacing.Axis.Z)
{
int start = (this.boundingBox.maxX - this.boundingBox.minX) / 2 - 1;
int end = (this.boundingBox.maxX - this.boundingBox.minX) / 2 + 1;
if (i > start && i <= end && j < 3 && j > 0)
{
if (getDirection() == EnumFacing.SOUTH && k == 0)
{
placeBlock = false;
}
else if (getDirection() == EnumFacing.NORTH && k == this.sizeZ)
{
placeBlock = false;
}
}
}
else
{
int start = (this.boundingBox.maxZ - this.boundingBox.minZ) / 2 - 1;
int end = (this.boundingBox.maxZ - this.boundingBox.minZ) / 2 + 1;
if (k > start && k <= end && j < 3 && j > 0)
{
if (getDirection() == EnumFacing.EAST && i == 0)
{
placeBlock = false;
}
else if (getDirection() == EnumFacing.WEST && i == this.sizeX)
{
placeBlock = false;
}
}
}
if (placeBlock)
{
DungeonConfigurationVenus venusConfig = (DungeonConfigurationVenus) this.configuration;
this.setBlockState(worldIn, j == 0 || j == this.sizeY ? venusConfig.getBrickBlockFloor() : this.configuration.getBrickBlock(), i, j, k, boundingBox);
}
else
{
this.setBlockState(worldIn, Blocks.air.getDefaultState(), i, j, k, boundingBox);
}
}
else if ((i == 1 && k == 1) || (i == 1 && k == this.sizeZ - 1) || (i == this.sizeX - 1 && k == 1) || (i == this.sizeX - 1 && k == this.sizeZ - 1))
{
this.setBlockState(worldIn, Blocks.glowstone.getDefaultState(), i, j, k, boundingBox);
}
else if (i == this.sizeX / 2 && j == 1 && k == this.sizeZ / 2)
{
this.setBlockState(worldIn, VenusBlocks.treasureChestTier3.getDefaultState().withProperty(BlockTier3TreasureChest.FACING, this.getDirection().getOpposite()), i, j, k, boundingBox);
}
else
{
this.setBlockState(worldIn, Blocks.air.getDefaultState(), i, j, k, boundingBox);
}
}
}
}
return true;
}
@Override
public PieceVenus getNextPiece(DungeonStartVenus startPiece, Random rand)
{
if (startPiece.attachedComponents.size() > 2)
{
StructureComponent component = startPiece.attachedComponents.get(startPiece.attachedComponents.size() - 3);
if (component instanceof RoomBossVenus)
{
BlockPos blockpos = new BlockPos(this.getXWithOffset(this.sizeX / 2, this.sizeZ / 2), this.getYWithOffset(1), this.getZWithOffset(this.sizeX / 2, this.sizeZ / 2));
((RoomBossVenus) component).setChestPos(new BlockPos(blockpos));
}
}
return null;
}
}