diff --git a/gradle.properties b/gradle.properties index edefb808..66888b8b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,20 +1,16 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx2G - #Loom loom_version=0.11-SNAPSHOT - # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version= 1.19-pre1 -loader_version= 0.14.5 -fabric_version = 0.52.4+1.19 - +minecraft_version=1.19-pre3 +loader_version=0.14.6 +fabric_version=0.53.4+1.19 # Mod Properties -mod_version = 2.0.0 -maven_group = org.betterx.bclib -archives_base_name = bclib - +mod_version=2.0.0 +maven_group=org.betterx.bclib +archives_base_name=bclib # Dependencies -patchouli_version = 50-FABRIC +patchouli_version=50-FABRIC modmenu_version=4.0.0-beta.3 \ No newline at end of file diff --git a/src/main/java/org/betterx/bclib/api/LifeCycleAPI.java b/src/main/java/org/betterx/bclib/api/LifeCycleAPI.java index 9d868941..81467908 100644 --- a/src/main/java/org/betterx/bclib/api/LifeCycleAPI.java +++ b/src/main/java/org/betterx/bclib/api/LifeCycleAPI.java @@ -8,9 +8,12 @@ import net.minecraft.server.level.progress.ChunkProgressListener; import net.minecraft.world.level.CustomSpawner; import net.minecraft.world.level.Level; import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.ServerLevelData; +import org.betterx.bclib.api.biomes.BiomeAPI; +import org.betterx.bclib.api.dataexchange.DataExchangeAPI; import org.betterx.bclib.api.datafixer.DataFixerAPI; import java.util.ArrayList; @@ -25,6 +28,25 @@ public class LifeCycleAPI { private final static List onLoadLevel = new ArrayList<>(2); private final static List beforeLoadLevel = new ArrayList<>(2); + public static void startingWorld(LevelStorageSource.LevelStorageAccess levelStorageAccess, + WorldGenSettings settings) { + DataExchangeAPI.prepareServerside(); + BiomeAPI.prepareNewLevel(); + + DataFixerAPI.createWorldData(levelStorageAccess, settings); + _runBeforeLevelLoad(); + } + + public static void startingWorld(String levelID, + WorldGenSettings worldGenSettings, + LevelStorageSource levelSource) { + DataExchangeAPI.prepareServerside(); + BiomeAPI.prepareNewLevel(); + + DataFixerAPI.createWorldData(levelSource, levelID, worldGenSettings); + _runBeforeLevelLoad(); + } + /** * A callback function that is used for each new ServerLevel instance */ @@ -121,18 +143,18 @@ public class LifeCycleAPI { List list, boolean bl2) { onLoadLevel.forEach(c -> c.onLoad( - world, - minecraftServer, - executor, - levelStorageAccess, - serverLevelData, - resourceKey, - chunkProgressListener, - bl, - l, - list, - bl2) - ); + world, + minecraftServer, + executor, + levelStorageAccess, + serverLevelData, + resourceKey, + chunkProgressListener, + bl, + l, + list, + bl2) + ); final long seed = world.getSeed(); final Registry biomeRegistry = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); diff --git a/src/main/java/org/betterx/bclib/api/biomes/BiomeAPI.java b/src/main/java/org/betterx/bclib/api/biomes/BiomeAPI.java index e5248965..6c37cc61 100644 --- a/src/main/java/org/betterx/bclib/api/biomes/BiomeAPI.java +++ b/src/main/java/org/betterx/bclib/api/biomes/BiomeAPI.java @@ -26,10 +26,10 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.PalettedContainer; +import net.minecraft.world.level.dimension.BuiltinDimensionTypes; +import net.minecraft.world.level.dimension.DimensionType; import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; -import net.minecraft.world.level.levelgen.SurfaceRules; -import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.Feature; import net.minecraft.world.level.levelgen.placement.PlacedFeature; @@ -56,7 +56,6 @@ import org.betterx.bclib.interfaces.SurfaceRuleProvider; import org.betterx.bclib.mixin.client.MinecraftMixin; import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor; import org.betterx.bclib.mixin.common.MobSpawnSettingsAccessor; -import org.betterx.bclib.mixin.common.NoiseGeneratorSettingsMixin; import org.betterx.bclib.util.CollectionsUtil; import org.betterx.bclib.world.biomes.BCLBiome; import org.betterx.bclib.world.biomes.FabricBiomesData; @@ -126,7 +125,7 @@ public class BiomeAPI { private static final Map, Integer> FEATURE_ORDER = Maps.newHashMap(); private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0); - private static final Map>>> MODIFICATIONS = Maps.newHashMap(); + private static final Map, List>>> MODIFICATIONS = Maps.newHashMap(); private static final Map>>> TAG_ADDERS = Maps.newHashMap(); private static final Set MODIFIED_SURFACE_PROVIDERS = new HashSet<>(8); @@ -560,7 +559,7 @@ public class BiomeAPI { * @param dimensionID {@link ResourceLocation} dimension ID, example: Level.OVERWORLD or "minecraft:overworld". * @param modification {@link BiConsumer} with {@link ResourceKey} biome ID and {@link Biome} parameters. */ - public static void registerBiomeModification(ResourceKey dimensionID, + public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer> modification) { List>> modifications = MODIFICATIONS.computeIfAbsent(dimensionID, k -> Lists.newArrayList()); @@ -573,7 +572,7 @@ public class BiomeAPI { * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ public static void registerOverworldBiomeModification(BiConsumer> modification) { - registerBiomeModification(Level.OVERWORLD, modification); + registerBiomeModification(BuiltinDimensionTypes.OVERWORLD, modification); } /** @@ -582,7 +581,7 @@ public class BiomeAPI { * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ public static void registerNetherBiomeModification(BiConsumer> modification) { - registerBiomeModification(Level.NETHER, modification); + registerBiomeModification(BuiltinDimensionTypes.NETHER, modification); } /** @@ -591,7 +590,7 @@ public class BiomeAPI { * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. */ public static void registerEndBiomeModification(BiConsumer> modification) { - registerBiomeModification(Level.END, modification); + registerBiomeModification(BuiltinDimensionTypes.END, modification); } /** @@ -656,7 +655,11 @@ public class BiomeAPI { * * @param level */ - public static void applyModifications(ServerLevel level) { + @Deprecated(forRemoval = true) + public static void applyModificationsDeprecated(ServerLevel level) { + //TODO: Now Disabled, because we fix the settings when everything gets loaded + if (level != null) return; + NoiseGeneratorSettings noiseGeneratorSettings = null; final ChunkGenerator chunkGenerator = level.getChunkSource().getGenerator(); final BiomeSource source = chunkGenerator.getBiomeSource(); @@ -675,7 +678,10 @@ public class BiomeAPI { } } - List>> modifications = MODIFICATIONS.get(level.dimension()); + List>> modifications = MODIFICATIONS.get(level + .dimensionTypeRegistration() + .unwrapKey() + .orElseThrow()); for (Holder biomeHolder : biomes) { if (biomeHolder.isBound()) { applyModificationsAndUpdateFeatures(modifications, biomeHolder); @@ -698,6 +704,18 @@ public class BiomeAPI { ((BiomeSourceAccessor) source).bclRebuildFeatures(); } + public static void applyModifications(BiomeSource source, ResourceKey dimension) { + BCLib.LOGGER.info("Apply Modifications for " + dimension.location() + " BiomeSource " + source); + final Set> biomes = source.possibleBiomes(); + List>> modifications = MODIFICATIONS.get(dimension); + for (Holder biomeHolder : biomes) { + if (biomeHolder.isBound()) { + applyModificationsAndUpdateFeatures(modifications, biomeHolder); + } + } + } + + private static void applyModificationsAndUpdateFeatures(List>> modifications, Holder biome) { ResourceLocation biomeID = getBiomeID(biome); @@ -727,7 +745,7 @@ public class BiomeAPI { } accessor.bclib_setFeatures(featureList); } - + /** * Adds new features to existing biome. * @@ -788,8 +806,8 @@ public class BiomeAPI { accessor.bclib_setFeatureSet(featureSet); accessor.bclib_setFlowerFeatures(flowerFeatures); } - - + + /** * Adds mob spawning to specified biome. * diff --git a/src/main/java/org/betterx/bclib/api/worldgen/BCLChunkGenerator.java b/src/main/java/org/betterx/bclib/api/worldgen/BCLChunkGenerator.java index 2428ea26..cadba8c8 100644 --- a/src/main/java/org/betterx/bclib/api/worldgen/BCLChunkGenerator.java +++ b/src/main/java/org/betterx/bclib/api/worldgen/BCLChunkGenerator.java @@ -3,16 +3,26 @@ package org.betterx.bclib.api.worldgen; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryOps; +import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.chunk.ChunkGenerator; +import net.minecraft.world.level.dimension.BuiltinDimensionTypes; +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.WorldGenSettings; import net.minecraft.world.level.levelgen.structure.StructureSet; import net.minecraft.world.level.levelgen.synth.NormalNoise; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.betterx.bclib.BCLib; +import org.betterx.bclib.api.biomes.BiomeAPI; import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider; +import org.betterx.bclib.interfaces.SurfaceRuleProvider; + +import java.util.Optional; public class BCLChunkGenerator extends NoiseBasedChunkGenerator { @@ -39,6 +49,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator { .apply(builderInstance, builderInstance.stable(BCLChunkGenerator::new)); }); + public BCLChunkGenerator(Registry registry, Registry registry2, BiomeSource biomeSource, @@ -47,6 +58,35 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator { System.out.println("Chunk Generator: " + this); } + public static void injectNoiseSettings(WorldGenSettings settings) { + injectNoiseSettings(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, settings); + injectNoiseSettings(LevelStem.END, BuiltinDimensionTypes.END, settings); + } + + public static void injectNoiseSettings(ResourceKey dimensionKey, + ResourceKey dimensionTypeKey, + WorldGenSettings settings) { + Optional> loadedStem = settings.dimensions().getHolder(dimensionKey); + final ChunkGenerator loadedChunkGenerator = loadedStem.map(h -> h.value().generator()).orElse(null); + injectNoiseSettings(dimensionTypeKey, loadedChunkGenerator); + } + + public static void injectNoiseSettings(ResourceKey dimensionTypeKey, + ChunkGenerator loadedChunkGenerator) { + BCLib.LOGGER.debug("Correcting Noise Settings for " + dimensionTypeKey.location().toString()); + final BiomeSource loadedBiomeSource = loadedChunkGenerator.getBiomeSource(); + BiomeAPI.applyModifications(loadedBiomeSource, dimensionTypeKey); + + if (loadedChunkGenerator instanceof NoiseBasedChunkGenerator nbc) { + if (((Object) nbc.generatorSettings().value()) instanceof SurfaceRuleProvider srp) { + srp.bclib_overwrite(SurfaceRuleUtil.addRulesForBiomeSource(nbc + .generatorSettings() + .value() + .surfaceRule(), loadedBiomeSource)); + } + } + } + @Override protected Codec codec() { return CODEC; diff --git a/src/main/java/org/betterx/bclib/api/worldgen/SurfaceRuleUtil.java b/src/main/java/org/betterx/bclib/api/worldgen/SurfaceRuleUtil.java index ef12fd41..4401f04c 100644 --- a/src/main/java/org/betterx/bclib/api/worldgen/SurfaceRuleUtil.java +++ b/src/main/java/org/betterx/bclib/api/worldgen/SurfaceRuleUtil.java @@ -1,8 +1,5 @@ package org.betterx.bclib.api.worldgen; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import net.minecraft.core.Holder; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -10,6 +7,10 @@ import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.levelgen.SurfaceRules; import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import org.betterx.bclib.api.biomes.BiomeAPI; import org.betterx.bclib.mixin.common.NoiseGeneratorSettingsMixin; @@ -20,71 +21,77 @@ import java.util.Set; import java.util.stream.Collectors; public class SurfaceRuleUtil { - private static final Map SURFACE_RULES = Maps.newHashMap(); - - private static List getRuleSourcesForBiomes(Set> biomes) { - Set biomeIDs = biomes - .stream() - .map(biome -> BiomeAPI.getBiomeID(biome)) - .collect(Collectors.toSet()); - return getRuleSourcesFromIDs(biomeIDs); - } - - /** - * Creates a list of SurfaceRules for all Biomes that are managed by the passed {@link BiomeSource}. - * If we have Surface rules for any of the Biomes from the given set of {@link BiomeSource}, they - * will be added to the result - *

