GT5-Unofficial/src/main/java/gregtech/api/items/GT_CoolantCell_Item.java

71 lines
2.4 KiB
Java
Raw Normal View History

2015-04-23 16:14:22 +00:00
package gregtech.api.items;
import gregtech.api.GregTech_API;
2015-08-02 11:00:23 +00:00
import ic2.core.util.StackUtil;
2016-03-20 16:08:33 +00:00
import net.minecraft.entity.player.EntityPlayer;
2015-04-23 16:14:22 +00:00
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2015-08-02 11:00:23 +00:00
import net.minecraft.util.StatCollector;
2015-04-23 16:14:22 +00:00
2015-10-22 02:06:25 +00:00
import java.util.List;
2015-04-23 16:14:22 +00:00
public class GT_CoolantCell_Item
2015-10-22 02:06:25 +00:00
extends GT_Generic_Item {
protected int heatStorage;
public GT_CoolantCell_Item(String aUnlocalized, String aEnglish, int aMaxStore) {
super(aUnlocalized, aEnglish, null);
this.setMaxStackSize(1);
this.setMaxDamage(100);
setNoRepair();
this.heatStorage = aMaxStore;
this.setCreativeTab(GregTech_API.TAB_GREGTECH);
2015-04-23 16:14:22 +00:00
}
2015-10-22 02:06:25 +00:00
protected static int getHeatOfStack(ItemStack aStack) {
NBTTagCompound tNBT = aStack.getTagCompound();
if (tNBT == null) {
tNBT = new NBTTagCompound();
aStack.setTagCompound(tNBT);
}
return tNBT.getInteger("heat");
2015-04-23 16:14:22 +00:00
}
2015-10-22 02:06:25 +00:00
protected void setHeatForStack(ItemStack aStack, int aHeat) {
NBTTagCompound tNBT = aStack.getTagCompound();
if (tNBT == null) {
tNBT = new NBTTagCompound();
aStack.setTagCompound(tNBT);
}
tNBT.setInteger("heat", aHeat);
if (this.heatStorage > 0) {
double var4 = (double) aHeat / (double) this.heatStorage;
int var6 = (int) (aStack.getMaxDamage() * var4);
if (var6 >= aStack.getMaxDamage()) {
var6 = aStack.getMaxDamage() - 1;
}
aStack.setItemDamage(var6);
2015-10-22 00:47:13 +00:00
}
2015-04-23 16:14:22 +00:00
}
2015-10-22 02:06:25 +00:00
2016-03-20 16:08:33 +00:00
public void addAdditionalToolTips(List aList, ItemStack aStack, EntityPlayer aPlayer) {
super.addAdditionalToolTips(aList, aStack, aPlayer);
2015-10-22 02:06:25 +00:00
aList.add("Stored Heat: " + getHeatOfStack(aStack));
switch (getControlTagOfStack(aStack)) {
case 1:
aList.add(StatCollector.translateToLocal("ic2.reactoritem.heatwarning.line1"));
aList.add(StatCollector.translateToLocal("ic2.reactoritem.heatwarning.line2"));
}
2015-10-22 00:47:13 +00:00
}
2015-10-22 02:06:25 +00:00
public int getControlTagOfStack(ItemStack stack) {
NBTTagCompound nbtData = StackUtil.getOrCreateNbtData(stack);
return nbtData.getInteger("tag");
}
public void setControlTagOfStack(ItemStack stack, int tag) {
NBTTagCompound nbtData = StackUtil.getOrCreateNbtData(stack);
nbtData.setInteger("tag", tag);
2015-10-22 00:47:13 +00:00
}
2015-04-23 16:14:22 +00:00
}