TerraFirmaCraft

TerraFirmaCraft

2M Downloads

1.18.2 Incompatibility with Alchemistry on MP

pehala opened this issue ยท 4 comments

commented

Summary

When running TFC with Alchemistry on multiplayer, I cannot join in with client due to
io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: Unknown recipe serializer minecraft:
It does happen only on multiplayer, I was not able to reproduce it on singleplayer.
I am not sure if TFC or Alchemistry is causing the error, so I created two identical issues in both projects SmashingMods/Alchemistry#258

What happens

The server showed that the client did successfully connect however it seemed it disconnected right after (after the first packet probably).
The client with debug mode shows a little bit more but not much:
debug (copy).log

Mods

  • alchemistry-1.18.2-2.1.2.jar
  • chemlib-1.18.2-2.0.11_340666_4035005.jar
  • framework-0.2.4-1.18.2_549225_3926054.jar
  • Patchouli-1.18.2-71.1_306770_3846086.jar
  • TerraFirmaCraft-Forge-1.18.2-2.1.15-beta.jar
  • Forge 40.1.80
commented

Can you go into the TFC common config on both the client and server and set enableNetworkDebugging = true, then try again? It might have a more informative error / crash log.

commented

Alright, I found the issue.

  • Alchemistry recipes have ItemStacks with values that are greater than 127 (Byte.MAX_VALUE), for instance in this recipe
  • Alchemistry syncs these item stacks using FriendlyByteBuf.writeItemStack() and FriendlyByteBuf.readItem
  • These methods write the item stack's count as a byte
  • When received on client, these item stacks now read a negative count (since writing 128 as a byte turns it into -128)
  • The client receives this recipe as producing "-128 air"

This is a bug in alchemistry. Their recipes are being synced incorrectly, and appear to be empty on client.

So why does this occur with TFC? Well, because we sync two additional bytes if the stack sent is not empty. So when we sync a stack, we write two additional bytes (because "128 silicon dioxide" is not empty) but then due to the bug in Alchemistry, when we receive "-128 air" on client, that's an empty stack - so we don't attempt to read these two bytes.

We might be able to safeguard this a bit better. As there is an explicit "empty" flag that is sent ahead of the item stack. However that would also be a more invasive mixin on our part. But, it wouldn't cause a full blown network issue when another mod tries to sync a item stack incorrectly. Alchemistry should fix their network serialization though.

commented

It sure did yield a much better error:
io.netty.handler.codec.DecoderException: java.lang.IllegalStateException: Recipe 'alchemistry:dissolver/ores/quartz' of type 'alchemistry:dissolver' with serializer 'alchemistry:dissolver' didn't pass parity check! [Parity: Expected 68 bytes | Read 66 bytes]
debug.log

commented

Chould be fixed in SmashingMods/Alchemistry@f378e1c. Thanks for reporting the issue!