Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.21.1] CustomIngredientPacketCodec always falls back. #4225

Open
MerchantPug opened this issue Nov 14, 2024 · 7 comments · Fixed by #4287
Open

[1.21.1] CustomIngredientPacketCodec always falls back. #4225

MerchantPug opened this issue Nov 14, 2024 · 7 comments · Fixed by #4287
Labels
bug Something isn't working

Comments

@MerchantPug
Copy link

MerchantPug commented Nov 14, 2024

Fabric Loader: 0.16.9
Fabric API: 0.108.0+1.21.1

Hello, I've found a bit of an edge case with the class I mentioned in the title.

Whenever a custom ingredient is attempted to be synced, it will always fall back.

I think that this might be because of the current supported ingredients set being cleared unconditionally.

@Inject(
at = {
// Normal target after writing
@At(
value = "INVOKE",
target = "Lnet/minecraft/network/codec/PacketCodec;encode(Ljava/lang/Object;Ljava/lang/Object;)V",
shift = At.Shift.AFTER,
by = 1
),
// In the catch handler in case some exception was thrown
@At(
value = "INVOKE",
target = "net/minecraft/network/packet/Packet.isWritingErrorSkippable()Z"
)
},
method = "encode(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/packet/Packet;Lio/netty/buffer/ByteBuf;)V"
)
private void releasePacketEncoder(ChannelHandlerContext channelHandlerContext, Packet<?> packet, ByteBuf byteBuf, CallbackInfo ci) {
CustomIngredientSync.CURRENT_SUPPORTED_INGREDIENTS.set(null);
}

@MerchantPug
Copy link
Author

If anybody is curious on how I found this. I was implementing an EMI plugin that required the custom ingredient data to be sent to the client, so that the remainder stack may be updated.

@PepperCode1
Copy link
Member

The mixin is correct and the set is supposed to be cleared unconditionally. CustomIngredientSync.CURRENT_SUPPORTED_INGREDIENTS is set before PacketCodec#encode is called and cleared right after encode is called. If there is an issue with syncing, this mixin is likely not the cause.

@PepperCode1
Copy link
Member

This may be because Ingredient.OPTIONAL_PACKET_CODEC is not patched at all by Fabric API, so if any mod uses it to sync an ingredient, custom ingredients will be ignored.

@Salandora
Copy link

I hope it's okay if I add this here, if not I can make a new issue for it.
I don't think this is fixed.

I'm investigating the issue currently because in the Sophisticated Storage port I need a CustomIngredient and also ran into this issue.

So far I found out that the EncoderHandler where the synced ingredients are stored is getting removed from the pipeline every so often.

In the EncoderHandler class the encode functions finally block calls into NetworkStateTransitionHandler.onEncoded and if the package that was sent has transitionsNetworkState return true, it removes the EncoderHandler from the channel pipeline.

Unfortunately before the recipes are being synced a ReadyC2S packet is sent and that has the transitionsNetworkState set to true.
So before ServerConfigurationNetworkHandler.onReady and further down the PlayerManager is called the EncoderHandler is already removed and with that the synced supported custom ingredients list.

This is a problem in 1.21.1 and I believe all the way to 1.21.4 but I only checked and debugged 1.21.1.

@PepperCode1
Copy link
Member

The linked commit was not backported to 1.21.1.

@Salandora
Copy link

I'm aware, I looked into the commit and wanted to backport it but quickly found out that the commit would not fix the issue.

As mentioned when the server is syncing the recipes with the client the list of supportedCustomIngredients is already lost due to the EncoderHandler being removed from the channel pipeline. Therefore the server is never even considering sending the Ingredients as CustomIngredients but always doing the fallback instead.

If you set a breakpoint in the ServerConfigurationNetworkHandler.onReady or PlayerManager.onPlayerConnect function and query the encoder pipeline you'll find that fabric_supportedCustomIngredients list is empty.
But at this point in time it should not be empty, it should at least have the built in custom ingredients in it.
So the client is never getting any serialized custom ingredient data.

I also tested it against 1.21.4 and it is affected by this too.

@PepperCode1
Copy link
Member

Thanks, good to know.

@PepperCode1 PepperCode1 reopened this Dec 21, 2024
@PepperCode1 PepperCode1 added the bug Something isn't working label Dec 21, 2024
Salandora added a commit to Salandora/fabric that referenced this issue Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants