From 9d824e76ca1a119a1bad3906c315aee52867ea22 Mon Sep 17 00:00:00 2001 From: Modmuss50 Date: Wed, 14 Oct 2015 21:37:21 +0100 Subject: [PATCH] Most of the stuff uses the new item power net now --- .../java/techreborn/client/hud/ChargeHud.java | 17 +- .../techreborn/items/ItemLapotronicOrb.java | 55 ++--- .../items/armor/ItemLapotronPack.java | 52 ++--- .../items/armor/ItemLithiumBatpack.java | 34 ++- .../items/tools/ItemAdvancedDrill.java | 44 ++-- .../techreborn/items/tools/ItemOmniTool.java | 46 ++-- .../items/tools/ItemRockCutter.java | 52 +++-- .../techreborn/powerSystem/PoweredArmor.java | 196 ++++++++++++++++++ .../techreborn/powerSystem/PoweredItem.java | 25 ++- 9 files changed, 333 insertions(+), 188 deletions(-) create mode 100644 src/main/java/techreborn/powerSystem/PoweredArmor.java diff --git a/src/main/java/techreborn/client/hud/ChargeHud.java b/src/main/java/techreborn/client/hud/ChargeHud.java index c030248ac..6c2a68590 100644 --- a/src/main/java/techreborn/client/hud/ChargeHud.java +++ b/src/main/java/techreborn/client/hud/ChargeHud.java @@ -4,8 +4,6 @@ import cpw.mods.fml.common.eventhandler.EventPriority; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import ic2.api.item.ElectricItem; -import ic2.api.item.IElectricItem; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.RenderHelper; @@ -15,6 +13,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import org.lwjgl.opengl.GL11; +import techreborn.api.power.IEnergyInterfaceItem; import techreborn.client.keybindings.KeyBindings; import techreborn.config.ConfigTechReborn; import techreborn.util.Color; @@ -37,7 +36,7 @@ public class ChargeHud { return; if (mc.inGameHasFocus || (mc.currentScreen != null && mc.gameSettings.showDebugInfo)) { - if (ConfigTechReborn.ShowChargeHud && ElectricItem.manager != null) + if (ConfigTechReborn.ShowChargeHud) drawChargeHud(event.resolution); } } @@ -48,9 +47,9 @@ public class ChargeHud { ItemStack stack2 = mc.thePlayer.inventory.getCurrentItem(); if (showHud) { if (stack2 != null) { - if ((stack2.getItem() instanceof IElectricItem)) { - double MaxCharge = ((IElectricItem) stack2.getItem()).getMaxCharge(stack2); - double CurrentCharge = ElectricItem.manager.getCharge(stack2); + if ((stack2.getItem() instanceof IEnergyInterfaceItem)) { + double MaxCharge = ((IEnergyInterfaceItem) stack2.getItem()).getMaxPower(stack2); + double CurrentCharge = ((IEnergyInterfaceItem) stack2.getItem()).getEnergy(stack2); Color color = Color.GREEN; double quarter = MaxCharge / 4; double half = MaxCharge / 2; @@ -72,9 +71,9 @@ public class ChargeHud { } if (stack != null) { - if ((stack.getItem() instanceof IElectricItem) && ConfigTechReborn.ShowChargeHud) { - double MaxCharge = ((IElectricItem) stack.getItem()).getMaxCharge(stack); - double CurrentCharge = ElectricItem.manager.getCharge(stack); + if ((stack.getItem() instanceof IEnergyInterfaceItem) && ConfigTechReborn.ShowChargeHud) { + double MaxCharge = ((IEnergyInterfaceItem) stack.getItem()).getMaxPower(stack); + double CurrentCharge = ((IEnergyInterfaceItem) stack2.getItem()).getEnergy(stack2); Color color = Color.GREEN; double quarter = MaxCharge / 4; double half = MaxCharge / 2; diff --git a/src/main/java/techreborn/items/ItemLapotronicOrb.java b/src/main/java/techreborn/items/ItemLapotronicOrb.java index 2dd5af745..b2fe7a94e 100644 --- a/src/main/java/techreborn/items/ItemLapotronicOrb.java +++ b/src/main/java/techreborn/items/ItemLapotronicOrb.java @@ -2,18 +2,14 @@ package techreborn.items; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import ic2.api.item.ElectricItem; -import ic2.api.item.IElectricItem; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.creativetab.CreativeTabs; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import techreborn.client.TechRebornCreativeTab; import techreborn.config.ConfigTechReborn; +import techreborn.powerSystem.PoweredItem; -import java.util.List; -public class ItemLapotronicOrb extends Item implements IElectricItem { +public class ItemLapotronicOrb extends PoweredItem { public static final int maxCharge = ConfigTechReborn.LapotronicOrbMaxCharge; public static final int tier = ConfigTechReborn.LithiumBatpackTier; @@ -33,50 +29,29 @@ public class ItemLapotronicOrb extends Item implements IElectricItem { this.itemIcon = iconRegister.registerIcon("techreborn:" + "lapotronicEnergyOrb"); } - @SuppressWarnings( - {"rawtypes", "unchecked"}) - @SideOnly(Side.CLIENT) - public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { - ItemStack itemStack = new ItemStack(this, 1); - if (getChargedItem(itemStack) == this && ElectricItem.manager != null) { - ItemStack charged = new ItemStack(this, 1); - ElectricItem.manager.charge(charged, 2147483647, 2147483647, true, - false); - itemList.add(charged); - } - if (getEmptyItem(itemStack) == this) { - itemList.add(new ItemStack(this, 1, getMaxDamage())); - } - } @Override - public boolean canProvideEnergy(ItemStack itemStack) { - return true; - } - - @Override - public Item getChargedItem(ItemStack itemStack) { - return this; - } - - @Override - public Item getEmptyItem(ItemStack itemStack) { - return this; - } - - @Override - public double getMaxCharge(ItemStack itemStack) { + public double getMaxPower(ItemStack stack) { return maxCharge; } @Override - public int getTier(ItemStack itemStack) { - return tier; + public boolean canAcceptEnergy(ItemStack stack) { + return true; } @Override - public double getTransferLimit(ItemStack itemStack) { + public boolean canProvideEnergy(ItemStack stack) { + return true; + } + + @Override + public double getMaxTransfer(ItemStack stack) { return transferLimit; } + @Override + public int getStackTeir(ItemStack stack) { + return tier; + } } diff --git a/src/main/java/techreborn/items/armor/ItemLapotronPack.java b/src/main/java/techreborn/items/armor/ItemLapotronPack.java index fd8c1d29d..ff132e004 100644 --- a/src/main/java/techreborn/items/armor/ItemLapotronPack.java +++ b/src/main/java/techreborn/items/armor/ItemLapotronPack.java @@ -12,10 +12,11 @@ import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import techreborn.client.TechRebornCreativeTab; import techreborn.config.ConfigTechReborn; +import techreborn.powerSystem.PoweredArmor; import java.util.List; -public class ItemLapotronPack extends ItemArmor implements IElectricItem { +public class ItemLapotronPack extends PoweredArmor { public static final int maxCharge = ConfigTechReborn.LapotronPackCharge; public static final int tier = ConfigTechReborn.LapotronPackTier; @@ -40,19 +41,14 @@ public class ItemLapotronPack extends ItemArmor implements IElectricItem { return "techreborn:" + "textures/models/lapotronpack.png"; } - @SuppressWarnings( - {"rawtypes", "unchecked"}) - @SideOnly(Side.CLIENT) - public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { - ItemStack itemStack = new ItemStack(this, 1); - if (getChargedItem(itemStack) == this && ElectricItem.manager != null) { - ItemStack charged = new ItemStack(this, 1); - ElectricItem.manager.charge(charged, 2147483647, 2147483647, true, false); - itemList.add(charged); - } - if (getEmptyItem(itemStack) == this) { - itemList.add(new ItemStack(this, 1, getMaxDamage())); - } + @Override + public double getMaxPower(ItemStack stack) { + return maxCharge; + } + + @Override + public boolean canAcceptEnergy(ItemStack stack) { + return true; } @Override @@ -61,28 +57,14 @@ public class ItemLapotronPack extends ItemArmor implements IElectricItem { } @Override - public Item getChargedItem(ItemStack itemStack) { - return this; - } - - @Override - public Item getEmptyItem(ItemStack itemStack) { - return this; - } - - @Override - public double getMaxCharge(ItemStack itemStack) { - return maxCharge; - } - - @Override - public int getTier(ItemStack itemStack) { - return tier; - } - - @Override - public double getTransferLimit(ItemStack itemStack) { + public double getMaxTransfer(ItemStack stack) { return transferLimit; } + @Override + public int getStackTeir(ItemStack stack) { + return tier; + } + + } diff --git a/src/main/java/techreborn/items/armor/ItemLithiumBatpack.java b/src/main/java/techreborn/items/armor/ItemLithiumBatpack.java index e924f34a4..d0c6775e7 100644 --- a/src/main/java/techreborn/items/armor/ItemLithiumBatpack.java +++ b/src/main/java/techreborn/items/armor/ItemLithiumBatpack.java @@ -12,10 +12,11 @@ import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; import techreborn.client.TechRebornCreativeTab; import techreborn.config.ConfigTechReborn; +import techreborn.powerSystem.PoweredArmor; import java.util.List; -public class ItemLithiumBatpack extends ItemArmor implements IElectricItem { +public class ItemLithiumBatpack extends PoweredArmor { public static final int maxCharge = ConfigTechReborn.LithiumBatpackCharge; public static final int tier = ConfigTechReborn.LithiumBatpackTier; @@ -56,34 +57,29 @@ public class ItemLithiumBatpack extends ItemArmor implements IElectricItem { } } - @Override - public boolean canProvideEnergy(ItemStack itemStack) { - return true; - } @Override - public Item getChargedItem(ItemStack itemStack) { - return this; - } - - @Override - public Item getEmptyItem(ItemStack itemStack) { - return this; - } - - @Override - public double getMaxCharge(ItemStack itemStack) { + public double getMaxPower(ItemStack stack) { return maxCharge; } @Override - public int getTier(ItemStack itemStack) { - return tier; + public boolean canAcceptEnergy(ItemStack stack) { + return true; } @Override - public double getTransferLimit(ItemStack itemStack) { + public boolean canProvideEnergy(ItemStack stack) { + return true; + } + + @Override + public double getMaxTransfer(ItemStack stack) { return transferLimit; } + @Override + public int getStackTeir(ItemStack stack) { + return tier; + } } diff --git a/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java b/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java index 1a40e185d..4fc34cf7e 100644 --- a/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java +++ b/src/main/java/techreborn/items/tools/ItemAdvancedDrill.java @@ -16,11 +16,12 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import techreborn.client.TechRebornCreativeTab; import techreborn.config.ConfigTechReborn; +import techreborn.powerSystem.PoweredPickaxe; import techreborn.util.TorchHelper; import java.util.List; -public class ItemAdvancedDrill extends ItemPickaxe implements IElectricItem { +public class ItemAdvancedDrill extends PoweredPickaxe { public static final int maxCharge = ConfigTechReborn.AdvancedDrillCharge; public int cost = 250; @@ -43,21 +44,6 @@ public class ItemAdvancedDrill extends ItemPickaxe implements IElectricItem { + "tool/advancedDrill"); } - @SuppressWarnings( - {"rawtypes", "unchecked"}) - @SideOnly(Side.CLIENT) - public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { - ItemStack itemStack = new ItemStack(this, 1); - if (getChargedItem(itemStack) == this && ElectricItem.manager != null) { - ItemStack charged = new ItemStack(this, 1); - ElectricItem.manager.charge(charged, 2147483647, 2147483647, true, false); - itemList.add(charged); - } - if (getEmptyItem(itemStack) == this) { - itemList.add(new ItemStack(this, 1, getMaxDamage())); - } - } - @Override public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int par4, int par5, int par6, EntityLivingBase entityLiving) { @@ -99,33 +85,29 @@ public class ItemAdvancedDrill extends ItemPickaxe implements IElectricItem { return false; } - @Override - public boolean canProvideEnergy(ItemStack itemStack) { - return false; - } @Override - public double getMaxCharge(ItemStack itemStack) { + public double getMaxPower(ItemStack stack) { return maxCharge; } @Override - public int getTier(ItemStack itemStack) { - return tier; + public boolean canAcceptEnergy(ItemStack stack) { + return true; } @Override - public double getTransferLimit(ItemStack itemStack) { + public boolean canProvideEnergy(ItemStack stack) { + return false; + } + + @Override + public double getMaxTransfer(ItemStack stack) { return transferLimit; } @Override - public Item getChargedItem(ItemStack itemStack) { - return this; - } - - @Override - public Item getEmptyItem(ItemStack itemStack) { - return this; + public int getStackTeir(ItemStack stack) { + return tier; } } diff --git a/src/main/java/techreborn/items/tools/ItemOmniTool.java b/src/main/java/techreborn/items/tools/ItemOmniTool.java index d1175e0a0..d5651b592 100644 --- a/src/main/java/techreborn/items/tools/ItemOmniTool.java +++ b/src/main/java/techreborn/items/tools/ItemOmniTool.java @@ -2,8 +2,6 @@ package techreborn.items.tools; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import ic2.api.item.ElectricItem; -import ic2.api.item.IElectricItem; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -17,11 +15,12 @@ import net.minecraft.util.DamageSource; import net.minecraft.world.World; import techreborn.client.TechRebornCreativeTab; import techreborn.config.ConfigTechReborn; +import techreborn.powerSystem.PoweredPickaxe; import techreborn.util.TorchHelper; import java.util.List; -public class ItemOmniTool extends ItemPickaxe implements IElectricItem { +public class ItemOmniTool extends PoweredPickaxe{ public static final int maxCharge = ConfigTechReborn.OmniToolCharge; public static final int tier = ConfigTechReborn.OmniToolTier; @@ -49,10 +48,9 @@ public class ItemOmniTool extends ItemPickaxe implements IElectricItem { public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { ItemStack itemStack = new ItemStack(this, 1); - if (getChargedItem(itemStack) == this && ElectricItem.manager != null) { + if (getChargedItem(itemStack) == this) { ItemStack charged = new ItemStack(this, 1); - ElectricItem.manager.charge(charged, 2147483647, 2147483647, true, - false); + setEnergy(maxCharge, charged); itemList.add(charged); } if (getEmptyItem(itemStack) == this) { @@ -63,8 +61,7 @@ public class ItemOmniTool extends ItemPickaxe implements IElectricItem { @Override public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int par4, int par5, int par6, EntityLivingBase entityLiving) { - - ElectricItem.manager.use(stack, cost, entityLiving); + useEnergy(cost, stack); return true; } @@ -80,7 +77,8 @@ public class ItemOmniTool extends ItemPickaxe implements IElectricItem { @Override public float getDigSpeed(ItemStack stack, Block block, int meta) { - if (!ElectricItem.manager.canUse(stack, cost)) { + if (canUseEnergy(cost, stack)) { + useEnergy(cost, stack); return 5.0F; } @@ -97,7 +95,8 @@ public class ItemOmniTool extends ItemPickaxe implements IElectricItem { @Override public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) { - if (ElectricItem.manager.use(itemstack, hitCost, attacker)) { + if (canUseEnergy(hitCost, itemstack)) { + useEnergy(hitCost, itemstack); entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 8F); } return false; @@ -114,14 +113,16 @@ public class ItemOmniTool extends ItemPickaxe implements IElectricItem { return false; } + + @Override - public Item getChargedItem(ItemStack itemStack) { - return this; + public double getMaxPower(ItemStack stack) { + return maxCharge; } @Override - public Item getEmptyItem(ItemStack itemStack) { - return this; + public boolean canAcceptEnergy(ItemStack stack) { + return true; } @Override @@ -130,18 +131,13 @@ public class ItemOmniTool extends ItemPickaxe implements IElectricItem { } @Override - public double getMaxCharge(ItemStack itemStack) { - return maxCharge; - } - - @Override - public int getTier(ItemStack itemStack) { - return 2; - } - - @Override - public double getTransferLimit(ItemStack itemStack) { + public double getMaxTransfer(ItemStack stack) { return 200; } + @Override + public int getStackTeir(ItemStack stack) { + return 2; + } + } diff --git a/src/main/java/techreborn/items/tools/ItemRockCutter.java b/src/main/java/techreborn/items/tools/ItemRockCutter.java index 0fcf262e1..8756983a5 100644 --- a/src/main/java/techreborn/items/tools/ItemRockCutter.java +++ b/src/main/java/techreborn/items/tools/ItemRockCutter.java @@ -2,8 +2,6 @@ package techreborn.items.tools; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import ic2.api.item.ElectricItem; -import ic2.api.item.IElectricItem; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; @@ -11,16 +9,16 @@ import net.minecraft.enchantment.Enchantment; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.Item; -import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import techreborn.client.TechRebornCreativeTab; import techreborn.config.ConfigTechReborn; +import techreborn.powerSystem.PoweredPickaxe; import techreborn.util.Color; import java.util.List; -public class ItemRockCutter extends ItemPickaxe implements IElectricItem { +public class ItemRockCutter extends PoweredPickaxe { public static final int maxCharge = ConfigTechReborn.RockCutterCharge; public int cost = 500; @@ -58,10 +56,9 @@ public class ItemRockCutter extends ItemPickaxe implements IElectricItem { @SideOnly(Side.CLIENT) public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { ItemStack itemStack = new ItemStack(this, 1); - if (getChargedItem(itemStack) == this && ElectricItem.manager != null) { + if (getChargedItem(itemStack) == this) { ItemStack charged = new ItemStack(this, 1); - ElectricItem.manager.charge(charged, 2147483647, 2147483647, true, - false); + setEnergy(maxCharge, charged); itemList.add(charged); } @@ -72,7 +69,13 @@ public class ItemRockCutter extends ItemPickaxe implements IElectricItem { @Override public boolean canHarvestBlock(Block block, ItemStack stack) { - return Items.diamond_pickaxe.canHarvestBlock(block, stack); + if(Items.diamond_pickaxe.canHarvestBlock(block, stack)) { + if (canUseEnergy(cost, stack)) { + useEnergy(cost, stack); + return true; + } + } + return false; } @Override @@ -100,34 +103,29 @@ public class ItemRockCutter extends ItemPickaxe implements IElectricItem { par1ItemStack.addEnchantment(Enchantment.silkTouch, 1); } - @Override - public boolean canProvideEnergy(ItemStack itemStack) { - return false; - } @Override - public Item getChargedItem(ItemStack itemStack) { - return this; - } - - @Override - public Item getEmptyItem(ItemStack itemStack) { - return this; - } - - @Override - public double getMaxCharge(ItemStack itemStack) { + public double getMaxPower(ItemStack stack) { return maxCharge; } @Override - public int getTier(ItemStack itemStack) { - return tier; + public boolean canAcceptEnergy(ItemStack stack) { + return true; } @Override - public double getTransferLimit(ItemStack itemStack) { - return 300; + public boolean canProvideEnergy(ItemStack stack) { + return false; } + @Override + public double getMaxTransfer(ItemStack stack) { + return 200; + } + + @Override + public int getStackTeir(ItemStack stack) { + return 2; + } } diff --git a/src/main/java/techreborn/powerSystem/PoweredArmor.java b/src/main/java/techreborn/powerSystem/PoweredArmor.java new file mode 100644 index 000000000..10a50ce96 --- /dev/null +++ b/src/main/java/techreborn/powerSystem/PoweredArmor.java @@ -0,0 +1,196 @@ +package techreborn.powerSystem; + +import cofh.api.energy.IEnergyContainerItem; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ic2.api.item.IElectricItem; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import techreborn.api.power.IEnergyInterfaceItem; +import techreborn.asm.Strippable; +import techreborn.config.ConfigTechReborn; + +import java.util.List; + +public abstract class PoweredArmor extends ItemArmor implements IEnergyInterfaceItem, IElectricItem, IEnergyContainerItem { + + public PoweredArmor(ArmorMaterial material, int renderIndex, int armorType) { + super(material, renderIndex, armorType); + } + + @SuppressWarnings( + {"rawtypes", "unchecked"}) + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { + ItemStack itemStack = new ItemStack(this, 1); + + if (getChargedItem(itemStack) == this) { + ItemStack charged = new ItemStack(this, 1); + setEnergy(getMaxCharge(charged), charged); + itemList.add(charged); + } + if (getEmptyItem(itemStack) == this) { + itemList.add(new ItemStack(this, 1, getMaxDamage())); + } + } + + //TechReborn + @Override + public double getEnergy(ItemStack stack) { + NBTTagCompound tagCompound = getOrCreateNbtData(stack); + if (tagCompound.hasKey("charge")) { + return tagCompound.getDouble("charge"); + } + return 0; + } + + @Override + public void setEnergy(double energy, ItemStack stack) { + NBTTagCompound tagCompound = getOrCreateNbtData(stack); + tagCompound.setDouble("charge", energy); + + if (this.getEnergy(stack) > getMaxPower(stack)) { + this.setEnergy(getMaxPower(stack), stack); + } else if (this.getEnergy(stack) < 0) { + this.setEnergy(0, stack); + } + } + + @Override + public double addEnergy(double energy, ItemStack stack) { + return addEnergy(energy, false, stack); + } + + @Override + public double addEnergy(double energy, boolean simulate, ItemStack stack) { + double energyReceived = Math.min(getMaxPower(stack) - energy, Math.min(this.getMaxPower(stack), energy)); + + if (!simulate) { + setEnergy(energy + energyReceived, stack); + } + return energyReceived; + } + + @Override + public boolean canUseEnergy(double input, ItemStack stack) { + return input <= getEnergy(stack); + } + + @Override + public double useEnergy(double energy, ItemStack stack) { + return useEnergy(energy, false, stack); + } + + @Override + public double useEnergy(double extract, boolean simulate, ItemStack stack) { + double energyExtracted = Math.min(extract, Math.min(this.getMaxTransfer(stack), extract)); + + if (!simulate) { + setEnergy(getEnergy(stack) - energyExtracted, stack); + } + return energyExtracted; + } + + @Override + public boolean canAddEnergy(double energy, ItemStack stack) { + return this.getEnergy(stack) + energy <= getMaxPower(stack); + } + + + public static NBTTagCompound getOrCreateNbtData(ItemStack itemStack) { + NBTTagCompound tagCompound = itemStack.getTagCompound(); + if (tagCompound == null) { + tagCompound = new NBTTagCompound(); + itemStack.setTagCompound(tagCompound); + } + + return tagCompound; + } + + + //End Techreborn + + + //IC2 + @Strippable("mod:IC2") + @Override + public Item getChargedItem(ItemStack itemStack) { + return this; + } + + @Strippable("mod:IC2") + @Override + public Item getEmptyItem(ItemStack itemStack) { + return this; + } + + @Strippable("mod:IC2") + @Override + public double getMaxCharge(ItemStack itemStack) { + return getMaxPower(itemStack); + } + + @Strippable("mod:IC2") + @Override + public int getTier(ItemStack itemStack) { + return getStackTeir(itemStack); + } + + @Strippable("mod:IC2") + @Override + public double getTransferLimit(ItemStack itemStack) { + return getMaxTransfer(itemStack); + } + //IC2 + + //COFH + @Override + public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { + if (!PowerSystem.RFPOWENET) + return 0; + if (!canAcceptEnergy(container)) { + return 0; + } + maxReceive *= ConfigTechReborn.euPerRF; + int energyReceived = Math.min(getMaxEnergyStored(container) - getEnergyStored(container), Math.min((int) this.getMaxTransfer(container) * ConfigTechReborn.euPerRF, maxReceive)); + + if (!simulate) { + setEnergy(getEnergy(container) + energyReceived, container); + } + return energyReceived / ConfigTechReborn.euPerRF; + } + + @Override + public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) { + if (!PowerSystem.RFPOWENET) + return 0; + if (!canAcceptEnergy(container)) { + return 0; + } + maxExtract *= ConfigTechReborn.euPerRF; + int energyExtracted = Math.min(getEnergyStored(container), Math.min(maxExtract, maxExtract)); + + if (!simulate) { + setEnergy(getEnergy(container) - energyExtracted, container); + } + return energyExtracted / ConfigTechReborn.euPerRF; + } + + @Override + public int getEnergyStored(ItemStack container) { + if (!PowerSystem.RFPOWENET) + return 0; + return ((int) getEnergy(container) / ConfigTechReborn.euPerRF); + } + + @Override + public int getMaxEnergyStored(ItemStack container) { + if (!PowerSystem.RFPOWENET) + return 0; + return ((int) getMaxPower(container) / ConfigTechReborn.euPerRF); + } + //Cofh +} diff --git a/src/main/java/techreborn/powerSystem/PoweredItem.java b/src/main/java/techreborn/powerSystem/PoweredItem.java index dd8f15440..895571549 100644 --- a/src/main/java/techreborn/powerSystem/PoweredItem.java +++ b/src/main/java/techreborn/powerSystem/PoweredItem.java @@ -2,7 +2,10 @@ package techreborn.powerSystem; import cofh.api.energy.IEnergyContainerItem; import cpw.mods.fml.common.Optional; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import ic2.api.item.IElectricItem; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -10,16 +13,34 @@ import techreborn.api.power.IEnergyInterfaceItem; import techreborn.asm.Strippable; import techreborn.config.ConfigTechReborn; +import java.util.List; + @Optional.InterfaceList(value = { @Optional.Interface(iface = "ic2.api.item.IElectricItem", modid = "IC2") }) public abstract class PoweredItem extends Item implements IEnergyInterfaceItem, IElectricItem, IEnergyContainerItem { + @SuppressWarnings( + {"rawtypes", "unchecked"}) + @SideOnly(Side.CLIENT) + public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) { + ItemStack itemStack = new ItemStack(this, 1); + + if (getChargedItem(itemStack) == this) { + ItemStack charged = new ItemStack(this, 1); + setEnergy(getMaxCharge(charged), charged); + itemList.add(charged); + } + if (getEmptyItem(itemStack) == this) { + itemList.add(new ItemStack(this, 1, getMaxDamage())); + } + } + //TechReborn @Override public double getEnergy(ItemStack stack) { NBTTagCompound tagCompound = getOrCreateNbtData(stack); - if(tagCompound.hasKey("charge")){ + if (tagCompound.hasKey("charge")) { return tagCompound.getDouble("charge"); } return 0; @@ -80,7 +101,7 @@ public abstract class PoweredItem extends Item implements IEnergyInterfaceItem, public static NBTTagCompound getOrCreateNbtData(ItemStack itemStack) { NBTTagCompound tagCompound = itemStack.getTagCompound(); - if(tagCompound == null) { + if (tagCompound == null) { tagCompound = new NBTTagCompound(); itemStack.setTagCompound(tagCompound); }