blob: 8e918fad7e39cf5fce9892d19458cb66ce70d393 (
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
|
package tectech.mechanics.dataTransport;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import tectech.recipe.TTRecipeAdder;
public class InventoryDataPacket extends DataPacket<ItemStack[]> {
public InventoryDataPacket(ItemStack[] content) {
super(content);
}
public InventoryDataPacket(NBTTagCompound compound) {
super(compound);
}
@Override
protected ItemStack[] contentFromNBT(NBTTagCompound nbt) {
int count = nbt.getInteger("count");
if (count > 0) {
ArrayList<ItemStack> stacks = new ArrayList<>();
for (int i = 0; i < count; i++) {
ItemStack stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(Integer.toString(i)));
if (stack != null) {
stacks.add(stack);
}
}
return !stacks.isEmpty() ? stacks.toArray(TTRecipeAdder.nullItem) : null;
}
return null;
}
@Override
protected NBTTagCompound contentToNBT() {
NBTTagCompound compound = new NBTTagCompound();
if (content != null && content.length > 0) {
compound.setInteger("count", content.length);
for (int i = 0; i < content.length; i++) {
compound.setTag(Integer.toString(i), content[i].writeToNBT(new NBTTagCompound()));
}
}
return compound;
}
@Override
public boolean extraCheck() {
return true;
}
@Override
protected ItemStack[] unifyContentWith(ItemStack[] content) {
throw new NoSuchMethodError("Unavailable to unify item stack data packet");
}
@Override
public String getContentString() {
return "Stack Count: " + (content == null ? 0 : content.length);
}
}
|