Posted July 6, 20223 yr @SubscribeEvent public static void gauntletGUI(final TickEvent.PlayerTickEvent event) { PlayerEntity player = event.player; ItemStack stack = event.player.getMainHandItem(); if (keyOpenGauntlet.isDown() && keyOpenGauntlet.consumeClick() && stack.getItem().equals(ItemInit.INFINITY_GAUNTLET.get())) { Main.NETWORK.sendToServer(new InputMessage(stack)); } } This is the event public static void handle(InputMessage message, Supplier<NetworkEvent.Context> contextSupplier) { NetworkEvent.Context context = contextSupplier.get(); context.enqueueWork( () -> { ServerPlayerEntity player = context.getSender(); INamedContainerProvider ncp = new InfinityGauntlet.InfinityGauntletContainerProvider(player.getMainHandItem().getItem(), message.stack); NetworkHooks.openGui(player, ncp); } ); context.setPacketHandled(true); } This opens the GUI. So the problem is that when I press the key in this case is B the GUI opens and instantly closes. https://github.com/Manueh333/Marvel-MOD
July 6, 20223 yr are you sure stillValid returns true, use debugger to check? because of the error you described I would say it returns false
July 6, 20223 yr Author Ok, so I have put this code and it doesn't work, I have to forms of opening the GUI one is on the useOn void of the item and this form work but the other form is to press 'B' but when the GUI opens it closes. If I put "return true;" in stillValid the GUI didn't close so it's obvious that the problem is there but I dont understand why @Override public boolean stillValid(PlayerEntity player) { return (player.getMainHandItem().equals(heldItem)); }
July 6, 20223 yr stillValid() runs on the server, where are you storing "heldItem" when you press B? 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.
July 6, 20223 yr ItemStack does not override equals, this means the == operator is used, you need to use IForgeItemStack#equals (requires an ItemStack and a boolean) or you check the Item of the ItemStack, therefore you can use a instanceof check, equals or the == operator depends on your purpose
July 6, 20223 yr Author 14 minutes ago, warjort said: stillValid() runs on the server, where are you storing "heldItem" when you press B? There is defined the heldItem https://github.com/Manueh333/Marvel-MOD/blob/1.16.5/src/main/java/manueh/marvel_themod/common/containers/InfinityGauntletContainer.java#L42 This is the one that works https://github.com/Manueh333/Marvel-MOD/blob/1.16.5/src/main/java/manueh/marvel_themod/common/items/InfinityGauntlet.java#L259-L260 This don't work https://github.com/Manueh333/Marvel-MOD/blob/1.16.5/src/main/java/manueh/marvel_themod/client/ClientEvents.java#L88 https://github.com/Manueh333/Marvel-MOD/blob/5adbb1ca06ed62bd4625c505cd9495566204670a/src/main/java/manueh/marvel_themod/core/network/message/InputMessage.java#L34-L45
July 6, 20223 yr 4 minutes ago, Grookey said: There is defined the heldItem https://github.com/Manueh333/Marvel-MOD/blob/1.16.5/src/main/java/manueh/marvel_themod/common/containers/InfinityGauntletContainer.java#L42 This is the one that works https://github.com/Manueh333/Marvel-MOD/blob/1.16.5/src/main/java/manueh/marvel_themod/common/items/InfinityGauntlet.java#L259-L260 16 minutes ago, Luis_ST said: ItemStack does not override equals, this means the == operator is used, you need to use IForgeItemStack#equals (requires an ItemStack and a boolean) or you check the Item of the ItemStack, therefore you can use a instanceof check, equals or the == operator depends on your purpose this is the issue 5 minutes ago, Grookey said: This don't work is the code called, use debugger to check
July 6, 20223 yr Author 8 minutes ago, Luis_ST said: ItemStack does not override equals, this means the == operator is used, you need to use IForgeItemStack#equals (requires an ItemStack and a boolean) or you check the Item of the ItemStack, therefore you can use a instanceof check, equals or the == operator depends on your purpose I dont understand what you mean, can you make an example pls 12 minutes ago, Luis_ST said: is the code called, use debugger to check yeah the code is called
July 6, 20223 yr 33 minutes ago, Grookey said: I dont understand what you mean, can you make an example pls when exactly should the player be able to open the container? please be as detailed as possible 33 minutes ago, Grookey said: yeah the code is called is the Packet received on server and how did you test if it works? Edited July 6, 20223 yr by Luis_ST
July 6, 20223 yr Author 8 minutes ago, Luis_ST said: is the Packet received on server and how did you test if it works? I tested it with a breakpoint and pressing B at the game 8 minutes ago, Luis_ST said: when exactly should the player be able to open the container? please be as detailed as possible You said I have to use a IForgeItemStack#equals with a ItemStack and a boolean so how? Edited July 6, 20223 yr by Grookey
July 6, 20223 yr You want to retrieve the held item on the server. Instead you are retrieving it on the client which will not be the same item stack as the held item on the server. It will be a copy. So == will be false. But I think you actually just need the following return (player.getMainHandItem().sameItem(heldItem)); to check the items are the same type. You are not interested in the stack count or tags? 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.
July 6, 20223 yr Author 3 minutes ago, warjort said: You are not interested in the stack count or tags? Actually, yes the Item is a container that contains items so its important that But I tried and It worked Also it would be good to make the item cant be moved in the inventory when my GUI is opened is there any form to do this? Edited July 6, 20223 yr by Grookey
July 6, 20223 yr Then use one of the ItemStack.matches() or the equals(ItemStack, boolean) defined by the IForgeItemStack interface. I am not sure of your requirements so you will have to figure out which one yourself 🙂 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.
July 6, 20223 yr Author 24 minutes ago, warjort said: return (player.getMainHandItem().sameItem(heldItem)); I thought that I need the tags but not because the item contain items if you add or remove some of the item it closes the GUI and the content of the container is not updated so I finally used this code Any of the codes worked for me because when i change a Item of the inside of the container it closes and not updates, and like after the problem is only when I use the key B to open the GUI @SubscribeEvent public static void gauntletGUI(TickEvent.PlayerTickEvent event) { PlayerEntity player = event.player; ItemStack stack = event.player.getItemBySlot(EquipmentSlotType.MAINHAND); if (keyOpenGauntlet.isDown() && keyOpenGauntlet.consumeClick() && stack.getItem().equals(ItemInit.INFINITY_GAUNTLET.get())) { Main.NETWORK.sendToServer(new InputMessage(stack)); } } Edited July 6, 20223 yr by Grookey
July 7, 20223 yr KeyBindings are client side only, you need to use TickEvent.ClientTickEvent instead why did you call KeyBinding#consumeClick, you should only check KeyBinding#isDown? last but not least i would recommend you to check the Item also on server side (in the handle method of the Message), since you should never trust the client
July 7, 20223 yr Author 43 minutes ago, Luis_ST said: TickEvent.ClientTickEvent instead In ClickTickEvent i dont know how to get the player 43 minutes ago, Luis_ST said: i would recommend you to check the Item also on server side (in the handle method of the Message) public static void handle(InputMessage message, Supplier<NetworkEvent.Context> contextSupplier) { NetworkEvent.Context context = contextSupplier.get(); ServerPlayerEntity player = context.getSender(); ItemStack gauntlet = player.getMainHandItem(); if(gauntlet.getItem() instanceof InfinityGauntlet) { INamedContainerProvider ncp = new InfinityGauntlet.InfinityGauntletContainerProvider((InfinityGauntlet) gauntlet.getItem(), gauntlet); NetworkHooks.openGui(player, ncp); context.setPacketHandled(false); } } You were right I check the item on the server and this code works Thanks
July 7, 20223 yr 2 minutes ago, Grookey said: In ClickTickEvent i dont know how to get the player on client you always can use Minecraft.getInstance(), then you be able to get the local player
July 7, 20223 yr Author 5 minutes ago, Luis_ST said: Minecraft.getInstance() @SubscribeEvent public static void gauntletGUI(final TickEvent.ClientTickEvent event) { PlayerEntity player = Minecraft.getInstance().player; if(player != null) { ItemStack stack = player.getMainHandItem(); if (keyOpenGauntlet.isDown() && stack.getItem().equals(ItemInit.INFINITY_GAUNTLET.get())) { Main.NETWORK.sendToServer(new InputMessage(stack)); } } } It works. Thanks!
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.