diff --git a/NeoForge/src/main/java/dev/cammiescorner/camsbackpacks/neoforge/services/NFMenuHelper.java b/NeoForge/src/main/java/dev/cammiescorner/camsbackpacks/neoforge/services/NFMenuHelper.java index a69cc90..a42df05 100644 --- a/NeoForge/src/main/java/dev/cammiescorner/camsbackpacks/neoforge/services/NFMenuHelper.java +++ b/NeoForge/src/main/java/dev/cammiescorner/camsbackpacks/neoforge/services/NFMenuHelper.java @@ -1,10 +1,15 @@ package dev.cammiescorner.camsbackpacks.neoforge.services; import dev.cammiescorner.camsbackpacks.block.entity.BackpackBlockEntity; +import dev.cammiescorner.camsbackpacks.menu.BackpackMenu; import dev.cammiescorner.camsbackpacks.util.platform.service.MenuHelper; +import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.Container; import net.minecraft.world.MenuProvider; import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.inventory.ContainerLevelAccess; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.network.NetworkHooks; public class NFMenuHelper implements MenuHelper { @@ -17,4 +22,19 @@ public MenuProvider getMenuProvider(BackpackBlockEntity backpack) { public void openMenu(ServerPlayer player, MenuProvider menu, BackpackBlockEntity backpack) { NetworkHooks.openScreen(player, menu, buf -> backpack.writeInitMenuData(player, buf)); } + + @Override + public void openMenu(ServerPlayer serverPlayer, ItemStack backpackStack, Container inventory) { + BlockPos pos = serverPlayer.blockPosition(); + + NetworkHooks.openScreen(serverPlayer, new SimpleMenuProvider( + (syncId, playerInventory, player) -> new BackpackMenu(syncId, playerInventory, inventory, ContainerLevelAccess.create(player.level(), pos), pos, false), + backpackStack.getHoverName() + ), + buf -> { + buf.writeBlockPos(pos); + buf.writeBoolean(false); + } + ); + } } diff --git a/Quilt/src/main/java/dev/cammiescorner/camsbackpacks/quilt/services/QMenuHelper.java b/Quilt/src/main/java/dev/cammiescorner/camsbackpacks/quilt/services/QMenuHelper.java index 5b0509d..ce6afa8 100644 --- a/Quilt/src/main/java/dev/cammiescorner/camsbackpacks/quilt/services/QMenuHelper.java +++ b/Quilt/src/main/java/dev/cammiescorner/camsbackpacks/quilt/services/QMenuHelper.java @@ -4,6 +4,7 @@ import dev.cammiescorner.camsbackpacks.menu.BackpackMenu; import dev.cammiescorner.camsbackpacks.util.platform.service.MenuHelper; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; +import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; @@ -45,10 +46,11 @@ public void openMenu(ServerPlayer player, MenuProvider menu, BackpackBlockEntity @Override public void openMenu(ServerPlayer player, ItemStack backpackStack, Container inventory) { + BlockPos pos = player.blockPosition(); player.openMenu(new ExtendedScreenHandlerFactory() { @Override public void writeScreenOpeningData(ServerPlayer player, FriendlyByteBuf buf) { - buf.writeBlockPos(player.blockPosition()); + buf.writeBlockPos(pos); buf.writeBoolean(false); } @@ -59,7 +61,7 @@ public Component getDisplayName() { @Override public AbstractContainerMenu createMenu(int syncId, Inventory playerInventory, Player player) { - return new BackpackMenu(syncId, playerInventory, inventory, ContainerLevelAccess.create(player.level(), player.blockPosition()), player.blockPosition(), false); + return new BackpackMenu(syncId, playerInventory, inventory, ContainerLevelAccess.create(player.level(), pos), pos, false); } }); }