Skip to content

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.

  • 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;
}
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());
}
}
  • pvpEnabled is just a flag — most mods enforce it at the damage-event level rather than via a game rule.
  • fixedSeed controls whether the next regen uses seed (true) or generates a random one (false).
  • The codec uses optionalFieldOf for every field, so older saved data is forward-compatible — missing fields fall back to defaults.