World settings
WorldSettings is an immutable record holding the world-level settings a mod’s lobby exposes to its host. It’s the data model behind the built-in WorldSettingsScreen and powers the save/discard pattern: hold two copies (applied + pending), render pending to the host, swap them on save, regen the world. A standard Codec ships for persistence.
When to use it
Section titled “When to use it”- You want to expose host-editable world rules through the engine’s standard UI.
- You’re persisting per-lobby settings to disk and want a ready-made codec.
- You’re applying settings to a freshly-acquired instance dimension.
package me.zlex.conduit.world;
public record WorldSettings( boolean pvpEnabled, boolean daylightCycle, boolean weatherCycle, boolean fixedSeed, long seed, boolean villageStart) { public static WorldSettings defaults();
public WorldSettings withPvp(boolean v); public WorldSettings withDaylight(boolean v); public WorldSettings withWeather(boolean v); public WorldSettings withFixedSeed(boolean v); public WorldSettings withSeed(long v); public WorldSettings withVillageStart(boolean v);
public static final Codec<WorldSettings> CODEC;}Example
Section titled “Example”import me.zlex.conduit.world.WorldSettings;import net.minecraft.server.level.ServerLevel;
public final class MyWorld {
private WorldSettings applied = WorldSettings.defaults(); private WorldSettings pending = applied;
public void onHostToggleDaylight() { pending = pending.withDaylight(!pending.daylightCycle()); }
public boolean dirty() { return !applied.equals(pending); }
public void saveAndRegen(ServerLevel level) { applied = pending; applyGameRules(level, applied); // ...trigger your world regen path here }
public void discard() { pending = applied; }
private void applyGameRules(ServerLevel level, WorldSettings s) { var server = level.getServer(); var src = server.createCommandSourceStack().withLevel(level).withSuppressedOutput(); server.getCommands().performPrefixedCommand(src, "gamerule doDaylightCycle " + s.daylightCycle()); server.getCommands().performPrefixedCommand(src, "gamerule doWeatherCycle " + s.weatherCycle()); }}pvpEnabledis just a flag — most mods enforce it at the damage-event level rather than via a game rule.fixedSeedcontrols whether the next regen usesseed(true) or generates a random one (false).- The codec uses
optionalFieldOffor every field, so older saved data is forward-compatible — missing fields fall back to defaults.