Make Sure BCLibs Default WorldPreset is applied by default for fresh Clients/Servers

This commit is contained in:
Frank 2022-05-21 17:51:49 +02:00
parent 9f8409ebe0
commit ab0895d48c
12 changed files with 226 additions and 44 deletions

View file

@ -4,10 +4,14 @@ import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.WorldLoader;
import net.minecraft.world.level.DataPackConfig;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import com.mojang.datafixers.util.Pair;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.presets.WorldPresets;
import org.spongepowered.asm.mixin.Mixin;
@ -28,8 +32,18 @@ public class CreateWorldScreenMixin {
BiomeAPI.initRegistry(worldGenSettingsComponent.registryHolder().registryOrThrow(Registry.BIOME_REGISTRY));
}
//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.BCL_WORLD);
return WorldPresets.DEFAULT;
}
//Make sure the WorldGenSettings match the default WorldPreset
@ModifyArg(method = "openFresh", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/WorldLoader;load(Lnet/minecraft/server/WorldLoader$InitConfig;Lnet/minecraft/server/WorldLoader$WorldDataSupplier;Lnet/minecraft/server/WorldLoader$ResultFactory;Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"))
private static WorldLoader.WorldDataSupplier<WorldGenSettings> bcl_NewDefaultSettings(WorldLoader.WorldDataSupplier<WorldGenSettings> worldDataSupplier) {
return (resourceManager, dataPackConfig) -> {
Pair<WorldGenSettings, RegistryAccess.Frozen> res = worldDataSupplier.get(resourceManager, dataPackConfig);
return WorldPresets.defaultWorldDataSupplier(res.getSecond());
};
}
}

View file

@ -0,0 +1,17 @@
package org.betterx.bclib.mixin.common;
import net.minecraft.server.dedicated.DedicatedServerProperties;
import org.betterx.bclib.presets.WorldPresets;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(DedicatedServerProperties.class)
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_foo(String levelType) {
return WorldPresets.DEFAULT.orElseThrow().location().toString();
}
}

View file

@ -11,7 +11,7 @@ import org.betterx.bclib.api.LifeCycleAPI;
import org.betterx.bclib.api.datafixer.DataFixerAPI;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.File;
@ -21,7 +21,16 @@ import java.util.Optional;
@Mixin(Main.class)
abstract public class MainMixin {
@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource;createDefault(Ljava/nio/file/Path;)Lnet/minecraft/world/level/storage/LevelStorageSource;"))
@ModifyVariable(method = "main", ordinal = 0, at = @At(value = "INVOKE", shift = At.Shift.AFTER, target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getSummary()Lnet/minecraft/world/level/storage/LevelSummary;"))
private static LevelStorageSource.LevelStorageAccess bc_createAccess(LevelStorageSource.LevelStorageAccess levelStorageAccess) {
DataFixerAPI.fixData(levelStorageAccess, false, (didFix) -> {/* not called when showUI==false */});
LifeCycleAPI._runBeforeLevelLoad();
return levelStorageAccess;
}
//@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource;createDefault(Ljava/nio/file/Path;)Lnet/minecraft/world/level/storage/LevelStorageSource;"))
private static void bclib_callServerFix(String[] args, CallbackInfo ci) {
OptionParser parser = new OptionParser();
ArgumentAcceptingOptionSpec<String> optionUniverse = parser.accepts("universe")

View file

@ -1,7 +1,10 @@
package org.betterx.bclib.mixin.common;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.dedicated.DedicatedServerProperties;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import org.betterx.bclib.presets.WorldPresets;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@ -12,4 +15,10 @@ public class WorldGenPropertiesMixin {
public long bcl_create(long seed) {
return seed;
}
//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.orElseThrow();
}
}

View file

@ -6,15 +6,12 @@ import net.minecraft.data.BuiltinRegistries;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.levelgen.presets.WorldPresets;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.minecraft.world.level.levelgen.synth.NormalNoise;
import org.betterx.bclib.world.generator.BCLibEndBiomeSource;
import org.betterx.bclib.world.generator.BCLibNetherBiomeSource;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@ -54,35 +51,27 @@ public abstract class WorldPresetsBootstrapMixin {
@ModifyArg(method = "run", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap;registerCustomOverworldPreset(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/LevelStem;)Lnet/minecraft/core/Holder;"))
private LevelStem bcl_getOverworldStem(LevelStem overworldStem) {
BCLibNetherBiomeSource netherSource = new BCLibNetherBiomeSource(this.biomes);
BCLibEndBiomeSource endSource = new BCLibEndBiomeSource(this.biomes);
LevelStem bclNether = new LevelStem(
this.netherDimensionType,
new NoiseBasedChunkGenerator(
this.structureSets,
this.noises,
netherSource,
this.netherNoiseSettings)
WorldPreset preset = new org.betterx.bclib.presets.WorldPresets.SortableWorldPreset(
Map.of(LevelStem.OVERWORLD,
overworldStem,
LevelStem.NETHER,
org.betterx.bclib.presets.WorldPresets.getBCLNetherLevelStem(this.biomes,
this.netherDimensionType,
this.structureSets,
this.noises,
this.netherNoiseSettings),
LevelStem.END,
org.betterx.bclib.presets.WorldPresets.getBCLEndLevelStem(this.biomes,
this.endDimensionType,
this.structureSets,
this.noises,
this.endNoiseSettings)
), 0
);
LevelStem bclEnd = new LevelStem(
this.endDimensionType,
new NoiseBasedChunkGenerator(
this.structureSets,
this.noises,
endSource,
this.endNoiseSettings)
);
WorldPreset preset = new org.betterx.bclib.presets.WorldPresets.SortableWorldPreset(Map.of(LevelStem.OVERWORLD,
overworldStem,
LevelStem.NETHER,
bclNether,
LevelStem.END,
bclEnd), 0);
BuiltinRegistries.register(this.presets, org.betterx.bclib.presets.WorldPresets.BCL_WORLD, preset);
return overworldStem;
}
}