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