How do i execute a command at an entity after some time? [closed]

Basically i want to make chickens drop feathers some times like they do with eggs. My idea was to have a scoreboard and a command that adds on that scoreboard then when it reaches a certain amount of time another command would spawn at the chicken the feather and finally another command that would reset the whole thing. The problem with this though is that this would make every single chicken in the world drop feathers at the exact same time so how do i do this and have the chickens having their own time, maybe one chicken will drop a feather after 5 mins and another would drop after 4 or 6?


Well, that's simples. In essence, we want to do three things:

  1. When a chicken spawns, assign it a random "drop time" value.
  2. Every second, all chickens have their "drop time" timers decreased by a second.
  3. When a chicken's "drop time" timer is 0, reset it, execute some stuff (make it drop a feather) and reset the timer to the chicken's "drop time" value.

Assigning "Drop Time" Values

Well, there's nothing fancy here. Just your usual trigger.

# Create your two variables.
scoreboard objectives create hasTimerValue dummy Has Timer Value
scoreboard objectives create timerValue dummy Drop Cycle Time

hasTimerValue would house a 1 or 0; whether or not a chicken has a timerValue assigned to it, and timerValue obviously is how long the timer starts at every time it resets.

Then, simply run this continously...

# Give a random chicken a drop time value.
scoreboard players set @e[sort=random,limit=1,scores={hasTimerValue=0}] timerValue 240 
scoreboard players set @e[sort=random,limit=1,scores={hasTimerValue=0}] timerValue 300 
scoreboard players set @e[sort=random,limit=1,scores={hasTimerValue=0}] timerValue 360 
scoreboard players set @e[sort=random,limit=1,scores={hasTimerValue=0}] timerValue 420 
# Set the 'hasTimerValue' flag to true to the chickens with a timer value.
scoreboard players set @e[scores={timerValue=1..}

Note: You can simplify it by simply just testing for timerValue being equal or less than 0 than to have a hasTimerValue flag.
Note: You'll want to reorder it, or have some sort of random selection. This is to simply illustrate. There are better ways to do it, such as this one.


Decrease All drop timers by 1.

Nothing fancy here either.

# Create new scoreboard for timer.
scoreboard objectives add dropTimer dummy Time until Drop
# Decrease Timer by One
scoreboard players remove @e[scores={hasTimerValue=1,dropTimer=1..}] 1

Do stuff when Timer is 0, then reset it.

This answer should show you how to change values by getting and setting a value of another thing. Nothing fancy here either with picking who to execute.

# Do stuff.
execute positioned as @e[scores={hasTimerValue=1,dropTimer=0}] Stuff
# Reset the timer back to whatever the original interval was.
scoreboard players operation @e[scores={hasTimerValue=1,dropTimer=0}] dropTimer = @e[scores={hasTimerValue=1,dropTimer=0},limit=1] timerValue

Replace Stuff with whatever you want to run.

execute positioned as <entity> <command> is like a /sudo for Minecraft entities without access to the usual Bukkit/admin stuff.