Started by
rozaly
on
Topic category: Help with Minecraft modding (Java Edition)
I'm trying to make a weapon that has an ability that is activated when using a custom keybind. I've been able to do everything so far, except, when activating the ability, if the cooldown ends while the weapon isn't in your main hand, the cooldown gets bugged and lasts forever. What do I do?
Edited by rozaly on Thu, 03/26/2026 - 19:40
I would recommend making the cooldown a number tag instead of logic. Then check if it is = 0 instead of if it is false, setting it to 200 instead of setting it to true, and removing the wait block and resetting it to false from this procedure.
Then create a second procedure that activates on item tick update, where if the tag is > 0, setting it to itself - 1. This second procedure will act as an item-based cooldown that will allow the item to cooldown from anywhere in the player's inventory.
Alternatively (and this may not be what you want, and it would only work for a shared cooldown across all abilities and all items of the same type), Minecraft has a built-in cooldown system like what is used for ender pearls, you could use that instead of data tags. MCreator has a procedure block to set an item on cooldown and I'm pretty sure one that checks if the item is on cooldown, so you could use those. An upside is that it would display a visual cooldown overlay on the item, downsides are that you would need to have one cooldown for all abilities, and it would also prevent right-click uses of the item. And another thing about the vanilla Minecraft cooldown mechanic is that it is player-based rather than item-based, so if you have two of the same item, they would both go on cooldown.
If you like the first method but want the player-based cooldowns (so a hotbar full of the same item only lets someone use the ability once within the normal cooldown time, rather then being able to spam it nine times), you could use a global variable with the scope of player persistent of player lifetime, instead of using a number tag. And for the second procedure, have it use the player tick global trigger, rather than the item's in inventory tick trigger.
Hopefully this helps.
I'm not sure if I quite understood you, but it didn't work. I couldn't find an "item tick update" option either, so I put the second procedure into the "when tool in inventory tick" of the weapon.
Yes, "when tool in inventory tick" is the trigger I meant to say, I just forgot the name.
It looks like you almost have it, just one thing you need to change in the second procedure. Instead of setting the tag to 1, there is a procedure block that lets you do mathematical operations (I think it defaults to +, but you can click on the center of it to change it). You can use that procedure block to set the tag to itself (by using another "Get custom data number tag" block, the operation block set to -, and the 1 you are already using).
Is this what you meant? It's working but there's two issues
1. It makes the model of the sword really buggy like it's constantly being used and lowered down when the cooldown is on.
2. The time it takes to recover is random for some reason, it's always slightly or a lot longer than the 200 ticks.
Yes, that's what I meant.
It's been a little while since I've done something like this, so I forgot about the first problem, but, yes, that's happened whenever I've done this method as well. Maybe you could try using the player variable method I mentioned in my earlier comment, but that would make the cooldown per-player rather than per-item, which might not be what you want.
The second problem is really weird. I'm not sure what's causing it, but it could be a client-server desynchronization issue, because those cause a lot of weird bugs. If it is a client-server desynchronization issue, it can be solved by putting the whole procedure in an if statement that checks "If" "Not" "Is provided world client-side". But if that doesn't solve it, I don't know how to fix it.
I think the second issue is because this is all depending on "item in main hand", so it doesn't count down when the item is not in your main hand.
I don't wanna use the player variable method because I'm trying to make weapons with two abilities with separate cooldowns, so having the entire item go on cooldown wouldn't work. If you figure out a fix for any of this, please let me know
I fixed the second issue by changing "item in main hand" to "provided itemstack" in the second procedure. Now the only issue is the model bugging out.
I realize now that I didn't explain it well, but you could use multiple player variables, one for each ability. They would be player-based rather than item-based, but you could still have multiple abilities, unlike the vanilla Minecraft cooldown mechanic.
Could you tell me how to do that then? I can't figure out how to make fix any of this right now
Never mind, I figured it out by just switching all of them from item to entity procedures. Thank you for all your help, seriously. You're amazing
No problem, I'm glad I was able to help.