ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/base/ItemEnergy.java

112 lines
3.2 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("ItemEnergy.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.items.base;
import cofh.api.energy.ItemEnergyContainer;
2016-01-08 20:51:03 +01:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2016-03-18 18:38:39 +01:00
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
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;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
2015-12-19 10:30:39 +01:00
public abstract class ItemEnergy extends ItemEnergyContainer{
2016-05-19 20:05:12 +02:00
private final String name;
public ItemEnergy(int maxPower, int transfer, String name){
super(maxPower, transfer);
this.setHasSubtypes(true);
this.setMaxStackSize(1);
this.name = name;
this.register();
}
private void register(){
2016-03-18 18:38:39 +01:00
ItemUtil.registerItem(this, this.getBaseName(), this.shouldAddCreative());
2016-01-08 16:52:53 +01:00
2016-01-08 20:51:03 +01:00
this.registerRendering();
}
protected String getBaseName(){
return this.name;
}
2015-12-19 10:30:39 +01:00
public boolean shouldAddCreative(){
return true;
}
2016-02-01 17:49:55 +01:00
protected void registerRendering(){
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this), this.getRegistryName(), "inventory");
2016-02-01 17:49:55 +01:00
}
@Override
2015-10-03 10:19:40 +02:00
public boolean getShareTag(){
return true;
}
@Override
public void onCreated(ItemStack stack, World world, EntityPlayer player){
this.setEnergy(stack, 0);
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool){
list.add(this.getEnergyStored(stack)+"/"+this.getMaxEnergyStored(stack)+" RF");
}
2016-02-01 17:49:55 +01:00
@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack stack){
return false;
}
@Override
@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){
2016-05-02 17:46:53 +02:00
double energyDif = this.getMaxEnergyStored(stack)-this.getEnergyStored(stack);
double maxAmount = this.getMaxEnergyStored(stack);
2015-10-03 10:19:40 +02:00
return energyDif/maxAmount;
}
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();
}
compound.setInteger("Energy", energy);
stack.setTagCompound(compound);
}
}