Using Coordinates
"How can I get a unique ID for every world / server / realm / etc to store my data under"
Coordinates are Java records that contain an ID based on the connection, and a generated human-readable name. Some may also contain extra data such as a singleplayer world's directory name, or a multiplayer server's address.
Singleplayer / LAN host
singleplayer/New World
Singleplayer: New World
LAN (remote player)
lan/Herobrine - New World
LAN:
Multiplayer Server
multiplayer/mc_hypixel_net
Multiplayer:
Realm Server
Minecraft Realms: Builder's Palace
User-friendly names for Singleplayer, Multiplayer and Realms coordinates are localized based on the user's current language.
A common use point might be on server connect, such as in Fabric's ClientPlayConnectionEvents#JOIN
:
Coordinates aren't available duringClientPlayConnectionEvents#DISCONNECT
- you may want to save the one you use loading data alongside the data itself. You can see this being done in the Example Notes Mod.
If you're making a mod specifically to work with a server, you can easily refine a coordinate and check it's address:
Last updated