WorldPreset serialization and better structure for BiomeGenerator builder;
This commit is contained in:
parent
d63d773bb8
commit
c74b7b2d28
20 changed files with 365 additions and 244 deletions
|
@ -1,9 +1,9 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import org.betterx.bclib.api.v2.LifeCycleAPI;
|
||||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPresets;
|
||||
import org.betterx.bclib.presets.worldgen.WorldBootstrap;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
@ -62,6 +62,7 @@ public class CreateWorldScreenMixin {
|
|||
//this is called when a new world is first created
|
||||
@Inject(method = "createNewWorldDirectory", at = @At("RETURN"))
|
||||
void bcl_createNewWorld(CallbackInfoReturnable<Optional<LevelStorageSource.LevelStorageAccess>> cir) {
|
||||
LifeCycleAPI.worldCreationStarted(cir.getReturnValue(), this.worldGenSettingsComponent);
|
||||
WorldBootstrap.InGUI.registryReady(this.worldGenSettingsComponent);
|
||||
WorldBootstrap.InGUI.setupNewWorld(cir.getReturnValue(), this.worldGenSettingsComponent);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,28 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import org.betterx.bclib.interfaces.WorldGenSettingsComponentAccessor;
|
||||
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mixin(WorldGenSettingsComponent.class)
|
||||
public class WorldGenSettingsComponentMixin {
|
||||
public abstract class WorldGenSettingsComponentMixin implements WorldGenSettingsComponentAccessor {
|
||||
@Override
|
||||
@Accessor("preset")
|
||||
public abstract Optional<Holder<WorldPreset>> bcl_getPreset();
|
||||
|
||||
@ModifyArg(method = "init", index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/CycleButton$Builder;withValues(Ljava/util/List;Ljava/util/List;)Lnet/minecraft/client/gui/components/CycleButton$Builder;"))
|
||||
public List<Holder<WorldPreset>> bcl_SortLists(List<Holder<WorldPreset>> list) {
|
||||
final Predicate<Holder<WorldPreset>> vanilla = (p -> p.unwrapKey()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import org.betterx.bclib.api.v2.LifeCycleAPI;
|
||||
import org.betterx.bclib.presets.worldgen.WorldBootstrap;
|
||||
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
@ -17,7 +17,7 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable;
|
|||
abstract public class MainMixin {
|
||||
@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) {
|
||||
LifeCycleAPI.newWorldSetup(levelStorageAccess);
|
||||
WorldBootstrap.DedicatedServer.setupWorld(levelStorageAccess);
|
||||
return levelStorageAccess;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ abstract public class MainMixin {
|
|||
@ModifyArg(method = "method_43613", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;getDataTag(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/world/level/DataPackConfig;Lcom/mojang/serialization/Lifecycle;)Lnet/minecraft/world/level/storage/WorldData;"))
|
||||
private static DynamicOps<Tag> bcl_onCreate(DynamicOps<Tag> dynamicOps) {
|
||||
if (dynamicOps instanceof RegistryOps<Tag> regOps) {
|
||||
LifeCycleAPI.worldCreationStarted(regOps);
|
||||
WorldBootstrap.DedicatedServer.registryReady(regOps);
|
||||
}
|
||||
return dynamicOps;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import org.betterx.bclib.api.v2.LifeCycleAPI;
|
||||
import org.betterx.bclib.api.v2.generator.BCLChunkGenerator;
|
||||
import org.betterx.bclib.presets.worldgen.WorldBootstrap;
|
||||
|
||||
import com.mojang.datafixers.DataFixer;
|
||||
import com.mojang.serialization.Dynamic;
|
||||
|
@ -36,8 +35,7 @@ public class PrimaryLevelDataMixin {
|
|||
//This is the way a created (new) world is initializing the PrimaryLevelData
|
||||
@ModifyArg(method = "<init>(Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
|
||||
private static WorldGenSettings bcl_fixOtherSettings(WorldGenSettings worldGenSettings) {
|
||||
BCLChunkGenerator.injectNoiseSettings(worldGenSettings);
|
||||
return worldGenSettings;
|
||||
return WorldBootstrap.enforceInNewWorld(worldGenSettings);
|
||||
}
|
||||
|
||||
@Inject(method = "parse", at = @At("HEAD"))
|
||||
|
@ -62,7 +60,8 @@ public class PrimaryLevelDataMixin {
|
|||
@ModifyArg(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
|
||||
private static WorldGenSettings bcl_fixSettings(WorldGenSettings settings) {
|
||||
Optional<RegistryOps<Tag>> registryOps = bcl_lastRegistryAccess.get();
|
||||
settings = LifeCycleAPI.worldLoadStarted(settings, registryOps);
|
||||
WorldBootstrap.InGUI.registryReady(registryOps);
|
||||
settings = WorldBootstrap.enforceInLoadedWorld(registryOps, settings);
|
||||
bcl_lastRegistryAccess.set(Optional.empty());
|
||||
return settings;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.betterx.bclib.mixin.common;
|
|||
import org.betterx.bclib.api.v2.LifeCycleAPI;
|
||||
import org.betterx.bclib.api.v2.generator.BCLBiomeSource;
|
||||
import org.betterx.bclib.api.v2.generator.BCLibNetherBiomeSource;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
@ -75,8 +74,6 @@ public abstract class ServerLevelMixin extends Level {
|
|||
bl2
|
||||
);
|
||||
|
||||
InternalBiomeAPI.applyModificationsDeprecated(ServerLevel.class.cast(this));
|
||||
|
||||
if (level.dimension() == Level.NETHER) {
|
||||
BCLibNetherBiomeSource.setWorldHeight(level.getChunkSource().getGenerator().getGenDepth());
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import org.betterx.bclib.api.v2.LifeCycleAPI;
|
||||
import org.betterx.bclib.api.v2.dataexchange.DataExchangeAPI;
|
||||
import org.betterx.bclib.api.v2.datafixer.DataFixerAPI;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.presets.worldgen.WorldBootstrap;
|
||||
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows;
|
||||
|
@ -22,6 +21,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(WorldOpenFlows.class)
|
||||
public abstract class WorldOpenFlowsMixin {
|
||||
|
||||
|
@ -34,8 +35,7 @@ public abstract class WorldOpenFlowsMixin {
|
|||
|
||||
@Inject(method = "loadLevel", cancellable = true, at = @At("HEAD"))
|
||||
private void bcl_callFixerOnLoad(Screen screen, String levelID, CallbackInfo ci) {
|
||||
DataExchangeAPI.prepareServerside();
|
||||
InternalBiomeAPI.prepareNewLevel();
|
||||
WorldBootstrap.InGUI.setupLoadedWorld(levelID, this.levelSource);
|
||||
|
||||
if (DataFixerAPI.fixData(this.levelSource, levelID, true, (appliedFixes) -> {
|
||||
LifeCycleAPI._runBeforeLevelLoad();
|
||||
|
@ -61,7 +61,7 @@ public abstract class WorldOpenFlowsMixin {
|
|||
WorldGenSettings worldGenSettings,
|
||||
CallbackInfo ci
|
||||
) {
|
||||
LifeCycleAPI.newWorldSetup(levelID, worldGenSettings, this.levelSource);
|
||||
WorldBootstrap.InFreshLevel.setupNewWorld(levelID, worldGenSettings, this.levelSource, Optional.empty());
|
||||
}
|
||||
|
||||
@Inject(method = "createLevelFromExistingSettings", at = @At("HEAD"))
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import org.betterx.bclib.presets.worldgen.BCLWorldPreset;
|
||||
import org.betterx.bclib.presets.worldgen.WorldPresetSettings;
|
||||
|
||||
import com.mojang.datafixers.kinds.App;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Mixin(WorldPreset.class)
|
||||
public class WorldPresetMixin {
|
||||
|
||||
|
||||
@ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/codecs/RecordCodecBuilder;create(Ljava/util/function/Function;)Lcom/mojang/serialization/Codec;"))
|
||||
private static Function<RecordCodecBuilder.Instance<WorldPreset>, ? extends App<RecordCodecBuilder.Mu<WorldPreset>, WorldPreset>> foo(
|
||||
Function<RecordCodecBuilder.Instance<WorldPreset>, ? extends App<RecordCodecBuilder.Mu<WorldPreset>, WorldPreset>> builder
|
||||
) {
|
||||
final Function<RecordCodecBuilder.Instance<WorldPreset>, App<RecordCodecBuilder.Mu<WorldPreset>, WorldPreset>> CODEC_FUNCTION = builderInstance -> {
|
||||
RecordCodecBuilder<WorldPreset, Map<ResourceKey<LevelStem>, LevelStem>> dimensionsBuilder = Codec
|
||||
.unboundedMap(
|
||||
ResourceKey.codec(Registry.LEVEL_STEM_REGISTRY),
|
||||
LevelStem.CODEC
|
||||
)
|
||||
.fieldOf("dimensions")
|
||||
.forGetter((wp) -> (wp instanceof WorldPresetAccessor)
|
||||
? ((WorldPresetAccessor) wp).bcl_getDimensions()
|
||||
: null);
|
||||
|
||||
RecordCodecBuilder<WorldPreset, Optional<Integer>> sortBuilder = Codec.INT
|
||||
.optionalFieldOf("sort_order")
|
||||
.forGetter(wp -> (wp instanceof BCLWorldPreset)
|
||||
? Optional.of(((BCLWorldPreset) wp).sortOrder)
|
||||
: Optional.empty());
|
||||
|
||||
RecordCodecBuilder<WorldPreset, Optional<WorldPresetSettings>> settingsBuilder = WorldPresetSettings.CODEC
|
||||
.optionalFieldOf("settings")
|
||||
.forGetter(wp -> (wp instanceof BCLWorldPreset)
|
||||
? Optional.of(((BCLWorldPreset) wp).settings)
|
||||
: Optional.empty());
|
||||
|
||||
return builderInstance
|
||||
.group(dimensionsBuilder, sortBuilder, settingsBuilder)
|
||||
.apply(builderInstance, BCLWorldPreset::new);
|
||||
};
|
||||
|
||||
return CODEC_FUNCTION;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue