TransWikia.com

Run a command block once every day

Arqade Asked by Arya Man on May 5, 2021

I created a device which gives out diamonds when a lever is pulled. The code is: setblock ~ ~5 ~ minecraft:diamond_ore destroy

I want this to run on repeat and give out a diamond everyday or every half-day.

It’s 1.16.5.

One Answer

First I would summon an armor stand to keep count of a scoreboard.

/summon armor_stand ~ ~ ~ {Invisible:1b,Invulnerable:1b,NoGravity:1b,CustomName:'{"text":"timer"}'}

Then I'd create a timer scoreboard.

/scoreboard objectives add timer dummy

Have a command block add 1 to this every tick.

/scoreboard players add @e[type=armor_stand,name=timer] timer 1

And calculate the time you want in ticks (20 ticks/s). For 1 real life day that would be 20x60x60x24, which is 1.728.000.

Then place the block exactly 1 tick before the timer is at the right time.

/execute if entity @e[type=armor_stand,name=timer,scores={timer=1727999..1727999}] run setblock ~ ~5 ~ minecraft:diamond_ore destroy

And then reset the score at the correct time.

/scoreboard players set @e[type=armor_stand,name=timer,scores={timer=1728000..}] timer 0

This should place/destroy the block every 24 hours. If you want minecraft days, they are 24.000 ticks instead of the 1.728.000.

Correct answer by Wicked Grinn on May 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP