How to make an armor piece have a toggle for a buff that it gives

Started by blahblahbal on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make an armor piece have a toggle for a buff that it gives

Alright, so I've got an armor piece that gives Night Vision, and I want to make it have a toggle so you can turn the Night Vision off without taking the piece off. Right now I'm thinking it's gonna need a global variable and some custom code, but not entirely sure how to make that global variable. As it works now, I think it's setting the boolean variable (global, defined in another file) to false always unless you release the keybinding I've made, even though I have it setting "toggle = !toggle" in the code, which should swap from true to false or false to true when you release the keybinding.

Joined Jun 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Just make 2 keybinds with…
Tue, 07/06/2021 - 22:04

Just make 2 keybinds with the same buttons. so on the first key, just do a procedure for an ''on key pressed'' trigger like this: https://prnt.sc/193xg0o.

In the second key, just do it like this: https://prnt.sc/193xrw5.

I didn't really understand your question, I hope I helped!

Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ah, the thing I'm trying to…
Tue, 07/06/2021 - 22:21

Ah, the thing I'm trying to do is a helmet piece that allows you to have permanent night vision. What I want to do is make it so this effect has a toggle using a keybind. So if you turn it off, your night vision goes away. But if you turn it on, you have permanent night vision until you turn it off. Not sure if that made any more sense or not haha.

I would suggest only one…
Wed, 07/07/2021 - 07:39

I would suggest only one keybind for turning on/off, no need for making it harder and splitting in two. It's enough to make one procedure for one key, just with "ifs", somehow like this:

If [night vision = true]
-> night vision = false
If [night vision = false]
-> night vision = true

Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Yeah that's what I have…
Wed, 07/07/2021 - 17:18

Yeah that's what I have currently, except it's simpler and it doesn't work lol. I have "nightVision = !nightVision" but it's just setting it to false all the time somehow unless you press the keybind.

Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It's actually a custom…
Wed, 07/07/2021 - 18:41

It's actually a custom element plus a code-edited procedure. I can screenshot it if you want, though. I used the custom element to declare a global variable so that it can be saved, then in the "keybind released" thing, I have it doing the "nightVision = !nightVision" piece of code so it will swap the true to a false or false to a true whenever the keybind is released.

Here are screenshots of the code: https://imgur.com/a/S84GTrL

Basically what I'm doing is running a player tick update to apply the night vision only if the flag is true.

I think you could just use…
Thu, 07/08/2021 - 00:55

I think you could just use NBT tags for it, not sure if global variables are needed, especially as I found out they are causing problems from time to time.
And I'm pretty sure it can be done easily without messing around with code, but I would need to try it myself to be completely sure. If using NBT tags won't help, I can try to do that to see if it works and guide you, if so. I'm complete noob on code, so unfortunately I have no idea on how it works from that :D

Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'd appreciate that, if you…
Thu, 07/08/2021 - 02:08

I'd appreciate that, if you can yeah. Let me know if what you do works haha.

Joined Jan 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Nevermind, I figured it out…
Thu, 07/08/2021 - 16:06

Nevermind, I figured it out haha. Was actually pretty easy.

Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If i can interfere, I would…
Wed, 05/22/2024 - 16:51

If i can interfere, I would also like to make a night vision goggles with keybind toggle but working with Trinkets Mod