Skip to content

Commit 950b305

Browse files
committed
Fix read/write in NEISetCraftingRecipe
1 parent ea46dde commit 950b305

File tree

3 files changed

+16
-37
lines changed

3 files changed

+16
-37
lines changed

common/logisticspipes/gui/popup/GuiRecipeImport.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ protected void renderGuiBackground(int mouseX, int mouseY) {
179179
protected void actionPerformed(GuiButton button) {
180180
int id = button.id;
181181
if (id == 0) {
182-
NonNullList<ItemStack> stackList = NonNullList.withSize(9, ItemStack.EMPTY);
182+
NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
183+
NonNullList<ItemStack> stackList = packet.getStackList();
183184
int i = 0;
184185
for (Canidates canidate : grid) {
185186
if (canidate == null) {
@@ -188,8 +189,7 @@ protected void actionPerformed(GuiButton button) {
188189
}
189190
stackList.set(i++, canidate.order.get(canidate.pos).makeNormalStack());
190191
}
191-
NEISetCraftingRecipe packet = PacketHandler.getPacket(NEISetCraftingRecipe.class);
192-
MainProxy.sendPacketToServer(packet.setStackList(stackList).setBlockPos(tile.getPos()));
192+
MainProxy.sendPacketToServer(packet.setBlockPos(tile.getPos()));
193193
exitGui();
194194
} else if (id == 1) {
195195
MainProxy.sendPacketToServer(PacketHandler.getPacket(FindMostLikelyRecipeComponents.class).setContent(list).setTilePos(tile));
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package logisticspipes.network.packets;
22

33
import net.minecraft.entity.player.EntityPlayer;
4-
import net.minecraft.item.Item;
54
import net.minecraft.item.ItemStack;
5+
import net.minecraft.nbt.NBTTagCompound;
66
import net.minecraft.tileentity.TileEntity;
77
import net.minecraft.util.NonNullList;
88

9-
import lombok.Getter;
10-
import lombok.Setter;
11-
129
import logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity;
1310
import logisticspipes.network.abstractpackets.CoordinatesPacket;
1411
import logisticspipes.network.abstractpackets.ModernPacket;
@@ -21,14 +18,16 @@
2118
@StaticResolve
2219
public class NEISetCraftingRecipe extends CoordinatesPacket {
2320

24-
@Getter
25-
@Setter
2621
private NonNullList<ItemStack> stackList = NonNullList.withSize(9, ItemStack.EMPTY);
2722

2823
public NEISetCraftingRecipe(int id) {
2924
super(id);
3025
}
3126

27+
public NonNullList<ItemStack> getStackList() {
28+
return this.stackList;
29+
}
30+
3231
@Override
3332
public void processPacket(EntityPlayer player) {
3433
TileEntity tile = getTileAs(player.world, TileEntity.class);
@@ -47,37 +46,16 @@ public ModernPacket template() {
4746
@Override
4847
public void writeData(LPDataOutput output) {
4948
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())));
6550
}
6651

6752
@Override
6853
public void readData(LPDataInput input) {
6954
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;
8260
}
8361
}

src/main/java/network/rs485/logisticspipes/util/LPDataIOWrapper.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ public <T> NonNullList<T> readNonNullList(IReadListObject<T> reader, @Nonnull T
692692

693693
NonNullList<T> list = NonNullList.withSize(size, fillItem);
694694
for (int i = 0; i < size; i++) {
695-
list.set(i, reader.readObject(this));
695+
T obj = reader.readObject(this);
696+
if (obj != null) list.set(i, obj);
696697
}
697698
return list;
698699
}

0 commit comments

Comments
 (0)