-
Notifications
You must be signed in to change notification settings - Fork 497
/
StatementParameterItemStackExact.java
118 lines (101 loc) · 2.76 KB
/
StatementParameterItemStackExact.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package buildcraft.core.statements;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementMouseClick;
public class StatementParameterItemStackExact implements IStatementParameter {
protected ItemStack stack;
@Override
public IIcon getIcon() {
return null;
}
@Override
public ItemStack getItemStack() {
return stack;
}
@Override
public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse) {
if (stack != null) {
if (areItemsEqual(this.stack, stack)) {
if (mouse.getButton() == 0) {
this.stack.stackSize += (mouse.isShift()) ? 16 : 1;
if (this.stack.stackSize > 64) {
this.stack.stackSize = 64;
}
} else {
this.stack.stackSize -= (mouse.isShift()) ? 16 : 1;
if (this.stack.stackSize < 0) {
this.stack.stackSize = 0;
}
}
} else {
this.stack = stack.copy();
}
} else {
if (this.stack != null) {
if (mouse.getButton() == 0) {
this.stack.stackSize += (mouse.isShift()) ? 16 : 1;
if (this.stack.stackSize > 64) {
this.stack.stackSize = 64;
}
} else {
this.stack.stackSize -= (mouse.isShift()) ? 16 : 1;
if (this.stack.stackSize < 0) {
this.stack = null;
}
}
}
}
}
@Override
public void writeToNBT(NBTTagCompound compound) {
if (stack != null) {
NBTTagCompound tagCompound = new NBTTagCompound();
stack.writeToNBT(tagCompound);
compound.setTag("stack", tagCompound);
}
}
@Override
public void readFromNBT(NBTTagCompound compound) {
stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack"));
}
@Override
public boolean equals(Object object) {
if (object instanceof StatementParameterItemStackExact) {
StatementParameterItemStackExact param = (StatementParameterItemStackExact) object;
return areItemsEqual(stack, param.stack);
} else {
return false;
}
}
private boolean areItemsEqual(ItemStack stack1, ItemStack stack2) {
if (stack1 != null) {
return stack2 != null && stack1.isItemEqual(stack2) && ItemStack.areItemStackTagsEqual(stack1, stack2);
} else {
return stack2 == null;
}
}
@Override
public String getDescription() {
if (stack != null) {
return stack.getDisplayName();
} else {
return "";
}
}
@Override
public String getUniqueTag() {
return "buildcraft:stackExact";
}
@Override
public void registerIcons(IIconRegister iconRegister) {
}
@Override
public IStatementParameter rotateLeft() {
return this;
}
}