r/MinecraftCommands • • 4d ago

Help | Java 26.3 Cooldown

Heyo! Anyone know how to put a cooldown on a spear when you left click with it? I tried the command below while in survival but it didnt give a cooldown :T

/give @.a iron_spear[enchantments={lunge:2},use_cooldown={seconds:10}]

6 Upvotes

5 comments sorted by

1

u/thedemontuanmc 2d ago

use_cooldown only fires when the item is used (right click), and the spear's jab (where Lunge triggers) is an attack, so it never applies there.

For a cooldown on the left-click attack you can use the attack charge instead: minimum_attack_charge=1.0 means the jab only goes through when the attack indicator is full, and a very low attack speed makes it take ~10 seconds to fill:

/give @s iron_spear[enchantments={lunge:2},minimum_attack_charge=1.0,attribute_modifiers=[{type:"attack_speed",id:"spear_cd",amount:-3.9,operation:"add_value",slot:"mainhand"},{type:"attack_damage",id:"spear_dmg",amount:4,operation:"add_value",slot:"mainhand"}]]

Player base attack speed is 4, so -3.9 leaves 0.1 attacks per second = 10 s. Setting attribute_modifiers replaces the spear's default ones, so add the damage back yourself (tune the 4). Side effect: the attack indicator shows the cooldown, which is kind of nice.

1

u/Adventurous-Cat1357 1d ago

this is actually pretty cool to keep in mind, and I would probably use this in the future for something else but it doesn't work in my case because the cooldown resets every time you pull out the spear. I think I would know a way to do it but it requires detecting when a player left clicks the a spear which I have no idea how to do :T

1

u/Adventurous-Cat1357 1d ago

Edit: I actually ended up having an interaction entity that is constantly in front only when holding a spear and then I did some more stuff and I got it to work :D

1

u/Ericristian_bros Command Experienced 1d ago

The thing is that what you are asking is hard unless you replace the logic of the spear enchantment to use scoreboard timers or other method since attribute swapping will allows players to bypass any methods involving an external entity or an attribute

1

u/Ok_Message_6051 Command Rookie 3d ago

I also once wondered about the cooldown for equipment. Unfortunately, the mechanics aren’t designed for that, and it’s not possible to implement it properly. The only thing I came up with is to replace the item with an consumable one at the right moment, which will restore the original item after consumption. But this method requires a mandatory right‑click to “reload” the item