Search in sources :

Example 26 with IItemHandlerModifiable

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

the class TileBase method readCapabilities.

protected void readCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
    IItemHandler inventory = this.getInventory(side);
    if (inventory != null && inventory instanceof IItemHandlerModifiable && nbt.hasKey("Inventory")) {
        for (int i = 0; i < inventory.getSlots(); i++) {
            // clear the inventory, otherwise empty stacks doesn't get overriden while syncing. Forge Bug?
            ((IItemHandlerModifiable) inventory).setStackInSlot(i, ItemStack.EMPTY);
        }
        CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, side, nbt.getTag("Inventory"));
    }
    IFluidHandler tank = getTank(side);
    if (tank != null && tank instanceof IFluidTank && nbt.hasKey("FluidTank")) {
        CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(tank, side, nbt.getCompoundTag("FluidTank"));
    }
    IEnergyStorage energy = getEnergy(side);
    if (energy != null && energy instanceof EnergyStorage && nbt.hasKey("Energy")) {
        CapabilityEnergy.ENERGY.readNBT(energy, side, nbt.getTag("Energy"));
    }
}
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 27 with IItemHandlerModifiable

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

the class EnergyContainerBatteryBuffer method update.

@Override
public void update() {
    if (!metaTileEntity.getWorld().isRemote) {
        this.batterySlotsUsedThisTick.clear();
        EnumFacing outFacing = metaTileEntity.getFrontFacing();
        TileEntity tileEntity = metaTileEntity.getWorld().getTileEntity(metaTileEntity.getPos().offset(outFacing));
        if (tileEntity == null) {
            return;
        }
        IEnergyContainer energyContainer = tileEntity.getCapability(GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER, outFacing.getOpposite());
        if (energyContainer == null) {
            return;
        }
        IItemHandlerModifiable inventory = getInventory();
        long voltage = getOutputVoltage();
        long maxAmperage = 0L;
        TIntList slotsList = new TIntArrayList();
        for (int i = 0; i < inventory.getSlots(); i++) {
            ItemStack batteryStack = inventory.getStackInSlot(i);
            IElectricItem electricItem = getBatteryContainer(batteryStack);
            if (electricItem == null)
                continue;
            if (electricItem.discharge(voltage, getTier(), true, true, true) == voltage) {
                slotsList.add(i);
                maxAmperage++;
            }
        }
        if (maxAmperage == 0)
            return;
        long amperageUsed = energyContainer.acceptEnergyFromNetwork(outFacing.getOpposite(), voltage, maxAmperage);
        if (amperageUsed == 0)
            return;
        for (int i : slotsList.toArray()) {
            ItemStack batteryStack = inventory.getStackInSlot(i);
            IElectricItem electricItem = getBatteryContainer(batteryStack);
            if (electricItem == null)
                continue;
            electricItem.discharge(voltage, getTier(), true, true, false);
            inventory.setStackInSlot(i, batteryStack);
            if (--amperageUsed == 0)
                break;
        }
        notifyEnergyListener(false);
    }
}
Also used : MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IElectricItem(gregtech.api.capability.IElectricItem) IEnergyContainer(gregtech.api.capability.IEnergyContainer) EnumFacing(net.minecraft.util.EnumFacing) TIntList(gnu.trove.list.TIntList) ItemStack(net.minecraft.item.ItemStack) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 28 with IItemHandlerModifiable

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

the class EnergyContainerBatteryBuffer method getEnergyCapacity.

@Override
public long getEnergyCapacity() {
    long energyCapacity = 0L;
    IItemHandlerModifiable inventory = getInventory();
    for (int i = 0; i < inventory.getSlots(); i++) {
        ItemStack batteryStack = inventory.getStackInSlot(i);
        IElectricItem electricItem = getBatteryContainer(batteryStack);
        if (electricItem == null)
            continue;
        energyCapacity += electricItem.getMaxCharge();
    }
    return energyCapacity;
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IElectricItem(gregtech.api.capability.IElectricItem) ItemStack(net.minecraft.item.ItemStack)

Example 29 with IItemHandlerModifiable

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

the class AbstractRecipeLogic method setupAndConsumeRecipeInputs.

protected boolean setupAndConsumeRecipeInputs(Recipe recipe) {
    int[] resultOverclock = calculateOverclock(recipe.getEUt(), recipe.getDuration());
    int totalEUt = resultOverclock[0] * resultOverclock[1];
    IItemHandlerModifiable importInventory = getInputInventory();
    IItemHandlerModifiable exportInventory = getOutputInventory();
    IMultipleTankHandler importFluids = getInputTank();
    IMultipleTankHandler exportFluids = getOutputTank();
    return (totalEUt >= 0 ? getEnergyStored() >= (totalEUt > getEnergyCapacity() / 2 ? resultOverclock[0] : totalEUt) : (getEnergyStored() - resultOverclock[0] <= getEnergyCapacity())) && MetaTileEntity.addItemsToItemHandler(exportInventory, true, recipe.getAllItemOutputs(exportInventory.getSlots())) && MetaTileEntity.addFluidsToFluidHandler(exportFluids, true, recipe.getFluidOutputs()) && recipe.matches(true, importInventory, importFluids);
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IMultipleTankHandler(gregtech.api.capability.IMultipleTankHandler)

Example 30 with IItemHandlerModifiable

use of net.minecraftforge.items.IItemHandlerModifiable in project MorePlanets by SteveKunG.

the class DoubleChestItemHandlerMP method setStackInSlot.

@Override
public void setStackInSlot(int slot, @Nonnull ItemStack itemStack) {
    boolean accessingUpperChest = slot < 27;
    int targetSlot = accessingUpperChest ? slot : slot - 27;
    TileEntityChestMP chest = this.getChest(accessingUpperChest);
    if (chest != null) {
        IItemHandler singleHandler = chest.getSingleChestHandler();
        if (singleHandler instanceof IItemHandlerModifiable) {
            ((IItemHandlerModifiable) singleHandler).setStackInSlot(targetSlot, itemStack);
        }
    }
    chest = this.getChest(!accessingUpperChest);
    if (chest != null) {
        chest.markDirty();
    }
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) TileEntityChestMP(stevekung.mods.moreplanets.utils.tileentity.TileEntityChestMP) IItemHandler(net.minecraftforge.items.IItemHandler)

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