-
-
Notifications
You must be signed in to change notification settings - Fork 56
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] Use RegistryFriendlyByteBuf for extended menus #534
base: 1.21
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this cause any breaking changes? Since if other mods are already using this, then they may have to recompile their mod.
I'm not sure if this will be a breaking change, but I don't know exactly how to check it to confirm it or not 😅 What I can say for sure is that If the type is left as a // Overriding the ExtendedMenuProvider
@Override
public void saveExtraData(FriendlyByteBuf buffer) {
RegistryFriendlyByteBuf b2 = (RegistryFriendlyByteBuf) buffer;
ItemStack itemInHand = ItemHelper.getItemInHand(ownerPlayer);
ItemStack.STREAM_CODEC.encode(b2, itemInHand);
}
// During registration
public static final RegistrySupplier<MenuType<MyMenu>> MY_MENU = MENU_TYPES.register("my_menu", () -> MenuRegistry.ofExtended((id, inventory, buffer) -> {
RegistryFriendlyByteBuf b2 = (RegistryFriendlyByteBuf) buffer;
ItemStack itemInHand = ItemStack.STREAM_CODEC.decode(b2);
return new MyMenu(id, inventory, itemInHand);
})); This example works, but that will still require the proposed changes in fabric/MenuRegistryImpl.java so the same type of buffer is returned by all mod loaders (Forge and NeoForge already use Edit: I forgot to mention that this change may be required in 1.20.6 too, as I think the codec and buffer changes were made in that version, but I may be wrong. |
all Also, in Java bytecode, both a method's name and signature are used to figure out what method to call:
so this would probably break all mods that currently use this. |
I did a few tests on my side and I can confirm that only merging the changes from fabric/MenuRegistryImpl.java doesn't break mods and will continue to work without recompiling. Merging the changes in the other two files (MenuRegistry.java and ExtendedMenuProvider.java) breaks them. But as I mentioned, those changes are still necessary to fix the custom Architectury's implementation of extended menus for Fabric and make it behave like Forge and NeoForge. Should I edit this PR with something or is it OK the way it is right now? I'm just asking in case something is blocking it from being merged :) |
I don't think we can afford breaking changes right now, for now you can get the RegistryAccess from the ServerPlayer and create the RegistryFriendlyByteBuf in the consumer yourself, we can merge this change for the next major version so keep this PR open for now. |
Extended menus use
FriendlyByteBuf
, so they can't be used with StreamCodecs to serialize things as they require aRegistryFriendlyByteBuf
.Forge and NeoForge already use
RegistryFriendlyByteBuf
natively when callingplayer.openMenu
, but Fabric's implementation is more custom on the Architectury side and it creates aFriendlyByteBuf
.This PR changes all
FriendlyByteBuf
intoRegistryFriendlyByteBuf
in all places I've seen it related to extended menus.