JackFredLib
Home
  • 🏑Home
  • 🐘Setup with Gradle
  • πŸ“…Supported Versions
  • JackFredLib: Base
    • 🧱Overview
    • β˜‘οΈCodecs
  • JackFredLib: Colour
    • 🎨Overview
    • 🟒Colours
    • 🌈Gradients
  • JackFredLib: Extra Command Source Data
    • ⌨️Overview
  • JackFredLib: GPS
    • πŸ›°οΈOverview
    • πŸ—ΊοΈUsing Coordinates
    • πŸ”Refining Further
  • JackFredLib: Lying
    • πŸ€₯Overview
  • JackFredLIb: Toasts
    • 🍞Overview
  • JackFredLib: Config
    • βš™οΈOverview
Powered by GitBook
On this page
  1. JackFredLib: GPS

Using Coordinates

"How can I get a unique ID for every world / server / realm / etc to store my data under"

PreviousOverviewNextRefining Further

Last updated 1 year ago

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.

Coordinate Type
Example ID
User-friendly Name

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:

ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
    Coordinate.getCurrent().ifPresent(coordinate -> {
        String id = coordinate.id();
        
        // load data, check server id, etc
    });
});

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 .

If you're making a mod specifically to work with a server, you can easily refine a coordinate and check it's address:

if (coord instanceof Coordinate.Multiplayer multi
    && multi.address().contains("hypixel.net")) {
    // hypixel specific stuff
}

πŸ—ΊοΈ
Example Notes Mod