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
83
84
85
86
87
88
89
90
91
92
93
94
|
package gtPlusPlus.core.slots;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import gregtech.api.items.GT_MetaGenerated_Tool;
import gtPlusPlus.api.objects.Logger;
import ic2.api.info.Info;
import ic2.api.item.ElectricItem;
import ic2.api.item.IElectricItem;
public class SlotGtToolElectric extends SlotGtTool {
public int tier;
private ItemStack content;
public SlotGtToolElectric(final IInventory base, final int x, final int y, final int z, final int tier,
final boolean allowRedstoneDust) {
super(base, x, y, z);
this.tier = tier;
this.allowRedstoneDust = allowRedstoneDust;
}
public boolean accepts(final ItemStack stack) {
if (stack == null) {
return false;
}
if ((stack.getItem() == Items.redstone) && (!this.allowRedstoneDust)) {
return false;
}
return (Info.itemEnergy.getEnergyValue(stack) > 0.0D)
|| (ElectricItem.manager.discharge(stack, (1.0D / 0.0D), this.tier, true, true, true) > 0.0D);
}
public double discharge(final double amount, final boolean ignoreLimit) {
if (amount <= 0.0D) {
throw new IllegalArgumentException("Amount must be > 0.");
}
final ItemStack stack = this.get(0);
if (stack == null) {
return 0.0D;
}
double realAmount = ElectricItem.manager.discharge(stack, amount, this.tier, ignoreLimit, true, false);
if (realAmount <= 0.0D) {
realAmount = Info.itemEnergy.getEnergyValue(stack);
if (realAmount <= 0.0D) {
return 0.0D;
}
stack.stackSize -= 1;
if (stack.stackSize <= 0) {
this.put(0, null);
}
}
return realAmount;
}
public void setTier(final int tier1) {
this.tier = tier1;
}
public boolean allowRedstoneDust = true;
public ItemStack get() {
return this.get(0);
}
public ItemStack get(final int index) {
return this.content;
}
public void put(final ItemStack content) {
this.put(0, content);
}
public void put(final int index, final ItemStack content) {
this.content = content;
this.onChanged();
}
public void onChanged() {
}
@Override
public boolean isItemValid(final ItemStack itemstack) {
if ((itemstack.getItem() instanceof GT_MetaGenerated_Tool) || (itemstack.getItem() instanceof IElectricItem)) {
Logger.WARNING(itemstack.getDisplayName() + " is a valid Tool.");
return true;
}
Logger.WARNING(itemstack.getDisplayName() + " is not a valid Tool.");
return false;
}
}
|