use of stevekung.mods.moreplanets.utils.tileentity.TileEntityChestMP in project MorePlanets by SteveKunG.
the class DoubleChestItemHandlerMP method get.
@Nullable
public static DoubleChestItemHandlerMP get(TileEntityChestMP chest) {
World world = chest.getWorld();
BlockPos pos = chest.getPos();
if (world == null || pos == null || !world.isBlockLoaded(pos)) {
// Still loading
return null;
}
Block blockType = chest.getBlockType();
EnumFacing[] horizontals = EnumFacing.HORIZONTALS;
for (// Use reverse order so we can return early
int i = horizontals.length - 1; // Use reverse order so we can return early
i >= 0; // Use reverse order so we can return early
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 TileEntityChestMP) {
TileEntityChestMP otherChest = (TileEntityChestMP) otherTE;
return new DoubleChestItemHandlerMP(chest, otherChest, enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH);
}
}
}
// All alone
return NO_ADJACENT_CHESTS_INSTANCE;
}
use of stevekung.mods.moreplanets.utils.tileentity.TileEntityChestMP 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, 2);
} else {
world.setBlockState(blockpos1, this.cobblestone, 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<EnumFacing> iterator = EnumFacing.Plane.HORIZONTAL.iterator();
while (iterator.hasNext()) {
EnumFacing enumfacing = iterator.next();
if (world.getBlockState(blockpos2.offset(enumfacing)).getMaterial().isSolid()) {
++k2;
}
}
if (k2 == 1) {
world.setBlockState(blockpos2, ((BlockChestMP) this.chest.getBlock()).correctFacing(world, blockpos2, this.chest), 2);
TileEntity tileentity1 = world.getTileEntity(blockpos2);
if (tileentity1 instanceof TileEntityChestMP) {
((TileEntityChestMP) tileentity1).setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, rand.nextLong());
}
break label100;
}
}
++i2;
continue;
}
}
++l1;
break;
}
}
world.setBlockState(pos, Blocks.MOB_SPAWNER.getDefaultState(), 2);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityMobSpawner) {
TileEntityMobSpawner spawner = (TileEntityMobSpawner) tile;
MobSpawnerBaseLogic logic = spawner.getSpawnerBaseLogic();
logic.setEntityId(EntityList.getKey(this.pickMobSpawner(rand)));
try {
Class<?> clazz = logic.getClass();
Method method = clazz.getMethod("getEntityId");
method.setAccessible(true);
LoggerMP.debug("Generate {} spawner at {} {} {}", method.invoke(logic).toString(), pos.getX(), pos.getY(), pos.getZ());
} catch (Exception e) {
}
} else {
LoggerMP.error("Failed to fetch mob spawner entity at {} {} {}", pos.getX(), pos.getY(), pos.getZ());
}
return true;
} else {
return false;
}
}
use of stevekung.mods.moreplanets.utils.tileentity.TileEntityChestMP in project MorePlanets by SteveKunG.
the class StructureNibiruIglooPieces method addComponentParts.
@Override
public boolean addComponentParts(World world, Random rand, StructureBoundingBox structureBoundingBox) {
if (!this.offsetToAverageGroundLevel(world, structureBoundingBox, -1)) {
return false;
} else {
StructureBoundingBox box = this.getBoundingBox();
BlockPos pos = new BlockPos(box.minX, box.minY, box.minZ);
Rotation[] arotation = CachedEnum.rotationValues;
MinecraftServer server = world.getMinecraftServer();
TemplateManager manager = world.getSaveHandler().getStructureTemplateManager();
PlacementSettings settings = new PlacementSettings().setRotation(arotation[rand.nextInt(arotation.length)]).setReplacedBlock(Blocks.STRUCTURE_VOID).setBoundingBox(box);
Template template = manager.getTemplate(server, IGLOO_TOP_ID);
template.addBlocksToWorldChunk(world, pos, settings);
if (rand.nextDouble() < 0.5D) {
Template template1 = manager.getTemplate(server, IGLOO_MIDDLE_ID);
Template template2 = manager.getTemplate(server, IGLOO_BOTTOM_ID);
int i = rand.nextInt(8) + 4;
for (int j = 0; j < i; ++j) {
BlockPos blockpos1 = template.calculateConnectedPos(settings, new BlockPos(3, -1 - j * 3, 5), settings, new BlockPos(1, 2, 1));
template1.addBlocksToWorldChunk(world, pos.add(blockpos1), settings);
}
BlockPos blockpos4 = pos.add(template.calculateConnectedPos(settings, new BlockPos(3, -1 - i * 3, 5), settings, new BlockPos(3, 5, 7)));
template2.addBlocksToWorldChunk(world, blockpos4, settings);
Map<BlockPos, String> map = template2.getDataBlocks(blockpos4, settings);
for (Entry<BlockPos, String> entry : map.entrySet()) {
if ("chest".equals(entry.getValue())) {
BlockPos blockpos2 = entry.getKey();
world.setBlockState(blockpos2, Blocks.AIR.getDefaultState(), 3);
TileEntity tile = world.getTileEntity(blockpos2.down());
if (tile instanceof TileEntityChestMP) {
((TileEntityChestMP) tile).setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, rand.nextLong());
}
}
}
} else {
BlockPos blockpos3 = Template.transformedBlockPos(settings, new BlockPos(3, 0, 5));
world.setBlockState(pos.add(blockpos3), MPBlocks.INFECTED_SNOW.getDefaultState(), 3);
}
return true;
}
}
use of stevekung.mods.moreplanets.utils.tileentity.TileEntityChestMP in project MorePlanets by SteveKunG.
the class DoubleChestItemHandlerMP method setStackInSlot.
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack itemStack) {
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityChestMP chest = this.getChest(accessingUpperChest);
if (chest != null) {
IItemHandler singleHandler = chest.getSingleChestHandler();
if (singleHandler instanceof IItemHandlerModifiable) {
((IItemHandlerModifiable) singleHandler).setStackInSlot(targetSlot, itemStack);
}
}
chest = this.getChest(!accessingUpperChest);
if (chest != null) {
chest.markDirty();
}
}
use of stevekung.mods.moreplanets.utils.tileentity.TileEntityChestMP in project MorePlanets by SteveKunG.
the class DoubleChestItemHandlerMP method extractItem.
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate) {
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityChestMP chest = this.getChest(accessingUpperChest);
if (chest == null) {
return ItemStack.EMPTY;
}
ItemStack ret = chest.getSingleChestHandler().extractItem(targetSlot, amount, simulate);
if (!ret.isEmpty() && !simulate) {
chest = this.getChest(!accessingUpperChest);
if (chest != null) {
chest.markDirty();
}
}
return ret;
}
Aggregations