From 9d16a7e5cdfbf4bd3f48dc432a3a200566a4e923 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 17 Feb 2021 23:18:15 -0500 Subject: [PATCH] Fix not being able to extract items with network counts > 127 from terminal --- .../phycon/networking/C2STerminalRequestItem.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/shadowfacts/phycon/networking/C2STerminalRequestItem.kt b/src/main/kotlin/net/shadowfacts/phycon/networking/C2STerminalRequestItem.kt index 1d28025..b364d51 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/networking/C2STerminalRequestItem.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/networking/C2STerminalRequestItem.kt @@ -26,7 +26,14 @@ object C2STerminalRequestItem: ServerReceiver { val buf = PacketByteBufs.create() buf.writeIdentifier(terminal.world!!.registryKey.value) buf.writeBlockPos(terminal.pos) - buf.writeItemStack(stack) + + // Force the count of the stack to be 1 before serializing for the network because + // PacketByteBuf serializes the stack count as a byte. Otherwise counts > 127 will result in + // an overflow and be negative on the receiving side. + val stackCopy = stack.copy() + stackCopy.count = 1 + buf.writeItemStack(stackCopy) + buf.writeVarInt(amount) return ClientPlayNetworking.createC2SPacket(CHANNEL, buf) }