Description
World Primer can automatically run a set of commands when a new world is first created, or every time a world is loaded, or every time a dimension gets loaded.
Configuration
The commands to run are set in the following config options. They can all be also configured via the in-game config menu:
- dimensionLoadingCommands - commands to run each time a dimension gets loaded
- earlyWorldCreationCommands - Commands to run on initial world creation, before the spawn chunks have been generated or loaded. If dimension load tracking is enabled, then this happens even before any dimensions have been loaded/initialized yet.
- earlyWorldLoadingCommands - Commands to run every time the world gets loaded (ie. when the server is starting). These are run when the server is starting, before any worlds have been loaded.
- postWorldCreationCommands - Commands to run on initial world creation, after the spawn chunks have been generated and loaded.
- postWorldLoadingCommands - Commands to run every time the world gets loaded (ie. when the server is starting). These are run when the server has started and the overworld spawn chunks have been loaded.
There are also separate config options to enable or disable all of these, without having to remove all the commands if you want to temporarily disable them:
- enableDimensionLoadingCommands
- enableDimensionLoadTracking - enables tracking the number of times dimensions have loaded, and how many times the server has started (ie. how many times the world has been loaded).
- enableEarlyWorldCreationCommands - Enables early world creation commands, which are executed before any dimensions have been loaded and thus before any chunks have been generated or loaded
- enableEarlyWorldLoadingCommands - Enables early world loading commands, which are executed once at each server start, before any dimensions have been loaded
- enablePostWorldCreationCommands - Enables late world creation commands, which are executed after the dimension have loaded, and the overworld spawn chunks have been generated
- enablePostWorldLoadingCommands - Enables late world loading commands, which are executed once at each server start, after all the dimensions and also the overworld spawn chunks have been loaded.
In addition to these, there is also the enableDebugLogging option, which prints log messages from the various events, so it is easy to track what happens and when.
Dimension loading commands
The dimension loading commands can be targeted to only run when a specific dimension loads, by specifying the command like this:
worldprimer-dim-command <dim id> <the actual command>.
So for example:
worldprimer-dim-command 1 say The End dimension has loaded!
If you just give a command without the prefix, then it will be run every time ANY dimension loads, for example:
say Some dimension has loaded!
As of version 0.3.0, there is now also another dimension loading command variant, which can run the command on a specific number of dimension loads, or on any multiple of the given value.
Note: This variant requires the option enableDimensionLoadTracking to be enabled!
The syntax for these is:
worldprimer-dim-command-nth <dim id> <load count> <the actual command>
So to only run a command when the Nether loads for the very first time, you could use:
worldprimer-dim-command-nth -1 1 say The Nether has loaded for the first time!
Or when the End loads for the 6th time:
worldprimer-dim-command-nth 1 6 say The End has loaded for the sixth time!
To run a command on any multiple of the given value, prefix the value with a '%':
worldprimer-dim-command-nth 1 %5 say The End has loaded a multiple of 5 times!
As of version 0.4.0, there is also support for substituting the dimension id, or the current world spawn coordinates into the commands.
The substitution strings are: {DIMENSION}, {SPAWNX}, {SPAWNY} and {SPAWNZ}. They also support simple addition and subtraction of constant numeric values.
So for example, you can now do this in postWorldCreationCommands, to make the player spawn in a 5x5x3 room under ground:
gameRule spawnRadius 0 (this sets the spawn fuzz to 0, so the player fill spawn exactly in the center of that small room, and not randomly somewhere around that spot, on the surface)
setworldspawn {SPAWNX} 7 {SPAWNZ} (moves the world spawnpoint down to y = 7)
fill {SPAWNX}-2 7 {SPAWNZ}-2 {SPAWNX}+2 9 {SPAWNZ}+2 minecraft:air (makes a 5x5x3 room of air inside the ground, or whatever happens to be at that spot)
Built-in commands
As of version 0.5.0 there is a new built-in command:
worldprimer-load-chunks <chunkXMin> <chunkZMin> <chunkXMax> <chunkZMax>.
It can be used to load a range of chunks, so that some other commands can actually work. For example the vanilla /fill command only works in loaded chunks, so this can be used to load the chunks before executing the fill command. The chunks are also immediately queued for unloading, so they shouldn't stay loaded even until the next world save happens (every 45 seconds), but instead unload on the next game tick.
The coordinates are chunk coordinates (so block coordinates divided by 16). The range is inclusive, meaning from the minimum up to and including the maximum.
Note that this isn't an actual registered command, and is thus not usable via chat/server console, but instead it's only used internally if found in one of the configured commands.
Here is an example of how to build a bedrock box at 0,0 in the End dimension when it loads for the first time. These would be added as dimensionLoadingCommands:
worldprimer-dim-command-nth 1 1 worldprimer-load-chunks -1 -1 0 0
worldprimer-dim-command-nth 1 1 fill 10 0 10 -10 7 -10 minecraft:bedrock
worldprimer-dim-command-nth 1 1 fill 9 1 9 -9 6 -9 minecraft:air
worldprimer-dim-command-nth 1 1 say Finished building your box!
Command: /worldprimer spread-player
This command exists starting from version 0.6.0-dev.20190814.220944.
Here is the description of the available options, and how the command works:
If the grid option is given with the grid size, then the grid mode is used.
Otherwise the randomized location mode is used.
Options:
- --find-surface=<true | false> - If true, then the y-position is set to the top solid block on the found x/z position.
- --grid=<integer> - If given, then an outwards spriraling grid search pattern is used instead of randomized locations.
- --max-radius=<integer> - The maximum distance from [0, 0] (per axis, not the absolute distance).
- --min-separation=<integer> - The minimum distance to previous player spread positions and any currently online players in the same dimension.
- --new - If given, then if the command is run again for a player who was spread previously, then a new location is generated, instead of teleporting them
- back to the original spread location.
- --y=<integer> - If given, then this fixed y height is used.
- --y-offset=<integer> - If given, and --find-surface=true, then this offset value will be added to the surface y position.
- This allows the position to be offset a certain distance under ground for example.
- --y-max=<integer> - Limits the (possibly offset) y position from the --find-surface=true case.
- --y-min=<integer> - Limits the (possibly offset) y position from the --find-surface=true case.
If you have ideas or questions or feedback, or maybe you just want to hang out, you can join us on Discord:
Masady!! Please I need this updated lol.
I run 10 servers, 5 on 1.12 which runs this great!! and 5 on 1.16 which doesn't have this, so I have to manually restart and run commands to clear up lagg. <3 keep us posted please :D
When i create a world minecraft is crashes.
I set WorldCreation command "srpevolution phase_1" from "Scape and Run: Parasites", and toggle WorldCreation commands
Help!
In reply to voltyx_apex:
I can't help with that little of a description (without a crash log). But if it crashes when running that command, then the crash probably comes from that mod command? The worldCreationCommand also might be too early for many commands. Maybe try it in dimensionLoadingCommands for the overworld (dimension 0), with the worldprimer-dim-command-nth 1 0 commandhere syntax, so that it only runs on the first load of dimension 0 (overworld).
In reply to masady:
I tried this, but work only vanilla commands. SRP command doesn't work
In reply to voltyx_apex:
Does it not find the command/does the command not exist yet at that point? Or do the srp commands not work at all from any of the World Primer commands? For example if you put it in dimensionLoadingCommands for the End with worldprimer-dim-command 1 commandhere and then you (slowly) throw items to an End portal, do you see it run or does it just print errors in the game/server console?
Would be great to have this on 1.16.5
In reply to cpm9_:
I've been working on a big internal rewrite of the mod in the past weeks and months (going very slowly, due to low modding motivation lately...), which is now finally getting pretty close to being finished. After it's done, I'll port the mod from 1.12.2 to 1.14.4, 1.15.2, 1.16.5 and 1.17.1. Not sure if I'll skip 1.14 and 1.15 though, might be wasted effort at this point... Not sure if I should even release that rewritten version for 1.12.2, as it would need some config changes, so people can't update directly to that version with their old configs as-is... (unless they don't use any of the prefix conditions).
In reply to masady:
awesome!
Is there a way to trigger something when a dimension unloads? Essentially trying to combine this with the temporary worlds from justenoughdimensions to send out a message to players when a world unloads, so they know they can now create a new version of that dimensions without loading the old data.
In reply to SeriousCreeper:
By unloading I assume you in this case mean when the dimension is actually deleted, not just when the dimension unloads (in case there were players tracked as being within that dimension, then the dimension would not be deleted even when it unloads)? In that case it would be better if JED would have a command or even just a message it sends when it deletes a temporary dimension. I guess I could add that, so you get an indication when it actually deletes a dimension.
It seems like currently World Primer doesn't even have dimension unloading commands at all, and it also doesn't have anything for detecting dimensions being deleted, as that's not something that normally ever happens in the game, so there isn't really any simple clean way to get such information, other than checking if the save directory for a given dimension vanishes at some point. But since this almost never happens outside of JED, I don't think it would make much sense in WP. So I'll see if I have the time to add the command or message option for dimension deletion to JED in the coming days.
In reply to masady:
Ah yes that's a good point, it would really only be if JED deletes it. and therefore be better as part of JED itself, hadn't considered that!
Thanks a lot for considering adding this, appreciate it a lot!
In reply to SeriousCreeper:
Okay try this JED version: https://masa.dy.fi/mcmods/justenoughdimensions/justenoughdimensions-1.12.2-1.6.0-dev.20210812.195739.jar
You would add a post_deletion_command to the main level of the dimension object, with the command you want to run as a string value.
For example my testing config for this new feature (line 10): https://pastebin.com/26Jyb7WV
In reply to masady:
That worked perfectly and exactly what i needed, thank you so much, really appreciate it :D
Hi!
I need to type the slash "/" before adding a command on the config?
In reply to criz004:
No, the commands in the config file do not need the slash. It's only required when running commands via the chat, to know that a string should be executed as a command rather than sent as a message to other players.
How would I go about loading a schematic to generate for the player to spawn on? I'd like to do this in a blank dimension for a sort of "tutorial level". I'm fairly new when it comes to modpack creation, so any help would be greatly appreciated.
In reply to Deathwray:
You can save/create the schematic itself with the /worldprimer create-structure command, once you have it built in some world. You can place it to a world/dimension by running the /worldprimer place-structure command when the dimension is loaded for the first time.
For saving it, use one of these commands. Which format (MCEdit schematic vs. vanilla structure) you use depends on whether or not your pack uses JEID or NEID to extend the block ID range, as the MCEdit schematic format does not work in that case. But on the other hand the vanilla structure format is a lot more memory heavy and slower with larger volumes of stuff. So use schematic if you don't have a mod that extends the block ID range, otherwise use vanilla structure.
/worldprimer create-structure <x1> <y1> <z1> <x2> <y2> <z2> vanilla something
/worldprimer create-structure <x1> <y1> <z1> <x2> <y2> <z2> schematic something
This will create the file in config/worldprimer/structures/
For example if you want to place the structure at the spawn of dimension 123, you would put this in the dimensionLoadingCommands in World Primer config (and also remember to enable that command type in the Toggles category).
worldprimer-dim-command-nth 1 123 worldprimer place-structure {SPAWN_X} {SPAWN_Y}-5 {SPAWN_Z} something.schematic none none centered
This would only run the command when dimension 123 is loaded for the first time. You can adjust the offset by using simple +/- arithmetic with the spawn point substitution, like in the example above, to get it to align nicely around the player for example. You will most likely also need to enable the spawnRadius 0 GameRule, otherwise it's not possible for a player to spawn under blocks (inside a building).
worldprimer-dim-command-nth 1 123 gamerule spawnRadius 0
As for getting an empty dimension, if you didn't have that yet, I would recommend the mod JED (Just Enough Dimensions), using for example this config: https://pastebin.com/BZat9rTp
On the other hand you can also use JED to place the spawn structure (depending on whether or not you need World Primer for other stuff anyway). You can still create it using the above mentioned World primer commands. Example JED config with spawn structure: https://pastebin.com/0uxLAF5Y
In reply to masady:
Wow, your response was far better than I was expecting. Thanks so much for the info, I'm sure you just saved me countless hours of research. I'll let you know if I'm successful or not.
In reply to masady:
Alright. I've been trying to get this to work on the weekends for a while now. I managed to make a void dimension and have the player spawn there using JED, but I have yet to have my schematic spawn in using world primer. Often after testing my world creation I look back at the config and see the file has been renamed "worldprimer.cfg_20210531_185108.errored" and replaced with the default config. I have no clue what I'm doing wrong.
Edit: Nvm, got the JED dimension to spawn a structure about an hour after writing this. I do have just one question left however, how do I send the player to the overworld from the "tutorial spawn dimension"?
In reply to Deathwray:
I have never seen the Forge configs getting renamed like that... is that a mechanism of Forge itself if there is some syntax error in the config, I wonder...?
As for teleporting the player around. This depends on how you want to accomplish it. You could probably set up some modded teleporters in that spawn structure schematic (Simple Teleporters mod maybe? or use Random Portals to create a custom portal). Or if you don't need anything fancy, you could also just use a vanilla command block with the command /tpj @p 0 to teleport the player to the overworld when they push a button or step on a pressure plate.