Tag handling in BiomeBuilder

This commit is contained in:
Frank 2022-05-27 17:01:23 +02:00
parent f70db44ffd
commit 3a514f7a78
3 changed files with 31 additions and 11 deletions

View file

@ -27,7 +27,7 @@ import java.util.function.Consumer;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class BCLBiome extends BCLBiomeSettings { public class BCLBiome extends BCLBiomeSettings {
private final Set<TagKey<Biome>> structureTags = Sets.newHashSet(); private final Set<TagKey<Biome>> biomeTags = Sets.newHashSet();
private final WeightedList<BCLBiome> subbiomes = new WeightedList<>(); private final WeightedList<BCLBiome> subbiomes = new WeightedList<>();
private final Map<String, Object> customData = Maps.newHashMap(); private final Map<String, Object> customData = Maps.newHashMap();
private final ResourceLocation biomeID; private final ResourceLocation biomeID;
@ -200,7 +200,7 @@ public class BCLBiome extends BCLBiomeSettings {
*/ */
void afterRegistration() { void afterRegistration() {
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(getBiome()).orElseThrow(); ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(getBiome()).orElseThrow();
this.structureTags.forEach(tagKey -> TagAPI.addBiomeTag(tagKey, biome)); this.biomeTags.forEach(tagKey -> TagAPI.addBiomeTag(tagKey, biome));
if (this.surfaceInit != null) { if (this.surfaceInit != null) {
surfaceInit.accept(key); surfaceInit.accept(key);
@ -280,8 +280,8 @@ public class BCLBiome extends BCLBiomeSettings {
* Adds structures to this biome. For internal use only. * Adds structures to this biome. For internal use only.
* Used inside {@link BCLBiomeBuilder}. * Used inside {@link BCLBiomeBuilder}.
*/ */
void attachStructures(List<TagKey<Biome>> structures) { void addBiomeTags(Set<TagKey<Biome>> tags) {
structureTags.addAll(structures); biomeTags.addAll(tags);
} }
/** /**

View file

@ -28,6 +28,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.betterx.bclib.api.surface.SurfaceRuleBuilder; import org.betterx.bclib.api.surface.SurfaceRuleBuilder;
import org.betterx.bclib.entity.BCLEntityWrapper; import org.betterx.bclib.entity.BCLEntityWrapper;
import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor; import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor;
@ -41,6 +42,7 @@ import org.betterx.bclib.world.structures.BCLStructure;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -53,7 +55,6 @@ public class BCLBiomeBuilder {
private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER,
-0.012); -0.012);
private final List<TagKey<Biome>> structureTags = new ArrayList<>(8);
private final List<Pair<GenerationStep.Carving, Holder<? extends ConfiguredWorldCarver<?>>>> carvers = new ArrayList<>( private final List<Pair<GenerationStep.Carving, Holder<? extends ConfiguredWorldCarver<?>>>> carvers = new ArrayList<>(
1); 1);
private BiomeGenerationSettings.Builder generationSettings; private BiomeGenerationSettings.Builder generationSettings;
@ -63,6 +64,8 @@ public class BCLBiomeBuilder {
private Precipitation precipitation; private Precipitation precipitation;
private ResourceLocation biomeID; private ResourceLocation biomeID;
private Set<TagKey<Biome>> tags = Sets.newHashSet();
private final List<Climate.ParameterPoint> parameters = Lists.newArrayList(); private final List<Climate.ParameterPoint> parameters = Lists.newArrayList();
//BiomeTags.IS_NETHER //BiomeTags.IS_NETHER
@ -88,7 +91,6 @@ public class BCLBiomeBuilder {
INSTANCE.generationSettings = null; INSTANCE.generationSettings = null;
INSTANCE.effectsBuilder = null; INSTANCE.effectsBuilder = null;
INSTANCE.spawnSettings = null; INSTANCE.spawnSettings = null;
INSTANCE.structureTags.clear();
INSTANCE.temperature = 1.0F; INSTANCE.temperature = 1.0F;
INSTANCE.fogDensity = 1.0F; INSTANCE.fogDensity = 1.0F;
INSTANCE.edgeSize = 0; INSTANCE.edgeSize = 0;
@ -99,6 +101,7 @@ public class BCLBiomeBuilder {
INSTANCE.edge = null; INSTANCE.edge = null;
INSTANCE.carvers.clear(); INSTANCE.carvers.clear();
INSTANCE.parameters.clear(); INSTANCE.parameters.clear();
INSTANCE.tags.clear();
return INSTANCE; return INSTANCE;
} }
@ -590,7 +593,7 @@ public class BCLBiomeBuilder {
* @return same {@link BCLBiomeBuilder} instance. * @return same {@link BCLBiomeBuilder} instance.
*/ */
public BCLBiomeBuilder structure(TagKey<Biome> structureTag) { public BCLBiomeBuilder structure(TagKey<Biome> structureTag) {
structureTags.add(structureTag); tags.add(structureTag);
return this; return this;
} }
@ -670,6 +673,13 @@ public class BCLBiomeBuilder {
return this; return this;
} }
public BCLBiomeBuilder tag(TagKey<Biome>... tag) {
for (TagKey<Biome> t : tag) {
tags.add(t);
}
return this;
}
/** /**
* Set terrain height for the biome. Can be used in custom generators, doesn't change vanilla biome distribution or generation. * Set terrain height for the biome. Can be used in custom generators, doesn't change vanilla biome distribution or generation.
* *
@ -755,7 +765,7 @@ 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.attachStructures(structureTags); res.addBiomeTags(tags);
res.setSurface(surfaceRule); res.setSurface(surfaceRule);
res.addClimateParameters(parameters); res.addClimateParameters(parameters);

View file

@ -169,6 +169,7 @@ public class BiomeAPI {
*/ */
public static void initRegistry(Registry<Biome> biomeRegistry) { public static void initRegistry(Registry<Biome> biomeRegistry) {
if (biomeRegistry != BiomeAPI.biomeRegistry) { if (biomeRegistry != BiomeAPI.biomeRegistry) {
System.out.println("Switching Registry to " + biomeRegistry);//17015, 19009, 19058, 19009
BiomeAPI.biomeRegistry = biomeRegistry; BiomeAPI.biomeRegistry = biomeRegistry;
CLIENT.clear(); CLIENT.clear();
} }
@ -420,11 +421,20 @@ public class BiomeAPI {
* @return biome {@link ResourceLocation}. * @return biome {@link ResourceLocation}.
*/ */
public static ResourceLocation getBiomeID(Biome biome) { public static ResourceLocation getBiomeID(Biome biome) {
ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome); ResourceLocation id = null;
if (id == null && biomeRegistry != null) { if (biomeRegistry != null) {
id = biomeRegistry.getKey(biome); id = biomeRegistry.getKey(biome);
} }
return id == null ? EMPTY_BIOME.getID() : id; if (id == null) {
id = BuiltinRegistries.BIOME.getKey(biome);
}
if (id == null) {
BCLib.LOGGER.error("Unable to get ID for " + biome + ". Falling back to empty Biome...");
id = EMPTY_BIOME.getID();
}
return id;
} }
/** /**