1
1
package logisticspipes .network .packets ;
2
2
3
3
import net .minecraft .entity .player .EntityPlayer ;
4
- import net .minecraft .item .Item ;
5
4
import net .minecraft .item .ItemStack ;
5
+ import net .minecraft .nbt .NBTTagCompound ;
6
6
import net .minecraft .tileentity .TileEntity ;
7
7
import net .minecraft .util .NonNullList ;
8
8
9
- import lombok .Getter ;
10
- import lombok .Setter ;
11
-
12
9
import logisticspipes .blocks .crafting .LogisticsCraftingTableTileEntity ;
13
10
import logisticspipes .network .abstractpackets .CoordinatesPacket ;
14
11
import logisticspipes .network .abstractpackets .ModernPacket ;
21
18
@ StaticResolve
22
19
public class NEISetCraftingRecipe extends CoordinatesPacket {
23
20
24
- @ Getter
25
- @ Setter
26
21
private NonNullList <ItemStack > stackList = NonNullList .withSize (9 , ItemStack .EMPTY );
27
22
28
23
public NEISetCraftingRecipe (int id ) {
29
24
super (id );
30
25
}
31
26
27
+ public NonNullList <ItemStack > getStackList () {
28
+ return this .stackList ;
29
+ }
30
+
32
31
@ Override
33
32
public void processPacket (EntityPlayer player ) {
34
33
TileEntity tile = getTileAs (player .world , TileEntity .class );
@@ -47,37 +46,16 @@ public ModernPacket template() {
47
46
@ Override
48
47
public void writeData (LPDataOutput output ) {
49
48
super .writeData (output );
50
-
51
- output .writeInt (stackList .size ());
52
-
53
- for (int i = 0 ; i < stackList .size (); i ++) {
54
- final ItemStack stack = stackList .get (i );
55
-
56
- if (!stack .isEmpty ()) {
57
- output .writeByte (i );
58
- output .writeInt (Item .getIdFromItem (stack .getItem ()));
59
- output .writeInt (stack .getCount ());
60
- output .writeInt (stack .getItemDamage ());
61
- output .writeNBTTagCompound (stack .getTagCompound ());
62
- }
63
- }
64
- output .writeByte (-1 ); // mark packet end
49
+ output .writeCollection (stackList , (out , stack ) -> out .writeNBTTagCompound (stack .isEmpty () ? null : stack .writeToNBT (new NBTTagCompound ())));
65
50
}
66
51
67
52
@ Override
68
53
public void readData (LPDataInput input ) {
69
54
super .readData (input );
70
-
71
- byte index = input .readByte ();
72
-
73
- while (index != -1 ) { // read until the end
74
- final int itemID = input .readInt ();
75
- int stackSize = input .readInt ();
76
- int damage = input .readInt ();
77
- ItemStack stack = new ItemStack (Item .getItemById (itemID ), stackSize , damage );
78
- stack .setTagCompound (input .readNBTTagCompound ());
79
- stackList .set (index , stack );
80
- index = input .readByte (); // read the next slot
81
- }
55
+ NonNullList <ItemStack > readList = input .readNonNullList (inp -> {
56
+ NBTTagCompound tag = inp .readNBTTagCompound ();
57
+ return tag == null ? null : new ItemStack (tag );
58
+ }, ItemStack .EMPTY );
59
+ if (readList != null ) stackList = readList ;
82
60
}
83
61
}
0 commit comments