Search in sources :

Example 1 with TileEntityBambooChest

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");
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest)

Example 2 with TileEntityBambooChest

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;
}
Also used : TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 3 with TileEntityBambooChest

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;
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILockableContainer(net.minecraft.world.ILockableContainer) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest) Nullable(javax.annotation.Nullable)

Example 4 with TileEntityBambooChest

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();
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IItemHandler(net.minecraftforge.items.IItemHandler) TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest)

Example 5 with TileEntityBambooChest

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;
}
Also used : TileEntityBambooChest(net.tropicraft.core.common.block.tileentity.TileEntityBambooChest) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

TileEntityBambooChest (net.tropicraft.core.common.block.tileentity.TileEntityBambooChest)10 BlockPos (net.minecraft.util.math.BlockPos)5 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)3 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 Block (net.minecraft.block.Block)2 EnumFacing (net.minecraft.util.EnumFacing)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 InventoryLargeChest (net.minecraft.inventory.InventoryLargeChest)1 ILockableContainer (net.minecraft.world.ILockableContainer)1 Teleporter (net.minecraft.world.Teleporter)1 World (net.minecraft.world.World)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)1