Search in sources :

Example 16 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project GregTech by GregTechCE.

the class ItemHandlerList method setStackInSlot.

@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
    IItemHandler itemHandler = handlerBySlotIndex.get(slot);
    if (!(itemHandler instanceof IItemHandlerModifiable))
        throw new UnsupportedOperationException("Handler " + itemHandler + " does not support this method");
    ((IItemHandlerModifiable) itemHandler).setStackInSlot(slot - baseIndexOffset.get(itemHandler), stack);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IItemHandler(net.minecraftforge.items.IItemHandler)

Example 17 with IItemHandlerModifiable

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

the class AbstractCombinedItemHandler method serializeNBT.

@SuppressWarnings(RAWTYPES)
@Override
public NBTTagCompound serializeNBT() {
    final NBTTagCompound compound = new NBTTagCompound();
    int index = 0;
    final NBTTagList handlerList = new NBTTagList();
    final NBTTagList indexList = new NBTTagList();
    for (final IItemHandlerModifiable handlerModifiable : handlers) {
        if (handlerModifiable instanceof INBTSerializable) {
            final INBTSerializable serializable = (INBTSerializable) handlerModifiable;
            handlerList.appendTag(serializable.serializeNBT());
            indexList.appendTag(new NBTTagInt(index));
        }
        index++;
    }
    compound.setTag(NBT_KEY_HANDLERS, handlerList);
    if (hasCustomName()) {
        compound.setString(NBT_KEY_NAME, customName);
    }
    return compound;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) NBTTagInt(net.minecraft.nbt.NBTTagInt) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) INBTSerializable(net.minecraftforge.common.util.INBTSerializable)

Example 18 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project BuildCraft by BuildCraft.

the class ContainerBC_Neptune method readSingleSetPhantom.

private void readSingleSetPhantom(PacketBufferBC buffer, MessageContext ctx) throws IOException {
    int idx = buffer.readVarInt();
    ItemStack stack = buffer.readItemStack();
    if (idx >= 0 && idx < inventorySlots.size()) {
        Slot s = inventorySlots.get(idx);
        if (s instanceof SlotPhantom) {
            SlotPhantom ph = (SlotPhantom) s;
            IItemHandlerAdv handler = ph.itemHandler;
            if (handler instanceof IItemHandlerModifiable && handler.canSet(ph.handlerIndex, stack)) {
                ((IItemHandlerModifiable) handler).setStackInSlot(ph.handlerIndex, stack);
            } else {
                // log rather than throw an exception because of bugged/naughty clients
                String s2 = "[lib.container] Received an illegal phantom slot setting request! ";
                s2 += "[The item handler disallowed the replacement] (Client = ";
                s2 += ctx.getServerHandler().player.getName() + ", slot_index = " + idx;
                s2 += ", stack = " + stack + ")";
                BCLog.logger.warn(s2);
            }
            return;
        }
    }
    // log rather than throw an exception because of bugged/naughty clients
    String s2 = "[lib.container] Received an illegal phantom slot setting request! ";
    s2 += "[Didn't find a phantom slot for the given index] (Client = ";
    s2 += ctx.getServerHandler().player.getName() + ", slot_index = " + idx;
    s2 += ", stack = " + stack + ")";
    BCLog.logger.warn(s2);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) SlotPhantom(buildcraft.lib.gui.slot.SlotPhantom) IPhantomSlot(buildcraft.lib.gui.slot.IPhantomSlot) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) IItemHandlerAdv(buildcraft.lib.tile.item.IItemHandlerAdv)

Example 19 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project BuildCraft by BuildCraft.

the class CombinedItemHandlerWrapper method getFilter.

@Override
public ItemStack getFilter(int slot) {
    int index = getIndexForSlot(slot);
    IItemHandlerModifiable handler = getHandlerFromIndex(index);
    slot = getSlotFromIndex(slot, index);
    if (handler instanceof IItemHandlerFiltered) {
        return ((IItemHandlerFiltered) handler).getFilter(slot);
    }
    return handler.getStackInSlot(slot);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IItemHandlerFiltered(buildcraft.api.inventory.IItemHandlerFiltered)

Example 20 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project BuildCraft by BuildCraft.

the class ItemHandlerManager method addInvHandler.

public <T extends INBTSerializable<NBTTagCompound> & IItemHandlerModifiable> T addInvHandler(String key, T handler, EnumAccess access, EnumPipePart... parts) {
    if (parts == null) {
        parts = new EnumPipePart[0];
    }
    IItemHandlerModifiable external = handler;
    if (access == EnumAccess.NONE || access == EnumAccess.PHANTOM) {
        external = null;
        if (parts.length > 0) {
            throw new IllegalArgumentException("Completely useless to not allow access to multiple sides! Just don't pass any sides!");
        }
    } else if (access == EnumAccess.EXTRACT) {
        external = new WrappedItemHandlerExtract(handler);
    } else if (access == EnumAccess.INSERT) {
        external = new WrappedItemHandlerInsert(handler);
    }
    if (external != null) {
        Set<EnumPipePart> visited = EnumSet.noneOf(EnumPipePart.class);
        for (EnumPipePart part : parts) {
            if (part == null)
                part = EnumPipePart.CENTER;
            if (visited.add(part)) {
                Wrapper wrapper = wrappers.get(part);
                wrapper.handlers.add(external);
                wrapper.genWrapper();
            }
        }
    }
    if (access != EnumAccess.PHANTOM) {
        handlersToDrop.add(handler);
    }
    handlers.put(key, handler);
    return handler;
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) EnumPipePart(buildcraft.api.core.EnumPipePart)

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