[Change] WorldPreset automatically sets DEFAULT to first registered Preset
This commit is contained in:
parent
e70823a587
commit
dd27373063
8 changed files with 24 additions and 8 deletions
|
@ -13,6 +13,6 @@ public class DedicatedServerPropertiesMixin {
|
|||
//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"))
|
||||
private String bcl_init(String levelType) {
|
||||
return WorldPresets.DEFAULT.location().toString();
|
||||
return WorldPresets.getDEFAULT().location().toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class PresetsRegistry {
|
|||
false
|
||||
);
|
||||
|
||||
WorldPresets.DEFAULT = BCL_WORLD;
|
||||
WorldPresets.setDEFAULT(BCL_WORLD);
|
||||
}
|
||||
|
||||
public static TogetherWorldPreset buildPreset(
|
||||
|
|
|
@ -58,7 +58,7 @@ public class WorldGenUtil {
|
|||
boolean generateBonusChest
|
||||
) {
|
||||
return createWorldFromPreset(
|
||||
WorldPresets.DEFAULT,
|
||||
WorldPresets.getDEFAULT(),
|
||||
registryAccess,
|
||||
seed,
|
||||
generateStructures,
|
||||
|
|
|
@ -46,7 +46,7 @@ public class CreateWorldScreenMixin {
|
|||
//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"))
|
||||
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
|
||||
|
|
|
@ -20,6 +20,6 @@ public class WorldGenPropertiesMixin {
|
|||
//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;"))
|
||||
private ResourceKey<WorldPreset> bcl_foo(ResourceKey<WorldPreset> resourceKey) {
|
||||
return WorldPresets.DEFAULT;
|
||||
return WorldPresets.getDEFAULT();
|
||||
}
|
||||
}
|
|
@ -72,7 +72,7 @@ public class WorldBootstrap {
|
|||
private static Holder<WorldPreset> defaultServerPreset() {
|
||||
return WorldPresets.get(
|
||||
LAST_REGISTRY_ACCESS,
|
||||
WorldPresets.DEFAULT
|
||||
WorldPresets.getDEFAULT()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ public class TogetherWorldPreset extends WorldPreset {
|
|||
final RegistryAccess registryAccess = WorldBootstrap.getLastRegistryAccessOrElseBuiltin();
|
||||
final RegistryOps<Tag> registryOps = RegistryOps.create(NbtOps.INSTANCE, registryAccess);
|
||||
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();
|
||||
|
|
|
@ -20,13 +20,14 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
|||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public class WorldPresets {
|
||||
|
||||
public static final TagRegistry.Simple<WorldPreset> WORLD_PRESETS =
|
||||
TagManager.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
|
||||
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) {
|
||||
return ((access != null) ? access : BuiltinRegistries.ACCESS)
|
||||
|
@ -47,6 +48,9 @@ public class WorldPresets {
|
|||
private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean visibleInUI) {
|
||||
ResourceKey<WorldPreset> key = ResourceKey.create(Registry.WORLD_PRESET_REGISTRY, loc);
|
||||
if (visibleInUI) {
|
||||
if (!didExplicitlySetDefault && DEFAULT == net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL) {
|
||||
DEFAULT = key;
|
||||
}
|
||||
WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location());
|
||||
}
|
||||
|
||||
|
@ -88,6 +92,18 @@ public class WorldPresets {
|
|||
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
|
||||
public interface PresetBuilder {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue