use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.
the class TeleporterTropics method buildTeleporterAt.
public void buildTeleporterAt(int x, int y, int z, Entity entity) {
System.out.println("start buildTeleporterAt");
y = y < 9 ? 9 : y;
for (int yOffset = 4; yOffset >= -7; yOffset--) {
for (int zOffset = -2; zOffset <= 2; zOffset++) {
for (int xOffset = -2; xOffset <= 2; xOffset++) {
int blockX = x + xOffset;
int blockY = y + yOffset;
int blockZ = z + zOffset;
BlockPos pos = new BlockPos(blockX, blockY, blockZ);
if (yOffset == -7) {
// Set bottom of portal to be solid
world.setBlockState(pos, PORTAL_WALL_BLOCK.getDefaultState());
} else if (yOffset > 0) {
// Set 4 blocks above portal to air
world.setBlockToAir(pos);
} else {
boolean isWall = xOffset == -2 || xOffset == 2 || zOffset == -2 || zOffset == 2;
if (isWall) {
// Set walls around portal
world.setBlockState(pos, PORTAL_WALL_BLOCK.getDefaultState());
} else {
// Set inside of portal
boolean isTeleportBlock = yOffset <= -5;
if (isTeleportBlock) {
world.setBlockState(pos, TELEPORTER_BLOCK.getDefaultState());
} else {
world.setBlockState(pos, PORTAL_BLOCK.getDefaultState());
}
}
}
boolean isCorner = (xOffset == -2 || xOffset == 2) && (zOffset == -2 || zOffset == 2);
if (yOffset == 0 && isCorner) {
world.setBlockState(pos.up(), BlockRegistry.tikiTorch.getDefaultState().withProperty(BlockTikiTorch.SECTION, BlockTikiTorch.TorchSection.LOWER), 3);
world.setBlockState(pos.up(2), BlockRegistry.tikiTorch.getDefaultState().withProperty(BlockTikiTorch.SECTION, BlockTikiTorch.TorchSection.MIDDLE), 3);
world.setBlockState(pos.up(3), BlockRegistry.tikiTorch.getDefaultState().withProperty(BlockTikiTorch.SECTION, BlockTikiTorch.TorchSection.UPPER), 3);
}
}
}
}
// because getWorldInfo() may not be set/correct yet
if (world.provider instanceof WorldProviderTropicraft) {
BlockPos chestPos = new BlockPos(x + 2, y + 1, z);
world.setBlockState(chestPos, BlockRegistry.bambooChest.getDefaultState(), 3);
TileEntityBambooChest tile = (TileEntityBambooChest) world.getTileEntity(chestPos);
if (tile != null) {
tile.setIsUnbreakable(true);
}
}
System.out.println("end buildTeleporterAt");
}
use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.
the class BambooDoubleChestItemHandler method insertItem.
@Override
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityBambooChest chest = getChest(accessingUpperChest);
if (chest == null)
return stack;
int starting = stack.getCount();
ItemStack ret = chest.getSingleChestHandler().insertItem(targetSlot, stack, simulate);
if (ret.getCount() != starting && !simulate) {
chest = getChest(!accessingUpperChest);
if (chest != null)
chest.markDirty();
}
return ret;
}
use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.
the class BlockBambooChest method getContainer.
/**
* Gets the chest inventory at the given location, returning null if there is no chest at that location or
* optionally if the chest is blocked. Handles large chests.
*
* @param worldIn The world
* @param pos The position to check
* @param allowBlocking If false, then if the chest is blocked then <code>null</code> will be returned. If true,
* ignores blocking for the chest at the given position (but, due to <a href="https://bugs.mojang.com/browse/MC-
* 99321">a bug</a>, still checks if the neighbor is blocked).
*/
@Nullable
@Override
public ILockableContainer getContainer(World worldIn, BlockPos pos, boolean allowBlocking) {
TileEntity tileentity = worldIn.getTileEntity(pos);
if (!(tileentity instanceof TileEntityBambooChest)) {
return null;
} else {
ILockableContainer ilockablecontainer = (TileEntityBambooChest) tileentity;
if (!allowBlocking && this.isBlocked(worldIn, pos)) {
return null;
} else {
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL) {
BlockPos blockpos = pos.offset(enumfacing);
Block block = worldIn.getBlockState(blockpos).getBlock();
if (block == this) {
if (this.isBlocked(worldIn, blockpos)) {
return null;
}
TileEntity tileentity1 = worldIn.getTileEntity(blockpos);
if (tileentity1 instanceof TileEntityBambooChest) {
if (enumfacing != EnumFacing.WEST && enumfacing != EnumFacing.NORTH) {
ilockablecontainer = new InventoryLargeChest("container.chestDouble", ilockablecontainer, (TileEntityBambooChest) tileentity1);
} else {
ilockablecontainer = new InventoryLargeChest("container.chestDouble", (TileEntityBambooChest) tileentity1, ilockablecontainer);
}
}
}
}
return ilockablecontainer;
}
}
}
use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.
the class BambooDoubleChestItemHandler method setStackInSlot.
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityBambooChest chest = getChest(accessingUpperChest);
if (chest != null) {
IItemHandler singleHandler = chest.getSingleChestHandler();
if (singleHandler instanceof IItemHandlerModifiable) {
((IItemHandlerModifiable) singleHandler).setStackInSlot(targetSlot, stack);
}
}
chest = getChest(!accessingUpperChest);
if (chest != null)
chest.markDirty();
}
use of net.tropicraft.core.common.block.tileentity.TileEntityBambooChest in project Tropicraft by Tropicraft.
the class BambooDoubleChestItemHandler method extractItem.
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate) {
boolean accessingUpperChest = slot < 27;
int targetSlot = accessingUpperChest ? slot : slot - 27;
TileEntityBambooChest chest = getChest(accessingUpperChest);
if (chest == null)
return ItemStack.EMPTY;
ItemStack ret = chest.getSingleChestHandler().extractItem(targetSlot, amount, simulate);
if (!ret.isEmpty() && !simulate) {
chest = getChest(!accessingUpperChest);
if (chest != null)
chest.markDirty();
}
return ret;
}
Aggregations