From f00214f7de42990ec5b447fda772834070c94f4d Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Tue, 3 Oct 2017 17:02:58 +0100 Subject: [PATCH] Rewrite item power distribution to support fe. should fix #1260 --- .../items/armor/ItemLapotronPack.java | 15 +---------- .../items/armor/ItemLithiumBatpack.java | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/main/java/techreborn/items/armor/ItemLapotronPack.java b/src/main/java/techreborn/items/armor/ItemLapotronPack.java index c95489ca1..973557b6e 100644 --- a/src/main/java/techreborn/items/armor/ItemLapotronPack.java +++ b/src/main/java/techreborn/items/armor/ItemLapotronPack.java @@ -103,20 +103,7 @@ public class ItemLapotronPack extends ItemArmor implements IEnergyItemInfo, IEne @Override public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) { - for (int i = 0; i < player.inventory.getSizeInventory(); i++) { - if (player.inventory.getStackInSlot(i) != ItemStack.EMPTY) { - ItemStack item = player.inventory.getStackInSlot(i); - if (item.getItem() instanceof IEnergyItemInfo) { - IEnergyItemInfo energyItemInfo = (IEnergyItemInfo) item.getItem(); - if (energyItemInfo.getMaxPower(item) != PoweredItem.getEnergy(item)) { - if (PoweredItem.canUseEnergy(energyItemInfo.getMaxPower(item), itemStack)) { - PoweredItem.useEnergy(energyItemInfo.getMaxTransfer(item), itemStack); - PoweredItem.setEnergy(PoweredItem.getEnergy(item) + energyItemInfo.getMaxTransfer(item), item); - } - } - } - } - } + ItemLithiumBatpack.distributePowerToInventory(world, player, itemStack, (int) transferLimit); } @Override diff --git a/src/main/java/techreborn/items/armor/ItemLithiumBatpack.java b/src/main/java/techreborn/items/armor/ItemLithiumBatpack.java index ce7d80776..95bca6b95 100644 --- a/src/main/java/techreborn/items/armor/ItemLithiumBatpack.java +++ b/src/main/java/techreborn/items/armor/ItemLithiumBatpack.java @@ -34,6 +34,8 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.NonNullList; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.ICapabilityProvider; +import net.minecraftforge.energy.CapabilityEnergy; +import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import reborncore.api.power.IEnergyInterfaceItem; @@ -61,18 +63,26 @@ public class ItemLithiumBatpack extends ItemArmor implements IEnergyItemInfo, IE @Override public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) { + distributePowerToInventory(world, player, itemStack, (int) transferLimit); + } + + public static void distributePowerToInventory(World world, EntityPlayer player, ItemStack itemStack, int maxSend){ + if(world.isRemote){ + return; + } + if(!itemStack.hasCapability(CapabilityEnergy.ENERGY, null)){ + return; + } + IEnergyStorage backpackPower = itemStack.getCapability(CapabilityEnergy.ENERGY, null); + for (int i = 0; i < player.inventory.getSizeInventory(); i++) { if (player.inventory.getStackInSlot(i) != ItemStack.EMPTY) { ItemStack item = player.inventory.getStackInSlot(i); - if (item.getItem() instanceof IEnergyItemInfo) { - IEnergyItemInfo energyItemInfo = (IEnergyItemInfo) item.getItem(); - if (energyItemInfo.getMaxPower(item) != PoweredItem.getEnergy(item)) { - if (PoweredItem.canUseEnergy(energyItemInfo.getMaxPower(item), itemStack)) { - PoweredItem.useEnergy(energyItemInfo.getMaxTransfer(item), itemStack); - PoweredItem.setEnergy(PoweredItem.getEnergy(item) + energyItemInfo.getMaxTransfer(item), item); - } - } + if(!item.hasCapability(CapabilityEnergy.ENERGY, null)){ + continue; } + IEnergyStorage itemPower = item.getCapability(CapabilityEnergy.ENERGY, null); + backpackPower.extractEnergy(itemPower.receiveEnergy(Math.min(backpackPower.getEnergyStored(), maxSend), false), false); } } }