Skip to content

Commit

Permalink
Tolerate when a vanilla dimension has more than one world.
Browse files Browse the repository at this point in the history
- Tolerate when a vanilla dimension has more than one world
  • Loading branch information
gniftygnome committed Aug 10, 2024
1 parent 4b6c330 commit e0c33bd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void handleServerStarting(MinecraftServer server) {
registryManager = server.getCombinedDynamicRegistries().getCombinedRegistryManager();
}

// When TerraBlender is present, it ignores our surface rules in the Overworld and Nether.
// When TerraBlender is present, it ignores our surface rules.
// To avoid this, we submit a duplicate registration to TerraBlender (but only once).
if (BiolithCompat.COMPAT_TERRABLENDER && !registeredWithTerrablender) {
Services.PLATFORM.getTerraBlenderCompat().registerSurfaceRules();
Expand All @@ -80,14 +80,26 @@ public static void handleWorldStarting(ServerWorld world) {

if (dimensionKey.isPresent()) {
if (DimensionTypes.THE_END.equals(dimensionKey.get())) {
END_STATE = new BiolithState(world, "end");
END.serverReplaced(END_STATE, world.getSeed());
if (END_STATE == null) {
END_STATE = new BiolithState(world, "end");
END.serverReplaced(END_STATE, world.getSeed());
} else {
Biolith.LOGGER.warn("More than one End dimension world created; cowardly ignoring '{}' in favor of '{}'", world.getRegistryKey().getValue(), END_STATE.getWorldId());
}
} else if (DimensionTypes.THE_NETHER.equals(dimensionKey.get())) {
NETHER_STATE = new BiolithState(world, "nether");
NETHER.serverReplaced(NETHER_STATE, world.getSeed());
if (NETHER_STATE == null) {
NETHER_STATE = new BiolithState(world, "nether");
NETHER.serverReplaced(NETHER_STATE, world.getSeed());
} else {
Biolith.LOGGER.warn("More than one Nether dimension world created; cowardly ignoring '{}' in favor of '{}'", world.getRegistryKey().getValue(), NETHER_STATE.getWorldId());
}
} else if (DimensionTypes.OVERWORLD.equals(dimensionKey.get())) {
OVERWORLD_STATE = new BiolithState(world, "overworld");
OVERWORLD.serverReplaced(OVERWORLD_STATE, world.getSeed());
if (OVERWORLD_STATE == null) {
OVERWORLD_STATE = new BiolithState(world, "overworld");
OVERWORLD.serverReplaced(OVERWORLD_STATE, world.getSeed());
} else {
Biolith.LOGGER.warn("More than one Overworld dimension world created; cowardly ignoring '{}' in favor of '{}'", world.getRegistryKey().getValue(), OVERWORLD_STATE.getWorldId());
}
} else {
Biolith.LOGGER.info("Ignoring world '{}'; unknown dimension type: {}", world.getRegistryKey().getValue(), dimensionKey.get().getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,16 @@ public void addBiomeReplacements(RegistryKey<Biome> target, Stream<RegistryKey<B

this.markDirty();
}

public Identifier getDimensionId() {
if (world.getDimensionEntry().getKey().isEmpty()) {
return Identifier.of("biolith", "unregistered_dimension");
}

return world.getDimensionEntry().getKey().get().getValue();
}

public Identifier getWorldId() {
return world.getRegistryKey().getValue();
}
}

0 comments on commit e0c33bd

Please sign in to comment.