-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathItemStack.java
More file actions
136 lines (108 loc) · 3.74 KB
/
ItemStack.java
File metadata and controls
136 lines (108 loc) · 3.74 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package cam72cam.mod.item;
import cam72cam.mod.entity.Player;
import cam72cam.mod.serialization.TagCompound;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.fluids.FluidUtil;
/** Wrapper around Minecraft ItemStack (Item, count, NBT) */
public class ItemStack {
public static final ItemStack EMPTY = new ItemStack(net.minecraft.item.ItemStack.EMPTY);
public final net.minecraft.item.ItemStack internal;
/** Wrap Minecraft ItemStack. Do not use directly */
public ItemStack(net.minecraft.item.ItemStack internal) {
this.internal = internal;
}
/** Deserialize from tag */
public ItemStack(TagCompound nbt) {
this(new net.minecraft.item.ItemStack(nbt.internal));
}
/** Construct from customItem */
public ItemStack(CustomItem item, int i) {
this(new net.minecraft.item.ItemStack(item.internal, i));
}
/** Tag attached to this stack */
public TagCompound getTagCompound() {
if (internal.getTagCompound() == null) {
internal.setTagCompound(new TagCompound().internal);
}
return new TagCompound(internal.getTagCompound());
}
/** Tag attached to this stack */
public void setTagCompound(TagCompound data) {
internal.setTagCompound(data.internal);
}
public ItemStack copy() {
return new ItemStack(internal.copy());
}
/** Serialize */
public TagCompound toTag() {
return new TagCompound(internal.serializeNBT());
}
/** Items in this stack */
public int getCount() {
return internal.getCount();
}
/** Set the items in this stack */
public void setCount(int count) {
internal.setCount(count);
}
/** Human readable name */
public String getDisplayName() {
return internal.getDisplayName();
}
/** Is count zero? */
public boolean isEmpty() {
return internal.isEmpty();
}
/** Reduce stack size by i */
public void shrink(int i) {
internal.shrink(i);
}
/** Compares: item, count, damage, data */
@Override
public boolean equals(Object other) {
return other instanceof ItemStack && net.minecraft.item.ItemStack.areItemStacksEqual(internal, ((ItemStack)other).internal);
}
/** Compares: item, damage */
public boolean is(ItemStack stack) {
return net.minecraft.item.ItemStack.areItemsEqual(internal, stack.internal);
}
public boolean is(Fuzzy fuzzy) {
return fuzzy.matches(this);
}
public boolean is(CustomItem item) {
return item.internal == this.internal.getItem();
}
/** Is a bucket or similar item */
public boolean isFluidContainer() {
return FluidUtil.getFluidHandler(internal) != null;
}
/** Can be burnt in a furnace */
public boolean isFlammable() {
return getBurnTime() != 0;
}
/** Ticks item will burn in a furnace (Make sure you multiply by count to get total burn time) */
public int getBurnTime() {
return TileEntityFurnace.getItemBurnTime(internal);
}
/** Max count of the stack */
public int getLimit() {
return internal.getMaxStackSize();
}
/** Is the item this type of tool? */
public boolean isValidTool(ToolType tool) {
return internal.getItem().getToolClasses(internal).contains(tool.toString());
}
@Override
public String toString() {
return internal.toString();
}
/** Increase the damage counter on the item by the player */
public void damageItem(int i, Player player) {
internal.damageItem(i, player.internal);
}
/** Completely null out the tag compound */
public void clearTagCompound() {
internal.setTagCompound(null);
}
}