From 4f853bd0e1ba158f7820a96015bae2ea5ac6e003 Mon Sep 17 00:00:00 2001 From: Urkaz Date: Sun, 7 Jul 2024 04:36:50 +0200 Subject: [PATCH] Use RegistryFriendlyByteBuf for extended menus --- .../registry/menu/ExtendedMenuProvider.java | 4 ++-- .../dev/architectury/registry/menu/MenuRegistry.java | 7 ++++--- .../registry/menu/fabric/MenuRegistryImpl.java | 10 ++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/dev/architectury/registry/menu/ExtendedMenuProvider.java b/common/src/main/java/dev/architectury/registry/menu/ExtendedMenuProvider.java index 9616ce7ee..313ecbb48 100644 --- a/common/src/main/java/dev/architectury/registry/menu/ExtendedMenuProvider.java +++ b/common/src/main/java/dev/architectury/registry/menu/ExtendedMenuProvider.java @@ -19,9 +19,9 @@ package dev.architectury.registry.menu; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.world.MenuProvider; public interface ExtendedMenuProvider extends MenuProvider { - void saveExtraData(FriendlyByteBuf buf); + void saveExtraData(RegistryFriendlyByteBuf buf); } diff --git a/common/src/main/java/dev/architectury/registry/menu/MenuRegistry.java b/common/src/main/java/dev/architectury/registry/menu/MenuRegistry.java index 8891844fc..765546ed5 100644 --- a/common/src/main/java/dev/architectury/registry/menu/MenuRegistry.java +++ b/common/src/main/java/dev/architectury/registry/menu/MenuRegistry.java @@ -25,6 +25,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.MenuProvider; @@ -50,10 +51,10 @@ private MenuRegistry() { * @param provider The {@link MenuProvider} that provides the menu * @param bufWriter That writer that sends extra data for {@link MenuType} created with {@link MenuRegistry#ofExtended(ExtendedMenuTypeFactory)} */ - public static void openExtendedMenu(ServerPlayer player, MenuProvider provider, Consumer bufWriter) { + public static void openExtendedMenu(ServerPlayer player, MenuProvider provider, Consumer bufWriter) { openExtendedMenu(player, new ExtendedMenuProvider() { @Override - public void saveExtraData(FriendlyByteBuf buf) { + public void saveExtraData(RegistryFriendlyByteBuf buf) { bufWriter.accept(buf); } @@ -183,6 +184,6 @@ public interface ExtendedMenuTypeFactory { * @param buf The {@link FriendlyByteBuf} for the menu to provide extra data * @return A new {@link T} that extends {@link AbstractContainerMenu} */ - T create(int id, Inventory inventory, FriendlyByteBuf buf); + T create(int id, Inventory inventory, RegistryFriendlyByteBuf buf); } } diff --git a/fabric/src/main/java/dev/architectury/registry/menu/fabric/MenuRegistryImpl.java b/fabric/src/main/java/dev/architectury/registry/menu/fabric/MenuRegistryImpl.java index c012b53be..81454c513 100644 --- a/fabric/src/main/java/dev/architectury/registry/menu/fabric/MenuRegistryImpl.java +++ b/fabric/src/main/java/dev/architectury/registry/menu/fabric/MenuRegistryImpl.java @@ -27,13 +27,13 @@ import io.netty.buffer.Unpooled; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.networking.v1.PacketByteBufs; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.core.RegistryAccess; +import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.server.level.ServerPlayer; @@ -51,7 +51,8 @@ public static void openExtendedMenu(ServerPlayer player, ExtendedMenuProvider pr player.openMenu(new ExtendedScreenHandlerFactory() { @Override public byte[] getScreenOpeningData(ServerPlayer player) { - FriendlyByteBuf buf = PacketByteBufs.create(); + RegistryAccess access = player.registryAccess(); + RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), access); provider.saveExtraData(buf); byte[] bytes = ByteBufUtil.getBytes(buf); buf.release(); @@ -77,7 +78,8 @@ public static MenuType of(SimpleMenuTypeFac public static MenuType ofExtended(ExtendedMenuTypeFactory factory) { return new ExtendedScreenHandlerType<>((syncId, inventory, data) -> { - FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(data)); + RegistryAccess access = inventory.player.registryAccess(); + RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(data), access); T menu = factory.create(syncId, inventory, buf); buf.release(); return menu;