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) }