[Change] WorldPreset automatically sets DEFAULT to first registered Preset

This commit is contained in:
Frank 2022-06-30 09:52:04 +02:00
parent e70823a587
commit dd27373063
8 changed files with 24 additions and 8 deletions

View file

@ -13,6 +13,6 @@ public class DedicatedServerPropertiesMixin {
//Make sure the default server properties use our Default World Preset //Make sure the default server properties use our Default World Preset
@ModifyArg(method = "<init>", index = 3, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedServerProperties$WorldGenProperties;<init>(Ljava/lang/String;Lcom/google/gson/JsonObject;ZLjava/lang/String;)V")) @ModifyArg(method = "<init>", index = 3, at = @At(value = "INVOKE", target = "Lnet/minecraft/server/dedicated/DedicatedServerProperties$WorldGenProperties;<init>(Ljava/lang/String;Lcom/google/gson/JsonObject;ZLjava/lang/String;)V"))
private String bcl_init(String levelType) { private String bcl_init(String levelType) {
return WorldPresets.DEFAULT.location().toString(); return WorldPresets.getDEFAULT().location().toString();
} }
} }

View file

@ -44,7 +44,7 @@ public class PresetsRegistry {
false false
); );
WorldPresets.DEFAULT = BCL_WORLD; WorldPresets.setDEFAULT(BCL_WORLD);
} }
public static TogetherWorldPreset buildPreset( public static TogetherWorldPreset buildPreset(

View file

@ -58,7 +58,7 @@ public class WorldGenUtil {
boolean generateBonusChest boolean generateBonusChest
) { ) {
return createWorldFromPreset( return createWorldFromPreset(
WorldPresets.DEFAULT, WorldPresets.getDEFAULT(),
registryAccess, registryAccess,
seed, seed,
generateStructures, generateStructures,

View file

@ -46,7 +46,7 @@ public class CreateWorldScreenMixin {
//Change the WorldPreset that is selected by default on the Create World Screen //Change the WorldPreset that is selected by default on the Create World Screen
@ModifyArg(method = "openFresh", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent;<init>(Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext;Ljava/util/Optional;Ljava/util/OptionalLong;)V")) @ModifyArg(method = "openFresh", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent;<init>(Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext;Ljava/util/Optional;Ljava/util/OptionalLong;)V"))
private static Optional<ResourceKey<WorldPreset>> bcl_NewDefault(Optional<ResourceKey<WorldPreset>> preset) { private static Optional<ResourceKey<WorldPreset>> bcl_NewDefault(Optional<ResourceKey<WorldPreset>> preset) {
return Optional.of(WorldPresets.DEFAULT); return Optional.of(WorldPresets.getDEFAULT());
} }
//Make sure the WorldGenSettings used to populate the create screen match the default WorldPreset //Make sure the WorldGenSettings used to populate the create screen match the default WorldPreset

View file

@ -20,6 +20,6 @@ public class WorldGenPropertiesMixin {
//Make sure Servers use our Default World Preset //Make sure Servers use our Default World Preset
@ModifyArg(method = "create", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/core/Registry;getHolder(Lnet/minecraft/resources/ResourceKey;)Ljava/util/Optional;")) @ModifyArg(method = "create", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/core/Registry;getHolder(Lnet/minecraft/resources/ResourceKey;)Ljava/util/Optional;"))
private ResourceKey<WorldPreset> bcl_foo(ResourceKey<WorldPreset> resourceKey) { private ResourceKey<WorldPreset> bcl_foo(ResourceKey<WorldPreset> resourceKey) {
return WorldPresets.DEFAULT; return WorldPresets.getDEFAULT();
} }
} }

View file

@ -72,7 +72,7 @@ public class WorldBootstrap {
private static Holder<WorldPreset> defaultServerPreset() { private static Holder<WorldPreset> defaultServerPreset() {
return WorldPresets.get( return WorldPresets.get(
LAST_REGISTRY_ACCESS, LAST_REGISTRY_ACCESS,
WorldPresets.DEFAULT WorldPresets.getDEFAULT()
); );
} }

View file

@ -105,7 +105,7 @@ public class TogetherWorldPreset extends WorldPreset {
final RegistryAccess registryAccess = WorldBootstrap.getLastRegistryAccessOrElseBuiltin(); final RegistryAccess registryAccess = WorldBootstrap.getLastRegistryAccessOrElseBuiltin();
final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess); final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
if (DEFAULT_DIMENSIONS_WRAPPER == null) { if (DEFAULT_DIMENSIONS_WRAPPER == null) {
DEFAULT_DIMENSIONS_WRAPPER = new DimensionsWrapper(TogetherWorldPreset.getDimensionsMap(WorldPresets.DEFAULT)); DEFAULT_DIMENSIONS_WRAPPER = new DimensionsWrapper(TogetherWorldPreset.getDimensionsMap(WorldPresets.getDEFAULT()));
} }
CompoundTag presetNBT = WorldGenUtil.getPresetsNbt(); CompoundTag presetNBT = WorldGenUtil.getPresetsNbt();

View file

@ -20,13 +20,14 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.ApiStatus;
public class WorldPresets { public class WorldPresets {
public static final TagRegistry.Simple<WorldPreset> WORLD_PRESETS = public static final TagRegistry.Simple<WorldPreset> WORLD_PRESETS =
TagManager.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset"); TagManager.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap(); private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
public static ResourceKey<WorldPreset> DEFAULT = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL; private static ResourceKey<WorldPreset> DEFAULT = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) { public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) {
return ((access != null) ? access : BuiltinRegistries.ACCESS) return ((access != null) ? access : BuiltinRegistries.ACCESS)
@ -47,6 +48,9 @@ public class WorldPresets {
private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean visibleInUI) { private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean visibleInUI) {
ResourceKey<WorldPreset> key = ResourceKey.create(Registry.WORLD_PRESET_REGISTRY, loc); ResourceKey<WorldPreset> key = ResourceKey.create(Registry.WORLD_PRESET_REGISTRY, loc);
if (visibleInUI) { if (visibleInUI) {
if (!didExplicitlySetDefault && DEFAULT == net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL) {
DEFAULT = key;
}
WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location()); WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location());
} }
@ -88,6 +92,18 @@ public class WorldPresets {
BUILDERS = null; BUILDERS = null;
} }
public static ResourceKey<WorldPreset> getDEFAULT() {
return DEFAULT;
}
private static boolean didExplicitlySetDefault = false;
@ApiStatus.Internal
public static void setDEFAULT(ResourceKey<WorldPreset> DEFAULT) {
didExplicitlySetDefault = true;
WorldPresets.DEFAULT = DEFAULT;
}
@FunctionalInterface @FunctionalInterface
public interface PresetBuilder { public interface PresetBuilder {