You can now use the CustomTriggers "loop" trigger inside of CustomItems block files. Keep in mind that this will loop through all loaded blocks, so be extra careful to take server performance into account here.
This will only run on blocks that have been loaded into memory since the server was started, and won't run on blocks that haven't been loaded. For example, let's say you have two custom blocks placed in the world. One block at position 0, 0, 0, and one at position 20000, 100, 70000. You restart the server, and initially, none of the loops will run (because no blocks have been loaded, cause there's no players to load them). Let's now say a player joins at the location 3, 120, 2. They're close enough to 0, 0, 0 for Minecraft to load those chunks, so the loop will start running on that block only.
Then, if a new player joins and teleports to 20000, 100, 70000, the block there will also load, so now the loop will run on both of the custom blocks.
If you're trying to do stuff with time, it is recommended that you use the {time} placeholder to avoid situations where blocks might not be loaded into memory when you want them to.
Code (Text):
# Inside myCustomBlock.yml
handlers:
loop:
interval: 600 # run this action every 600 ticks = 30 seconds
actions:
-
action: console broadcastMessage # You should use CustomTriggers notation in your actions here
message: "Ran a loop on a block at {block.x}, {block.y}, {block.z}"
-
action: setGlobal
name: "block_{block.x}_{block.y}_{block.z}_last_loaded_time"
value: "{time}"
[code]