Datapack friendly features
This commit is contained in:
parent
43f6d72dda
commit
3e18eb839f
3 changed files with 103 additions and 15 deletions
|
@ -1,9 +1,11 @@
|
|||
package ru.bclib.api.biomes;
|
||||
|
||||
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.data.worldgen.BiomeDefaultFeatures;
|
||||
import net.minecraft.data.worldgen.placement.OrePlacements;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.Music;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
|
@ -32,15 +34,22 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
|||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import ru.bclib.api.surface.SurfaceRuleBuilder;
|
||||
import ru.bclib.entity.BCLEntityWrapper;
|
||||
import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
||||
import ru.bclib.util.ColorUtil;
|
||||
import ru.bclib.util.Pair;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
import ru.bclib.world.features.BCLFeature;
|
||||
import ru.bclib.world.structures.BCLStructureFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BCLBiomeBuilder {
|
||||
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
|
||||
|
@ -583,13 +592,33 @@ public class BCLBiomeBuilder {
|
|||
|
||||
builder.mobSpawnSettings(getSpawns().build());
|
||||
builder.specialEffects(getEffects().build());
|
||||
builder.generationSettings(getGeneration().build());
|
||||
|
||||
Map<Decoration, List<Supplier<PlacedFeature>>> defferedFeatures = new HashMap<>();
|
||||
BiomeGenerationSettingsAccessor acc = (BiomeGenerationSettingsAccessor)getGeneration().build();
|
||||
if (acc!=null){
|
||||
builder.generationSettings(new BiomeGenerationSettings.Builder().build());
|
||||
var decorations = acc.bclib_getFeatures();
|
||||
|
||||
for (Decoration d : Decoration.values()){
|
||||
int i = d.ordinal();
|
||||
|
||||
if (i>=0 && i<decorations.size()) {
|
||||
var features = decorations.get(i);
|
||||
defferedFeatures.put(d, features.stream().collect(Collectors.toList()));
|
||||
} else {
|
||||
defferedFeatures.put(d, new ArrayList<>(0));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
builder.generationSettings(getGeneration().build());
|
||||
}
|
||||
|
||||
final T res = biomeConstructor.apply(biomeID, builder.build());
|
||||
res.attachStructures(structures);
|
||||
res.setSurface(surfaceRule);
|
||||
res.setFogDensity(fogDensity);
|
||||
res.setGenChance(genChance);
|
||||
res.setFeatures(defferedFeatures);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -150,15 +150,14 @@ public class BiomeAPI {
|
|||
RegistryEntryAddedCallback
|
||||
.event(biomeRegistry)
|
||||
.register((rawId, id, biome)->{
|
||||
|
||||
BCLib.LOGGER.info(" #### " + rawId + ", " + biome + ", " + id);
|
||||
|
||||
//BCLib.LOGGER.info(" #### " + rawId + ", " + biome + ", " + id);
|
||||
onAddedBiome(biome);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void onAddedBiome(Biome biome) {
|
||||
//BCLib.LOGGER.info(" ++++ " + getBiomeID(biome) + ", " + getBiomeKey(biome) + ", " + biome);
|
||||
for (var dim : MODIFICATIONS.keySet()) {
|
||||
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(dim);
|
||||
if (modifications == null) {
|
||||
|
@ -541,6 +540,12 @@ public class BiomeAPI {
|
|||
consumer.accept(biomeID, biome);
|
||||
});
|
||||
}
|
||||
|
||||
final BCLBiome bclBiome = BiomeAPI.getBiome(biome);
|
||||
if (bclBiome!=null) {
|
||||
addBiomeFeature(biome, bclBiome.getFeatures());
|
||||
}
|
||||
|
||||
sortBiomeFeatures(biome);
|
||||
}
|
||||
|
||||
|
@ -605,22 +610,57 @@ public class BiomeAPI {
|
|||
*
|
||||
*/
|
||||
public static void addBiomeFeature(Biome biome, BCLFeature feature) {
|
||||
addBiomeFeature(biome, feature.getPlacedFeature(), feature.getDecoration());
|
||||
addBiomeFeature(biome, feature.getDecoration(), feature.getPlacedFeature());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new features to existing biome.
|
||||
* @param biome {@link Biome} to add features in.
|
||||
* @param feature {@link ConfiguredFeature} to add.
|
||||
* @param step a {@link Decoration} step for the feature.
|
||||
* @param featureList {@link ConfiguredFeature} to add.
|
||||
*/
|
||||
public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) {
|
||||
public static void addBiomeFeature(Biome biome, Decoration step, PlacedFeature... featureList) {
|
||||
addBiomeFeature(biome, step, List.of(featureList));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new features to existing biome.
|
||||
* @param biome {@link Biome} to add features in.
|
||||
* @param step a {@link Decoration} step for the feature.
|
||||
* @param featureList List of {@link ConfiguredFeature} to add.
|
||||
*/
|
||||
public static void addBiomeFeature(Biome biome, Decoration step, List<PlacedFeature> featureList) {
|
||||
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
|
||||
List<List<Supplier<PlacedFeature>>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
||||
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet());
|
||||
List<Supplier<PlacedFeature>> features = getFeaturesList(allFeatures, step);
|
||||
features.add(() -> feature);
|
||||
set.add(feature);
|
||||
for (var feature : featureList) {
|
||||
features.add(() -> feature);
|
||||
set.add(feature);
|
||||
}
|
||||
accessor.bclib_setFeatures(allFeatures);
|
||||
accessor.bclib_setFeatureSet(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new features to existing biome.
|
||||
* @param biome {@link Biome} to add features in.
|
||||
* @param featureMap Map of {@link ConfiguredFeature} to add.
|
||||
*/
|
||||
public static void addBiomeFeature(Biome biome, Map<Decoration, List<Supplier<PlacedFeature>>> featureMap) {
|
||||
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) biome.getGenerationSettings();
|
||||
List<List<Supplier<PlacedFeature>>> allFeatures = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
|
||||
Set<PlacedFeature> set = CollectionsUtil.getMutable(accessor.bclib_getFeatureSet());
|
||||
|
||||
for (Decoration step: featureMap.keySet()) {
|
||||
List<Supplier<PlacedFeature>> features = getFeaturesList(allFeatures, step);
|
||||
List<Supplier<PlacedFeature>> featureList = featureMap.get(step);
|
||||
|
||||
for (Supplier<PlacedFeature> feature : featureList) {
|
||||
features.add(feature);
|
||||
set.add(feature.get());
|
||||
}
|
||||
}
|
||||
accessor.bclib_setFeatures(allFeatures);
|
||||
accessor.bclib_setFeatureSet(set);
|
||||
}
|
||||
|
@ -632,7 +672,7 @@ public class BiomeAPI {
|
|||
* @param step a {@link Decoration} step for the feature.
|
||||
*/
|
||||
private static void addBiomeFeature(ResourceLocation biomeID, PlacedFeature feature, Decoration step) {
|
||||
addBiomeFeature(BuiltinRegistries.BIOME.get(biomeID), feature, step);
|
||||
addBiomeFeature(BuiltinRegistries.BIOME.get(biomeID), step, feature);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -846,11 +886,6 @@ public class BiomeAPI {
|
|||
public static void registerStructureEvents(){
|
||||
DynamicRegistrySetupCallback.EVENT.register(registryManager -> {
|
||||
Optional<? extends Registry<NoiseGeneratorSettings>> oGeneratorRegistry = registryManager.registry(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY);
|
||||
Optional<? extends Registry<Biome>> oBiomeRegistry = registryManager.registry(Registry.BIOME_REGISTRY);
|
||||
if (oBiomeRegistry.isPresent()){
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (oGeneratorRegistry.isPresent()) {
|
||||
RegistryEntryAddedCallback
|
||||
|
|
|
@ -7,18 +7,24 @@ import net.minecraft.data.BuiltinRegistries;
|
|||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules;
|
||||
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.api.biomes.BiomeAPI;
|
||||
import ru.bclib.util.Pair;
|
||||
import ru.bclib.util.WeightedList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class BCLBiome {
|
||||
private final List<ConfiguredStructureFeature> structures = Lists.newArrayList();
|
||||
|
@ -355,4 +361,22 @@ public class BCLBiome {
|
|||
BiomeAPI.addSurfaceRule(biomeID, SurfaceRules.ifTrue(SurfaceRules.isBiome(key), surface));
|
||||
};
|
||||
}
|
||||
|
||||
private Map<Decoration, List<Supplier<PlacedFeature>>> features = new HashMap<>(0);
|
||||
|
||||
/**
|
||||
* Sets the biome features.
|
||||
* @param features the feature list.
|
||||
*/
|
||||
public void setFeatures(Map<Decoration, List<Supplier<PlacedFeature>>> features) {
|
||||
this.features = features;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the built-in set of Features for this biome (as they were set with {@link #setFeatures(Map)})
|
||||
* @return List of all features
|
||||
*/
|
||||
public Map<Decoration, List<Supplier<PlacedFeature>>> getFeatures(){
|
||||
return features;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue