Posted May 5, 20232 yr I am trying to make a GUI. It is supposed to replace the normal inventory. I made a keybind and such and here's the procedure when E is released: package net.the_typholorian.skilled.procedures; import net.the_typholorian.skilled.world.inventory.InventoryGUIMenu; import net.minecraftforge.server.ServerLifecycleHooks; import net.minecraftforge.network.NetworkHooks; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.Entity; import net.minecraft.world.MenuProvider; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.network.chat.Component; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.core.BlockPos; import io.netty.buffer.Unpooled; public class OpenInventoryProcedure { public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) { if (entity == null) return; if (entity instanceof Player _plr ? _plr.containerMenu instanceof InventoryGUIMenu : false) { if (entity instanceof Player _player) { _player.closeContainer(); } if (!world.isClientSide()) { MinecraftServer _mcserv = ServerLifecycleHooks.getCurrentServer(); if (_mcserv != null) _mcserv.getPlayerList().broadcastSystemMessage(Component.literal("close"), false); } } else if (!(entity instanceof Player _plr ? _plr.containerMenu instanceof InventoryGUIMenu : false)) { { if (entity instanceof ServerPlayer _ent) { BlockPos _bpos = new BlockPos(x, y, z); NetworkHooks.openScreen((ServerPlayer) _ent, new MenuProvider() { @Override public Component getDisplayName() { return Component.literal("InventoryGUI"); } @Override public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) { return new InventoryGUIMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(_bpos)); } }, _bpos); } } if (!world.isClientSide()) { MinecraftServer _mcserv = ServerLifecycleHooks.getCurrentServer(); if (_mcserv != null) _mcserv.getPlayerList().broadcastSystemMessage(Component.literal("open"), false); } } } } I added text messages for debugging. It opens the inventory just fine, but it does not close or send the message in chat. It can only close by pressing 'Escape', which closes all GUIs. Can somebody help me?
May 6, 20232 yr Author Found the issue. I think that the keybind does not work when the GUI is open. How to fix?
May 6, 20232 yr https://github.com/MinecraftForge/MinecraftForge/blob/9a25527a54011378c1a1e6b3b6dd0e90bd52fafb/src/main/java/net/minecraftforge/client/event/ScreenEvent.java#L847 Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
May 6, 20232 yr Author What do I do with it? Do I just put it in the ModKeyMappings.java? Edited May 6, 20232 yr by The Typholorian
May 6, 20232 yr Author New issue. I got the keybind to work, but I have an issue with the procedure. It opens the GUI, but closes it nearly instantly. I set it to run the procedure when the key gets released. Here's my procedure code: package net.the_typholorian.skilled.procedures; import net.the_typholorian.skilled.world.inventory.InventoryGUIMenu; import net.minecraftforge.server.ServerLifecycleHooks; import net.minecraftforge.network.NetworkHooks; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.Entity; import net.minecraft.world.MenuProvider; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.MinecraftServer; import net.minecraft.network.chat.Component; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.core.BlockPos; import io.netty.buffer.Unpooled; public class InventoryProcedureProcedure { public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) { if (entity == null) return; boolean Disabler = false; Disabler = false; if ((entity instanceof Player _plr ? _plr.containerMenu instanceof InventoryGUIMenu : false) && Disabler == false) { if (!world.isClientSide()) { MinecraftServer _mcserv = ServerLifecycleHooks.getCurrentServer(); if (_mcserv != null) _mcserv.getPlayerList().broadcastSystemMessage(Component.literal("close"), false); } if (entity instanceof Player _player) _player.closeContainer(); Disabler = true; } if (!(entity instanceof Player _plr ? _plr.containerMenu instanceof InventoryGUIMenu : false) && Disabler == false) { if (!world.isClientSide()) { MinecraftServer _mcserv = ServerLifecycleHooks.getCurrentServer(); if (_mcserv != null) _mcserv.getPlayerList().broadcastSystemMessage(Component.literal("open"), false); } { if (entity instanceof ServerPlayer _ent) { BlockPos _bpos = new BlockPos(x, y, z); NetworkHooks.openScreen((ServerPlayer) _ent, new MenuProvider() { @Override public Component getDisplayName() { return Component.literal("InventoryGUI"); } @Override public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) { return new InventoryGUIMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(_bpos)); } }, _bpos); } } Disabler = true; } } }
May 6, 20232 yr Author Update: I did some investigating and it is running twice. I thought it was running on server and client, and added some code to fix that but it wasn't the problem.
May 9, 20232 yr This is a bit messy and could be implemented so much easier and cleaner. Just create your own AbstractContainerMenu at this point and have your own AbstractContainerScreen, make sure you override the stillValid() method in your Menu class and do whatever logic you deem necessary to keep that container open for that player.
May 9, 20232 yr On 5/6/2023 at 3:37 PM, The Typholorian said: Update: I did some investigating and it is running twice. I thought it was running on server and client, and added some code to fix that but it wasn't the problem. It should run twice, it does logic on both sides.
May 12, 20232 yr Author But it runs the command twice, which opens it then closes it immediately. Can you give me some example code for what you mentioned?
May 12, 20232 yr 3 hours ago, The Typholorian said: But it runs the command twice, which opens it then closes it immediately. Can you give me some example code for what you mentioned? Create a new abstractcontainermenu, attach a screen to it, override isValid to return true with given logic, then call the menu wherever you seem it is fit.
May 12, 20232 yr https://docs.minecraftforge.net/en/latest/gui/menus/ Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.