Cleaned up Item Power System

This commit is contained in:
modmuss50 2015-11-08 13:59:36 +00:00
parent ef03cf50a9
commit d4222693c0
18 changed files with 448 additions and 636 deletions

View file

@ -74,7 +74,7 @@ public class Core {
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
public void init(FMLInitializationEvent event) throws IllegalAccessException, InstantiationException {
// Register ModBlocks
ModBlocks.init();
// Register Fluids

View file

@ -2,7 +2,7 @@ package techreborn.api.power;
import net.minecraft.item.ItemStack;
public interface IEnergyInterfaceItem {
public interface IEnergyInterfaceItem extends IEnergyItemInfo{
/**
* @return Amount of energy in the tile
*/
@ -15,12 +15,6 @@ public interface IEnergyInterfaceItem {
*/
public void setEnergy(double energy, ItemStack stack);
/**
* Gets the max stored energy in the tile
*
* @return The max energy
*/
public double getMaxPower(ItemStack stack);
/**
* @param energy amount of energy to add to the tile
@ -69,20 +63,5 @@ public interface IEnergyInterfaceItem {
*/
public double useEnergy(double energy, boolean simulate, ItemStack stack);
/**
* @return if it can accept energy
*/
public boolean canAcceptEnergy(ItemStack stack);
/**
* @return if it can provide energy
*/
public boolean canProvideEnergy(ItemStack stack);
public double getMaxTransfer(ItemStack stack);
public int getStackTeir(ItemStack stack);
}

View file

@ -0,0 +1,28 @@
package techreborn.api.power;
import net.minecraft.item.ItemStack;
public interface IEnergyItemInfo {
/**
* Gets the max stored energy in the tile
*
* @return The max energy
*/
double getMaxPower(ItemStack stack);
/**
* @return if it can accept energy
*/
boolean canAcceptEnergy(ItemStack stack);
/**
* @return if it can provide energy
*/
boolean canProvideEnergy(ItemStack stack);
double getMaxTransfer(ItemStack stack);
int getStackTeir(ItemStack stack);
}

View file

@ -11,6 +11,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import reborncore.client.gui.GuiUtil;
import reborncore.client.multiblock.Multiblock;
import reborncore.client.multiblock.MultiblockSet;
import reborncore.common.misc.Location;
import techreborn.client.container.ContainerBlastFurnace;
import techreborn.init.ModBlocks;
import techreborn.lib.ModInfo;

View file

@ -17,6 +17,7 @@ import techreborn.items.*;
import techreborn.items.armor.ItemLapotronPack;
import techreborn.items.armor.ItemLithiumBatpack;
import techreborn.items.tools.*;
import techreborn.powerSystem.PoweredItem;
public class ModItems {
@ -76,7 +77,7 @@ public class ModItems {
public static Item upgrades;
public static void init() {
public static void init() throws InstantiationException, IllegalAccessException {
gems = new ItemGems();
GameRegistry.registerItem(gems, "gem");
ingots = new ItemIngots();
@ -97,17 +98,17 @@ public class ModItems {
GameRegistry.registerItem(parts, "part");
cells = new ItemCells();
GameRegistry.registerItem(cells, "cell");
rockCutter = new ItemRockCutter(ToolMaterial.EMERALD);
rockCutter = PoweredItem.createItem(ItemRockCutter.class);
GameRegistry.registerItem(rockCutter, "rockCutter");
lithiumBatpack = new ItemLithiumBatpack(ArmorMaterial.DIAMOND, 7, 1);
lithiumBatpack = PoweredItem.createItem(ItemLithiumBatpack.class);
GameRegistry.registerItem(lithiumBatpack, "lithiumBatpack");
lapotronpack = new ItemLapotronPack(ArmorMaterial.DIAMOND, 7, 1);
lapotronpack = PoweredItem.createItem(ItemLapotronPack.class);
GameRegistry.registerItem(lapotronpack, "lapotronPack");
lapotronicOrb = new ItemLapotronicOrb();
lapotronicOrb = PoweredItem.createItem(ItemLapotronicOrb.class);
GameRegistry.registerItem(lapotronicOrb, "lapotronicOrb");
omniTool = new ItemOmniTool(ToolMaterial.EMERALD);
omniTool = PoweredItem.createItem(ItemOmniTool.class);
GameRegistry.registerItem(omniTool, "omniTool");
advancedDrill = new ItemAdvancedDrill();
advancedDrill = PoweredItem.createItem(ItemAdvancedDrill.class);
GameRegistry.registerItem(advancedDrill, "advancedDrill");
manuel = new ItemTechPda();
GameRegistry.registerItem(manuel, "techmanuel");
@ -117,7 +118,7 @@ public class ModItems {
upgrades = new ItemUpgrade();
GameRegistry.registerItem(upgrades, "upgrades");
cloakingDevice = new ItemCloakingDevice();
cloakingDevice = PoweredItem.createItem(ItemCloakingDevice.class);
GameRegistry.registerItem(cloakingDevice, "cloakingdevice");
// buckets

View file

@ -3,13 +3,15 @@ package techreborn.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import techreborn.api.power.IEnergyItemInfo;
import techreborn.client.TechRebornCreativeTab;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.PoweredItem;
public class ItemLapotronicOrb extends PoweredItem {
public class ItemLapotronicOrb extends Item implements IEnergyItemInfo{
public static final int maxCharge = ConfigTechReborn.LapotronicOrbMaxCharge;
public static final int tier = ConfigTechReborn.LithiumBatpackTier;

View file

@ -3,20 +3,26 @@ package techreborn.items.armor;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import techreborn.api.power.IEnergyItemInfo;
import techreborn.client.TechRebornCreativeTab;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.PoweredArmor;
import techreborn.powerSystem.PoweredItem;
public class ItemLapotronPack extends PoweredArmor {
import java.util.List;
public class ItemLapotronPack extends ItemArmor implements IEnergyItemInfo {
public static final int maxCharge = ConfigTechReborn.LapotronPackCharge;
public static final int tier = ConfigTechReborn.LapotronPackTier;
public double transferLimit = 100000;
public ItemLapotronPack(ArmorMaterial armormaterial, int par2, int par3) {
super(armormaterial, par2, par3);
public ItemLapotronPack() {
super(ItemArmor.ArmorMaterial.DIAMOND, 7, 1);
setCreativeTab(TechRebornCreativeTab.instance);
setUnlocalizedName("techreborn.lapotronpack");
setMaxStackSize(1);
@ -59,5 +65,29 @@ public class ItemLapotronPack extends PoweredArmor {
return tier;
}
@SuppressWarnings(
{"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
PoweredItem.setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
}

View file

@ -3,20 +3,26 @@ package techreborn.items.armor;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import techreborn.api.power.IEnergyItemInfo;
import techreborn.client.TechRebornCreativeTab;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.PoweredArmor;
import techreborn.powerSystem.PoweredItem;
public class ItemLithiumBatpack extends PoweredArmor {
import java.util.List;
public class ItemLithiumBatpack extends ItemArmor implements IEnergyItemInfo {
public static final int maxCharge = ConfigTechReborn.LithiumBatpackCharge;
public static final int tier = ConfigTechReborn.LithiumBatpackTier;
public double transferLimit = 10000;
public ItemLithiumBatpack(ArmorMaterial armorMaterial, int par3, int par4) {
super(armorMaterial, par3, par4);
public ItemLithiumBatpack() {
super(ItemArmor.ArmorMaterial.DIAMOND, 7, 1);
setMaxStackSize(1);
setUnlocalizedName("techreborn.lithiumbatpack");
setCreativeTab(TechRebornCreativeTab.instance);
@ -58,4 +64,28 @@ public class ItemLithiumBatpack extends PoweredArmor {
public int getStackTeir(ItemStack stack) {
return tier;
}
@SuppressWarnings(
{"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
PoweredItem.setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
}

View file

@ -5,17 +5,23 @@ import cpw.mods.fml.relauncher.SideOnly;
import ic2.api.item.ElectricItem;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
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 reborncore.common.util.TorchHelper;
import techreborn.api.power.IEnergyItemInfo;
import techreborn.client.TechRebornCreativeTab;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.PoweredPickaxe;
import techreborn.powerSystem.PoweredItem;
public class ItemAdvancedDrill extends PoweredPickaxe {
import java.util.List;
public class ItemAdvancedDrill extends ItemPickaxe implements IEnergyItemInfo {
public static final int maxCharge = ConfigTechReborn.AdvancedDrillCharge;
public int cost = 250;
@ -104,4 +110,28 @@ public class ItemAdvancedDrill extends PoweredPickaxe {
public int getStackTeir(ItemStack stack) {
return tier;
}
@SuppressWarnings(
{"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
PoweredItem.setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
}

View file

@ -3,16 +3,21 @@ package techreborn.items.tools;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.world.World;
import techreborn.api.power.IEnergyItemInfo;
import techreborn.client.TechRebornCreativeTab;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.PoweredItem;
public class ItemCloakingDevice extends PoweredItem {
import java.util.List;
public class ItemCloakingDevice extends Item implements IEnergyItemInfo {
public static int Teir = ConfigTechReborn.CloakingDeviceTier;
public static int MaxCharge = ConfigTechReborn.CloakingDeviceCharge;
public static int Limit = 100;
@ -27,8 +32,8 @@ public class ItemCloakingDevice extends PoweredItem {
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
if (canUseEnergy(ConfigTechReborn.CloakingDeviceEUTick, itemStack)) {
useEnergy(ConfigTechReborn.CloakingDeviceEUTick, itemStack);
if (PoweredItem.canUseEnergy(ConfigTechReborn.CloakingDeviceEUTick, itemStack)) {
PoweredItem.useEnergy(ConfigTechReborn.CloakingDeviceEUTick, itemStack);
player.setInvisible(true);
} else {
if (!player.isPotionActive(Potion.invisibility)) {
@ -91,5 +96,25 @@ public class ItemCloakingDevice extends PoweredItem {
+ "techreborn.cloakingdevice");
}
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
PoweredItem.setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
}

View file

@ -4,26 +4,32 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
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.util.DamageSource;
import net.minecraft.world.World;
import reborncore.common.util.TorchHelper;
import techreborn.api.power.IEnergyItemInfo;
import techreborn.client.TechRebornCreativeTab;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.PoweredPickaxe;
import techreborn.powerSystem.PoweredItem;
public class ItemOmniTool extends PoweredPickaxe {
import java.util.List;
public class ItemOmniTool extends ItemPickaxe implements IEnergyItemInfo {
public static final int maxCharge = ConfigTechReborn.OmniToolCharge;
public static final int tier = ConfigTechReborn.OmniToolTier;
public int cost = 100;
public int hitCost = 125;
public ItemOmniTool(ToolMaterial toolMaterial) {
super(toolMaterial);
public ItemOmniTool() {
super(ToolMaterial.EMERALD);
efficiencyOnProperMaterial = 13F;
setCreativeTab(TechRebornCreativeTab.instance);
setMaxStackSize(1);
@ -40,7 +46,7 @@ public class ItemOmniTool extends PoweredPickaxe {
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, Block block,
int par4, int par5, int par6, EntityLivingBase entityLiving) {
useEnergy(cost, stack);
PoweredItem.useEnergy(cost, stack);
return true;
}
@ -56,8 +62,8 @@ public class ItemOmniTool extends PoweredPickaxe {
@Override
public float getDigSpeed(ItemStack stack, Block block, int meta) {
if (canUseEnergy(cost, stack)) {
useEnergy(cost, stack);
if (PoweredItem.canUseEnergy(cost, stack)) {
PoweredItem.useEnergy(cost, stack);
return 5.0F;
}
@ -74,8 +80,8 @@ public class ItemOmniTool extends PoweredPickaxe {
@Override
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase attacker) {
if (canUseEnergy(hitCost, itemstack)) {
useEnergy(hitCost, itemstack);
if (PoweredItem.canUseEnergy(hitCost, itemstack)) {
PoweredItem.useEnergy(hitCost, itemstack);
entityliving.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 8F);
}
return false;
@ -118,4 +124,28 @@ public class ItemOmniTool extends PoweredPickaxe {
return 2;
}
@SuppressWarnings(
{"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
PoweredItem.setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
}

View file

@ -4,26 +4,30 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
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 reborncore.common.util.Color;
import techreborn.api.power.IEnergyItemInfo;
import techreborn.client.TechRebornCreativeTab;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.PoweredPickaxe;
import techreborn.powerSystem.PoweredItem;
import java.util.List;
public class ItemRockCutter extends PoweredPickaxe {
public class ItemRockCutter extends ItemPickaxe implements IEnergyItemInfo {
public static final int maxCharge = ConfigTechReborn.RockCutterCharge;
public int cost = 500;
public static final int tier = ConfigTechReborn.RockCutterTier;
public ItemRockCutter(ToolMaterial toolMaterial) {
super(toolMaterial);
public ItemRockCutter() {
super(Item.ToolMaterial.EMERALD);
setUnlocalizedName("techreborn.rockcutter");
setCreativeTab(TechRebornCreativeTab.instance);
setMaxStackSize(1);
@ -52,8 +56,8 @@ public class ItemRockCutter extends PoweredPickaxe {
@Override
public boolean canHarvestBlock(Block block, ItemStack stack) {
if (Items.diamond_pickaxe.canHarvestBlock(block, stack)) {
if (canUseEnergy(cost, stack)) {
useEnergy(cost, stack);
if (PoweredItem.canUseEnergy(cost, stack)) {
PoweredItem.useEnergy(cost, stack);
return true;
}
}
@ -110,4 +114,28 @@ public class ItemRockCutter extends PoweredPickaxe {
public int getStackTeir(ItemStack stack) {
return 2;
}
@SuppressWarnings(
{"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
PoweredItem.setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (PoweredItem.getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
}

View file

@ -1,199 +0,0 @@
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.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);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
//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
@Override
public Item getChargedItem(ItemStack itemStack) {
return this;
}
@Override
public Item getEmptyItem(ItemStack itemStack) {
return this;
}
@Override
public double getMaxCharge(ItemStack itemStack) {
return getMaxPower(itemStack);
}
@Override
public int getTier(ItemStack itemStack) {
return getStackTeir(itemStack);
}
@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
}

View file

@ -1,198 +1,49 @@
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;
import reborncore.jtraits.MixinFactory;
import techreborn.api.power.IEnergyInterfaceItem;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.traits.BasePowerTrait;
import techreborn.powerSystem.traits.EUItemPowerTrait;
import techreborn.powerSystem.traits.RFItemPowerTrait;
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 {
public abstract class PoweredItem {
@SuppressWarnings(
{"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
public static Item createItem(Class itemClass) throws IllegalAccessException, InstantiationException {
return (Item) MixinFactory.mixin(itemClass,BasePowerTrait.class, RFItemPowerTrait.class, EUItemPowerTrait.class).newInstance();
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
//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);
public static boolean canUseEnergy(double energy, ItemStack stack){
if(stack.getItem() instanceof IEnergyInterfaceItem){
return ((IEnergyInterfaceItem) stack.getItem()).canUseEnergy(energy, stack);
} else {
return false;
}
}
@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
@Override
public Item getChargedItem(ItemStack itemStack) {
return this;
}
@Override
public Item getEmptyItem(ItemStack itemStack) {
return this;
}
@Override
public double getMaxCharge(ItemStack itemStack) {
return getMaxPower(itemStack);
}
@Override
public int getTier(ItemStack itemStack) {
return getStackTeir(itemStack);
}
@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)) {
public static double useEnergy(double energy, ItemStack stack){
if(stack.getItem() instanceof IEnergyInterfaceItem){
return ((IEnergyInterfaceItem) stack.getItem()).useEnergy(energy, stack);
} else {
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)) {
public static void setEnergy(double energy, ItemStack stack){
if(stack.getItem() instanceof IEnergyInterfaceItem){
((IEnergyInterfaceItem) stack.getItem()).setEnergy(energy, stack);
}
}
public static double getEnergy(ItemStack stack){
if(stack.getItem() instanceof IEnergyInterfaceItem){
return ((IEnergyInterfaceItem) stack.getItem()).getEnergy(stack);
} else {
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
}

View file

@ -1,200 +0,0 @@
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.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import techreborn.api.power.IEnergyInterfaceItem;
import techreborn.config.ConfigTechReborn;
import java.util.List;
public abstract class PoweredPickaxe extends ItemPickaxe implements IEnergyInterfaceItem, IElectricItem, IEnergyContainerItem {
protected PoweredPickaxe(ToolMaterial toolMaterial) {
super(toolMaterial);
}
@SuppressWarnings(
{"rawtypes", "unchecked"})
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
double charge = (getEnergy(stack) / getMaxPower(stack));
return 1 - charge;
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
//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
@Override
public Item getChargedItem(ItemStack itemStack) {
return this;
}
@Override
public Item getEmptyItem(ItemStack itemStack) {
return this;
}
@Override
public double getMaxCharge(ItemStack itemStack) {
return getMaxPower(itemStack);
}
@Override
public int getTier(ItemStack itemStack) {
return getStackTeir(itemStack);
}
@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
}

View file

@ -0,0 +1,88 @@
package techreborn.powerSystem.traits;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import reborncore.jtraits.JTrait;
import techreborn.api.power.IEnergyInterfaceItem;
public abstract class BasePowerTrait extends JTrait<Item> implements IEnergyInterfaceItem {
@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 NBTTagCompound getOrCreateNbtData(ItemStack itemStack) {
NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound == null) {
tagCompound = new NBTTagCompound();
itemStack.setTagCompound(tagCompound);
}
return tagCompound;
}
}

View file

@ -0,0 +1,41 @@
package techreborn.powerSystem.traits;
import ic2.api.item.IElectricItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import reborncore.jtraits.JTrait;
import techreborn.api.power.IEnergyInterfaceItem;
public class EUItemPowerTrait extends JTrait<IEnergyInterfaceItem> implements IElectricItem {
@Override
public boolean canProvideEnergy(ItemStack itemStack) {
return _self.canAcceptEnergy(itemStack);
}
@Override
public Item getChargedItem(ItemStack itemStack) {
return (Item) _self;
}
@Override
public Item getEmptyItem(ItemStack itemStack) {
return (Item) _self;
}
@Override
public double getMaxCharge(ItemStack itemStack) {
return _self.getMaxPower(itemStack);
}
@Override
public int getTier(ItemStack itemStack) {
return _self.getStackTeir(itemStack);
}
@Override
public double getTransferLimit(ItemStack itemStack) {
return _self.getMaxTransfer(itemStack);
}
}

View file

@ -1,11 +1,58 @@
package techreborn.powerSystem.traits;
import cofh.api.energy.IEnergyContainerItem;
import net.minecraft.item.ItemStack;
import reborncore.jtraits.JTrait;
import techreborn.powerSystem.PoweredItem;
import techreborn.api.power.IEnergyInterfaceItem;
import techreborn.config.ConfigTechReborn;
import techreborn.powerSystem.PowerSystem;
public class RFItemPowerTrait extends JTrait<IEnergyInterfaceItem> implements IEnergyContainerItem {
public class RFItemPowerTrait extends JTrait<PoweredItem> {
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
if (!PowerSystem.RFPOWENET)
return 0;
if (!_self.canAcceptEnergy(container)) {
return 0;
}
maxReceive *= ConfigTechReborn.euPerRF;
int energyReceived = Math.min(getMaxEnergyStored(container) - getEnergyStored(container), Math.min((int) _self.getMaxTransfer(container) * ConfigTechReborn.euPerRF, maxReceive));
if (!simulate) {
_self.setEnergy(_self.getEnergy(container) + energyReceived, container);
}
return energyReceived / ConfigTechReborn.euPerRF;
}
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
if (!PowerSystem.RFPOWENET)
return 0;
if (!_self.canAcceptEnergy(container)) {
return 0;
}
maxExtract *= ConfigTechReborn.euPerRF;
int energyExtracted = Math.min(getEnergyStored(container), Math.min(maxExtract, maxExtract));
if (!simulate) {
_self.setEnergy(_self.getEnergy(container) - energyExtracted, container);
}
return energyExtracted / ConfigTechReborn.euPerRF;
}
@Override
public int getEnergyStored(ItemStack container) {
if (!PowerSystem.RFPOWENET)
return 0;
return ((int) _self.getEnergy(container) / ConfigTechReborn.euPerRF);
}
@Override
public int getMaxEnergyStored(ItemStack container) {
if (!PowerSystem.RFPOWENET)
return 0;
return ((int) _self.getMaxPower(container) / ConfigTechReborn.euPerRF);
}
}