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
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
package ellpeck.actuallyadditions.items.base;
|
2015-07-07 20:20:24 +02:00
|
|
|
|
|
|
|
import cofh.api.energy.ItemEnergyContainer;
|
2015-12-03 20:15:07 +01:00
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
2015-07-07 20:20:24 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-12-03 20:15:07 +01:00
|
|
|
import ellpeck.actuallyadditions.creative.CreativeTab;
|
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
2015-07-07 20:20:24 +02:00
|
|
|
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;
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public abstract class ItemEnergy extends ItemEnergyContainer {
|
2015-07-07 20:20:24 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
private String name;
|
|
|
|
|
|
|
|
public ItemEnergy(int maxPower, int transfer, String name){
|
2015-07-07 20:20:24 +02:00
|
|
|
super(maxPower, transfer);
|
|
|
|
this.setHasSubtypes(true);
|
|
|
|
this.setMaxStackSize(1);
|
2015-12-03 20:15:07 +01:00
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
this.register();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void register(){
|
|
|
|
this.setUnlocalizedName(ModUtil.MOD_ID_LOWER+"."+this.getBaseName());
|
|
|
|
GameRegistry.registerItem(this, this.getBaseName());
|
|
|
|
if(this.shouldAddCreative()){
|
|
|
|
this.setCreativeTab(CreativeTab.instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean shouldAddCreative(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String getBaseName(){
|
|
|
|
return this.name;
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public boolean getShareTag(){
|
2015-07-07 20:20:24 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreated(ItemStack stack, World world, EntityPlayer player){
|
|
|
|
this.setEnergy(stack, 0);
|
|
|
|
}
|
|
|
|
|
2015-10-05 19:55:28 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
|
|
|
|
list.add(this.getEnergyStored(stack)+"/"+this.getMaxEnergyStored(stack)+" RF");
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:20:24 +02:00
|
|
|
@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);
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public boolean showDurabilityBar(ItemStack itemStack){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getDurabilityForDisplay(ItemStack stack){
|
|
|
|
double energyDif = getMaxEnergyStored(stack)-getEnergyStored(stack);
|
|
|
|
double maxAmount = getMaxEnergyStored(stack);
|
|
|
|
return energyDif/maxAmount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public boolean hasEffect(ItemStack stack, int pass){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:20:24 +02:00
|
|
|
public void setEnergy(ItemStack stack, int energy){
|
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
2015-10-03 10:16:18 +02:00
|
|
|
if(compound == null){
|
|
|
|
compound = new NBTTagCompound();
|
|
|
|
}
|
2015-07-07 20:20:24 +02:00
|
|
|
compound.setInteger("Energy", energy);
|
|
|
|
stack.setTagCompound(compound);
|
|
|
|
}
|
|
|
|
}
|