Search in sources :

Example 21 with IItemHandler

use of net.minecraftforge.items.IItemHandler in project BetterWithAddons by DaedalusGame.

the class TileEntityChute method attemptToEjectStackFromInv.

private void attemptToEjectStackFromInv(boolean powered) {
    int stackIndex = InventoryUtil.getFirstOccupiedStackInRange(inventory, 0, 17);
    if (stackIndex > -1 && stackIndex < 18) {
        ItemStack invStack = inventory.getStackInSlot(stackIndex);
        int ejectStackSize = 1;
        ItemStack ejectStack = new ItemStack(invStack.getItem(), ejectStackSize, invStack.getItemDamage());
        InventoryUtil.copyTags(ejectStack, invStack);
        BlockPos ejectpos = pos.offset(ejectDir);
        boolean ejectIntoWorld = false;
        if (!getOutputBlocked(ejectDir))
            if (this.getWorld().isAirBlock(ejectpos))
                ejectIntoWorld = true;
            else if (this.getWorld().getBlockState(ejectpos).getBlock().isReplaceable(this.getWorld(), ejectpos))
                ejectIntoWorld = true;
            else {
                Block block = this.getWorld().getBlockState(ejectpos).getBlock();
                if (block == null || (!world.isSideSolid(ejectpos, ejectDir.getOpposite())) && (this.getWorld().getTileEntity(ejectpos) == null || !(this.getWorld().getTileEntity(ejectpos).hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, ejectDir.getOpposite()))))
                    ejectIntoWorld = true;
                else if (powered) {
                    TileEntity tile = this.getWorld().getTileEntity(ejectpos);
                    if (tile != null && tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, ejectDir.getOpposite())) {
                        IItemHandler below = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, ejectDir.getOpposite());
                        ItemStack leftover;
                        for (int slot = 0; slot < below.getSlots(); slot++) {
                            leftover = below.insertItem(slot, ejectStack, false);
                            if (leftover.isEmpty()) {
                                inventory.extractItem(stackIndex, ejectStackSize, false);
                                break;
                            }
                        }
                    } else
                        setOutputBlocked(ejectDir, true);
                } else {
                    setOutputBlocked(ejectDir, true);
                }
            }
        if (ejectIntoWorld) {
            ejectStack(ejectStack, ejectDir);
            inventory.extractItem(stackIndex, ejectStackSize, false);
        }
        rotateToNextOutput(powered, world.rand);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 22 with IItemHandler

use of net.minecraftforge.items.IItemHandler in project Almura by AlmuraDev.

the class CapabilityDualItemHandlerGuiHandler method getServerGuiElement.

@Nullable
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
    final TileEntity te = world.getTileEntity(new BlockPos(x, y, z));
    if (te == null || !(te instanceof MultiSlotTileEntity)) {
        return null;
    }
    final IItemHandler teItemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    if (teItemHandler == null) {
        return null;
    }
    final IItemHandler playerItemHandler = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    if (playerItemHandler == null) {
        return null;
    }
    return new DualItemHandlerContainer(teItemHandler, playerItemHandler);
}
Also used : MultiSlotTileEntity(com.almuradev.almura.shared.tileentity.MultiSlotTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) BlockPos(net.minecraft.util.math.BlockPos) DualItemHandlerContainer(com.almuradev.almura.shared.inventory.DualItemHandlerContainer) MultiSlotTileEntity(com.almuradev.almura.shared.tileentity.MultiSlotTileEntity) Nullable(javax.annotation.Nullable)

Aggregations

IItemHandler (net.minecraftforge.items.IItemHandler)22 ItemStack (net.minecraft.item.ItemStack)17 TileEntity (net.minecraft.tileentity.TileEntity)7 BlockPos (net.minecraft.util.math.BlockPos)4 IBlockState (net.minecraft.block.state.IBlockState)3 MultiSlotTileEntity (com.almuradev.almura.shared.tileentity.MultiSlotTileEntity)2 ISoulbound (convenientadditions.api.item.ISoulbound)2 Nullable (javax.annotation.Nullable)2 ItemDoll (mdc.voodoocraft.items.ItemDoll)2 TileDollPedestal (mdc.voodoocraft.tile.TileDollPedestal)2 TileEntityTeleporter (net.dyeo.teleporter.tileentity.TileEntityTeleporter)2 Block (net.minecraft.block.Block)2 EntityItem (net.minecraft.entity.item.EntityItem)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ISpecialMeasuringBehavior (betterwithaddons.util.ISpecialMeasuringBehavior)1 TileEntityFilteredHopper (betterwithmods.common.blocks.mechanical.tile.TileEntityFilteredHopper)1 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1 IEInventoryHandler (blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler)1 IIEInventory (blusunrize.immersiveengineering.common.util.inventory.IIEInventory)1 DualItemHandlerContainer (com.almuradev.almura.shared.inventory.DualItemHandlerContainer)1