How to make GUI open when crouching and right-clicking (While holding a specific item)

Started by Lilyofluck on Sat, 08/20/2022 - 14:20

Topic category: Help with MCreator software

Last seen on 02:47, 23. Aug 2022
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How to make GUI open when crouching and right-clicking (While holding a specific item)
Sat, 08/20/2022 - 14:20

I'm trying to make a wand and magic system where you can cast spells with a right click and change the spells you can cast by crouching and right-clicking. The problem is GUI opens whenever I right-click and hold the wand (Because the GUI is linked to the item). I don't know if I can change how I can open GUIs.

Last seen on 02:47, 23. Aug 2022
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
We can close any open GUI…
Sat, 08/20/2022 - 14:35

We can close any open GUI whenever you right-click unless you are crouching. Though, if anyone has a better way I would greatly appreciate

Last seen on 07:52, 21. Nov 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
It would take custom code to…
Sun, 08/21/2022 - 16:36

It would take custom code to do this, it is easy though. I hope mcreator adds options like these in the future.

I have done things similar to this in some of my mods. You have to add this line of code in a certain spot so it only opens the bound inventory when the player is/isn't sneaking.

 

Open your WandItemNameItem.java file in the editor.

Step 1: Find the below class.

@Override
public InteractionResultHolder<ItemStack> use(Level world, Player entity, InteractionHand hand) {

In this class change one line of code.

 

Step 2: Change this line

if (entity instanceof ServerPlayer serverPlayer) {

To this if you want it to open when they aren't pressing shift

Example 1:

if ((entity instanceof ServerPlayer serverPlayer) && (!entity.isShiftKeyDown())) {

Or this if you want it to open when they are pressing shift

Example 2:

if ((entity instanceof ServerPlayer serverPlayer) && (entity.isShiftKeyDown())) {

Just make sure to do this when you are done creating the item!

 

Step 3: In Spell Cast Procedure, check for the opposite of above

For example: If you want your inventory to only open when you are sneaking use the second example. Then in your Spell Casting procedure, check if the entity is not sneaking before the rest of your procedure.

 

I just tested this is in a test pack and it works fine. Alternatively you could edit the gui but the item is much easier as it is just one line of code and you could literally copy and paste it from right here into that spot.

Last seen on 23:18, 27. Aug 2022
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
In the procedure for the…
Sun, 08/21/2022 - 16:59

In the procedure for the wand casting, put an if block that checks if the player is crouching (There is a block that checks for this)

If they ARE crouching, open the GUI.

If not, then cast the current spell.

Last seen on 07:52, 21. Nov 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Mr_Arrhythmia that won't…
Sun, 08/21/2022 - 17:10

Mr_Arrhythmia that won't bind the gui to the item though, the way I described does, so it will keep items in their slots if he is using items.

Last seen on 02:47, 23. Aug 2022
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Well, I already save the…
Sun, 08/21/2022 - 20:36

Well, I already save the items in the GUI in NBT tags so I can check if they are the right item (To cast a spell). So the one up top could work. Thanks for the info though. MCreator definitely needs the ability to specify when to open GUIs.