- * Note: This Method is used in the {@link NoiseGeneratorSettingsMixin} which in turn - * is called from {@link BiomeAPI#applyModifications(ServerLevel)}. - * - * @param sources The Set of {@link BiomeSource} we want to consider - * @return A list of {@link RuleSource}-Objects that are needed to create those Biomes - */ - public static List getRuleSources(Set sources) { - final Set> biomes = new HashSet<>(); - for (BiomeSource s : sources) { - biomes.addAll(s.possibleBiomes()); - } + private static final Map SURFACE_RULES = Maps.newHashMap(); - return getRuleSourcesForBiomes(biomes); - } - - public static List getRuleSources(BiomeSource biomeSource) { - return getRuleSourcesForBiomes(Sets.newHashSet(biomeSource.possibleBiomes())); - } - - private static List getRuleSourcesFromIDs(Set biomeIDs) { - List rules = Lists.newArrayList(); - SURFACE_RULES.forEach((biomeID, rule) -> { - if (biomeIDs.contains(biomeID)) { - rules.add(rule); - } - }); - return rules; - } - - /** - * Adds surface rule to specified biome. - * - * @param biomeID biome {@link ResourceLocation}. - * @param source {@link RuleSource}. - */ - public static void addSurfaceRule(ResourceLocation biomeID, RuleSource source) { - SURFACE_RULES.put(biomeID, source); - //NOISE_GENERATOR_SETTINGS.forEach(BiomeAPI::changeSurfaceRulesForGenerator); - } - - public static RuleSource addRulesForBiomeSource(RuleSource org, BiomeSource biomeSource) { - List additionalRules = getRuleSources(biomeSource); - if (org instanceof SurfaceRules.SequenceRuleSource sequenceRule) { - List existingSequence = sequenceRule.sequence(); - additionalRules = additionalRules.stream().filter(r -> existingSequence.indexOf(r) < 0).collect(Collectors.toList()); - additionalRules.addAll(sequenceRule.sequence()); - } else { - additionalRules.add(org); - } - - return SurfaceRules.sequence(additionalRules.toArray(new RuleSource[additionalRules.size()])); - } + private static List getRuleSourcesForBiomes(Set> biomes) { + Set biomeIDs = biomes + .stream() + .map(biome -> BiomeAPI.getBiomeID(biome)) + .collect(Collectors.toSet()); + return getRuleSourcesFromIDs(biomeIDs); + } + + /** + * Creates a list of SurfaceRules for all Biomes that are managed by the passed {@link BiomeSource}. + * If we have Surface rules for any of the Biomes from the given set of {@link BiomeSource}, they + * will be added to the result + *

+ * Note: This Method is used in the {@link NoiseGeneratorSettingsMixin} which in turn + * is called from {@link BiomeAPI#applyModificationsDeprecated(ServerLevel)}. + * + * @param sources The Set of {@link BiomeSource} we want to consider + * @return A list of {@link RuleSource}-Objects that are needed to create those Biomes + */ + public static List getRuleSources(Set sources) { + final Set> biomes = new HashSet<>(); + for (BiomeSource s : sources) { + biomes.addAll(s.possibleBiomes()); + } + + return getRuleSourcesForBiomes(biomes); + } + + public static List getRuleSources(BiomeSource biomeSource) { + return getRuleSourcesForBiomes(Sets.newHashSet(biomeSource.possibleBiomes())); + } + + private static List getRuleSourcesFromIDs(Set biomeIDs) { + List rules = Lists.newArrayList(); + SURFACE_RULES.forEach((biomeID, rule) -> { + if (biomeIDs.contains(biomeID)) { + rules.add(rule); + } + }); + return rules; + } + + /** + * Adds surface rule to specified biome. + * + * @param biomeID biome {@link ResourceLocation}. + * @param source {@link RuleSource}. + */ + public static void addSurfaceRule(ResourceLocation biomeID, RuleSource source) { + SURFACE_RULES.put(biomeID, source); + //NOISE_GENERATOR_SETTINGS.forEach(BiomeAPI::changeSurfaceRulesForGenerator); + } + + public static RuleSource addRulesForBiomeSource(RuleSource org, BiomeSource biomeSource) { + List additionalRules = getRuleSources(biomeSource); + if (org instanceof SurfaceRules.SequenceRuleSource sequenceRule) { + List existingSequence = sequenceRule.sequence(); + additionalRules = additionalRules + .stream() + .filter(r -> existingSequence.indexOf(r) < 0) + .collect(Collectors.toList()); + if (additionalRules.size() == 0) return org; + additionalRules.addAll(sequenceRule.sequence()); + } else { + if (additionalRules.size() == 0) return org; + if (!additionalRules.contains(org)) + additionalRules.add(org); + } + + return SurfaceRules.sequence(additionalRules.toArray(new RuleSource[additionalRules.size()])); + } } diff --git a/src/main/java/org/betterx/bclib/interfaces/SurfaceRuleProvider.java b/src/main/java/org/betterx/bclib/interfaces/SurfaceRuleProvider.java index acebef04..ebb2dc55 100644 --- a/src/main/java/org/betterx/bclib/interfaces/SurfaceRuleProvider.java +++ b/src/main/java/org/betterx/bclib/interfaces/SurfaceRuleProvider.java @@ -1,8 +1,10 @@ package org.betterx.bclib.interfaces; import net.minecraft.world.level.biome.BiomeSource; +import net.minecraft.world.level.levelgen.SurfaceRules; public interface SurfaceRuleProvider { void bclib_addBiomeSource(BiomeSource source); void bclib_clearBiomeSources(); + void bclib_overwrite(SurfaceRules.RuleSource surfaceRule); } diff --git a/src/main/java/org/betterx/bclib/mixin/client/CreateWorldScreenMixin.java b/src/main/java/org/betterx/bclib/mixin/client/CreateWorldScreenMixin.java index 0e83b2b2..19fd70ab 100644 --- a/src/main/java/org/betterx/bclib/mixin/client/CreateWorldScreenMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/client/CreateWorldScreenMixin.java @@ -10,21 +10,30 @@ 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 net.minecraft.world.level.storage.LevelStorageSource; import com.mojang.datafixers.util.Pair; +import org.betterx.bclib.api.LifeCycleAPI; import org.betterx.bclib.api.biomes.BiomeAPI; -import org.betterx.bclib.presets.worldgen.BCLWorldPresets; import org.betterx.bclib.api.worldgen.WorldGenUtil; +import org.betterx.bclib.presets.worldgen.BCLWorldPresets; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Optional; @Mixin(CreateWorldScreen.class) public class CreateWorldScreenMixin { + @Shadow + @Final + public WorldGenSettingsComponent worldGenSettingsComponent; + @Inject(method = "", at = @At("TAIL")) private void bcl_init(Screen screen, DataPackConfig dataPackConfig, @@ -47,4 +56,14 @@ public class CreateWorldScreenMixin { return WorldGenUtil.defaultWorldDataSupplier(res.getSecond()); }; } + + @Inject(method = "createNewWorldDirectory", at = @At("RETURN")) + void bcl_createNewWorld(CallbackInfoReturnable> cir) { + Optional levelStorageAccess = cir.getReturnValue(); + if (levelStorageAccess.isPresent()) { + LifeCycleAPI.startingWorld(levelStorageAccess.get(), + worldGenSettingsComponent.settings().worldGenSettings()); + } + } + } diff --git a/src/main/java/org/betterx/bclib/mixin/client/SignEditScreenMixin.java b/src/main/java/org/betterx/bclib/mixin/client/SignEditScreenMixin.java index 72a15df8..459b1e59 100644 --- a/src/main/java/org/betterx/bclib/mixin/client/SignEditScreenMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/client/SignEditScreenMixin.java @@ -40,7 +40,7 @@ public abstract class SignEditScreenMixin extends Screen { super(component); } - @Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V", locals = LocalCapture.CAPTURE_FAILSOFT, at = @At( + @Inject(method = "render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V", locals = LocalCapture.CAPTURE_FAILSOFT, at = @At(ordinal = 1, value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V", shift = Shift.BEFORE diff --git a/src/main/java/org/betterx/bclib/mixin/common/NoiseBasedChunkGeneratorMixin.java b/src/main/java/org/betterx/bclib/mixin/common/NoiseBasedChunkGeneratorMixin.java index 97d98dea..2a5f1caa 100644 --- a/src/main/java/org/betterx/bclib/mixin/common/NoiseBasedChunkGeneratorMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/common/NoiseBasedChunkGeneratorMixin.java @@ -2,12 +2,8 @@ package org.betterx.bclib.mixin.common; import net.minecraft.core.Holder; import net.minecraft.core.Registry; -import net.minecraft.world.level.StructureManager; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkAccess; -import net.minecraft.world.level.levelgen.*; -import net.minecraft.world.level.levelgen.blending.Blender; +import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator; +import net.minecraft.world.level.levelgen.NoiseGeneratorSettings; import net.minecraft.world.level.levelgen.synth.NormalNoise; import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider; @@ -16,8 +12,6 @@ import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import java.lang.reflect.Constructor; - @Mixin(NoiseBasedChunkGenerator.class) public abstract class NoiseBasedChunkGeneratorMixin implements SurfaceProvider, NoiseGeneratorSettingsProvider { @Final @@ -27,12 +21,6 @@ public abstract class NoiseBasedChunkGeneratorMixin implements SurfaceProvider, @Shadow @Final private Registry noises; - @Final - @Shadow - private Aquifer.FluidPicker globalFluidPicker; - - private static final BlockState bclib_air = Blocks.AIR.defaultBlockState(); - private static Constructor bclib_constructor; @Override public NoiseGeneratorSettings bclib_getNoiseGeneratorSettings() { @@ -48,11 +36,4 @@ public abstract class NoiseBasedChunkGeneratorMixin implements SurfaceProvider, public Registry bclib_getNoises() { return noises; } - - @Shadow - protected abstract NoiseChunk createNoiseChunk(ChunkAccess chunkAccess, - StructureManager structureManager, - Blender blender, - RandomState randomState); - } diff --git a/src/main/java/org/betterx/bclib/mixin/common/NoiseGeneratorSettingsMixin.java b/src/main/java/org/betterx/bclib/mixin/common/NoiseGeneratorSettingsMixin.java index 4474d29f..13379878 100644 --- a/src/main/java/org/betterx/bclib/mixin/common/NoiseGeneratorSettingsMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/common/NoiseGeneratorSettingsMixin.java @@ -68,6 +68,15 @@ public class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider { bclib_setSurfaceRule(SurfaceRules.sequence(rules.toArray(new RuleSource[rules.size()]))); } + public void bclib_overwrite(SurfaceRules.RuleSource surfaceRule) { + if (surfaceRule == this.surfaceRule) return; + if (this.bcl_containsOverride) { + System.out.println("Adding another override"); + } + this.bcl_containsOverride = true; + this.surfaceRule = surfaceRule; + } + void bclib_setSurfaceRule(SurfaceRules.RuleSource surfaceRule) { if (bclib_originalSurfaceRule == null) { bclib_originalSurfaceRule = this.surfaceRule; @@ -75,6 +84,8 @@ public class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider { this.surfaceRule = surfaceRule; } + private boolean bcl_containsOverride = false; + RuleSource bclib_getOriginalSurfaceRule() { if (bclib_originalSurfaceRule == null) { return surfaceRule; diff --git a/src/main/java/org/betterx/bclib/mixin/common/PrimaryLevelDataMixin.java b/src/main/java/org/betterx/bclib/mixin/common/PrimaryLevelDataMixin.java index 7d37fba9..2efeeb6f 100644 --- a/src/main/java/org/betterx/bclib/mixin/common/PrimaryLevelDataMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/common/PrimaryLevelDataMixin.java @@ -11,8 +11,11 @@ import net.minecraft.world.level.storage.PrimaryLevelData; import com.mojang.datafixers.DataFixer; import com.mojang.serialization.Dynamic; import com.mojang.serialization.Lifecycle; +import org.betterx.bclib.api.worldgen.BCLChunkGenerator; import org.betterx.bclib.api.worldgen.WorldGenUtil; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyArg; @@ -23,9 +26,18 @@ import org.jetbrains.annotations.Nullable; @Mixin(PrimaryLevelData.class) public class PrimaryLevelDataMixin { + @Shadow + @Final + private WorldGenSettings worldGenSettings; private static final ThreadLocal>> bcl_lastRegistryAccess = ThreadLocal.withInitial( () -> Optional.empty()); + @ModifyArg(method = "(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;(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; + } + @Inject(method = "parse", at = @At("HEAD")) private static void bcl_parse(Dynamic dynamic, DataFixer dataFixer, diff --git a/src/main/java/org/betterx/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/org/betterx/bclib/mixin/common/ServerLevelMixin.java index 6344725b..4c401d21 100644 --- a/src/main/java/org/betterx/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/common/ServerLevelMixin.java @@ -57,18 +57,18 @@ public abstract class ServerLevelMixin extends Level { CallbackInfo ci) { ServerLevel level = ServerLevel.class.cast(this); LifeCycleAPI._runLevelLoad(level, - server, - executor, - levelStorageAccess, - serverLevelData, - resourceKey, - chunkProgressListener, - bl, - l, - list, - bl2); + server, + executor, + levelStorageAccess, + serverLevelData, + resourceKey, + chunkProgressListener, + bl, + l, + list, + bl2); - BiomeAPI.applyModifications(ServerLevel.class.cast(this)); + BiomeAPI.applyModificationsDeprecated(ServerLevel.class.cast(this)); if (level.dimension() == Level.NETHER) { BCLibNetherBiomeSource.setWorldHeight(level.getChunkSource().getGenerator().getGenDepth()); diff --git a/src/main/java/org/betterx/bclib/mixin/common/WorldOpenFlowsMixin.java b/src/main/java/org/betterx/bclib/mixin/common/WorldOpenFlowsMixin.java index eae0c1c2..78fe28e6 100644 --- a/src/main/java/org/betterx/bclib/mixin/common/WorldOpenFlowsMixin.java +++ b/src/main/java/org/betterx/bclib/mixin/common/WorldOpenFlowsMixin.java @@ -58,11 +58,7 @@ public abstract class WorldOpenFlowsMixin { RegistryAccess registryAccess, WorldGenSettings worldGenSettings, CallbackInfo ci) { - DataExchangeAPI.prepareServerside(); - BiomeAPI.prepareNewLevel(); - - DataFixerAPI.createWorldData(this.levelSource, levelID, worldGenSettings); - LifeCycleAPI._runBeforeLevelLoad(); + LifeCycleAPI.startingWorld(levelID, worldGenSettings, this.levelSource); } @Inject(method = "createLevelFromExistingSettings", at = @At("HEAD")) @@ -71,10 +67,6 @@ public abstract class WorldOpenFlowsMixin { RegistryAccess.Frozen frozen, WorldData worldData, CallbackInfo ci) { - DataExchangeAPI.prepareServerside(); - BiomeAPI.prepareNewLevel(); - - DataFixerAPI.createWorldData(levelStorageAccess, worldData.worldGenSettings()); - LifeCycleAPI._runBeforeLevelLoad(); + //LifeCycleAPI.startWorld(levelStorageAccess, worldData.worldGenSettings()); } } diff --git a/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresetSettings.java b/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresetSettings.java index 825fc633..a9510889 100644 --- a/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresetSettings.java +++ b/src/main/java/org/betterx/bclib/presets/worldgen/BCLWorldPresetSettings.java @@ -15,6 +15,7 @@ import net.minecraft.world.level.levelgen.WorldGenSettings; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import org.betterx.bclib.BCLib; +import org.betterx.bclib.api.biomes.BiomeAPI; import org.betterx.bclib.api.worldgen.BCLChunkGenerator; import org.betterx.bclib.api.worldgen.SurfaceRuleUtil; import org.betterx.bclib.api.worldgen.WorldGenUtil; @@ -140,15 +141,16 @@ public class BCLWorldPresetSettings extends WorldPresetSettings { public WorldGenSettings fixSettingsInCurrentWorld(RegistryAccess access, ResourceKey dimensionKey, ResourceKey dimensionTypeKey, WorldGenSettings settings) { - var oldNether = settings.dimensions().getHolder(dimensionKey); - int loaderVersion = WorldGenUtil.getBiomeVersionForGenerator(oldNether + Optional> loadedStem = settings.dimensions().getHolder(dimensionKey); + final ChunkGenerator loadedChunkGenerator = loadedStem.map(h -> h.value().generator()).orElse(null); + final int loaderVersion = WorldGenUtil.getBiomeVersionForGenerator(loadedStem .map(h -> h.value().generator()) .orElse(null)); - int targetVersion = getVersion(dimensionKey); + final int targetVersion = getVersion(dimensionKey); if (loaderVersion != targetVersion) { BCLib.LOGGER.info("Enforcing Correct Generator for " + dimensionKey.location().toString() + "."); - var chunkGenerator = oldNether.map(h -> h.value().generator()).orElse(null); + Optional> refLevelStem = WorldGenUtil.referenceStemForVersion( dimensionKey, targetVersion, @@ -164,10 +166,11 @@ public class BCLWorldPresetSettings extends WorldPresetSettings { return settings; } - if (chunkGenerator instanceof ChunkGeneratorAccessor generator) { - if (chunkGenerator instanceof NoiseGeneratorSettingsProvider noiseProvider) { - final Set> biomes = chunkGenerator.getBiomeSource().possibleBiomes(); + if (loadedChunkGenerator instanceof ChunkGeneratorAccessor generator) { + if (loadedChunkGenerator instanceof NoiseGeneratorSettingsProvider noiseProvider) { + final Set> biomes = loadedChunkGenerator.getBiomeSource().possibleBiomes(); final BiomeSource bs = fixBiomeSource(referenceGenerator.getBiomeSource(), biomes); + BiomeAPI.applyModifications(bs, dimensionTypeKey); referenceGenerator = new BCLChunkGenerator(generator.bclib_getStructureSetsRegistry(), noiseProvider.bclib_getNoises(), bs, @@ -181,6 +184,8 @@ public class BCLWorldPresetSettings extends WorldPresetSettings { access, settings, referenceGenerator); + } else { + BCLChunkGenerator.injectNoiseSettings(dimensionTypeKey, loadedChunkGenerator); } return settings; } diff --git a/src/main/java/org/betterx/bclib/util/ModUtil.java b/src/main/java/org/betterx/bclib/util/ModUtil.java index 63d30e73..32e068a4 100644 --- a/src/main/java/org/betterx/bclib/util/ModUtil.java +++ b/src/main/java/org/betterx/bclib/util/ModUtil.java @@ -57,8 +57,8 @@ public class ModUtil { private static ModMetadata readJSON(InputStream is, String sourceFile) throws IOException { try (com.google.gson.stream.JsonReader reader = new JsonReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { - JsonObject data = new JsonParser().parse(reader) - .getAsJsonObject(); + JsonObject data = JsonParser.parseReader(reader) + .getAsJsonObject(); Version ver; try { ver = new SemanticVersionImpl(data.get("version") diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 94a9d1f0..b2662f50 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -37,9 +37,9 @@ "bclib.mixins.client.json" ], "depends": { - "fabricloader": ">=0.14.5", - "fabric": ">=0.52.4", - "minecraft": "1.19-beta.1" + "fabricloader": ">=0.14.6", + "fabric": ">=0.53.4", + "minecraft": "1.19-beta.3" }, "custom": { "modmenu": {