Search in sources :

Example 1 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project minecolonies by Minecolonies.

the class AbstractCombinedItemHandler method deserializeNBT.

@SuppressWarnings({ RAWTYPES, UNCHECKED })
@Override
public void deserializeNBT(final NBTTagCompound nbt) {
    final NBTTagList handlerList = nbt.getTagList(NBT_KEY_NAME, Constants.NBT.TAG_COMPOUND);
    final NBTTagList indexList = nbt.getTagList(NBT_KEY_HANDLERS_INDEXLIST, Constants.NBT.TAG_INT);
    if (handlerList.tagCount() == handlers.length) {
        for (int i = 0; i < handlerList.tagCount(); i++) {
            final NBTTagCompound handlerCompound = handlerList.getCompoundTagAt(i);
            final IItemHandlerModifiable modifiable = handlers[indexList.getIntAt(i)];
            if (modifiable instanceof INBTSerializable) {
                final INBTSerializable serializable = (INBTSerializable) modifiable;
                serializable.deserializeNBT(handlerCompound);
            }
        }
    }
    setName(nbt.hasKey(NBT_KEY_NAME) ? nbt.getString(NBT_KEY_NAME) : null);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) INBTSerializable(net.minecraftforge.common.util.INBTSerializable)

Example 2 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project minecolonies by Minecolonies.

the class TileEntityRack method upgradeItemStorage.

/**
 * Upgrade the rack by 1. This adds 9 more slots and copies the inventory to the new one.
 */
public void upgradeItemStorage() {
    ++size;
    final IItemHandlerModifiable tempInventory = new ItemStackHandler(DEFAULT_SIZE + size * SLOT_PER_LINE) {

        @Override
        protected void onContentsChanged(final int slot) {
            updateItemStorage();
            super.onContentsChanged(slot);
        }
    };
    for (int slot = 0; slot < inventory.getSlots(); slot++) {
        tempInventory.setStackInSlot(slot, inventory.getStackInSlot(slot));
    }
    inventory = tempInventory;
    final IBlockState state = world.getBlockState(pos);
    world.notifyBlockUpdate(pos, state, state, 0x03);
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IBlockState(net.minecraft.block.state.IBlockState)

Example 3 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project MineCamera by PorPit.

the class EntityTripod method setDead.

@Override
public void setDead() {
    // System.out.println("death and drop");
    if (!this.getEntityWorld().isRemote) {
        Block.spawnAsEntity(this.getEntityWorld(), this.getPosition(), new ItemStack(ItemLoader.itemTripod, 1));
        // last slot useless,so= -2 !=-1
        for (int i = Inventory.getSlots() - 2; i >= 0; --i) {
            if (Inventory.getStackInSlot(i) != null) {
                Block.spawnAsEntity(this.getEntityWorld(), this.getPosition(), Inventory.getStackInSlot(i));
                ((IItemHandlerModifiable) Inventory).setStackInSlot(i, null);
            }
        }
    }
    super.setDead();
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project MineCamera by PorPit.

the class BlockPhotoProcessor method breakBlock.

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
    TileEntityPhotoProcessor te = (TileEntityPhotoProcessor) worldIn.getTileEntity(pos);
    IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
    for (int i = inv.getSlots() - 1; i >= 0; --i) {
        if (inv.getStackInSlot(i) != null) {
            Block.spawnAsEntity(worldIn, pos, inv.getStackInSlot(i));
            ((IItemHandlerModifiable) inv).setStackInSlot(i, null);
        }
    }
    super.breakBlock(worldIn, pos, state);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) TileEntityPhotoProcessor(com.porpit.minecamera.tileentity.TileEntityPhotoProcessor) IItemHandler(net.minecraftforge.items.IItemHandler)

Example 5 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project Metalworks by canitzp.

the class BlockSuperCharger method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    if (!stack.isEmpty()) {
        if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
            if (!world.isRemote) {
                TileEntity tile = world.getTileEntity(pos);
                if (tile instanceof TileSuperCharger) {
                    if (((TileSuperCharger) tile).getInventory(facing).getStackInSlot(0).isEmpty()) {
                        player.setHeldItem(hand, ((TileSuperCharger) tile).getInventory(facing).insertItem(0, stack, false));
                    }
                    ((TileSuperCharger) tile).syncToClients();
                }
            }
            return true;
        }
    } else {
        TileEntity tile = world.getTileEntity(pos);
        if (tile instanceof TileSuperCharger) {
            if (!((TileSuperCharger) tile).getInventory(facing).getStackInSlot(0).isEmpty()) {
                if (!world.isRemote) {
                    player.setHeldItem(hand, ((TileSuperCharger) tile).getInventory(facing).getStackInSlot(0));
                    ((IItemHandlerModifiable) ((TileSuperCharger) tile).getInventory(facing)).setStackInSlot(0, ItemStack.EMPTY);
                    ((TileSuperCharger) tile).syncToClients();
                }
                return true;
            }
        }
    }
    return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)39 ItemStack (net.minecraft.item.ItemStack)15 IItemHandler (net.minecraftforge.items.IItemHandler)9 IElectricItem (gregtech.api.capability.IElectricItem)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 NBTTagList (net.minecraft.nbt.NBTTagList)5 Nonnull (javax.annotation.Nonnull)4 TileEntity (net.minecraft.tileentity.TileEntity)4 INBTSerializable (net.minecraftforge.common.util.INBTSerializable)4 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 NBTTagInt (net.minecraft.nbt.NBTTagInt)2 EnumFacing (net.minecraft.util.EnumFacing)2 World (net.minecraft.world.World)2 EnumPipePart (buildcraft.api.core.EnumPipePart)1 IItemHandlerFiltered (buildcraft.api.inventory.IItemHandlerFiltered)1 IPhantomSlot (buildcraft.lib.gui.slot.IPhantomSlot)1 SlotPhantom (buildcraft.lib.gui.slot.SlotPhantom)1 IItemHandlerAdv (buildcraft.lib.tile.item.IItemHandlerAdv)1 ImmutableCollection (com.google.common.collect.ImmutableCollection)1