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-1.21.4] Custom Ingredients sync fix #4322

Merged
merged 4 commits into from
Dec 30, 2024

Conversation

Salandora
Copy link
Contributor

Fixes #4225.
The synced fabric_supportedCustomIngredients list was lost due to minecraft removing the EncoderHandler before joining the world.
Therefore all recipes were synced with the fallback method instead.
This PR fixes that issue by storing the list in the ClientConnection class instead and making use of the packet_handler pipeline which points to the ClientConnection instance.

@MerchantPug could you maybe test this fix against your implementation?

@modmuss50
Copy link
Member

Hi, got a few questions: is there a reason why this targets 1.21.1 and not 1.21.4? Could this be a backport of #4287 instead? Ill have to have a proper look with the code in front of me as well.

@Salandora
Copy link
Contributor Author

I targeted 1.21.1 because my Sophisticated Storage port is still on 1.21.1 so I would need the fix there. I want to make 2 more PRs against .3 and .4 just wanted to get the okay first that the changes are okay and not do the work twice.

#4287 is unfortunately not a fix to the issue, I tried to explain my findings in #4225.

I can look into backporting #4276 and what applies from #4287 and either add them here or make a new PR for it.
The thing with #4287 is that in 1.21.1 for example there is no Ingredient.OPTIONAL_PACKET_CODEC so all of that part does not apply.

Yeah please take your time, I would like to have MerchantPug confirm the fix works for them too so we can be sure that there isn't a second bug.

fabric-recipe-api-v1/build.gradle Outdated Show resolved Hide resolved
@@ -26,4 +26,6 @@
*/
public interface SupportedIngredientsPacketEncoder {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface should be renamed to SupportedIngredientsClientConnection to match the name of the class it's actually implemented on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change that and also fix the comment as it was still on EncoderHandler

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to change the indentation of the whole file. All Fabric API mixin json files use 2 spaces for indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, will undo that

@@ -51,7 +40,11 @@ public void fabric_setSupportedCustomIngredients(Set<Identifier> supportedCustom
method = "encode(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/packet/Packet;Lio/netty/buffer/ByteBuf;)V"
)
private void capturePacketEncoder(ChannelHandlerContext channelHandlerContext, Packet<?> packet, ByteBuf byteBuf, CallbackInfo ci) {
CustomIngredientSync.CURRENT_SUPPORTED_INGREDIENTS.set(fabric_supportedCustomIngredients);
ChannelHandler client = channelHandlerContext.pipeline().get("packet_handler");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: client as a variable name here doesn't make sense to me. I think a simple channelHandler would be fine.

CustomIngredientSync.CURRENT_SUPPORTED_INGREDIENTS.set(fabric_supportedCustomIngredients);
ChannelHandler client = channelHandlerContext.pipeline().get("packet_handler");

if (client != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to replace this check with client instanceof SupportedIngredientsPacketEncoder.

@MerchantPug
Copy link

Will test this soonish.

@MerchantPug
Copy link

Before PR

Before

After PR

After

Looks like it works for me! 👍

@modmuss50 modmuss50 changed the title [1.21.1] Custom Ingredients sync fix [1.21.1-1.21.4] Custom Ingredients sync fix Dec 29, 2024
@modmuss50 modmuss50 added bug Something isn't working priority:high High priority PRs that need review and work now. Review these first. labels Dec 29, 2024
@modmuss50 modmuss50 self-requested a review December 29, 2024 16:49
@modmuss50 modmuss50 added the merge me please Pull requests that are ready to merge label Dec 29, 2024
@modmuss50 modmuss50 merged commit 248df81 into FabricMC:1.21.1 Dec 30, 2024
modmuss50 pushed a commit that referenced this pull request Dec 30, 2024
* Fix customIngredients sync (#4225)

* Add client side test for custom ingredients sync

* Fixed styling issues and missing license header

* Applied requested changes and styling fixes

(cherry picked from commit 248df81)
modmuss50 pushed a commit that referenced this pull request Dec 30, 2024
* Fix customIngredients sync (#4225)

* Add client side test for custom ingredients sync

* Fixed styling issues and missing license header

* Applied requested changes and styling fixes

(cherry picked from commit 248df81)
(cherry picked from commit 1572dc3)
@vico93
Copy link

vico93 commented Dec 30, 2024

dumb question but does this changes the behavior i reported in #4170 in any way?

@Salandora
Copy link
Contributor Author

@vico93 yes and no, the recipe book will still not work with this.

But your client side is now aware of custom ingredients again meaning that if REI has support for custom ingredients it should work but from my own testings with REI I at least need to write a custom TransferHandler, unfortunately I'm not sure if this is required for you too.

EMI is a bit nicer in that regard as I only needed to override the recipe and let EMI know that it needs to use a ListIngredient but for that I need to know about the current recipe and its custom ingredient on the client side,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working merge me please Pull requests that are ready to merge priority:high High priority PRs that need review and work now. Review these first.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants