Started by
Obzor
on
Topic category: Help with Minecraft modding (Java Edition)
If the villager is unemployed, they GUI does not open.
If there is no chest on the horse, they GUI does not open.
How to implement it? When linking a GUI to an entity, it always opens by clicking the RMB.
I couldn't find a way to bind another key or make the opening conditional. The only thing I've managed is to auto-close the GUI after 1 tick, but it's flickering.
Edited by Obzor on Wed, 08/06/2025 - 13:47
In procedures under the advanced section, there is a block called "Cancel event that triggered global trigger"
You can use this to for instance make it as if you never right clicked on an entity IF a certain condition is or is not met. Therefore not opening the tied GUI. This block can only be used in a procedure with a global trigger however. Otherwise the only other way I know of is to yes close open gui after 1 tick..
Unfortunately event cancellation does not work with GUI. I also rummaged through the code, but I didn't find anything responsible for opening the GUI.
Anyway, thanks for the reply.
Yes but you don't want to/cant cancel opening GUI directly, in this case you want to cancel a right click that would in turn open a GUI. The cancel trigger block must be in the procedure that checks for your right click. Obviously add the conditions for when you want to cancel the trigger. I've used this for the same kinda thing, closing a GUI when clicking on a chest with certain NBT data.
I see what you mean now. Try creating a procedure that runs when a player right clicks on an entity, then simply add an IF statement underneath that, that checks if the entity is your custom entity, and if so, cancel event that triggered global trigger. Then you can add a condition that doesn't cancel right click on that entity if (insert condition here) up to you
If I translated it correctly, you meant this procedure.
Logically, it should cancel the opening of the entity GUI, but in practice it does nothing. I couldn't get this procedure to work, I guess I don't understand something.
At that time, the same procedure, but with blocks, is working.
I have yet to make my own custom entity so im just offering what I do know, sorry, but I do have one more idea! If you go into the generated code viewer and search through the (Entityname)Entity.java tab, IF you have a gui bound to the entity it will have a line that looks like this but with your custom name in it. Remove this section, save and lock the code to your entity and I cant imagine it would open the GUI anymore, as this is the code that handles the interaction. If you ever unlock the code and edit your entity in the future, you will need to redo this as mcreator will remake the code.
Yes, it works. It's a pity that every time you change an entity, you have to edit it manually, but the main thing is that it works, even if only that way.