aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/items/GT_CoolantCell_Item.java
blob: fe56ffc310e7021bf66c084e45016a098cb2fec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package gregtech.api.items;

import gregtech.api.GregTech_API;
import ic2.core.util.StackUtil;

import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;

public class GT_CoolantCell_Item
  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);
  }
  
  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);
    }
  }
  
  public void addAdditionalToolTips(List aList, ItemStack aStack)
  {
    super.addAdditionalToolTips(aList, aStack);
    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"));
    }
  }
  
  protected static int getHeatOfStack(ItemStack aStack)
  {
    NBTTagCompound tNBT = aStack.getTagCompound();
    if (tNBT == null)
    {
      tNBT = new NBTTagCompound();
      aStack.setTagCompound(tNBT);
    }
    return tNBT.getInteger("heat");
  }
  
  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);
  }
  
}