[Changes] Make sure BCLBiomes do not keep cyclic/order dependant references
This commit is contained in:
parent
abaef11682
commit
29b8e96bbe
12 changed files with 117 additions and 107 deletions
|
@ -145,7 +145,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
|
|||
}
|
||||
|
||||
|
||||
if (bclBiome != null || bclBiome != BCLBiomeRegistry.EMPTY_BIOME) {
|
||||
if (!BCLBiomeRegistry.isEmptyBiome(bclBiome)) {
|
||||
if (bclBiome.getParentBiome() == null) {
|
||||
//ignore small islands when void biomes are disabled
|
||||
if (!config.withVoidBiomes) {
|
||||
|
@ -165,7 +165,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
|
|||
}
|
||||
|
||||
if (!didForceAdd) {
|
||||
if (biomeID.equals(BCLBiomeRegistry.EMPTY_BIOME.getID())
|
||||
if (BCLBiomeRegistry.isEmptyBiome(biomeID)
|
||||
|| bclBiome.getIntendedType().is(BiomeAPI.BiomeType.END_IGNORE)) {
|
||||
//we should not add this biome anywhere, so just ignore it
|
||||
} else {
|
||||
|
|
|
@ -103,7 +103,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
|
|||
} else {
|
||||
BCLBiome bclBiome = BiomeAPI.getBiome(biomeID);
|
||||
|
||||
if (bclBiome != BCLBiomeRegistry.EMPTY_BIOME) {
|
||||
if (!BCLBiomeRegistry.isEmptyBiome(bclBiome)) {
|
||||
if (bclBiome.getParentBiome() == null) {
|
||||
biomePicker.addBiome(bclBiome);
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class BiomePicker {
|
|||
subbiomes.add(create(b), w);
|
||||
});
|
||||
|
||||
if (bclBiome.getEdge() != null && isAllowed(bclBiome.getEdge())) {
|
||||
if (bclBiome.hasEdge() && isAllowed(bclBiome.getEdge())) {
|
||||
edge = create(bclBiome.getEdge());
|
||||
} else {
|
||||
edge = null;
|
||||
|
|
|
@ -89,6 +89,9 @@ public class MapStack implements BiomeMap {
|
|||
for (int z = 0; z < side; z++) {
|
||||
if (biomeMap[x][z] == null) {
|
||||
BiomePicker.ActualBiome biome = chunks[i].getBiome(x, z);
|
||||
if (biome == null) {
|
||||
biome = chunks[i].getBiome(x, z);
|
||||
}
|
||||
if (biome.bclBiome.isVertical()) {
|
||||
biomeMap[x][z] = biome;
|
||||
isNoEmpty = true;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.betterx.bclib.api.v2.generator.map.hex;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.v2.generator.BiomePicker;
|
||||
import org.betterx.bclib.interfaces.BiomeChunk;
|
||||
|
||||
|
@ -72,12 +73,22 @@ public class HexBiomeChunk implements BiomeChunk {
|
|||
outBuffer[getIndex(SIDE_MASK, index)] = outBuffer[getIndex(preN, index)];
|
||||
}
|
||||
|
||||
int lastAction = -1;
|
||||
BiomePicker.ActualBiome lBiome = null;
|
||||
for (short index = 0; index < SIZE; index++) {
|
||||
if (outBuffer[index] == null) {
|
||||
lastAction = 0;
|
||||
lBiome = null;
|
||||
outBuffer[index] = picker.getBiome(random);
|
||||
} else if (random.nextInt(4) == 0) {
|
||||
lastAction = 1;
|
||||
lBiome = outBuffer[index];
|
||||
circle(outBuffer, index, outBuffer[index].getSubBiome(random), outBuffer[index]);
|
||||
}
|
||||
|
||||
if (outBuffer[index] == null) {
|
||||
BCLib.LOGGER.error("Invalid Biome at " + index + ", " + lastAction + ", " + lBiome);
|
||||
}
|
||||
}
|
||||
|
||||
System.arraycopy(outBuffer, 0, this.biomes, 0, SIZE);
|
||||
|
|
|
@ -1,18 +1,19 @@
|
|||
package org.betterx.bclib.api.v2.levelgen.biomes;
|
||||
|
||||
import org.betterx.bclib.util.WeightedList;
|
||||
import org.betterx.worlds.together.world.event.WorldBootstrap;
|
||||
|
||||
import com.mojang.datafixers.Products;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.KeyDispatchDataCodec;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Climate;
|
||||
import net.minecraft.world.level.levelgen.WorldgenRandom;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
@ -73,7 +74,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
.orElse(Optional.empty())
|
||||
.forGetter((T o1) -> o1.edge == null
|
||||
? Optional.empty()
|
||||
: Optional.of(o1.edge.biomeID));
|
||||
: Optional.of(o1.edge));
|
||||
public RecordCodecBuilder<T, ResourceLocation> t6 =
|
||||
ResourceLocation.CODEC.fieldOf("biome")
|
||||
.forGetter((T o) -> ((BCLBiome) o).biomeID);
|
||||
|
@ -94,26 +95,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
((BCLBiome) o1).biomeParent == null
|
||||
? Optional.empty()
|
||||
: Optional.of(
|
||||
((BCLBiome) o1).biomeParent.biomeID));
|
||||
public RecordCodecBuilder<T, Optional<WeightedList<ResourceLocation>>> t9 =
|
||||
WeightedList.listCodec(
|
||||
ResourceLocation.CODEC,
|
||||
"biomes",
|
||||
"biome"
|
||||
)
|
||||
.optionalFieldOf("sub_biomes")
|
||||
.forGetter(
|
||||
(T o) -> {
|
||||
if (o.subbiomes == null
|
||||
|| o.subbiomes.isEmpty()
|
||||
|| (o.subbiomes.size() == 1 && o.subbiomes.contains(
|
||||
o))) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(
|
||||
o.subbiomes.map(
|
||||
b -> b.biomeID));
|
||||
});
|
||||
((BCLBiome) o1).biomeParent));
|
||||
public RecordCodecBuilder<T, Optional<String>> t10 =
|
||||
Codec.STRING.optionalFieldOf("intended_for")
|
||||
.orElse(Optional.of(BiomeAPI.BiomeType.NONE.getName()))
|
||||
|
@ -123,52 +105,51 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
: Optional.of(((BCLBiome) o).intendedType.getName()));
|
||||
}
|
||||
|
||||
public static <T extends BCLBiome, P12> Products.P12<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<WeightedList<ResourceLocation>>, Optional<String>, P12> codecWithSettings(
|
||||
public static <T extends BCLBiome, P11> Products.P11<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<String>, P11> codecWithSettings(
|
||||
RecordCodecBuilder.Instance<T> instance,
|
||||
final RecordCodecBuilder<T, P11> p11
|
||||
) {
|
||||
CodecAttributes<T> a = new CodecAttributes<>();
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t10, p11);
|
||||
}
|
||||
|
||||
public static <T extends BCLBiome, P11, P12> Products.P12<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<String>, P11, P12> codecWithSettings(
|
||||
RecordCodecBuilder.Instance<T> instance,
|
||||
final RecordCodecBuilder<T, P11> p11,
|
||||
final RecordCodecBuilder<T, P12> p12
|
||||
) {
|
||||
CodecAttributes<T> a = new CodecAttributes<>();
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t9, a.t10, p12);
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t10, p11, p12);
|
||||
}
|
||||
|
||||
public static <T extends BCLBiome, P12, P13> Products.P13<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<WeightedList<ResourceLocation>>, Optional<String>, P12, P13> codecWithSettings(
|
||||
RecordCodecBuilder.Instance<T> instance,
|
||||
final RecordCodecBuilder<T, P12> p12,
|
||||
final RecordCodecBuilder<T, P13> p13
|
||||
) {
|
||||
CodecAttributes<T> a = new CodecAttributes<>();
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t9, a.t10, p12, p13);
|
||||
}
|
||||
|
||||
public static <T extends BCLBiome, P12, P13, P14, P15> Products.P15<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<WeightedList<ResourceLocation>>, Optional<String>, P12, P13, P14, P15> codecWithSettings(
|
||||
RecordCodecBuilder.Instance<T> instance,
|
||||
final RecordCodecBuilder<T, P12> p12,
|
||||
final RecordCodecBuilder<T, P13> p13,
|
||||
final RecordCodecBuilder<T, P14> p14,
|
||||
final RecordCodecBuilder<T, P15> p15
|
||||
) {
|
||||
CodecAttributes<T> a = new CodecAttributes<>();
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t9, a.t10, p12, p13, p14, p15);
|
||||
}
|
||||
|
||||
public static <T extends BCLBiome, P12, P13, P14> Products.P14<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<WeightedList<ResourceLocation>>, Optional<String>, P12, P13, P14> codecWithSettings(
|
||||
public static <T extends BCLBiome, P11, P12, P13, P14> Products.P14<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<String>, P11, P12, P13, P14> codecWithSettings(
|
||||
RecordCodecBuilder.Instance<T> instance,
|
||||
final RecordCodecBuilder<T, P11> p11,
|
||||
final RecordCodecBuilder<T, P12> p12,
|
||||
final RecordCodecBuilder<T, P13> p13,
|
||||
final RecordCodecBuilder<T, P14> p14
|
||||
) {
|
||||
CodecAttributes<T> a = new CodecAttributes<>();
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t9, a.t10, p12, p13, p14);
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t10, p11, p12, p13, p14);
|
||||
}
|
||||
|
||||
public static <T extends BCLBiome> Products.P11<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<WeightedList<ResourceLocation>>, Optional<String>> codecWithSettings(
|
||||
public static <T extends BCLBiome, P11, P12, P13> Products.P13<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<String>, P11, P12, P13> codecWithSettings(
|
||||
RecordCodecBuilder.Instance<T> instance,
|
||||
final RecordCodecBuilder<T, P11> p11,
|
||||
final RecordCodecBuilder<T, P12> p12,
|
||||
final RecordCodecBuilder<T, P13> p13
|
||||
) {
|
||||
CodecAttributes<T> a = new CodecAttributes<>();
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t10, p11, p12, p13);
|
||||
}
|
||||
|
||||
public static <T extends BCLBiome> Products.P10<RecordCodecBuilder.Mu<T>, Float, Float, Float, Integer, Boolean, Optional<ResourceLocation>, ResourceLocation, Optional<List<Climate.ParameterPoint>>, Optional<ResourceLocation>, Optional<String>> codecWithSettings(
|
||||
RecordCodecBuilder.Instance<T> instance
|
||||
) {
|
||||
CodecAttributes<T> a = new CodecAttributes<>();
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t9, a.t10);
|
||||
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t10);
|
||||
}
|
||||
|
||||
protected final WeightedList<BCLBiome> subbiomes = new WeightedList<>();
|
||||
private final Map<String, Object> customData = Maps.newHashMap();
|
||||
private final ResourceLocation biomeID;
|
||||
private final ResourceKey<Biome> biomeKey;
|
||||
|
@ -176,7 +157,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
|
||||
protected final List<Climate.ParameterPoint> parameterPoints = Lists.newArrayList();
|
||||
|
||||
private BCLBiome biomeParent;
|
||||
private ResourceLocation biomeParent;
|
||||
|
||||
private BiomeAPI.BiomeType intendedType = BiomeAPI.BiomeType.NONE;
|
||||
|
||||
|
@ -190,30 +171,15 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
ResourceLocation biomeID,
|
||||
Optional<List<Climate.ParameterPoint>> parameterPoints,
|
||||
Optional<ResourceLocation> biomeParent,
|
||||
Optional<WeightedList<ResourceLocation>> subbiomes,
|
||||
Optional<String> intendedType
|
||||
) {
|
||||
super(terrainHeight, fogDensity, genChance, edgeSize, vertical, edge.map(BiomeAPI::getBiome).orElse(null));
|
||||
biomeToRegister = null;
|
||||
this.biomeID = biomeID;
|
||||
this.biomeKey = ResourceKey.create(Registry.BIOME_REGISTRY, biomeID);
|
||||
if (subbiomes.isEmpty() || subbiomes.get().size() == 0) {
|
||||
this.subbiomes.add(this, 1);
|
||||
} else {
|
||||
this.subbiomes.addAll(subbiomes.get().map(BiomeAPI::getBiome));
|
||||
}
|
||||
this.biomeParent = biomeParent.map(BiomeAPI::getBiome).orElse(null);
|
||||
this.biomeParent = biomeParent.orElse(null);
|
||||
if (parameterPoints.isPresent()) this.parameterPoints.addAll(parameterPoints.get());
|
||||
this.setIntendedType(intendedType.map(t -> BiomeAPI.BiomeType.create(t)).orElse(BiomeAPI.BiomeType.NONE));
|
||||
|
||||
//make sure we are registered properly
|
||||
if (this.biomeParent != null)
|
||||
this.biomeParent.addSubBiome(this);
|
||||
|
||||
//make sure edges are set up correct
|
||||
if (this.edge != null) {
|
||||
this.setEdge(this.edge);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -289,7 +255,6 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
*/
|
||||
protected BCLBiome(ResourceKey<Biome> biomeKey, Biome biomeToRegister, BCLBiomeSettings defaults) {
|
||||
this.biomeToRegister = biomeToRegister;
|
||||
this.subbiomes.add(this, 1.0F);
|
||||
this.biomeID = biomeKey.location();
|
||||
this.biomeKey = biomeKey;
|
||||
|
||||
|
@ -324,7 +289,11 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
*/
|
||||
@Nullable
|
||||
public BCLBiome getEdge() {
|
||||
return edge;
|
||||
return BiomeAPI.getBiome(edge);
|
||||
}
|
||||
|
||||
public boolean hasEdge() {
|
||||
return !BCLBiomeRegistry.isEmptyBiome(edge);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -333,9 +302,8 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
* @param edge {@link BCLBiome} as the edge biome.
|
||||
* @return same {@link BCLBiome}.
|
||||
*/
|
||||
BCLBiome setEdge(BCLBiome edge) {
|
||||
BCLBiome setEdge(ResourceLocation edge) {
|
||||
this.edge = edge;
|
||||
edge.biomeParent = this;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -348,9 +316,10 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
*/
|
||||
public BCLBiome addEdge(BCLBiome edge) {
|
||||
if (this.edge != null) {
|
||||
this.edge.addSubBiome(edge);
|
||||
this.setEdge(edge.biomeID);
|
||||
edge.biomeParent = edge.biomeID;
|
||||
} else {
|
||||
this.setEdge(edge);
|
||||
this.setEdge((ResourceLocation) null);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -363,19 +332,26 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
* @return same {@link BCLBiome}.
|
||||
*/
|
||||
public BCLBiome addSubBiome(BCLBiome biome) {
|
||||
biome.biomeParent = this;
|
||||
subbiomes.add(biome, biome.getGenChance());
|
||||
biome.biomeParent = this.biomeID;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if specified biome is a sub-biome of this one.
|
||||
*
|
||||
* @param biome {@link Random}.
|
||||
* @return true if this instance contains specified biome as a sub-biome.
|
||||
*/
|
||||
public boolean containsSubBiome(BCLBiome biome) {
|
||||
return subbiomes.contains(biome);
|
||||
private WeightedList<BCLBiome> getSubBiomes() {
|
||||
RegistryAccess acc = WorldBootstrap.getLastRegistryAccess();
|
||||
WeightedList<BCLBiome> subbiomes = new WeightedList<>();
|
||||
subbiomes.add(this, 1.0f);
|
||||
if (acc == null) return subbiomes;
|
||||
|
||||
Registry<BCLBiome> reg = acc.registryOrThrow(BCLBiomeRegistry.BCL_BIOMES_REGISTRY);
|
||||
|
||||
for (Map.Entry<ResourceKey<BCLBiome>, BCLBiome> entry : reg.entrySet()) {
|
||||
BCLBiome b = entry.getValue();
|
||||
if (this.biomeID.equals(entry.getValue().biomeParent)) {
|
||||
subbiomes.add(b, b.genChance);
|
||||
}
|
||||
}
|
||||
|
||||
return subbiomes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -384,11 +360,11 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
* @param random {@link Random}.
|
||||
* @return {@link BCLBiome}.
|
||||
*/
|
||||
public BCLBiome getSubBiome(WorldgenRandom random) {
|
||||
return subbiomes.get(random);
|
||||
}
|
||||
|
||||
// public BCLBiome getSubBiome(WorldgenRandom random) {
|
||||
// return getSubBiomes().get(random);
|
||||
// }
|
||||
public void forEachSubBiome(BiConsumer<BCLBiome, Float> consumer) {
|
||||
final WeightedList<BCLBiome> subbiomes = getSubBiomes();
|
||||
for (int i = 0; i < subbiomes.size(); i++)
|
||||
consumer.accept(subbiomes.get(i), subbiomes.getWeight(i));
|
||||
}
|
||||
|
@ -400,7 +376,11 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
*/
|
||||
@Nullable
|
||||
public BCLBiome getParentBiome() {
|
||||
return this.biomeParent;
|
||||
return BiomeAPI.getBiome(this.biomeParent);
|
||||
}
|
||||
|
||||
public boolean hasParentBiome() {
|
||||
return !BCLBiomeRegistry.isEmptyBiome(biomeParent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -410,7 +390,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
* @return true if biome or its parent is same.
|
||||
*/
|
||||
public boolean isSame(BCLBiome biome) {
|
||||
return biome == this || (biome.biomeParent != null && biome.biomeParent == this);
|
||||
return biome == this || (biome.biomeParent != null && biome.biomeParent.equals(this.biomeID));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -422,6 +402,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
return biomeID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Getter for biomeKey
|
||||
*
|
||||
|
@ -488,8 +469,9 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
|
|||
private final boolean didLoadConfig = false;
|
||||
|
||||
public boolean isEdgeBiome() {
|
||||
if (getParentBiome() == null) return false;
|
||||
return getParentBiome().edge == this;
|
||||
final BCLBiome parent = getParentBiome();
|
||||
if (parent == null) return false;
|
||||
return this.biomeID.equals(parent.edge);
|
||||
}
|
||||
|
||||
boolean allowFabricRegistration() {
|
||||
|
|
|
@ -42,6 +42,14 @@ public class BCLBiomeRegistry {
|
|||
**/
|
||||
public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location());
|
||||
|
||||
public static boolean isEmptyBiome(ResourceLocation l) {
|
||||
return l == null || Biomes.THE_VOID.location().equals(l);
|
||||
}
|
||||
|
||||
public static boolean isEmptyBiome(BCLBiome b) {
|
||||
return b == null || b == EMPTY_BIOME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a codec for a custom subclass of {@link BCLBiome}. Each subclass needs to provide
|
||||
* a codec, otherwise the instance will get rebuild as a regular BCLib biome loosing the Type
|
||||
|
@ -134,9 +142,9 @@ public class BCLBiomeRegistry {
|
|||
return getOrElseEmpty(WorldBootstrap.getLastRegistryAccess(), loc);
|
||||
}
|
||||
|
||||
public static BCLBiome getOrElseEmpty(@Nullable RegistryAccess access, ResourceLocation loc) {
|
||||
public static @Nullable BCLBiome getOrElseEmpty(@Nullable RegistryAccess access, ResourceLocation loc) {
|
||||
BCLBiome res = access == null ? null : get(access, loc);
|
||||
if (res == null) return EMPTY_BIOME;
|
||||
//if (res == null) return EMPTY_BIOME;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.betterx.bclib.api.v2.levelgen.biomes;
|
|||
import org.betterx.bclib.api.v2.generator.BiomePicker;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
public class BCLBiomeSettings {
|
||||
|
@ -87,7 +88,7 @@ public class BCLBiomeSettings {
|
|||
* @return same {@link Builder}.
|
||||
*/
|
||||
public R setEdge(BCLBiome edge) {
|
||||
storage.edge = edge;
|
||||
storage.edge = edge == null ? null : edge.getID();
|
||||
return (R) this;
|
||||
}
|
||||
|
||||
|
@ -116,7 +117,7 @@ public class BCLBiomeSettings {
|
|||
this.genChance = genChance;
|
||||
this.edgeSize = edgeSize;
|
||||
this.vertical = vertical;
|
||||
this.edge = edge;
|
||||
this.edge = edge == null ? null : edge.getID();
|
||||
}
|
||||
|
||||
protected BCLBiomeSettings() {
|
||||
|
@ -133,7 +134,7 @@ public class BCLBiomeSettings {
|
|||
float genChance;
|
||||
int edgeSize;
|
||||
boolean vertical;
|
||||
BCLBiome edge;
|
||||
ResourceLocation edge;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -187,7 +188,7 @@ public class BCLBiomeSettings {
|
|||
* @return The assigned edge biome.
|
||||
*/
|
||||
public BCLBiome getEdge() {
|
||||
return edge;
|
||||
return BiomeAPI.getBiome(edge);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -554,7 +554,7 @@ public class BiomeAPI {
|
|||
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
|
||||
*/
|
||||
public static BCLBiome getBiome(ResourceLocation biomeID) {
|
||||
if (biomeID == null) return BCLBiomeRegistry.EMPTY_BIOME;
|
||||
if (biomeID == null) return null;
|
||||
return BCLBiomeRegistry.getOrElseEmpty(biomeID);
|
||||
}
|
||||
|
||||
|
@ -618,9 +618,11 @@ public class BiomeAPI {
|
|||
}
|
||||
|
||||
public static boolean wasRegisteredAs(ResourceLocation biomeID, BiomeType dim) {
|
||||
if (BCLBiomeRegistry.EMPTY_BIOME.getID().equals(biomeID))
|
||||
if (BCLBiomeRegistry.isEmptyBiome(biomeID))
|
||||
return false;
|
||||
return BCLBiomeRegistry.getOrElseEmpty(biomeID).getIntendedType().is(dim);
|
||||
final BCLBiome res = BCLBiomeRegistry.getOrElseEmpty(biomeID);
|
||||
if (res == null) return false;
|
||||
return res.getIntendedType().is(dim);
|
||||
}
|
||||
|
||||
public static boolean wasRegisteredAsNetherBiome(ResourceLocation biomeID) {
|
||||
|
|
|
@ -264,7 +264,7 @@ public class InternalBiomeAPI {
|
|||
BiomeAPI.BiomeType type
|
||||
) {
|
||||
BCLBiome bclBiome = BiomeAPI.getBiome(biomeKey.location());
|
||||
if (bclBiome == BCLBiomeRegistry.EMPTY_BIOME) {
|
||||
if (BCLBiomeRegistry.isEmptyBiome(bclBiome)) {
|
||||
bclBiome = new BCLBiome(biomeKey, setings);
|
||||
bclBiome._setIntendedType(type);
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ public class InternalBiomeAPI {
|
|||
.event(oBiomeRegistry.get())
|
||||
.register((rawId, id, biome) -> {
|
||||
BCLBiome b = BiomeAPI.getBiome(id);
|
||||
if (!"minecraft".equals(id.getNamespace()) && (b == null || b == BCLBiomeRegistry.EMPTY_BIOME)) {
|
||||
if (!"minecraft".equals(id.getNamespace()) && BCLBiomeRegistry.isEmptyBiome(b)) {
|
||||
//BCLib.LOGGER.info(" #### " + rawId + ", " + biome + ", " + id);
|
||||
//BIOMES_TO_SORT.add(id);
|
||||
// BIOME_ADDITIONS.computeIfAbsent(oBiomeRegistry.get(), reg -> new AtomicInteger(0))
|
||||
|
|
|
@ -117,12 +117,15 @@ public class CustomFogRenderer {
|
|||
|
||||
private static boolean shouldIgnore(Level level, int x, int y, int z) {
|
||||
Biome biome = level.getBiome(MUT_POS.set(x, y, z)).value();
|
||||
return BiomeAPI.getRenderBiome(biome) == BCLBiomeRegistry.EMPTY_BIOME;
|
||||
return BCLBiomeRegistry.isEmptyBiome(BiomeAPI.getRenderBiome(biome));
|
||||
}
|
||||
|
||||
private static float getFogDensityI(Level level, int x, int y, int z) {
|
||||
Biome biome = level.getBiome(MUT_POS.set(x, y, z)).value();
|
||||
BCLBiome renderBiome = BiomeAPI.getRenderBiome(biome);
|
||||
if (renderBiome == null) {
|
||||
return BCLBiomeRegistry.EMPTY_BIOME.getFogDensity();
|
||||
}
|
||||
return renderBiome.getFogDensity();
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ public class WeightedList<T> {
|
|||
* @return {@link T} value.
|
||||
*/
|
||||
public T get(RandomSource random) {
|
||||
if (maxWeight < 1) {
|
||||
if (maxWeight <= 0) {
|
||||
return null;
|
||||
}
|
||||
float weight = random.nextFloat() * maxWeight;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue