1
Constantly run a function from within the data pack
I'm playing around with a data pack, and I have a function that will check a player's death count objective to see if it's 1, then run a couple of other commands before setting their death count back to 0.
Is there a way I could have this function automatically run inside the data pack constantly? And if so, could it lead to any lag issues?
Is there a way I could have this function automatically run inside the data pack constantly? And if so, could it lead to any lag issues?
Create an account or sign in to comment.
1
1
Do you have a data pack already set up? If not, check out the countless pile of tutorials for creating one. No offense, but this is a very easy question which most good data pack tutorials will have covered. Don't be afraid to post and ask questions, but also do your due diligence before asking. You probably could have found the answer in less time than it took to create this thread. Still, I appreciate that you're not afraid to ask questions. :^)
In your data pack folder (with pack.mcmeta and the data folder), go to <the folder>\data\minecraft\tags\functions. If there's a folder missing at any point there, create them. Then create a file named "tick.json", and its contents should be this:
You can even put multiple in there. Just add a comma between them (the last line shouldn't have a trailing comma).
Now go into that function you pointed to in the tick.json file and write your commands. It will be executed every tick (1/20 of a second, the refresh rate of the game. Think of it like the "frames per second" of the server. A game tick is how often the game updates, doing all the calculations in between). Regarding lag issues, a few commands every tick will have unnoticeable impact on the game. That's only a worry if you're running hundreds or even thousands of commands every tick which is only a worry in large-scale or horribly optimized data packs.
Obviously, YMMV and certain commands, like /fill and /clone, are extremely laggy, while commands like /execute and /scoreboard cause very little lag.
LMK if you need more help.
In your data pack folder (with pack.mcmeta and the data folder), go to <the folder>\data\minecraft\tags\functions. If there's a folder missing at any point there, create them. Then create a file named "tick.json", and its contents should be this:
{
"values": [
"<your_data_pack_namespace>:<your_constant_function (I recommend naming it 'tick' or main')>"
]
}
You can even put multiple in there. Just add a comma between them (the last line shouldn't have a trailing comma).
Now go into that function you pointed to in the tick.json file and write your commands. It will be executed every tick (1/20 of a second, the refresh rate of the game. Think of it like the "frames per second" of the server. A game tick is how often the game updates, doing all the calculations in between). Regarding lag issues, a few commands every tick will have unnoticeable impact on the game. That's only a worry if you're running hundreds or even thousands of commands every tick which is only a worry in large-scale or horribly optimized data packs.
Obviously, YMMV and certain commands, like /fill and /clone, are extremely laggy, while commands like /execute and /scoreboard cause very little lag.
LMK if you need more help.