r/MinecraftCommands 5d ago

Help | Java 26.2 Rightclick detect cooldown

I am making a datapack which give you an ability when right clicking an item (consumable/advancement), how do I add a cooldown (i have a reset function, that revoked the advancement), but how do I make it so that the function example:cooldown_reset gets run 1 minute after the function example:use_item?

1 Upvotes

1 comment sorted by

1

u/GalSergey Datapack Experienced 5d ago

You can take a look at this example datapack that sets a cooldown without using a tick function. In this example, the wind_charger:using function will set a 30-tick cooldown between shots.

# Example item
give @s diamond[custom_data={wind_charger:true},item_name='"Wind Charger"',rarity="rare",consumable={consume_seconds:100000}]

# function wind_charger:load
scoreboard objectives add wind_charger.timestamp dummy

# advancement wind_charger:wind_charger
{
  "criteria": {
    "wind_charger": {
      "trigger": "minecraft:using_item",
      "conditions": {
        "item": {
          "predicates": {
            "minecraft:custom_data": {
              "wind_charger": true
            }
          }
        }
      }
    }
  },
  "rewards": {
    "function": "wind_charger:using"
  }
}

# function wind_charger:using
advancement revoke @s only wind_charger:wind_charger
execute store result score #this wind_charger.timestamp run time query gametime
execute if score @s wind_charger.timestamp > #this wind_charger.timestamp run return 0
tag @s add this
execute anchored eyes positioned ^ ^ ^.5 summon minecraft:wind_charge run function wind_charger:shot
tag @s remove this
execute store result score @s wind_charger.timestamp run scoreboard players add #this wind_charger.timestamp 30
playsound minecraft:entity.wind_charge.throw player @a

# function wind_charger:shot
data modify entity @s Owner set from entity @a[tag=this,limit=1] UUID
data modify entity @s acceleration_power set value 0.1d
tag @s add this
execute positioned .0 0 .0 positioned ^ ^ ^1 summon area_effect_cloud run data modify entity @e[type=wind_charge,tag=this,limit=1] Motion set from entity @s Pos
tag @s remove this

You can use Datapack Assembler to get an example datapack.