Search in sources :

Example 11 with IItemHandlerModifiable

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

the class AbstractRecipeLogic method trySearchNewRecipe.

protected void trySearchNewRecipe() {
    long maxVoltage = getMaxVoltage();
    Recipe currentRecipe = null;
    IItemHandlerModifiable importInventory = getInputInventory();
    IMultipleTankHandler importFluids = getInputTank();
    if (previousRecipe != null && previousRecipe.matches(false, importInventory, importFluids)) {
        // if previous recipe still matches inputs, try to use it
        currentRecipe = previousRecipe;
    } else {
        boolean dirty = checkRecipeInputsDirty(importInventory, importFluids);
        if (dirty || forceRecipeRecheck) {
            this.forceRecipeRecheck = false;
            // else, try searching new recipe for given inputs
            currentRecipe = findRecipe(maxVoltage, importInventory, importFluids);
            if (currentRecipe != null) {
                this.previousRecipe = currentRecipe;
            }
        }
    }
    if (currentRecipe != null && setupAndConsumeRecipeInputs(currentRecipe)) {
        setupRecipe(currentRecipe);
    }
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) Recipe(gregtech.api.recipes.Recipe) IMultipleTankHandler(gregtech.api.capability.IMultipleTankHandler)

Example 12 with IItemHandlerModifiable

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

the class EnergyContainerBatteryBuffer method getEnergyStored.

@Override
public long getEnergyStored() {
    long energyStored = 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;
        energyStored += electricItem.getCharge();
    }
    return energyStored;
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IElectricItem(gregtech.api.capability.IElectricItem) ItemStack(net.minecraft.item.ItemStack)

Example 13 with IItemHandlerModifiable

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

the class EnergyContainerBatteryBuffer method changeEnergy.

@Override
public long changeEnergy(long energyToAdd) {
    boolean isDischarge = energyToAdd < 0L;
    energyToAdd = Math.abs(energyToAdd);
    long initialEnergyToAdd = energyToAdd;
    IItemHandlerModifiable inventory = getInventory();
    for (int i = 0; i < inventory.getSlots(); i++) {
        ItemStack batteryStack = inventory.getStackInSlot(i);
        IElectricItem electricItem = getBatteryContainer(batteryStack);
        if (electricItem == null)
            continue;
        long charged = chargeItem(electricItem, energyToAdd, getTier(), isDischarge);
        energyToAdd -= charged;
        if (energyToAdd == 0L)
            break;
    }
    long energyAdded = initialEnergyToAdd - energyToAdd;
    if (energyAdded > 0L) {
        notifyEnergyListener(false);
    }
    return energyAdded;
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IElectricItem(gregtech.api.capability.IElectricItem) ItemStack(net.minecraft.item.ItemStack)

Example 14 with IItemHandlerModifiable

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

the class EnergyContainerBatteryBuffer method acceptEnergyFromNetwork.

@Override
public long acceptEnergyFromNetwork(EnumFacing side, long voltage, long amperage) {
    long initialAmperage = amperage;
    if (side == null || inputsEnergy(side)) {
        if (voltage > getInputVoltage()) {
            GTUtility.doOvervoltageExplosion(metaTileEntity, voltage);
            return Math.min(amperage, getInputAmperage());
        }
        IItemHandlerModifiable inventory = getInventory();
        for (int i = 0; i < inventory.getSlots(); i++) {
            if (batterySlotsUsedThisTick.get(i))
                continue;
            ItemStack batteryStack = inventory.getStackInSlot(i);
            IElectricItem electricItem = getBatteryContainer(batteryStack);
            if (electricItem == null)
                continue;
            if (chargeItemWithVoltage(electricItem, voltage, getTier(), true)) {
                chargeItemWithVoltage(electricItem, voltage, getTier(), false);
                inventory.setStackInSlot(i, batteryStack);
                this.batterySlotsUsedThisTick.set(i);
                if (--amperage == 0)
                    break;
            }
        }
    }
    long amperageUsed = initialAmperage - amperage;
    if (amperageUsed > 0L) {
        notifyEnergyListener(false);
    }
    return amperageUsed;
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IElectricItem(gregtech.api.capability.IElectricItem) ItemStack(net.minecraft.item.ItemStack)

Example 15 with IItemHandlerModifiable

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

the class EnergyContainerBatteryBuffer method getInputAmperage.

@Override
public long getInputAmperage() {
    long inputAmperage = 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;
        inputAmperage++;
    }
    return inputAmperage;
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) IElectricItem(gregtech.api.capability.IElectricItem) 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