Search in sources :

Example 6 with IItemHandlerModifiable

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

the class TileBase method writeCapabilities.

protected void writeCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
    IItemHandler inventory = this.getInventory(side);
    if (inventory != null && inventory instanceof IItemHandlerModifiable) {
        nbt.setTag("Inventory", CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.writeNBT(inventory, side));
    }
    IFluidHandler tank = getTank(side);
    if (tank != null && tank instanceof IFluidTank) {
        nbt.setTag("FluidTank", CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.writeNBT(tank, side));
    }
    IEnergyStorage energy = getEnergy(side);
    if (energy != null && energy instanceof EnergyStorage) {
        nbt.setTag("Energy", CapabilityEnergy.ENERGY.writeNBT(energy, side));
    }
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IItemHandler(net.minecraftforge.items.IItemHandler) EnergyStorage(net.minecraftforge.energy.EnergyStorage) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 7 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project ImmersiveEngineering by BluSunrize.

the class ItemDrill method setHead.

public void setHead(ItemStack drill, ItemStack head) {
    IItemHandler inv = drill.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    ((IItemHandlerModifiable) inv).setStackInSlot(0, head);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IItemHandler(net.minecraftforge.items.IItemHandler)

Example 8 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project ICBM-Classic by BuiltBrokenModding.

the class CapabilityEmpInventory method applyEmpAction.

@Override
public float applyEmpAction(World world, double x, double y, double z, IBlast emp_blast, float power, boolean doAction) {
    final IItemHandlerModifiable iItemHandler = getCapability();
    if (iItemHandler != null) {
        // Loop items
        for (int slotIndex = 0; slotIndex < iItemHandler.getSlots(); slotIndex++) {
            final ItemStack slotStack = iItemHandler.getStackInSlot(slotIndex);
            // Check to make sure its not a placeholder
            if (!slotStack.isEmpty()) {
                // Copy stack for editing
                final ItemStack itemStack = slotStack.copy();
                // Run call
                power = empItemStack(itemStack, world, x, y, z, getHost(), emp_blast, power, doAction);
                // Only apply changes if we are not simulating and there was a change in the stack
                if (doAction && !InventoryUtility.stacksMatchExact(itemStack, slotStack)) {
                    try {
                        iItemHandler.setStackInSlot(slotIndex, itemStack);
                    } catch (// Safety check, just in case
                    RuntimeException e) {
                        ICBMClassic.logger().error("BlastEMP: Unexpected error while updating inventory item '" + itemStack + "' from slot '" + slotIndex + "' in '" + iItemHandler + "' contained in '" + getHost() + "' while running " + this, e);
                    }
                }
            }
        }
    }
    return power;
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) ItemStack(net.minecraft.item.ItemStack)

Example 9 with IItemHandlerModifiable

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

the class CombinedInvWrapper method getStackInSlot.

@Override
@Nonnull
public ItemStack getStackInSlot(int slot) {
    int index = getIndexForSlot(slot);
    IItemHandlerModifiable handler = getHandlerFromIndex(index);
    slot = getSlotFromIndex(slot, index);
    return handler.getStackInSlot(slot);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Nonnull(javax.annotation.Nonnull)

Example 10 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project RecurrentComplex by Ivorforce.

the class ItemHandlers method complete.

public static CombinedInvWrapper complete(ICapabilityProvider provider) {
    List<IItemHandlerModifiable> handlers = new ArrayList<>();
    Arrays.stream(EnumFacing.VALUES).forEach(f -> {
        if (provider.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, f)) {
            IItemHandler capability = provider.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, f);
            if (capability instanceof IItemHandlerModifiable)
                handlers.add((IItemHandlerModifiable) capability);
        }
    });
    return new CombinedInvWrapper(handlers.toArray(new IItemHandlerModifiable[0]));
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) CombinedInvWrapper(net.minecraftforge.items.wrapper.CombinedInvWrapper) IItemHandler(net.minecraftforge.items.IItemHandler) ArrayList(java.util.ArrayList)

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