use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.
the class RoomChestMP method addComponentParts.
@Override
public boolean addComponentParts(World world, Random rand, StructureBoundingBox boundingBox) {
if (super.addComponentParts(world, rand, boundingBox)) {
int chestX = this.sizeX / 2;
int chestY = 1;
int chestZ = this.sizeZ / 2;
this.setBlockState(world, this.configuration.getAncientChestBlock().withProperty(BlockStateHelper.FACING_HORIZON, this.getDirection().getOpposite()), chestX, chestY, chestZ, boundingBox);
BlockPos blockpos = new BlockPos(this.getXWithOffset(chestX, chestZ), this.getYWithOffset(chestY), this.getZWithOffset(chestX, chestZ));
TileEntityAncientChestMP chest = (TileEntityAncientChestMP) world.getTileEntity(blockpos);
if (chest != null) {
chest.setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, rand.nextLong());
}
return true;
}
return false;
}
use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.
the class WorldGenSpaceDungeons method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
int i = rand.nextInt(2) + 2;
int j = -i - 1;
int k = i + 1;
int l = rand.nextInt(2) + 2;
int i1 = -l - 1;
int j1 = l + 1;
int k1 = 0;
int l1;
int i2;
int j2;
BlockPos blockpos1;
for (l1 = j; l1 <= k; ++l1) {
for (i2 = -1; i2 <= 4; ++i2) {
for (j2 = i1; j2 <= j1; ++j2) {
blockpos1 = pos.add(l1, i2, j2);
Material material = world.getBlockState(blockpos1).getMaterial();
boolean flag3 = material.isSolid();
if (i2 == -1 && !flag3) {
return false;
}
if (i2 == 4 && !flag3) {
return false;
}
if ((l1 == j || l1 == k || j2 == i1 || j2 == j1) && i2 == 0 && world.isAirBlock(blockpos1) && world.isAirBlock(blockpos1.up())) {
++k1;
}
}
}
}
if (k1 >= 1 && k1 <= 5) {
for (l1 = j; l1 <= k; ++l1) {
for (i2 = 3; i2 >= -1; --i2) {
for (j2 = i1; j2 <= j1; ++j2) {
blockpos1 = pos.add(l1, i2, j2);
if (l1 != j && i2 != -1 && j2 != i1 && l1 != k && i2 != 4 && j2 != j1) {
if (world.getBlockState(blockpos1).getBlock() != this.chest) {
world.setBlockToAir(blockpos1);
}
} else if (blockpos1.getY() >= 0 && !world.getBlockState(blockpos1.down()).getMaterial().isSolid()) {
world.setBlockToAir(blockpos1);
} else if (world.getBlockState(blockpos1).getMaterial().isSolid() && world.getBlockState(blockpos1).getBlock() != this.chest) {
if (i2 == -1 && rand.nextInt(4) != 0) {
world.setBlockState(blockpos1, this.moss.getStateFromMeta(this.mossMeta), 2);
} else {
world.setBlockState(blockpos1, this.cobblestone.getStateFromMeta(this.cobbleMeta), 2);
}
}
}
}
}
l1 = 0;
while (l1 < 2) {
i2 = 0;
while (true) {
if (i2 < 3) {
label100: {
j2 = pos.getX() + rand.nextInt(i * 2 + 1) - i;
int l2 = pos.getY();
int i3 = pos.getZ() + rand.nextInt(l * 2 + 1) - l;
BlockPos blockpos2 = new BlockPos(j2, l2, i3);
if (world.isAirBlock(blockpos2)) {
int k2 = 0;
Iterator iterator = EnumFacing.Plane.HORIZONTAL.iterator();
while (iterator.hasNext()) {
EnumFacing enumfacing = (EnumFacing) iterator.next();
if (world.getBlockState(blockpos2.offset(enumfacing)).getMaterial().isSolid()) {
++k2;
}
}
if (k2 == 1) {
world.setBlockState(blockpos2, ((BlockAncientChestMP) this.chest).correctFacing(world, blockpos2, this.chest.getDefaultState()), 2);
TileEntity tileentity1 = world.getTileEntity(blockpos2);
if (tileentity1 instanceof TileEntityAncientChestMP) {
((TileEntityAncientChestMP) tileentity1).setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, rand.nextLong());
}
break label100;
}
}
++i2;
continue;
}
}
++l1;
break;
}
}
world.setBlockState(pos, Blocks.MOB_SPAWNER.getDefaultState(), 2);
TileEntity tileentity = world.getTileEntity(pos);
if (tileentity instanceof TileEntityMobSpawner) {
((TileEntityMobSpawner) tileentity).getSpawnerBaseLogic().setEntityId(this.pickMobSpawner(rand));
} else {
MPLog.error("Failed to fetch mob spawner entity at x:{} y:{} z:{}", pos.getX(), pos.getY(), pos.getZ());
}
MPLog.debug("Generate {} spawner at: x:{} y:{} z:{}", ((TileEntityMobSpawner) tileentity).getSpawnerBaseLogic().getEntityId().toString(), pos.getX(), pos.getY(), pos.getZ());
return true;
} else {
return false;
}
}
use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.
the class DoubleAncientChestItemHandlerMP method get.
public static DoubleAncientChestItemHandlerMP get(TileEntityAncientChestMP chest) {
World world = chest.getWorld();
BlockPos pos = chest.getPos();
if (world == null || pos == null || !world.isBlockLoaded(pos)) {
return null;
}
Block blockType = chest.getBlockType();
EnumFacing[] horizontals = EnumFacing.HORIZONTALS;
for (int i = horizontals.length - 1; i >= 0; i--) {
EnumFacing enumfacing = horizontals[i];
BlockPos blockpos = pos.offset(enumfacing);
Block block = world.getBlockState(blockpos).getBlock();
if (block == blockType) {
TileEntity otherTE = world.getTileEntity(blockpos);
if (otherTE instanceof TileEntityAncientChestMP) {
TileEntityAncientChestMP otherChest = (TileEntityAncientChestMP) otherTE;
return new DoubleAncientChestItemHandlerMP(chest, otherChest, enumfacing != net.minecraft.util.EnumFacing.WEST && enumfacing != net.minecraft.util.EnumFacing.NORTH);
}
}
}
return NO_ADJACENT_CHESTS_INSTANCE;
}
use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.
the class DoubleAncientChestItemHandlerMP method getStackInSlot.
@Override
public ItemStack getStackInSlot(int slot) {
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityAncientChestMP chest = this.getChest(accessingUpperChest);
return chest != null ? chest.getStackInSlot(targetSlot) : ItemStack.EMPTY;
}
use of stevekung.mods.moreplanets.util.tileentity.TileEntityAncientChestMP in project MorePlanets by SteveKunG.
the class DoubleAncientChestItemHandlerMP method equals.
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || this.getClass() != o.getClass()) {
return false;
}
DoubleAncientChestItemHandlerMP that = (DoubleAncientChestItemHandlerMP) o;
if (this.hashCode != that.hashCode) {
return false;
}
TileEntityAncientChestMP otherChest = this.getOtherChest();
if (this.mainChestIsUpper == that.mainChestIsUpper) {
return Objects.equal(this.mainChest, that.mainChest) && Objects.equal(otherChest, that.getOtherChest());
} else {
return Objects.equal(this.mainChest, that.getOtherChest()) && Objects.equal(otherChest, that.mainChest);
}
}
Aggregations