-
Notifications
You must be signed in to change notification settings - Fork 755
/
ModFlux.java
82 lines (65 loc) · 2.5 KB
/
ModFlux.java
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 tconstruct.modifiers.tools;
import cofh.api.energy.IEnergyContainerItem;
import java.util.ArrayList;
import tconstruct.library.tools.ToolCore;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/* TE3 support */
public class ModFlux extends ModBoolean
{
public ArrayList<ItemStack> batteries = new ArrayList<ItemStack>();
public ModFlux()
{
super(new ItemStack[0], 9, "Flux", "\u00a7e", "");
}
@Override
public boolean matches (ItemStack[] input, ItemStack tool)
{
boolean battery = false;
if (input[0] != null)
{
for (ItemStack stack : batteries)
{
if (stack.itemID == input[0].itemID && input[0].getItem() instanceof IEnergyContainerItem)
{
battery = true;
}
}
return battery && canModify(tool, input);
}
if (input[1] != null)
{
for (ItemStack stack : batteries)
{
if (stack.itemID == input[1].itemID && input[1].getItem() instanceof IEnergyContainerItem)
{
battery = true;
}
return battery && canModify(tool, input);
}
}
return false;
}
@Override
public void modify (ItemStack[] input, ItemStack tool)
{
NBTTagCompound tags = tool.getTagCompound();
if (!tags.hasKey(key))
{
tags.setBoolean(key, true);
int modifiers = tags.getCompoundTag("InfiTool").getInteger("Modifiers");
modifiers -= 1;
tags.getCompoundTag("InfiTool").setInteger("Modifiers", modifiers);
int charge = 0;
if (input[0] != null && input[0].getItem() != null && input[0].getItem() instanceof IEnergyContainerItem && input[0].hasTagCompound())
charge = input[0].getTagCompound().getInteger("Energy");
if (input[1] != null && input[1].getItem() != null && input[1].getItem() instanceof IEnergyContainerItem && input[1].hasTagCompound())
charge = input[1].getTagCompound().getInteger("Energy");
tags.setInteger("Energy", charge);
tags.setInteger(key, 1);
addModifierTip(tool, "\u00a7eFlux");
ToolCore toolcore = (ToolCore) tool.getItem();
tool.setItemDamage(1 + (toolcore.getMaxEnergyStored(tool) - charge) * (tool.getMaxDamage() - 1) / toolcore.getMaxEnergyStored(tool));
}
}
}