[Changes] Cleanup of old SurfaceRule code
This commit is contained in:
parent
da1d4c6b40
commit
cc36c090a1
19 changed files with 305 additions and 147 deletions
|
@ -1,10 +1,7 @@
|
||||||
package org.betterx.bclib.api.v2.generator;
|
package org.betterx.bclib.api.v2.generator;
|
||||||
|
|
||||||
import org.betterx.bclib.BCLib;
|
import org.betterx.bclib.BCLib;
|
||||||
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
|
||||||
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleUtil;
|
|
||||||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||||
import org.betterx.bclib.interfaces.SurfaceRuleProvider;
|
|
||||||
import org.betterx.bclib.mixin.common.ChunkGeneratorAccessor;
|
import org.betterx.bclib.mixin.common.ChunkGeneratorAccessor;
|
||||||
import org.betterx.worlds.together.WorldsTogether;
|
import org.betterx.worlds.together.WorldsTogether;
|
||||||
import org.betterx.worlds.together.world.WorldGenUtil;
|
import org.betterx.worlds.together.world.WorldGenUtil;
|
||||||
|
@ -32,9 +29,7 @@ import net.minecraft.world.level.levelgen.synth.NormalNoise;
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
|
|
||||||
|
@ -101,7 +96,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
if (initialBiomeSource != getBiomeSource()) {
|
if (initialBiomeSource != getBiomeSource()) {
|
||||||
if (this instanceof ChunkGeneratorAccessor acc) {
|
if (this instanceof ChunkGeneratorAccessor acc) {
|
||||||
BiomeSource bs = WorldGenUtil.getWorldSettings()
|
BiomeSource bs = WorldGenUtil.getWorldSettings()
|
||||||
.fixBiomeSource(initialBiomeSource, getBiomeSource().possibleBiomes());
|
.addDatapackBiomes(initialBiomeSource, getBiomeSource().possibleBiomes());
|
||||||
acc.bcl_setBiomeSource(bs);
|
acc.bcl_setBiomeSource(bs);
|
||||||
rebuildFeaturesPerStep(getBiomeSource());
|
rebuildFeaturesPerStep(getBiomeSource());
|
||||||
}
|
}
|
||||||
|
@ -109,43 +104,6 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void injectNoiseSettings(
|
|
||||||
ResourceKey<LevelStem> dimensionKey,
|
|
||||||
ChunkGenerator loadedChunkGenerator
|
|
||||||
) {
|
|
||||||
BCLib.LOGGER.debug("Checking Noise Settings for " + dimensionKey.location().toString());
|
|
||||||
final BiomeSource loadedBiomeSource = loadedChunkGenerator.getBiomeSource();
|
|
||||||
InternalBiomeAPI.applyModifications(loadedBiomeSource, dimensionKey);
|
|
||||||
|
|
||||||
if (loadedChunkGenerator instanceof NoiseBasedChunkGenerator nbc) {
|
|
||||||
if (((Object) nbc.generatorSettings().value()) instanceof SurfaceRuleProvider srp) {
|
|
||||||
srp.bclib_overwrite(SurfaceRuleUtil.addRulesForBiomeSource(nbc
|
|
||||||
.generatorSettings()
|
|
||||||
.value()
|
|
||||||
.surfaceRule(), loadedBiomeSource));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Predicate<ResourceKey<LevelStem>> NON_MANAGED_DIMENSIONS = dim -> dim != LevelStem.NETHER && dim != LevelStem.END;
|
|
||||||
|
|
||||||
public static void injectNoiseSettings(WorldGenSettings settings, Predicate<ResourceKey<LevelStem>> filter) {
|
|
||||||
List<ResourceKey<LevelStem>> otherDimensions = settings
|
|
||||||
.dimensions()
|
|
||||||
.entrySet()
|
|
||||||
.stream()
|
|
||||||
.map(e -> e.getKey())
|
|
||||||
.filter(filter)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
for (ResourceKey<LevelStem> key : otherDimensions) {
|
|
||||||
Optional<Holder<LevelStem>> stem = settings.dimensions().getHolder(key);
|
|
||||||
if (stem.isPresent()) {
|
|
||||||
injectNoiseSettings(key, stem.get().value().generator());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Codec<? extends ChunkGenerator> codec() {
|
protected Codec<? extends ChunkGenerator> codec() {
|
||||||
return CODEC;
|
return CODEC;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.betterx.bclib.util.CollectionsUtil;
|
||||||
import org.betterx.bclib.util.ColorUtil;
|
import org.betterx.bclib.util.ColorUtil;
|
||||||
import org.betterx.bclib.util.Pair;
|
import org.betterx.bclib.util.Pair;
|
||||||
import org.betterx.bclib.util.TriFunction;
|
import org.betterx.bclib.util.TriFunction;
|
||||||
|
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||||
|
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.HolderSet;
|
import net.minecraft.core.HolderSet;
|
||||||
|
@ -737,6 +738,7 @@ public class BCLBiomeBuilder {
|
||||||
*
|
*
|
||||||
* @param biomeConstructor {@link BiFunction} biome constructor.
|
* @param biomeConstructor {@link BiFunction} biome constructor.
|
||||||
* @return created {@link BCLBiome} instance.
|
* @return created {@link BCLBiome} instance.
|
||||||
|
* @deprecated Replaced with {@link #build(BiomeSupplier)}
|
||||||
*/
|
*/
|
||||||
@Deprecated(forRemoval = true)
|
@Deprecated(forRemoval = true)
|
||||||
public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) {
|
public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) {
|
||||||
|
@ -787,9 +789,11 @@ public class BCLBiomeBuilder {
|
||||||
final Biome biome = builder.build();
|
final Biome biome = builder.build();
|
||||||
final T res = biomeConstructor.apply(biomeID, biome, settings);
|
final T res = biomeConstructor.apply(biomeID, biome, settings);
|
||||||
res.addBiomeTags(tags);
|
res.addBiomeTags(tags);
|
||||||
res.setSurface(surfaceRule);
|
//res.setSurface(surfaceRule);
|
||||||
|
SurfaceRuleRegistry.registerRule(biomeID, surfaceRule, biomeID);
|
||||||
res.addClimateParameters(parameters);
|
res.addClimateParameters(parameters);
|
||||||
|
|
||||||
|
|
||||||
//carvers.forEach(cfg -> BiomeAPI.addBiomeCarver(biome, cfg.second, cfg.first));
|
//carvers.forEach(cfg -> BiomeAPI.addBiomeCarver(biome, cfg.second, cfg.first));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,8 @@ package org.betterx.bclib.api.v2.levelgen.biomes;
|
||||||
import org.betterx.bclib.BCLib;
|
import org.betterx.bclib.BCLib;
|
||||||
import org.betterx.bclib.interfaces.BiomeSourceAccessor;
|
import org.betterx.bclib.interfaces.BiomeSourceAccessor;
|
||||||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||||
import org.betterx.bclib.interfaces.SurfaceRuleProvider;
|
|
||||||
import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
||||||
|
import org.betterx.worlds.together.surfaceRules.SurfaceRuleProvider;
|
||||||
|
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
@ -205,7 +205,8 @@ public class InternalBiomeAPI {
|
||||||
// This happens for example when using the MiningDimensions, which reuses the generator for the
|
// This happens for example when using the MiningDimensions, which reuses the generator for the
|
||||||
// Nethering Dimension
|
// Nethering Dimension
|
||||||
//MODIFIED_SURFACE_PROVIDERS.add(provider);
|
//MODIFIED_SURFACE_PROVIDERS.add(provider);
|
||||||
provider.bclib_addBiomeSource(source);
|
|
||||||
|
//provider.bclib_addBiomeSource(source);
|
||||||
} else {
|
} else {
|
||||||
BCLib.LOGGER.warning("No generator for " + source);
|
BCLib.LOGGER.warning("No generator for " + source);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,13 @@ package org.betterx.bclib.api.v2.levelgen.surface;
|
||||||
|
|
||||||
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
|
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
|
||||||
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||||
import org.betterx.bclib.mixin.common.NoiseGeneratorSettingsMixin;
|
import org.betterx.worlds.together.mixin.common.NoiseGeneratorSettingsMixin;
|
||||||
|
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.level.biome.Biome;
|
import net.minecraft.world.level.biome.Biome;
|
||||||
import net.minecraft.world.level.biome.BiomeSource;
|
import net.minecraft.world.level.biome.BiomeSource;
|
||||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
|
||||||
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
@ -77,22 +76,12 @@ public class SurfaceRuleUtil {
|
||||||
SURFACE_RULES.put(biomeID, source);
|
SURFACE_RULES.put(biomeID, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RuleSource addRulesForBiomeSource(RuleSource org, BiomeSource biomeSource) {
|
public static RuleSource addRulesForBiomeSource(RuleSource orgiginalSource, BiomeSource biomeSource) {
|
||||||
List<RuleSource> additionalRules = getRuleSources(biomeSource);
|
List<RuleSource> additionalRules = getRuleSources(biomeSource);
|
||||||
if (org instanceof SurfaceRules.SequenceRuleSource sequenceRule) {
|
return org.betterx.worlds.together.surfaceRules.SurfaceRuleUtil.mergeSurfaceRules(
|
||||||
List<RuleSource> existingSequence = sequenceRule.sequence();
|
orgiginalSource,
|
||||||
additionalRules = 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()]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,14 @@ import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.resources.RegistryOps;
|
import net.minecraft.resources.RegistryOps;
|
||||||
|
import net.minecraft.tags.TagEntry;
|
||||||
|
import net.minecraft.tags.TagFile;
|
||||||
import net.minecraft.util.KeyDispatchDataCodec;
|
import net.minecraft.util.KeyDispatchDataCodec;
|
||||||
import net.minecraft.world.effect.MobEffect;
|
import net.minecraft.world.effect.MobEffect;
|
||||||
import net.minecraft.world.level.gameevent.GameEvent;
|
import net.minecraft.world.level.gameevent.GameEvent;
|
||||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.templatesystem.PosRuleTestType;
|
||||||
|
import net.minecraft.world.level.levelgen.structure.templatesystem.RuleTestType;
|
||||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList;
|
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorList;
|
||||||
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType;
|
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessorType;
|
||||||
import net.minecraft.world.level.material.Fluid;
|
import net.minecraft.world.level.material.Fluid;
|
||||||
|
@ -55,20 +59,37 @@ public class DumpDatapack {
|
||||||
File base = new File(System.getProperty("user.dir"), "bclib_datapack_dump");
|
File base = new File(System.getProperty("user.dir"), "bclib_datapack_dump");
|
||||||
BCLib.LOGGER.info(registry.key().toString());
|
BCLib.LOGGER.info(registry.key().toString());
|
||||||
// Tag Output
|
// Tag Output
|
||||||
// registry.value()
|
registry.value()
|
||||||
// .getTagNames()
|
.getTagNames()
|
||||||
// .map(tagKey -> registry.value().getTag(tagKey))
|
.map(tagKey -> registry.value().getTag(tagKey))
|
||||||
// .filter(tag -> tag.isPresent())
|
.filter(tag -> tag.isPresent())
|
||||||
// .map(tag -> tag.get())
|
.map(tag -> tag.get())
|
||||||
// .forEach(tag -> {
|
.forEach(tag -> {
|
||||||
// tag.stream()
|
File f1 = new File(base, tag.key().location().getNamespace());
|
||||||
// .map(holder -> holder.unwrapKey())
|
f1 = new File(f1, "tags");
|
||||||
// .filter(k -> k.isPresent())
|
f1 = new File(f1, registry.key().location().getPath());
|
||||||
// .map(k -> k.get())
|
f1.mkdirs();
|
||||||
// .forEach(key -> {
|
f1 = new File(f1, tag.key().location().getPath() + ".json");
|
||||||
//
|
|
||||||
// });
|
TagFile tf = new TagFile(
|
||||||
// });
|
tag.stream()
|
||||||
|
.map(holder -> holder.unwrapKey())
|
||||||
|
.filter(k -> k.isPresent())
|
||||||
|
.map(k -> TagEntry.element(k.get().location()))
|
||||||
|
.toList(),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
var o = TagFile.CODEC
|
||||||
|
.encodeStart(registryOps, tf)
|
||||||
|
.result()
|
||||||
|
.orElse(new JsonObject());
|
||||||
|
String content = gson.toJson(o);
|
||||||
|
try {
|
||||||
|
Files.writeString(f1.toPath(), content, StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
BCLib.LOGGER.error(" ->> Unable to WRITE: " + e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
registry
|
registry
|
||||||
.value()
|
.value()
|
||||||
|
@ -102,6 +123,10 @@ public class DumpDatapack {
|
||||||
return;
|
return;
|
||||||
} else if (obj instanceof BaseStairsBlock) {
|
} else if (obj instanceof BaseStairsBlock) {
|
||||||
return;
|
return;
|
||||||
|
} else if (obj instanceof RuleTestType<?>) {
|
||||||
|
codec[0] = registry.value().byNameCodec();
|
||||||
|
} else if (obj instanceof PosRuleTestType<?>) {
|
||||||
|
codec[0] = registry.value().byNameCodec();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codec[0] == null) {
|
if (codec[0] == null) {
|
||||||
|
@ -113,6 +138,7 @@ public class DumpDatapack {
|
||||||
try {
|
try {
|
||||||
codec[0] = (Codec) m.invoke(obj);
|
codec[0] = (Codec) m.invoke(obj);
|
||||||
BCLib.LOGGER.info(" Got Codec from " + m);
|
BCLib.LOGGER.info(" Got Codec from " + m);
|
||||||
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
BCLib.LOGGER.error(" !!! Unable to get Codec from " + m);
|
BCLib.LOGGER.error(" !!! Unable to get Codec from " + m);
|
||||||
}
|
}
|
||||||
|
@ -120,6 +146,7 @@ public class DumpDatapack {
|
||||||
try {
|
try {
|
||||||
codec[0] = ((KeyDispatchCodec) m.invoke(obj)).codec();
|
codec[0] = ((KeyDispatchCodec) m.invoke(obj)).codec();
|
||||||
BCLib.LOGGER.info(" Got Codec from " + m);
|
BCLib.LOGGER.info(" Got Codec from " + m);
|
||||||
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
BCLib.LOGGER.error(" !!! Unable to get Codec from " + m);
|
BCLib.LOGGER.error(" !!! Unable to get Codec from " + m);
|
||||||
}
|
}
|
||||||
|
@ -127,6 +154,7 @@ public class DumpDatapack {
|
||||||
try {
|
try {
|
||||||
codec[0] = ((KeyDispatchDataCodec) m.invoke(obj)).codec();
|
codec[0] = ((KeyDispatchDataCodec) m.invoke(obj)).codec();
|
||||||
BCLib.LOGGER.info(" Got Codec from " + m);
|
BCLib.LOGGER.info(" Got Codec from " + m);
|
||||||
|
break;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
BCLib.LOGGER.error(" !!! Unable to get Codec from " + m);
|
BCLib.LOGGER.error(" !!! Unable to get Codec from " + m);
|
||||||
}
|
}
|
||||||
|
@ -138,7 +166,7 @@ public class DumpDatapack {
|
||||||
|
|
||||||
if (codec[0] == null) {
|
if (codec[0] == null) {
|
||||||
//Try to find DIRECT_CODEC field
|
//Try to find DIRECT_CODEC field
|
||||||
for (Field f : obj.getClass().getDeclaredFields()) {
|
for (Field f : obj.getClass().getFields()) {
|
||||||
if (Modifier.isStatic(f.getModifiers())) {
|
if (Modifier.isStatic(f.getModifiers())) {
|
||||||
if ("DIRECT_CODEC".equals(f.getName())) {
|
if ("DIRECT_CODEC".equals(f.getName())) {
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
|
@ -155,7 +183,7 @@ public class DumpDatapack {
|
||||||
|
|
||||||
//Try to find CODEC field
|
//Try to find CODEC field
|
||||||
if (codec[0] == null) {
|
if (codec[0] == null) {
|
||||||
for (Field f : obj.getClass().getDeclaredFields()) {
|
for (Field f : obj.getClass().getFields()) {
|
||||||
if (Modifier.isStatic(f.getModifiers())) {
|
if (Modifier.isStatic(f.getModifiers())) {
|
||||||
if ("CODEC".equals(f.getName())) {
|
if ("CODEC".equals(f.getName())) {
|
||||||
try {
|
try {
|
||||||
|
@ -172,7 +200,7 @@ public class DumpDatapack {
|
||||||
|
|
||||||
//Try to find any Codec field
|
//Try to find any Codec field
|
||||||
if (codec[0] == null) {
|
if (codec[0] == null) {
|
||||||
for (Field f : obj.getClass().getDeclaredFields()) {
|
for (Field f : obj.getClass().getFields()) {
|
||||||
if (Modifier.isStatic(f.getModifiers())) {
|
if (Modifier.isStatic(f.getModifiers())) {
|
||||||
if (Codec.class.isAssignableFrom(f.getType())) {
|
if (Codec.class.isAssignableFrom(f.getType())) {
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
|
@ -187,6 +215,10 @@ public class DumpDatapack {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (codec[0] == null) {
|
||||||
|
codec[0] = registry.value().byNameCodec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (codec[0] != null) {
|
if (codec[0] != null) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -6,9 +6,10 @@ import org.betterx.bclib.api.v2.generator.BCLChunkGenerator;
|
||||||
import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
|
import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource;
|
||||||
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
import org.betterx.bclib.api.v2.levelgen.LevelGenUtil;
|
||||||
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||||
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleUtil;
|
|
||||||
import org.betterx.bclib.interfaces.ChunkGeneratorAccessor;
|
import org.betterx.bclib.interfaces.ChunkGeneratorAccessor;
|
||||||
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
import org.betterx.bclib.interfaces.NoiseGeneratorSettingsProvider;
|
||||||
|
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||||
|
import org.betterx.worlds.together.surfaceRules.SurfaceRuleUtil;
|
||||||
import org.betterx.worlds.together.world.WorldGenUtil;
|
import org.betterx.worlds.together.world.WorldGenUtil;
|
||||||
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
import org.betterx.worlds.together.worldPreset.TogetherWorldPreset;
|
||||||
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
import org.betterx.worlds.together.worldPreset.settings.WorldPresetSettings;
|
||||||
|
@ -125,35 +126,38 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
||||||
return LevelGenUtil.getBCLEndLevelStem(ctx, Optional.of(endVersion));
|
return LevelGenUtil.getBCLEndLevelStem(ctx, Optional.of(endVersion));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BiomeSource fixBiomeSource(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes) {
|
public BiomeSource addDatapackBiomes(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes) {
|
||||||
if (biomeSource instanceof BCLBiomeSource bs) {
|
if (biomeSource instanceof BCLBiomeSource bs) {
|
||||||
return bs.createCopyForDatapack(datapackBiomes);
|
return bs.createCopyForDatapack(datapackBiomes);
|
||||||
}
|
}
|
||||||
return biomeSource;
|
return biomeSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Holder<NoiseGeneratorSettings> fixNoiseSettings(
|
private static Holder<NoiseGeneratorSettings> injectSurfaceRules(
|
||||||
Holder<NoiseGeneratorSettings> reference,
|
Holder<NoiseGeneratorSettings> reference,
|
||||||
Holder<NoiseGeneratorSettings> settings,
|
Holder<NoiseGeneratorSettings> settings,
|
||||||
BiomeSource biomeSource
|
BiomeSource biomeSource
|
||||||
) {
|
) {
|
||||||
NoiseGeneratorSettings old = settings.value();
|
SurfaceRuleUtil.injectSurfaceRules(settings.value(), biomeSource);
|
||||||
NoiseGeneratorSettings noise = new NoiseGeneratorSettings(
|
return settings;
|
||||||
old.noiseSettings(),
|
// NoiseGeneratorSettings old = settings.value();
|
||||||
old.defaultBlock(),
|
// NoiseGeneratorSettings noise = new NoiseGeneratorSettings(
|
||||||
old.defaultFluid(),
|
// old.noiseSettings(),
|
||||||
old.noiseRouter(),
|
// old.defaultBlock(),
|
||||||
SurfaceRuleUtil.addRulesForBiomeSource(old.surfaceRule(), biomeSource),
|
// old.defaultFluid(),
|
||||||
old.spawnTarget(),
|
// old.noiseRouter(),
|
||||||
old.seaLevel(),
|
// SurfaceRuleRegistry.mergeSurfaceRulesFromBiomes(old.surfaceRule(), biomeSource),
|
||||||
old.disableMobGeneration(),
|
// //SurfaceRuleUtil.addRulesForBiomeSource(old.surfaceRule(), biomeSource),
|
||||||
old.aquifersEnabled(),
|
// old.spawnTarget(),
|
||||||
old.oreVeinsEnabled(),
|
// old.seaLevel(),
|
||||||
old.useLegacyRandomSource()
|
// old.disableMobGeneration(),
|
||||||
);
|
// old.aquifersEnabled(),
|
||||||
|
// old.oreVeinsEnabled(),
|
||||||
|
// old.useLegacyRandomSource()
|
||||||
return Holder.direct(noise);
|
// );
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// return Holder.direct(noise);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -200,13 +204,13 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
||||||
if (loadedChunkGenerator instanceof NoiseGeneratorSettingsProvider noiseProvider) {
|
if (loadedChunkGenerator instanceof NoiseGeneratorSettingsProvider noiseProvider) {
|
||||||
if (referenceGenerator instanceof NoiseGeneratorSettingsProvider referenceProvider) {
|
if (referenceGenerator instanceof NoiseGeneratorSettingsProvider referenceProvider) {
|
||||||
final Set<Holder<Biome>> biomes = loadedChunkGenerator.getBiomeSource().possibleBiomes();
|
final Set<Holder<Biome>> biomes = loadedChunkGenerator.getBiomeSource().possibleBiomes();
|
||||||
final BiomeSource bs = fixBiomeSource(referenceGenerator.getBiomeSource(), biomes);
|
final BiomeSource bs = addDatapackBiomes(referenceGenerator.getBiomeSource(), biomes);
|
||||||
InternalBiomeAPI.applyModifications(bs, dimensionKey);
|
InternalBiomeAPI.applyModifications(bs, dimensionKey);
|
||||||
referenceGenerator = new BCLChunkGenerator(
|
referenceGenerator = new BCLChunkGenerator(
|
||||||
generator.bclib_getStructureSetsRegistry(),
|
generator.bclib_getStructureSetsRegistry(),
|
||||||
noiseProvider.bclib_getNoises(),
|
noiseProvider.bclib_getNoises(),
|
||||||
bs,
|
bs,
|
||||||
fixNoiseSettings(
|
injectSurfaceRules(
|
||||||
referenceProvider.bclib_getNoiseGeneratorSettingHolders(),
|
referenceProvider.bclib_getNoiseGeneratorSettingHolders(),
|
||||||
noiseProvider.bclib_getNoiseGeneratorSettingHolders(),
|
noiseProvider.bclib_getNoiseGeneratorSettingHolders(),
|
||||||
bs
|
bs
|
||||||
|
@ -224,7 +228,7 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
||||||
referenceGenerator
|
referenceGenerator
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
BCLChunkGenerator.injectNoiseSettings(dimensionKey, loadedChunkGenerator);
|
SurfaceRuleUtil.injectSurfaceRules(dimensionKey, loadedChunkGenerator);
|
||||||
}
|
}
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +236,7 @@ public class BCLWorldPresetSettings extends WorldPresetSettings {
|
||||||
public WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings) {
|
public WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings) {
|
||||||
settings = fixSettingsInCurrentWorld(registryAccess, LevelStem.NETHER, BuiltinDimensionTypes.NETHER, settings);
|
settings = fixSettingsInCurrentWorld(registryAccess, LevelStem.NETHER, BuiltinDimensionTypes.NETHER, settings);
|
||||||
settings = fixSettingsInCurrentWorld(registryAccess, LevelStem.END, BuiltinDimensionTypes.END, settings);
|
settings = fixSettingsInCurrentWorld(registryAccess, LevelStem.END, BuiltinDimensionTypes.END, settings);
|
||||||
BCLChunkGenerator.injectNoiseSettings(settings, BCLChunkGenerator.NON_MANAGED_DIMENSIONS);
|
SurfaceRuleUtil.injectSurfaceRules(settings, SurfaceRuleRegistry.NON_MANAGED_DIMENSIONS);
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.data.BuiltinRegistries;
|
import net.minecraft.data.BuiltinRegistries;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
@ -18,7 +17,7 @@ public class BuiltinRegistriesMixin {
|
||||||
|
|
||||||
@Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Ljava/util/Map;forEach(Ljava/util/function/BiConsumer;)V"))
|
@Inject(method = "<clinit>", at = @At(value = "INVOKE", target = "Ljava/util/Map;forEach(Ljava/util/function/BiConsumer;)V"))
|
||||||
private static void together_registerSurface(CallbackInfo ci) {
|
private static void together_registerSurface(CallbackInfo ci) {
|
||||||
SurfaceRuleRegistry.SURFACE_RULES = (Registry<SurfaceRules.RuleSource>) registerSimple(
|
SurfaceRuleRegistry.BUILTIN_SURFACE_RULES = registerSimple(
|
||||||
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
|
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
|
||||||
SurfaceRuleRegistry::bootstrap
|
SurfaceRuleRegistry::bootstrap
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.betterx.bclib.mixin.common;
|
package org.betterx.worlds.together.mixin.common;
|
||||||
|
|
||||||
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleUtil;
|
import org.betterx.bclib.api.v2.levelgen.surface.SurfaceRuleUtil;
|
||||||
import org.betterx.bclib.interfaces.SurfaceRuleProvider;
|
import org.betterx.worlds.together.surfaceRules.SurfaceRuleProvider;
|
||||||
|
|
||||||
import net.minecraft.world.level.biome.BiomeSource;
|
import net.minecraft.world.level.biome.BiomeSource;
|
||||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||||
|
@ -16,7 +16,6 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Mixin(NoiseGeneratorSettings.class)
|
@Mixin(NoiseGeneratorSettings.class)
|
||||||
public class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider {
|
public class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider {
|
||||||
|
@ -34,39 +33,39 @@ public class NoiseGeneratorSettingsMixin implements SurfaceRuleProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bclib_addBiomeSource(BiomeSource source) {
|
public void bclib_addBiomeSource(BiomeSource source) {
|
||||||
bclib_biomeSources.add(source);
|
// bclib_biomeSources.add(source);
|
||||||
bclib_updateCustomRules();
|
// bclib_updateCustomRules();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bclib_clearBiomeSources() {
|
public void bclib_clearBiomeSources() {
|
||||||
bclib_biomeSources.clear();
|
// bclib_biomeSources.clear();
|
||||||
bclib_clearCustomRules();
|
// bclib_clearCustomRules();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bclib_clearCustomRules() {
|
private void bclib_clearCustomRules() {
|
||||||
if (bclib_originalSurfaceRule != null) {
|
// if (bclib_originalSurfaceRule != null) {
|
||||||
this.surfaceRule = bclib_originalSurfaceRule;
|
// this.surfaceRule = bclib_originalSurfaceRule;
|
||||||
bclib_originalSurfaceRule = null;
|
// bclib_originalSurfaceRule = null;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bclib_setCustomRules(List<RuleSource> rules) {
|
private void bclib_setCustomRules(List<RuleSource> rules) {
|
||||||
if (rules.size() == 0) {
|
// if (rules.size() == 0) {
|
||||||
bclib_clearCustomRules();
|
// bclib_clearCustomRules();
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
RuleSource org = bclib_getOriginalSurfaceRule();
|
// RuleSource org = bclib_getOriginalSurfaceRule();
|
||||||
if (org instanceof SurfaceRules.SequenceRuleSource sequenceRule) {
|
// if (org instanceof SurfaceRules.SequenceRuleSource sequenceRule) {
|
||||||
List<RuleSource> currentSequence = sequenceRule.sequence();
|
// List<RuleSource> currentSequence = sequenceRule.sequence();
|
||||||
rules = rules.stream().filter(r -> currentSequence.indexOf(r) < 0).collect(Collectors.toList());
|
// rules = rules.stream().filter(r -> currentSequence.indexOf(r) < 0).collect(Collectors.toList());
|
||||||
rules.addAll(sequenceRule.sequence());
|
// rules.addAll(sequenceRule.sequence());
|
||||||
} else {
|
// } else {
|
||||||
rules.add(org);
|
// rules.add(org);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
bclib_setSurfaceRule(SurfaceRules.sequence(rules.toArray(new RuleSource[rules.size()])));
|
// bclib_setSurfaceRule(SurfaceRules.sequence(rules.toArray(new RuleSource[rules.size()])));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bclib_overwrite(SurfaceRules.RuleSource surfaceRule) {
|
public void bclib_overwrite(SurfaceRules.RuleSource surfaceRule) {
|
|
@ -1,12 +1,12 @@
|
||||||
package org.betterx.worlds.together.mixin.common;
|
package org.betterx.worlds.together.mixin.common;
|
||||||
|
|
||||||
|
import org.betterx.worlds.together.surfaceRules.AssignedSurfaceRule;
|
||||||
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
@ -29,7 +29,7 @@ public interface RegistryAccessMixin {
|
||||||
ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder = ImmutableMap.builder();
|
ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder = ImmutableMap.builder();
|
||||||
|
|
||||||
builder.putAll(res);
|
builder.putAll(res);
|
||||||
put(builder, SurfaceRuleRegistry.SURFACE_RULES_REGISTRY, SurfaceRules.RuleSource.CODEC);
|
put(builder, SurfaceRuleRegistry.SURFACE_RULES_REGISTRY, AssignedSurfaceRule.CODEC);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,19 @@
|
||||||
package org.betterx.worlds.together.surfaceRules;
|
package org.betterx.worlds.together.surfaceRules;
|
||||||
|
|
||||||
|
import com.mojang.serialization.Codec;
|
||||||
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||||
|
|
||||||
public class AssignedSurfaceRule {
|
public class AssignedSurfaceRule {
|
||||||
|
public static final Codec<AssignedSurfaceRule> CODEC = RecordCodecBuilder.create(instance -> instance
|
||||||
|
.group(
|
||||||
|
SurfaceRules.RuleSource.CODEC.fieldOf("ruleSource").forGetter(o -> o.ruleSource),
|
||||||
|
ResourceLocation.CODEC.fieldOf("biome").forGetter(o -> o.biomeID)
|
||||||
|
)
|
||||||
|
.apply(instance, AssignedSurfaceRule::new)
|
||||||
|
);
|
||||||
|
|
||||||
public final SurfaceRules.RuleSource ruleSource;
|
public final SurfaceRules.RuleSource ruleSource;
|
||||||
public final ResourceLocation biomeID;
|
public final ResourceLocation biomeID;
|
||||||
|
|
||||||
|
@ -12,4 +22,5 @@ public class AssignedSurfaceRule {
|
||||||
this.biomeID = biomeID;
|
this.biomeID = biomeID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.betterx.bclib.interfaces;
|
package org.betterx.worlds.together.surfaceRules;
|
||||||
|
|
||||||
import net.minecraft.world.level.biome.BiomeSource;
|
import net.minecraft.world.level.biome.BiomeSource;
|
||||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
import net.minecraft.world.level.levelgen.SurfaceRules;
|
|
@ -8,26 +8,55 @@ import net.minecraft.data.BuiltinRegistries;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.block.Blocks;
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
import net.minecraft.world.level.dimension.LevelStem;
|
||||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||||
|
|
||||||
public class SurfaceRuleRegistry {
|
import java.util.function.Predicate;
|
||||||
public static final ResourceKey<Registry<SurfaceRules.RuleSource>> SURFACE_RULES_REGISTRY =
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
createRegistryKey(WorldsTogether.makeID("worldgen/surface_rules"));
|
|
||||||
|
|
||||||
public static Registry<SurfaceRules.RuleSource> SURFACE_RULES;
|
public class SurfaceRuleRegistry {
|
||||||
|
public static final ResourceKey<Registry<AssignedSurfaceRule>> SURFACE_RULES_REGISTRY =
|
||||||
|
createRegistryKey(WorldsTogether.makeID("worldgen/surface_rules"));
|
||||||
|
public static final Predicate<ResourceKey<LevelStem>> NON_MANAGED_DIMENSIONS = dim -> dim != LevelStem.NETHER && dim != LevelStem.END;
|
||||||
|
public static final Predicate<ResourceKey<LevelStem>> ALL_DIMENSIONS = dim -> true;
|
||||||
|
|
||||||
|
public static Registry<AssignedSurfaceRule> BUILTIN_SURFACE_RULES;
|
||||||
|
|
||||||
private static <T> ResourceKey<Registry<T>> createRegistryKey(ResourceLocation location) {
|
private static <T> ResourceKey<Registry<T>> createRegistryKey(ResourceLocation location) {
|
||||||
return ResourceKey.createRegistryKey(location);
|
return ResourceKey.createRegistryKey(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Holder<SurfaceRules.RuleSource> bootstrap(Registry<SurfaceRules.RuleSource> registry) {
|
@ApiStatus.Internal
|
||||||
|
public static Holder<AssignedSurfaceRule> bootstrap(Registry<AssignedSurfaceRule> registry) {
|
||||||
return BuiltinRegistries.register(
|
return BuiltinRegistries.register(
|
||||||
registry,
|
registry,
|
||||||
WorldsTogether.makeID("test"),
|
WorldsTogether.makeID("dummy"),
|
||||||
SurfaceRules.state(Blocks.SCULK.defaultBlockState())
|
new AssignedSurfaceRule(
|
||||||
|
SurfaceRules.state(Blocks.YELLOW_CONCRETE.defaultBlockState()),
|
||||||
|
WorldsTogether.makeID("none")
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ResourceKey<AssignedSurfaceRule> registerRule(
|
||||||
|
ResourceLocation ruleID,
|
||||||
|
SurfaceRules.RuleSource rules,
|
||||||
|
ResourceLocation biomeID
|
||||||
|
) {
|
||||||
|
ResourceKey<AssignedSurfaceRule> key = ResourceKey.create(
|
||||||
|
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
|
||||||
|
ruleID
|
||||||
|
);
|
||||||
|
Registry.register(SurfaceRuleRegistry.BUILTIN_SURFACE_RULES, key, new AssignedSurfaceRule(
|
||||||
|
SurfaceRules.ifTrue(
|
||||||
|
SurfaceRules.isBiome(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID)),
|
||||||
|
rules
|
||||||
|
), biomeID
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
public static void ensureStaticallyLoaded() {
|
public static void ensureStaticallyLoaded() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
package org.betterx.worlds.together.surfaceRules;
|
||||||
|
|
||||||
|
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||||
|
import org.betterx.worlds.together.WorldsTogether;
|
||||||
|
import org.betterx.worlds.together.world.event.WorldBootstrap;
|
||||||
|
|
||||||
|
import net.minecraft.core.Holder;
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.biome.BiomeSource;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
|
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.SurfaceRules;
|
||||||
|
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class SurfaceRuleUtil {
|
||||||
|
public static List<SurfaceRules.RuleSource> getRulesForBiome(ResourceLocation biomeID) {
|
||||||
|
Registry<AssignedSurfaceRule> registry = SurfaceRuleRegistry.BUILTIN_SURFACE_RULES;
|
||||||
|
if (WorldBootstrap.getLastRegistryAccess() != null)
|
||||||
|
registry = WorldBootstrap.getLastRegistryAccess()
|
||||||
|
.registryOrThrow(SurfaceRuleRegistry.SURFACE_RULES_REGISTRY);
|
||||||
|
return registry.stream()
|
||||||
|
.filter(a -> a != null && a.biomeID != null && a.biomeID.equals(
|
||||||
|
biomeID))
|
||||||
|
.map(a -> a.ruleSource)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<SurfaceRules.RuleSource> getRulesForBiomes(List<Biome> biomes) {
|
||||||
|
Registry<Biome> biomeRegistry = WorldBootstrap.getLastRegistryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
|
||||||
|
List<ResourceLocation> biomeIDs = biomes.stream()
|
||||||
|
.map(b -> biomeRegistry.getKey(b))
|
||||||
|
.filter(id -> id != null)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return biomeIDs.stream().map(biomeID -> getRulesForBiome(biomeID)).flatMap(List::stream).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SurfaceRules.RuleSource mergeSurfaceRulesFromBiomes(
|
||||||
|
SurfaceRules.RuleSource org,
|
||||||
|
BiomeSource source
|
||||||
|
) {
|
||||||
|
return mergeSurfaceRules(org, getRulesForBiomes(source.possibleBiomes().stream().map(h -> h.value()).toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SurfaceRules.RuleSource mergeSurfaceRulesFromBiomes(
|
||||||
|
SurfaceRules.RuleSource org,
|
||||||
|
List<Biome> biomes
|
||||||
|
) {
|
||||||
|
return mergeSurfaceRules(org, getRulesForBiomes(biomes));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SurfaceRules.RuleSource mergeSurfaceRules(
|
||||||
|
SurfaceRules.RuleSource org,
|
||||||
|
List<SurfaceRules.RuleSource> additionalRules
|
||||||
|
) {
|
||||||
|
if (additionalRules == null || additionalRules.isEmpty()) return org;
|
||||||
|
|
||||||
|
if (org instanceof SurfaceRules.SequenceRuleSource sequenceRule) {
|
||||||
|
List<SurfaceRules.RuleSource> existingSequence = sequenceRule.sequence();
|
||||||
|
additionalRules = additionalRules
|
||||||
|
.stream()
|
||||||
|
.filter(r -> existingSequence.indexOf(r) < 0)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (additionalRules.size() == 0) return org;
|
||||||
|
additionalRules.addAll(existingSequence);
|
||||||
|
} else {
|
||||||
|
if (!additionalRules.contains(org))
|
||||||
|
additionalRules.add(org);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SurfaceRules.SequenceRuleSource(additionalRules);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void injectSurfaceRules(
|
||||||
|
ResourceKey<LevelStem> dimensionKey,
|
||||||
|
ChunkGenerator loadedChunkGenerator
|
||||||
|
) {
|
||||||
|
WorldsTogether.LOGGER.debug("Checking Surface Rules for " + dimensionKey.location().toString());
|
||||||
|
|
||||||
|
final BiomeSource loadedBiomeSource = loadedChunkGenerator.getBiomeSource();
|
||||||
|
InternalBiomeAPI.applyModifications(loadedBiomeSource, dimensionKey);
|
||||||
|
|
||||||
|
if (loadedChunkGenerator instanceof NoiseBasedChunkGenerator nbc) {
|
||||||
|
injectSurfaceRules(nbc.generatorSettings().value(), loadedBiomeSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void injectSurfaceRules(NoiseGeneratorSettings noiseSettings, BiomeSource loadedBiomeSource) {
|
||||||
|
if (((Object) noiseSettings) instanceof SurfaceRuleProvider srp) {
|
||||||
|
SurfaceRules.RuleSource originalRules = noiseSettings.surfaceRule();
|
||||||
|
srp.bclib_overwrite(mergeSurfaceRulesFromBiomes(originalRules, loadedBiomeSource));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void injectSurfaceRules(WorldGenSettings settings, Predicate<ResourceKey<LevelStem>> filter) {
|
||||||
|
List<ResourceKey<LevelStem>> otherDimensions = settings
|
||||||
|
.dimensions()
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(e -> e.getKey())
|
||||||
|
.filter(filter)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
for (ResourceKey<LevelStem> key : otherDimensions) {
|
||||||
|
Optional<Holder<LevelStem>> stem = settings.dimensions().getHolder(key);
|
||||||
|
if (stem.isPresent()) {
|
||||||
|
injectSurfaceRules(key, stem.get().value().generator());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,10 @@ import org.jetbrains.annotations.ApiStatus;
|
||||||
public class WorldBootstrap {
|
public class WorldBootstrap {
|
||||||
private static RegistryAccess LAST_REGISTRY_ACCESS = null;
|
private static RegistryAccess LAST_REGISTRY_ACCESS = null;
|
||||||
|
|
||||||
|
public static RegistryAccess getLastRegistryAccess() {
|
||||||
|
return LAST_REGISTRY_ACCESS;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Helpers {
|
public static class Helpers {
|
||||||
private static void initializeWorldDataAPI(
|
private static void initializeWorldDataAPI(
|
||||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package org.betterx.worlds.together.worldPreset.settings;
|
package org.betterx.worlds.together.worldPreset.settings;
|
||||||
|
|
||||||
|
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||||
|
import org.betterx.worlds.together.surfaceRules.SurfaceRuleUtil;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import net.minecraft.core.Holder;
|
import net.minecraft.core.Holder;
|
||||||
import net.minecraft.core.RegistryAccess;
|
import net.minecraft.core.RegistryAccess;
|
||||||
|
@ -20,11 +23,12 @@ public class VanillaWorldPresetSettings extends WorldPresetSettings {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings) {
|
public WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings) {
|
||||||
|
SurfaceRuleUtil.injectSurfaceRules(settings, SurfaceRuleRegistry.ALL_DIMENSIONS);
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BiomeSource fixBiomeSource(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes) {
|
public BiomeSource addDatapackBiomes(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes) {
|
||||||
return biomeSource;
|
return biomeSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,5 +51,5 @@ public abstract class WorldPresetSettings {
|
||||||
|
|
||||||
public abstract Codec<? extends WorldPresetSettings> codec();
|
public abstract Codec<? extends WorldPresetSettings> codec();
|
||||||
public abstract WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings);
|
public abstract WorldGenSettings repairSettingsOnLoad(RegistryAccess registryAccess, WorldGenSettings settings);
|
||||||
public abstract BiomeSource fixBiomeSource(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes);
|
public abstract BiomeSource addDatapackBiomes(BiomeSource biomeSource, Set<Holder<Biome>> datapackBiomes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,10 @@ accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSou
|
||||||
accessible class net/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap
|
accessible class net/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap
|
||||||
extendable class net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator
|
extendable class net/minecraft/world/level/levelgen/NoiseBasedChunkGenerator
|
||||||
accessible class net/minecraft/data/BuiltinRegistries$RegistryBootstrap
|
accessible class net/minecraft/data/BuiltinRegistries$RegistryBootstrap
|
||||||
|
accessible class net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource
|
||||||
|
|
||||||
#Methods
|
#Methods
|
||||||
accessible method net/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent updateSettings (Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext$Updater;)V
|
accessible method net/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent updateSettings (Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext$Updater;)V
|
||||||
accessible method net/minecraft/world/level/storage/loot/LootPool <init> ([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;)V
|
accessible method net/minecraft/world/level/storage/loot/LootPool <init> ([Lnet/minecraft/world/level/storage/loot/entries/LootPoolEntryContainer;[Lnet/minecraft/world/level/storage/loot/predicates/LootItemCondition;[Lnet/minecraft/world/level/storage/loot/functions/LootItemFunction;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;Lnet/minecraft/world/level/storage/loot/providers/number/NumberProvider;)V
|
||||||
accessible method net/minecraft/world/entity/ai/village/poi/PoiTypes register (Lnet/minecraft/core/Registry;Lnet/minecraft/resources/ResourceKey;Ljava/util/Set;II)Lnet/minecraft/world/entity/ai/village/poi/PoiType;
|
accessible method net/minecraft/world/entity/ai/village/poi/PoiTypes register (Lnet/minecraft/core/Registry;Lnet/minecraft/resources/ResourceKey;Ljava/util/Set;II)Lnet/minecraft/world/entity/ai/village/poi/PoiType;
|
||||||
|
accessible method net/minecraft/world/level/levelgen/SurfaceRules$SequenceRuleSource <init> (Ljava/util/List;)V
|
|
@ -26,7 +26,6 @@
|
||||||
"MinecraftServerMixinLate",
|
"MinecraftServerMixinLate",
|
||||||
"MobSpawnSettingsAccessor",
|
"MobSpawnSettingsAccessor",
|
||||||
"NoiseBasedChunkGeneratorMixin",
|
"NoiseBasedChunkGeneratorMixin",
|
||||||
"NoiseGeneratorSettingsMixin",
|
|
||||||
"PistonBaseBlockMixin",
|
"PistonBaseBlockMixin",
|
||||||
"PortalShapeMixin",
|
"PortalShapeMixin",
|
||||||
"PotionBrewingAccessor",
|
"PotionBrewingAccessor",
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
"BuiltinRegistriesMixin",
|
"BuiltinRegistriesMixin",
|
||||||
"DiggerItemAccessor",
|
"DiggerItemAccessor",
|
||||||
"MainMixin",
|
"MainMixin",
|
||||||
|
"NoiseGeneratorSettingsMixin",
|
||||||
"PrimaryLevelDataMixin",
|
"PrimaryLevelDataMixin",
|
||||||
"RegistryAccessMixin",
|
"RegistryAccessMixin",
|
||||||
"RegistryOpsAccessor",
|
"RegistryOpsAccessor",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue