2015-08-29 14:33:25 +02:00
|
|
|
|
/*
|
|
|
|
|
* This file ("ItemEnergy.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD> 2015 Ellpeck
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-07 20:20:24 +02:00
|
|
|
|
package ellpeck.actuallyadditions.items;
|
|
|
|
|
|
|
|
|
|
import cofh.api.energy.ItemEnergyContainer;
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public abstract class ItemEnergy extends ItemEnergyContainer{
|
|
|
|
|
|
2015-09-23 21:34:12 +02:00
|
|
|
|
public ItemEnergy(int maxPower, int transfer){
|
2015-07-07 20:20:24 +02:00
|
|
|
|
super(maxPower, transfer);
|
|
|
|
|
this.setHasSubtypes(true);
|
|
|
|
|
this.setMaxStackSize(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public double getDurabilityForDisplay(ItemStack stack){
|
|
|
|
|
double energyDif = getMaxEnergyStored(stack)-getEnergyStored(stack);
|
|
|
|
|
double maxAmount = getMaxEnergyStored(stack);
|
|
|
|
|
return energyDif/maxAmount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean showDurabilityBar(ItemStack itemStack){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreated(ItemStack stack, World world, EntityPlayer player){
|
|
|
|
|
this.setEnergy(stack, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public boolean hasEffect(ItemStack stack, int pass){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean getShareTag(){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
|
public void getSubItems(Item item, CreativeTabs tabs, List list){
|
|
|
|
|
ItemStack stackFull = new ItemStack(this);
|
|
|
|
|
this.setEnergy(stackFull, this.getMaxEnergyStored(stackFull));
|
|
|
|
|
list.add(stackFull);
|
|
|
|
|
|
|
|
|
|
ItemStack stackEmpty = new ItemStack(this);
|
|
|
|
|
this.setEnergy(stackEmpty, 0);
|
|
|
|
|
list.add(stackEmpty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnergy(ItemStack stack, int energy){
|
|
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
|
|
|
|
if(compound == null) compound = new NBTTagCompound();
|
|
|
|
|
compound.setInteger("Energy", energy);
|
|
|
|
|
stack.setTagCompound(compound);
|
|
|
|
|
}
|
|
|
|
|
}
|