[Change] BCLBiome is no longer a wrapper around a Biome-Instance but references the Biome by ResourceKey

[Fix] Crash with Promenade (#15)
This commit is contained in:
Frank 2022-07-03 12:42:30 +02:00
parent 89737d5f6c
commit 3e81071b96
8 changed files with 274 additions and 139 deletions

View file

@ -114,7 +114,10 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
String biomeStr = biomeID.toString(); String biomeStr = biomeID.toString();
//exclude everything that was listed //exclude everything that was listed
if (excludeList != null && excludeList.contains(biomeStr)) return; if (excludeList != null && excludeList.contains(biomeStr)) return;
if (!biome.isBound()) {
BCLib.LOGGER.warning("Biome " + biomeStr + " is requested but not yet bound.");
return;
}
final BCLBiome bclBiome; final BCLBiome bclBiome;
if (!BiomeAPI.hasBiome(biomeID)) { if (!BiomeAPI.hasBiome(biomeID)) {
bclBiome = new BCLBiome(biomeID, biome.value()); bclBiome = new BCLBiome(biomeID, biome.value());

View file

@ -81,13 +81,16 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
biomePicker = new BiomePicker(biomeRegistry); biomePicker = new BiomePicker(biomeRegistry);
this.possibleBiomes().forEach(biome -> { this.possibleBiomes().forEach(biome -> {
ResourceLocation key = biome.unwrapKey().orElseThrow().location(); ResourceLocation biomeID = biome.unwrapKey().orElseThrow().location();
if (!biome.isBound()) {
if (!BiomeAPI.hasBiome(key)) { BCLib.LOGGER.warning("Biome " + biomeID.toString() + " is requested but not yet bound.");
BCLBiome bclBiome = new BCLBiome(key, biome.value()); return;
}
if (!BiomeAPI.hasBiome(biomeID)) {
BCLBiome bclBiome = new BCLBiome(biomeID, biome.value());
biomePicker.addBiome(bclBiome); biomePicker.addBiome(bclBiome);
} else { } else {
BCLBiome bclBiome = BiomeAPI.getBiome(key); BCLBiome bclBiome = BiomeAPI.getBiome(biomeID);
if (bclBiome != BiomeAPI.EMPTY_BIOME) { if (bclBiome != BiomeAPI.EMPTY_BIOME) {
if (bclBiome.getParentBiome() == null) { if (bclBiome.getParentBiome() == null) {

View file

@ -17,7 +17,7 @@ import org.jetbrains.annotations.ApiStatus;
*/ */
public class TheEndBiomesHelper { public class TheEndBiomesHelper {
@ApiStatus.Internal @ApiStatus.Internal
public static Map<BiomeAPI.BiomeType, Set<ResourceKey<Biome>>> END_BIOMES = new HashMap<>(); private static Map<BiomeAPI.BiomeType, Set<ResourceKey<Biome>>> END_BIOMES = new HashMap<>();
@ApiStatus.Internal @ApiStatus.Internal
public static void add(BiomeAPI.BiomeType type, ResourceKey<Biome> biome) { public static void add(BiomeAPI.BiomeType type, ResourceKey<Biome> biome) {

View file

@ -3,6 +3,7 @@ package org.betterx.bclib.api.v2.levelgen.biomes;
import org.betterx.bclib.util.WeightedList; import org.betterx.bclib.util.WeightedList;
import org.betterx.worlds.together.tag.v3.TagManager; import org.betterx.worlds.together.tag.v3.TagManager;
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.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -28,7 +29,8 @@ public class BCLBiome extends BCLBiomeSettings {
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;
private final Biome biome; private final ResourceKey<Biome> biomeKey;
final Biome biomeToRegister;
private final List<Climate.ParameterPoint> parameterPoints = Lists.newArrayList(); private final List<Climate.ParameterPoint> parameterPoints = Lists.newArrayList();
@ -49,43 +51,74 @@ public class BCLBiome extends BCLBiomeSettings {
* @param biomeID {@link ResourceLocation} biome ID. * @param biomeID {@link ResourceLocation} biome ID.
*/ */
protected BCLBiome(ResourceLocation biomeID) { protected BCLBiome(ResourceLocation biomeID) {
this(biomeID, BuiltinRegistries.BIOME.get(biomeID), null); this(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID), null);
} }
/** /**
* Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}. * Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}.
* *
* @param biome {@link Biome} to wrap. * @param biomeToRegister {@link Biome} to wrap.
*/ */
protected BCLBiome(Biome biome) { @Deprecated(forRemoval = true)
this(biome, null); protected BCLBiome(Biome biomeToRegister) {
this(biomeToRegister, null);
} }
/** /**
* Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}. * Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}.
* *
* @param biome {@link Biome} to wrap. * @param biomeToRegister {@link Biome} to wrap.
* @param settings The Settings for this Biome or {@code null} if you want to apply default settings * @param settings The Settings for this Biome or {@code null} if you want to apply default settings
*/ */
protected BCLBiome(Biome biome, VanillaBiomeSettings settings) { @Deprecated(forRemoval = true)
this(BiomeAPI.getBiomeID(biome), biome, settings); protected BCLBiome(Biome biomeToRegister, VanillaBiomeSettings settings) {
this(BiomeAPI.getBiomeID(biomeToRegister), biomeToRegister, settings);
} }
public BCLBiome(ResourceLocation biomeID, Biome biome) { /**
this(biomeID, biome, null); * Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}.
*
* @param biomeToRegister {@link Biome} to wrap.
* @param biomeID Teh ResoureLocation for this Biome
*/
@Deprecated(forRemoval = true)
public BCLBiome(ResourceLocation biomeID, Biome biomeToRegister) {
this(biomeID, biomeToRegister, null);
} }
/** /**
* Create a new Biome * Create a new Biome
* *
* @param biomeID {@link ResourceLocation} biome ID. * @param biomeID {@link ResourceLocation} biome ID.
* @param biome {@link Biome} to wrap. * @param biomeToRegister {@link Biome} to wrap.
* @param defaults The Settings for this Biome or null if you want to apply the defaults
*/
protected BCLBiome(ResourceLocation biomeID, Biome biomeToRegister, BCLBiomeSettings defaults) {
this(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID), biomeToRegister, defaults);
}
/**
* Create a new Biome
*
* @param biomeKey {@link ResourceKey<Biome>} of the wrapped Biome
* @param defaults The Settings for this Biome or null if you want to apply the defaults * @param defaults The Settings for this Biome or null if you want to apply the defaults
*/ */
protected BCLBiome(ResourceLocation biomeID, Biome biome, BCLBiomeSettings defaults) { protected BCLBiome(ResourceKey<Biome> biomeKey, BCLBiomeSettings defaults) {
this(biomeKey, null, defaults);
}
/**
* Create a new Biome
*
* @param biomeKey {@link ResourceKey<Biome>} of the wrapped Biome
* @param biomeToRegister The biome you want to use when this instance gets registered through the {@link BiomeAPI}
* @param defaults The Settings for this Biome or null if you want to apply the defaults
*/
protected BCLBiome(ResourceKey<Biome> biomeKey, Biome biomeToRegister, BCLBiomeSettings defaults) {
this.biomeToRegister = biomeToRegister;
this.subbiomes.add(this, 1.0F); this.subbiomes.add(this, 1.0F);
this.biomeID = biomeID; this.biomeID = biomeKey.location();
this.biome = biome; this.biomeKey = biomeKey;
if (defaults != null) { if (defaults != null) {
defaults.applyWithDefaults(this); defaults.applyWithDefaults(this);
@ -203,16 +236,26 @@ public class BCLBiome extends BCLBiomeSettings {
* *
* @return {@link Biome}. * @return {@link Biome}.
*/ */
public Biome getBiome() { @Deprecated(forRemoval = true)
return biome; public Biome getBiomeOld() {
if (biomeToRegister != null) return biomeToRegister;
return BiomeAPI.getFromBuiltinRegistry(biomeKey).value();
}
/**
* Getter for biomeKey
*
* @return {@link ResourceKey<Biome>}.
*/
public ResourceKey<Biome> getBiomeKey() {
return biomeKey;
} }
/** /**
* For internal use from BiomeAPI only * For internal use from BiomeAPI only
*/ */
void afterRegistration() { void afterRegistration() {
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(getBiome()).orElseThrow(); this.biomeTags.forEach(tagKey -> TagManager.BIOMES.add(tagKey, this));
this.biomeTags.forEach(tagKey -> TagManager.BIOMES.add(tagKey, biome));
} }

View file

@ -10,6 +10,7 @@ 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 org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import org.betterx.worlds.together.tag.v3.TagManager;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet; import net.minecraft.core.HolderSet;
@ -72,7 +73,6 @@ public class BCLBiomeBuilder {
private final List<Climate.ParameterPoint> parameters = Lists.newArrayList(); private final List<Climate.ParameterPoint> parameters = Lists.newArrayList();
//BiomeTags.IS_NETHER
private float temperature; private float temperature;
private float fogDensity; private float fogDensity;
private float genChance; private float genChance;
@ -82,6 +82,8 @@ public class BCLBiomeBuilder {
private BCLBiome edge; private BCLBiome edge;
private boolean vertical; private boolean vertical;
private BiomeAPI.BiomeType biomeType;
/** /**
* Starts new biome building process. * Starts new biome building process.
@ -106,6 +108,7 @@ public class BCLBiomeBuilder {
INSTANCE.carvers.clear(); INSTANCE.carvers.clear();
INSTANCE.parameters.clear(); INSTANCE.parameters.clear();
INSTANCE.tags.clear(); INSTANCE.tags.clear();
INSTANCE.biomeType = null;
return INSTANCE; return INSTANCE;
} }
@ -114,6 +117,17 @@ public class BCLBiomeBuilder {
return this; return this;
} }
/**
* Set the type for this Biome. If the type was set, the Biome can be registered.
*
* @param type selected Type
* @return same {@link BCLBiomeBuilder} instance.
*/
public BCLBiomeBuilder type(BiomeAPI.BiomeType type) {
this.biomeType = type;
return this;
}
/** /**
* Set biome {@link Precipitation}. Affect biome visual effects (rain, snow, none). * Set biome {@link Precipitation}. Affect biome visual effects (rain, snow, none).
* *
@ -724,26 +738,6 @@ public class BCLBiomeBuilder {
return this; return this;
} }
/**
* Finalize biome creation.
*
* @return created {@link BCLBiome} instance.
*/
public BCLBiome build() {
return build((BiomeSupplier<BCLBiome>) BCLBiome::new);
}
/**
* Finalize biome creation.
*
* @param biomeConstructor {@link BiFunction} biome constructor.
* @return created {@link BCLBiome} instance.
* @deprecated Replaced with {@link #build(BiomeSupplier)}
*/
@Deprecated(forRemoval = true)
public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) {
return build((id, biome, settings) -> biomeConstructor.apply(id, biome));
}
private static BiomeGenerationSettings fixGenerationSettings(BiomeGenerationSettings settings) { private static BiomeGenerationSettings fixGenerationSettings(BiomeGenerationSettings settings) {
//Fabric Biome Modification API can not handle an empty carver map, thus we will create one with //Fabric Biome Modification API can not handle an empty carver map, thus we will create one with
@ -760,43 +754,6 @@ public class BCLBiomeBuilder {
return settings; return settings;
} }
/**
* Finalize biome creation.
*
* @param biomeConstructor {@link BiomeSupplier} biome constructor.
* @return created {@link BCLBiome} instance.
*/
public <T extends BCLBiome> T build(BiomeSupplier<T> biomeConstructor) {
BiomeBuilder builder = new BiomeBuilder()
.precipitation(precipitation)
.temperature(temperature)
.downfall(downfall);
builder.mobSpawnSettings(getSpawns().build());
builder.specialEffects(getEffects().build());
builder.generationSettings(fixGenerationSettings(getGeneration().build()));
BCLBiomeSettings settings = BCLBiomeSettings.createBCL()
.setTerrainHeight(height)
.setFogDensity(fogDensity)
.setGenChance(genChance)
.setEdgeSize(edgeSize)
.setEdge(edge)
.setVertical(vertical)
.build();
final Biome biome = builder.build();
final T res = biomeConstructor.apply(biomeID, biome, settings);
res.addBiomeTags(tags);
//res.setSurface(surfaceRule);
SurfaceRuleRegistry.registerRule(biomeID, surfaceRule, biomeID);
res.addClimateParameters(parameters);
//carvers.forEach(cfg -> BiomeAPI.addBiomeCarver(biome, cfg.second, cfg.first));
return res;
}
/** /**
* Get or create {@link BiomeSpecialEffects.Builder} for biome visual effects. * Get or create {@link BiomeSpecialEffects.Builder} for biome visual effects.
@ -837,4 +794,65 @@ public class BCLBiomeBuilder {
} }
return generationSettings; return generationSettings;
} }
/**
* Finalize biome creation.
*
* @return created {@link BCLBiome} instance.
*/
public BCLBiome build() {
return build((BiomeSupplier<BCLBiome>) BCLBiome::new);
}
/**
* Finalize biome creation.
*
* @param biomeConstructor {@link BiFunction} biome constructor.
* @return created {@link BCLBiome} instance.
* @deprecated Replaced with {@link #build(BiomeSupplier)}
*/
@Deprecated(forRemoval = true)
public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) {
return build((id, biome, settings) -> biomeConstructor.apply(id, biome));
}
/**
* Finalize biome creation.
*
* @param biomeConstructor {@link BiomeSupplier} biome constructor.
* @return created {@link BCLBiome} instance.
*/
public <T extends BCLBiome> T build(BiomeSupplier<T> biomeConstructor) {
BiomeBuilder builder = new BiomeBuilder()
.precipitation(precipitation)
.temperature(temperature)
.downfall(downfall);
builder.mobSpawnSettings(getSpawns().build());
builder.specialEffects(getEffects().build());
builder.generationSettings(fixGenerationSettings(getGeneration().build()));
BCLBiomeSettings settings = BCLBiomeSettings.createBCL()
.setTerrainHeight(height)
.setFogDensity(fogDensity)
.setGenChance(genChance)
.setEdgeSize(edgeSize)
.setEdge(edge)
.setVertical(vertical)
.build();
final Biome biome = builder.build();
final T res = biomeConstructor.apply(biomeID, biome, settings);
tags.forEach(tagKey -> TagManager.BIOMES.add(tagKey, res));
//res.addBiomeTags(tags);
//res.setSurface(surfaceRule);
SurfaceRuleRegistry.registerRule(biomeID, surfaceRule, biomeID);
res.addClimateParameters(parameters);
//carvers.forEach(cfg -> BiomeAPI.addBiomeCarver(biome, cfg.second, cfg.first));
return res;
}
} }

View file

@ -26,7 +26,6 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.WorldGenLevel; import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeGenerationSettings;
import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -174,19 +173,29 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerBiome(BCLBiome bclbiome, BiomeType dim) { public static BCLBiome registerBiome(BCLBiome bclbiome, BiomeType dim) {
if (BuiltinRegistries.BIOME.get(bclbiome.getID()) == null) { return registerBiome(bclbiome, dim, BuiltinRegistries.BIOME);
final Biome biome = bclbiome.getBiome(); }
ResourceLocation loc = bclbiome.getID();
Registry.register(BuiltinRegistries.BIOME, loc, biome); /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary.
*
* @param bclbiome {@link BCLBiome}
* @param dim The Dimension fo rthis Biome
* @return {@link BCLBiome}
*/
static BCLBiome registerBiome(BCLBiome bclbiome, BiomeType dim, Registry<Biome> registryOrNull) {
if (registryOrNull != null && bclbiome.biomeToRegister != null && registryOrNull.get(bclbiome.getID()) == null) {
Registry.register(registryOrNull, bclbiome.getBiomeKey(), bclbiome.biomeToRegister);
} }
ID_MAP.put(bclbiome.getID(), bclbiome); ID_MAP.put(bclbiome.getID(), bclbiome);
BiomeType.BIOME_TYPE_MAP.put(bclbiome.getID(), dim); BiomeType.BIOME_TYPE_MAP.put(bclbiome.getID(), dim);
if (dim != null && dim.is(BiomeType.NETHER)) { if (dim != null && dim.is(BiomeType.NETHER)) {
TagManager.BIOMES.add(BiomeTags.IS_NETHER, bclbiome.getBiome()); TagManager.BIOMES.add(BiomeTags.IS_NETHER, bclbiome);
TagManager.BIOMES.add(CommonBiomeTags.IN_NETHER, bclbiome.getBiome()); TagManager.BIOMES.add(CommonBiomeTags.IN_NETHER, bclbiome);
} else if (dim != null && dim.is(BiomeType.END)) { } else if (dim != null && dim.is(BiomeType.END)) {
TagManager.BIOMES.add(BiomeTags.IS_END, bclbiome.getBiome()); TagManager.BIOMES.add(BiomeTags.IS_END, bclbiome);
} }
bclbiome.afterRegistration(); bclbiome.afterRegistration();
@ -234,10 +243,10 @@ public class BiomeAPI {
registerBiome(biome, BiomeType.BCL_END_LAND); registerBiome(biome, BiomeType.BCL_END_LAND);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = getBiomeKey(biome.getBiome()); ResourceKey<Biome> key = biome.getBiomeKey();
if (biome.allowFabricRegistration()) { if (biome.allowFabricRegistration()) {
if (biome.isEdgeBiome()) { if (biome.isEdgeBiome()) {
ResourceKey<Biome> parentKey = getBiomeKey(biome.getParentBiome().getBiome()); ResourceKey<Biome> parentKey = biome.getParentBiome().getBiomeKey();
TheEndBiomes.addMidlandsBiome(parentKey, key, weight); TheEndBiomes.addMidlandsBiome(parentKey, key, weight);
} else { } else {
TheEndBiomes.addHighlandsBiome(key, weight); TheEndBiomes.addHighlandsBiome(key, weight);
@ -258,7 +267,7 @@ public class BiomeAPI {
registerBiome(biome, BiomeType.BCL_END_VOID); registerBiome(biome, BiomeType.BCL_END_VOID);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = getBiomeKey(biome.getBiome()); ResourceKey<Biome> key = biome.getBiomeKey();
if (biome.allowFabricRegistration()) { if (biome.allowFabricRegistration()) {
TheEndBiomes.addSmallIslandsBiome(key, weight); TheEndBiomes.addSmallIslandsBiome(key, weight);
} }
@ -277,7 +286,7 @@ public class BiomeAPI {
registerBiome(biome, BiomeType.BCL_END_CENTER); registerBiome(biome, BiomeType.BCL_END_CENTER);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = getBiomeKey(biome.getBiome()); ResourceKey<Biome> key = biome.getBiomeKey();
if (biome.allowFabricRegistration()) { if (biome.allowFabricRegistration()) {
TheEndBiomes.addMainIslandBiome(key, weight); TheEndBiomes.addMainIslandBiome(key, weight);
} }
@ -296,9 +305,9 @@ public class BiomeAPI {
registerBiome(biome, BiomeType.BCL_END_BARRENS); registerBiome(biome, BiomeType.BCL_END_BARRENS);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = getBiomeKey(biome.getBiome()); ResourceKey<Biome> key = biome.getBiomeKey();
if (biome.allowFabricRegistration()) { if (biome.allowFabricRegistration()) {
ResourceKey<Biome> parentKey = getBiomeKey(highlandBiome.getBiome()); ResourceKey<Biome> parentKey = highlandBiome.getBiomeKey();
TheEndBiomes.addBarrensBiome(parentKey, key, weight); TheEndBiomes.addBarrensBiome(parentKey, key, weight);
} }
return biome; return biome;
@ -416,23 +425,29 @@ public class BiomeAPI {
} }
public static Holder<Biome> getBiomeHolder(BCLBiome biome) { public static Holder<Biome> getBiomeHolder(BCLBiome biome) {
return getBiomeHolder(biome.getBiome()); return getBiomeHolder(biome.getBiomeKey());
} }
public static Holder<Biome> getBiomeHolder(Biome biome) { public static Holder<Biome> getBiomeHolder(Biome biome) {
Optional<ResourceKey<Biome>> key = Optional.empty();
if (InternalBiomeAPI.biomeRegistry != null) { if (InternalBiomeAPI.biomeRegistry != null) {
Optional<ResourceKey<Biome>> key = InternalBiomeAPI.biomeRegistry.getResourceKey(biome); key = InternalBiomeAPI.biomeRegistry.getResourceKey(biome);
if (key.isPresent()) return InternalBiomeAPI.biomeRegistry.getOrCreateHolderOrThrow(key.get()); } else {
key = BuiltinRegistries.BIOME.getResourceKey(biome);
} }
return BuiltinRegistries.BIOME.getOrCreateHolderOrThrow(BiomeAPI.getBiomeKey(biome)); return getBiomeHolder(key.orElseThrow());
}
public static Holder<Biome> getBiomeHolder(ResourceKey<Biome> biomeKey) {
if (InternalBiomeAPI.biomeRegistry != null) {
return InternalBiomeAPI.biomeRegistry.getOrCreateHolderOrThrow(biomeKey);
}
return BuiltinRegistries.BIOME.getOrCreateHolderOrThrow(biomeKey);
} }
public static Holder<Biome> getBiomeHolder(ResourceLocation biome) { public static Holder<Biome> getBiomeHolder(ResourceLocation biome) {
if (InternalBiomeAPI.biomeRegistry != null) { return getBiomeHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biome));
return getBiomeHolder(InternalBiomeAPI.biomeRegistry.get(biome));
}
return getBiomeHolder(BuiltinRegistries.BIOME.get(biome));
} }
/** /**
@ -475,18 +490,45 @@ public class BiomeAPI {
return ID_MAP.containsKey(biomeID); return ID_MAP.containsKey(biomeID);
} }
@Nullable public static Holder<Biome> getFromRegistry(ResourceLocation biomeID) {
public static Holder<Biome> getFromRegistry(ResourceLocation key) { if (InternalBiomeAPI.biomeRegistry != null)
return BuiltinRegistries.BIOME.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, key)).orElseThrow(); return InternalBiomeAPI.biomeRegistry.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID))
.orElseThrow();
return getFromBuiltinRegistry(biomeID);
} }
@Nullable @Nullable
public static Holder<Biome> getFromRegistry(ResourceKey<Biome> key) { public static Holder<Biome> getFromRegistry(ResourceKey<Biome> key) {
if (InternalBiomeAPI.biomeRegistry != null)
return InternalBiomeAPI.biomeRegistry.getHolder(key).orElseThrow();
return getFromBuiltinRegistry(key);
}
@Nullable
public static Holder<Biome> getFromBuiltinRegistry(ResourceLocation biomeID) {
return BuiltinRegistries.BIOME.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID)).orElseThrow();
}
@Nullable
public static Holder<Biome> getFromBuiltinRegistry(ResourceKey<Biome> key) {
return BuiltinRegistries.BIOME.getOrCreateHolderOrThrow(key); return BuiltinRegistries.BIOME.getOrCreateHolderOrThrow(key);
} }
@Deprecated(forRemoval = true)
public static boolean registryContains(ResourceKey<Biome> key) {
if (InternalBiomeAPI.biomeRegistry != null)
return InternalBiomeAPI.biomeRegistry.containsKey(key);
return builtinRegistryContains(key);
}
@Nullable
@Deprecated(forRemoval = true)
public static boolean builtinRegistryContains(ResourceKey<Biome> key) {
return BuiltinRegistries.BIOME.containsKey(key);
}
public static boolean isDatapackBiome(ResourceLocation biomeID) { public static boolean isDatapackBiome(ResourceLocation biomeID) {
return getFromRegistry(biomeID) == null; return getFromBuiltinRegistry(biomeID) == null;
} }
public static boolean wasRegisteredAs(ResourceLocation biomeID, BiomeType dim) { public static boolean wasRegisteredAs(ResourceLocation biomeID, BiomeType dim) {
@ -619,16 +661,16 @@ public class BiomeAPI {
} }
static void sortBiomeFeatures(Biome biome) { static void sortBiomeFeatures(Biome biome) {
BiomeGenerationSettings settings = biome.getGenerationSettings(); // BiomeGenerationSettings settings = biome.getGenerationSettings();
BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) settings; // BiomeGenerationSettingsAccessor accessor = (BiomeGenerationSettingsAccessor) settings;
List<HolderSet<PlacedFeature>> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures()); // List<HolderSet<PlacedFeature>> featureList = CollectionsUtil.getMutable(accessor.bclib_getFeatures());
final int size = featureList.size(); // final int size = featureList.size();
for (int i = 0; i < size; i++) { // for (int i = 0; i < size; i++) {
List<Holder<PlacedFeature>> features = getFeaturesListCopy(featureList, i); // List<Holder<PlacedFeature>> features = getFeaturesListCopy(featureList, i);
sortFeatures(features); // sortFeatures(features);
featureList.set(i, HolderSet.direct(features)); // featureList.set(i, HolderSet.direct(features));
} // }
accessor.bclib_setFeatures(featureList); // accessor.bclib_setFeatures(featureList);
} }
/** /**
@ -846,7 +888,7 @@ public class BiomeAPI {
public static BCLBiome registerNetherBiome(BCLBiome bclBiome) { public static BCLBiome registerNetherBiome(BCLBiome bclBiome) {
registerBiome(bclBiome, BiomeType.BCL_NETHER); registerBiome(bclBiome, BiomeType.BCL_NETHER);
ResourceKey<Biome> key = getBiomeKey(bclBiome.getBiome()); ResourceKey<Biome> key = bclBiome.getBiomeKey();
if (bclBiome.allowFabricRegistration()) { if (bclBiome.allowFabricRegistration()) {
bclBiome.forEachClimateParameter(p -> NetherBiomes.addNetherBiome(key, p)); bclBiome.forEachClimateParameter(p -> NetherBiomes.addNetherBiome(key, p));
} }

View file

@ -273,31 +273,31 @@ public class InternalBiomeAPI {
* Register {@link BCLBiome} wrapper for {@link Biome}. * Register {@link BCLBiome} wrapper for {@link Biome}.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands).
* *
* @param biome The source biome to wrap * @param biomeKey The source biome to wrap
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome wrapNativeBiome(ResourceKey<Biome> biome, BiomeAPI.BiomeType type) { public static BCLBiome wrapNativeBiome(ResourceKey<Biome> biomeKey, BiomeAPI.BiomeType type) {
return wrapNativeBiome(biome, -1, type); return wrapNativeBiome(biomeKey, -1, type);
} }
/** /**
* Register {@link BCLBiome} wrapper for {@link Biome}. * Register {@link BCLBiome} wrapper for {@link Biome}.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands).
* *
* @param biome The source biome to wrap * @param biomeKey The source biome to wrap
* @param genChance generation chance. If &lt;0 the default genChance is used * @param genChance generation chance. If &lt;0 the default genChance is used
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome wrapNativeBiome(ResourceKey<Biome> biome, float genChance, BiomeAPI.BiomeType type) { public static BCLBiome wrapNativeBiome(ResourceKey<Biome> biomeKey, float genChance, BiomeAPI.BiomeType type) {
return wrapNativeBiome( return wrapNativeBiome(
biome, biomeKey,
genChance < 0 ? null : VanillaBiomeSettings.createVanilla().setGenChance(genChance).build(), genChance < 0 ? null : VanillaBiomeSettings.createVanilla().setGenChance(genChance).build(),
type type
); );
} }
public static BCLBiome wrapNativeBiome( public static BCLBiome wrapNativeBiome(
ResourceKey<Biome> biome, ResourceKey<Biome> biomeKey,
BCLBiome edgeBiome, BCLBiome edgeBiome,
int edgeBiomeSize, int edgeBiomeSize,
float genChance, float genChance,
@ -307,28 +307,25 @@ public class InternalBiomeAPI {
if (genChance >= 0) settings.setGenChance(genChance); if (genChance >= 0) settings.setGenChance(genChance);
settings.setEdge(edgeBiome); settings.setEdge(edgeBiome);
settings.setEdgeSize(edgeBiomeSize); settings.setEdgeSize(edgeBiomeSize);
return wrapNativeBiome(biome, settings.build(), type); return wrapNativeBiome(biomeKey, settings.build(), type);
} }
/** /**
* Register {@link BCLBiome} wrapper for {@link Biome}. * Register {@link BCLBiome} wrapper for {@link Biome}.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands).
* *
* @param biome The source biome to wrap * @param biomeKey The source biome to wrap
* @param setings the {@link VanillaBiomeSettings} to use * @param setings the {@link VanillaBiomeSettings} to use
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
private static BCLBiome wrapNativeBiome( private static BCLBiome wrapNativeBiome(
ResourceKey<Biome> biome, ResourceKey<Biome> biomeKey,
VanillaBiomeSettings setings, VanillaBiomeSettings setings,
BiomeAPI.BiomeType type BiomeAPI.BiomeType type
) { ) {
BCLBiome bclBiome = BiomeAPI.getBiome(biome.location()); BCLBiome bclBiome = BiomeAPI.getBiome(biomeKey.location());
if (bclBiome == BiomeAPI.EMPTY_BIOME) { if (bclBiome == BiomeAPI.EMPTY_BIOME) {
bclBiome = new BCLBiome( bclBiome = new BCLBiome(biomeKey, setings);
BiomeAPI.getFromRegistry(biome).value(),
setings
);
} }
BiomeAPI.registerBiome(bclBiome, type); BiomeAPI.registerBiome(bclBiome, type);
@ -343,6 +340,7 @@ public class InternalBiomeAPI {
* @param genChance generation chance. * @param genChance generation chance.
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
@Deprecated(forRemoval = true)
static BCLBiome wrapNativeBiome(Biome biome, float genChance, BiomeAPI.BiomeType type) { static BCLBiome wrapNativeBiome(Biome biome, float genChance, BiomeAPI.BiomeType type) {
BCLBiome bclBiome = BiomeAPI.getBiome(biome); BCLBiome bclBiome = BiomeAPI.getBiome(biome);
if (bclBiome == BiomeAPI.EMPTY_BIOME) { if (bclBiome == BiomeAPI.EMPTY_BIOME) {
@ -352,7 +350,7 @@ public class InternalBiomeAPI {
); );
} }
BiomeAPI.registerBiome(bclBiome, type); BiomeAPI.registerBiome(bclBiome, type, null);
return bclBiome; return bclBiome;
} }
@ -370,4 +368,14 @@ public class InternalBiomeAPI {
}); });
}); });
} }
public static boolean registryContainsBound(ResourceKey<Biome> key) {
Registry<Biome> reg = biomeRegistry;
if (reg == null) reg = BuiltinRegistries.BIOME;
if (reg.containsKey(key)) {
return reg.getOrCreateHolderOrThrow(key).isBound();
}
return false;
}
} }

View file

@ -1,6 +1,7 @@
package org.betterx.worlds.together.tag.v3; package org.betterx.worlds.together.tag.v3;
import org.betterx.bclib.BCLib; import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI; import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
import net.minecraft.core.DefaultedRegistry; import net.minecraft.core.DefaultedRegistry;
@ -83,6 +84,23 @@ public class TagRegistry<T> {
super(Registry.BIOME_REGISTRY, directory, locationProvider); super(Registry.BIOME_REGISTRY, directory, locationProvider);
} }
/**
* Adds one Tag to multiple Elements.
*
* @param tagID {@link TagKey< Biome >} tag ID.
* @param elements array of Elements to add into tag.
*/
public void add(TagKey<Biome> tagID, BCLBiome... elements) {
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
Set<TagEntry> set = getSetForTag(tagID);
for (BCLBiome element : elements) {
ResourceLocation id = element.getID();
if (id != null) {
set.add(TagEntry.element(id));
}
}
}
public TagKey<Biome> makeStructureTag(String modID, String name) { public TagKey<Biome> makeStructureTag(String modID, String name) {
return makeTag(modID, "has_structure/" + name); return makeTag(modID, "has_structure/" + name);
} }