CraftTweaker

CraftTweaker

186M Downloads

[1.20.1] CraftTweaker's recipe serializer resolves tags too early

embeddedt opened this issue ยท 1 comments

commented

Issue description

Newer versions of ModernFix include an optimization that is able to sync tag-backed Ingredients over the network using the tag ID instead of having to send the full list of item stacks. 1.20.1's packet handling is adjusted so that the tag packet will always be sent before the recipe packet. However, packet ordering only affects the order in which the packet handlers are run, not the order in which the packets are deserialized. This means that tags cannot safely be accessed from within the recipe deserializer itself, as they are not yet bound to the game registries.

Vanilla does not resolve the tag from within the serializer, it just unpacks the tag key. However, CraftTweaker's shapeless recipe serializer seems to resolve tags when it sees an ingredient with an Ingredient.TagValue, in the process of trying to create its own IIngredient (which fails).

[19:36:43] [Netty Epoll Client IO #0/WARN] [co.co.Connectivity/]: Decoding error for packet:class net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket
java.lang.RuntimeException: Error while converting ingredient: 'net.minecraft.world.item.crafting.Ingredient$TagValue@6422d044' to an IIngredient!
	at com.blamejared.crafttweaker.api.ingredient.IngredientConverter.lambda$fromTagList$5(IngredientConverter.java:83) ~[CraftTweaker-forge-1.20.1-14.0.57.jar%23151!/:14.0.57] {re:classloading}
	at java.util.Optional.orElseThrow(Optional.java:403) ~[?:?] {re:mixin}
	at com.blamejared.crafttweaker.api.ingredient.IngredientConverter.fromTagList(IngredientConverter.java:83) ~[CraftTweaker-forge-1.20.1-14.0.57.jar%23151!/:14.0.57] {re:classloading}
	at com.blamejared.crafttweaker.api.ingredient.IngredientConverter.fromIItemList(IngredientConverter.java:64) ~[CraftTweaker-forge-1.20.1-14.0.57.jar%23151!/:14.0.57] {re:classloading}
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[?:?] {}
	at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024) ~[?:?] {}
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?] {}
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?] {}
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:575) ~[?:?] {}
	at java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:260) ~[?:?] {}
	at java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:616) ~[?:?] {}
	at com.blamejared.crafttweaker.api.ingredient.IngredientConverter.fromIItemLists(IngredientConverter.java:52) ~[CraftTweaker-forge-1.20.1-14.0.57.jar%23151!/:14.0.57] {re:classloading}
	at com.blamejared.crafttweaker.api.ingredient.IngredientConverter.fromIngredient(IngredientConverter.java:44) ~[CraftTweaker-forge-1.20.1-14.0.57.jar%23151!/:14.0.57] {re:classloading}
	at com.blamejared.crafttweaker.api.ingredient.IIngredient.fromIngredient(IIngredient.java:368) ~[CraftTweaker-forge-1.20.1-14.0.57.jar%23151!/:14.0.57] {re:classloading}
	at com.blamejared.crafttweaker.api.recipe.serializer.CTShapelessRecipeSerializer.fromNetwork(CTShapelessRecipeSerializer.java:66) ~[CraftTweaker-forge-1.20.1-14.0.57.jar%23151!/:14.0.57] {re:classloading}
	at com.blamejared.crafttweaker.api.recipe.serializer.CTShapelessRecipeSerializer.m_8005_(CTShapelessRecipeSerializer.java:21) ~[CraftTweaker-forge-1.20.1-14.0.57.jar%23151!/:14.0.57] {re:classloading}
	at net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket.m_133647_(ClientboundUpdateRecipesPacket.java:45) ~[client-1.20.1-20230612.114412-srg.jar%23154!/:?] {re:classloading}

To fix the issue, the tags should not be resolved until after the deserialized recipe is made available to the main thread.

I will work around the issue in ModernFix by disabling the optimization when CraftTweaker is present, but this will likely increase RAM usage by 100+ MB in bigger packs that use it.

Steps to reproduce

Please see the linked GitHub issue below for steps on how to reproduce.

Script used

embeddedt/ModernFix#570

The crafttweaker.log file

N/A

Minecraft version

1.20.1

Modloader

Forge

Modloader version

47.4.0

CraftTweaker version

14.0.57

Other relevant information

No response

The latest.log file

N/A (stacktrace provided above)

commented

Closed by e18c48a