On First World Load
This system will run your desired commands on the event that the world is loaded for the first time.
Note: a Function Pack is required to achieve this system since it is the
tick.jsonfile which allows us to run commands as soon as the world is initialised.
scoreboard objectives add world dummy
scoreboard players add initialised world 0
#Your Commands Here (example)
execute if score initialised world matches 0 run say New world created!
scoreboard players set initialised world 1
Here we have used an
execute - say command as an example but you can use any command you prefer and as many as you require.
Just make sure to follow the given order and properly use the
execute if score command as shown to run the commands you need.
initialised=0this means the world has just initialised and we are yet to run the initlisation commands.
initialised=1this means the world has been initialised and we have already run the initialisation commands.
An objective of the name
world is added for us to save scores to it so that we can track whether the world has been initialised or not. This also allows us to structure our commands to only execute at world initialisation.
Following the creation of the objective, a score of
0 is added to the FakePlayer name
initialised. This will register it to the objective and enable us to use the
execute if score command structure to run our desired commands.
Finally the score for
initialised is set to 1 after all the commands are run in order to prevent it from executing more than once.
Note: the scoreboard names (in this case: 'world') may end up being used by other people. Appending
_and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the