Feature sorting
This commit is contained in:
parent
ac279c29fc
commit
cb16ea86b3
2 changed files with 40 additions and 1 deletions
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
||||||
import net.minecraft.core.particles.ParticleOptions;
|
import net.minecraft.core.particles.ParticleOptions;
|
||||||
|
@ -34,6 +35,8 @@ import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||||
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||||
|
import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
||||||
|
import ru.bclib.util.CollectionsUtil;
|
||||||
import ru.bclib.util.ColorUtil;
|
import ru.bclib.util.ColorUtil;
|
||||||
import ru.bclib.world.biomes.BCLBiome;
|
import ru.bclib.world.biomes.BCLBiome;
|
||||||
import ru.bclib.world.features.BCLFeature;
|
import ru.bclib.world.features.BCLFeature;
|
||||||
|
@ -576,7 +579,17 @@ public class BCLBiomeBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generationSettings != null) {
|
if (generationSettings != null) {
|
||||||
builder.generationSettings(generationSettings.build());
|
BiomeGenerationSettings settings = generationSettings.build();
|
||||||
|
BiomeGenerationSettingsAccessor accessor = BiomeGenerationSettingsAccessor.class.cast(settings);
|
||||||
|
List<List<Supplier<PlacedFeature>>> featureLists = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
||||||
|
final int size = featureLists.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
List<Supplier<PlacedFeature>> list = CollectionsUtil.getMutable(featureLists.get(i));
|
||||||
|
BiomeAPI.sortFeatures(list);
|
||||||
|
featureLists.add(i, list);
|
||||||
|
}
|
||||||
|
accessor.bclib_setFeatures(featureLists);
|
||||||
|
builder.generationSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
final T res = biomeConstructor.apply(biomeID, builder.build());
|
final T res = biomeConstructor.apply(biomeID, builder.build());
|
||||||
|
|
|
@ -41,6 +41,7 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||||
|
import org.apache.commons.lang3.mutable.MutableInt;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.bclib.BCLib;
|
import ru.bclib.BCLib;
|
||||||
import ru.bclib.config.Configs;
|
import ru.bclib.config.Configs;
|
||||||
|
@ -83,6 +84,8 @@ public class BiomeAPI {
|
||||||
private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap();
|
private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap();
|
||||||
private static Registry<Biome> biomeRegistry;
|
private static Registry<Biome> biomeRegistry;
|
||||||
|
|
||||||
|
private static final Map<PlacedFeature, Integer> FEATURE_ORDER = Maps.newHashMap();
|
||||||
|
|
||||||
private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Biome>>> MODIFICATIONS = Maps.newHashMap();
|
private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Biome>>> MODIFICATIONS = Maps.newHashMap();
|
||||||
private static final Map<ResourceLocation, SurfaceRules.RuleSource> SURFACE_RULES = Maps.newHashMap();
|
private static final Map<ResourceLocation, SurfaceRules.RuleSource> SURFACE_RULES = Maps.newHashMap();
|
||||||
private static final Set<ResourceLocation> MODIFIED_BIOMES = Sets.newHashSet();
|
private static final Set<ResourceLocation> MODIFIED_BIOMES = Sets.newHashSet();
|
||||||
|
@ -100,6 +103,21 @@ public class BiomeAPI {
|
||||||
public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")));
|
public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")));
|
||||||
public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")));
|
public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")));
|
||||||
|
|
||||||
|
public static void init() {
|
||||||
|
MutableInt integer = new MutableInt(0);
|
||||||
|
BuiltinRegistries.BIOME.entrySet().forEach(entry -> {
|
||||||
|
Biome biome = entry.getValue();
|
||||||
|
BiomeGenerationSettingsAccessor accessor = BiomeGenerationSettingsAccessor.class.cast(biome.getGenerationSettings());
|
||||||
|
List<List<Supplier<PlacedFeature>>> features = accessor.bclib_getFeatures();
|
||||||
|
features.forEach(step -> {
|
||||||
|
step.forEach(provider -> {
|
||||||
|
PlacedFeature feature = provider.get();
|
||||||
|
FEATURE_ORDER.computeIfAbsent(feature, f -> integer.getAndIncrement());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize registry for current server.
|
* Initialize registry for current server.
|
||||||
* @param biomeRegistry - {@link Registry} for {@link Biome}.
|
* @param biomeRegistry - {@link Registry} for {@link Biome}.
|
||||||
|
@ -688,6 +706,14 @@ public class BiomeAPI {
|
||||||
return Blocks.AIR.defaultBlockState();
|
return Blocks.AIR.defaultBlockState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void sortFeatures(List<Supplier<PlacedFeature>> features) {
|
||||||
|
features.sort((f1, f2) -> {
|
||||||
|
int v1 = FEATURE_ORDER.getOrDefault(f1.get(), 0);
|
||||||
|
int v2 = FEATURE_ORDER.getOrDefault(f2.get(), 0);
|
||||||
|
return Integer.compare(v1, v2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static void configureBiome(BCLBiome biome) {
|
private static void configureBiome(BCLBiome biome) {
|
||||||
String group = biome.getID().getNamespace() + "." + biome.getID().getPath();
|
String group = biome.getID().getNamespace() + "." + biome.getID().getPath();
|
||||||
float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", biome.getGenChance());
|
float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", biome.getGenChance());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue