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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations