Simplified BCLBiome inheritance, and removed redundant biome configs (replaced by builtin datapack)

This commit is contained in:
Frank 2022-12-05 00:53:14 +01:00
parent b4494faae5
commit 2af0731a81
10 changed files with 52 additions and 108 deletions

View file

@ -81,7 +81,7 @@ public class BiomePicker {
biomes.forEach(biome -> {
if (biome.isValid)
list.add(biome, biome.bclBiome.getGenChance());
list.add(biome, biome.bclBiome.settings.getGenChance());
});
//only a single biome, we need to add the edges as well
if (list.size() == 1) {
@ -89,7 +89,7 @@ public class BiomePicker {
if (biome.getEdge() != null) {
float defaultBiomeSize = 128;
float edgeSize = (biome.bclBiome.getEdgeSize() * list.getWeight(0)) / defaultBiomeSize;
float edgeSize = (biome.bclBiome.settings.getEdgeSize() * list.getWeight(0)) / defaultBiomeSize;
list.add(biome.getEdge(), edgeSize);
}
}

View file

@ -92,7 +92,7 @@ public class MapStack implements BiomeMap {
if (biome == null) {
biome = chunks[i].getBiome(x, z);
}
if (biome.bclBiome.isVertical()) {
if (biome.bclBiome.settings.isVertical()) {
biomeMap[x][z] = biome;
isNoEmpty = true;
}

View file

@ -56,11 +56,11 @@ public class HexBiomeMap implements BiomeMap {
public BiomePicker.ActualBiome getBiome(double x, double y, double z) {
BiomePicker.ActualBiome biome = getRawBiome(x, z);
BiomePicker.ActualBiome edge = biome.getEdge();
int size = biome.bclBiome.getEdgeSize();
int size = biome.bclBiome.settings.getEdgeSize();
if (edge == null && biome.getParentBiome() != null) {
edge = biome.getParentBiome().getEdge();
size = biome.getParentBiome().bclBiome.getEdgeSize();
size = biome.getParentBiome().bclBiome.settings.getEdgeSize();
}
if (edge == null) {

View file

@ -55,7 +55,7 @@ public class SquareBiomeMap implements BiomeMap {
search = biome.getParentBiome();
}
int size = search.bclBiome.getEdgeSize();
int size = search.bclBiome.settings.getEdgeSize();
boolean edge = !search.isSame(getRawBiome(x + size, z));
edge = edge || !search.isSame(getRawBiome(x - size, z));
edge = edge || !search.isSame(getRawBiome(x, z + size));

View file

@ -40,7 +40,7 @@ import org.jetbrains.annotations.Nullable;
* You may use {@link BCLBiome#codecWithSettings(RecordCodecBuilder.Instance)} to create a Codec that includes
* all default settings for {@link BCLBiome} as well as additional Data for your specific subclass.
*/
public class BCLBiome extends BCLBiomeSettings implements BiomeData {
public class BCLBiome implements BiomeData {
public static final Codec<BCLBiome> CODEC = RecordCodecBuilder.create(instance -> codecWithSettings(instance).apply(
instance,
BCLBiome::new
@ -54,27 +54,27 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
private static class CodecAttributes<T extends BCLBiome> {
public RecordCodecBuilder<T, Float> t0 = Codec.FLOAT.fieldOf("terrainHeight")
.orElse(0.1f)
.forGetter((T o1) -> o1.terrainHeight);
.forGetter((T o1) -> o1.settings.terrainHeight);
public RecordCodecBuilder<T, Float> t1 = Codec.FLOAT.fieldOf("fogDensity")
.orElse(1.0f)
.forGetter((T o1) -> o1.fogDensity);
.forGetter((T o1) -> o1.settings.fogDensity);
public RecordCodecBuilder<T, Float> t2 = Codec.FLOAT.fieldOf("genChance")
.orElse(1.0f)
.forGetter((T o1) -> o1.genChance);
.forGetter((T o1) -> o1.settings.genChance);
public RecordCodecBuilder<T, Integer> t3 = Codec.INT.fieldOf("edgeSize")
.orElse(0)
.forGetter((T o1) -> o1.edgeSize);
.forGetter((T o1) -> o1.settings.edgeSize);
public RecordCodecBuilder<T, Boolean> t4 = Codec.BOOL.fieldOf("vertical")
.orElse(false)
.forGetter((T o1) -> o1.vertical);
.forGetter((T o1) -> o1.settings.vertical);
public RecordCodecBuilder<T, Optional<ResourceLocation>> t5 =
ResourceLocation.CODEC
.optionalFieldOf("edge")
.orElse(Optional.empty())
.forGetter((T o1) -> o1.edge == null
.forGetter((T o1) -> ((BCLBiome) o1).edge == null
? Optional.empty()
: Optional.of(o1.edge));
: Optional.of(((BCLBiome) o1).edge));
public RecordCodecBuilder<T, ResourceLocation> t6 =
ResourceLocation.CODEC.fieldOf("biome")
.forGetter((T o) -> ((BCLBiome) o).biomeID);
@ -150,6 +150,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
return instance.group(a.t0, a.t1, a.t2, a.t3, a.t4, a.t5, a.t6, a.t7, a.t8, a.t10);
}
public final BCLBiomeSettings settings;
private final Map<String, Object> customData = Maps.newHashMap();
private final ResourceLocation biomeID;
private final ResourceKey<Biome> biomeKey;
@ -157,6 +158,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
protected final List<Climate.ParameterPoint> parameterPoints = Lists.newArrayList();
private ResourceLocation biomeParent;
private ResourceLocation edge;
private BiomeAPI.BiomeType intendedType = BiomeAPI.BiomeType.NONE;
@ -172,7 +174,14 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
Optional<ResourceLocation> biomeParent,
Optional<String> intendedType
) {
super(terrainHeight, fogDensity, genChance, edgeSize, vertical, edge.orElse(null));
this.settings = new BCLBiomeSettings(
terrainHeight,
fogDensity,
genChance,
edgeSize,
vertical
);
this.edge = edge.orElse(null);
this.biomeID = biomeID;
this.biomeKey = ResourceKey.create(Registries.BIOME, biomeID);
this.biomeParent = biomeParent.orElse(null);
@ -216,12 +225,9 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
* @param defaults The Settings for this Biome or null if you want to apply the defaults
*/
protected BCLBiome(ResourceKey<Biome> biomeKey, BCLBiomeSettings defaults) {
this.settings = defaults;
this.biomeID = biomeKey.location();
this.biomeKey = biomeKey;
if (defaults != null) {
defaults.applyWithDefaults(this);
}
}
/**
@ -231,12 +237,9 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
* @param defaults The Settings for this Biome or null if you want to apply the defaults
*/
protected BCLBiome(ResourceLocation biomeID, BCLBiomeSettings defaults) {
this.settings = defaults;
this.biomeID = biomeID;
this.biomeKey = ResourceKey.create(Registries.BIOME, biomeID);
if (defaults != null) {
defaults.applyWithDefaults(this);
}
}
/**
@ -272,20 +275,14 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
return !BCLBiomeRegistry.isEmptyBiome(edge);
}
/**
* Set biome edge for this biome instance.
*
* @param edge {@link BCLBiome} as the edge biome.
* @return same {@link BCLBiome}.
*/
BCLBiome setEdgeID(ResourceLocation edge) {
this.edge = edge;
return this;
}
BCLBiome setEdge(BCLBiome edge) {
BCLBiome _setEdge(BCLBiome edge) {
if (edge != null) {
this.edge = edge.biomeID;
edge.biomeParent = this.biomeID;
} else {
this.edge = null;
}
return this;
}
@ -300,7 +297,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
if (this.edge != null) {
newEdge.biomeParent = this.edge;
} else {
this.setEdge(newEdge);
this._setEdge(newEdge);
}
return this;
}
@ -329,9 +326,9 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
BCLBiome b = entry.getValue();
if (
this.biomeID.equals(entry.getValue().biomeParent)
&& !entry.getValue().getID().equals(edge)
&& !entry.getValue().isEdgeBiome()
) {
subbiomes.add(b, b.genChance);
subbiomes.add(b, b.settings.genChance);
}
}

View file

@ -930,7 +930,6 @@ public class BCLBiomeBuilder {
.setFogDensity(fogDensity)
.setGenChance(genChance)
.setEdgeSize(edgeSize)
.setEdge(edge)
.setVertical(vertical)
.build();
final T bclBiome = biomeConstructor.apply(ResourceKey.create(Registries.BIOME, biomeID), settings);
@ -951,7 +950,7 @@ public class BCLBiomeBuilder {
builder.specialEffects(getEffects().build());
if (edge != null) {
bclBiome.setEdge(edge);
bclBiome._setEdge(edge);
}
//res.addBiomeTags(tags);

View file

@ -1,10 +1,6 @@
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 {
public static Builder createBCL() {
@ -81,17 +77,6 @@ public class BCLBiomeSettings {
return (R) this;
}
/**
* Set edges:biome for this biome.
*
* @param edge The {@link Biome}.
* @return same {@link Builder}.
*/
public R setEdge(BCLBiome edge) {
storage.edge = edge == null ? null : edge.getID();
return (R) this;
}
/**
* Sets fog density for this biome.
*
@ -109,15 +94,13 @@ public class BCLBiomeSettings {
float fogDensity,
float genChance,
int edgeSize,
boolean vertical,
ResourceLocation edge
boolean vertical
) {
this.terrainHeight = terrainHeight;
this.fogDensity = fogDensity;
this.genChance = genChance;
this.edgeSize = edgeSize;
this.vertical = vertical;
this.edge = edge;
}
protected BCLBiomeSettings() {
@ -126,7 +109,6 @@ public class BCLBiomeSettings {
this.genChance = 1.0F;
this.edgeSize = 0;
this.vertical = false;
this.edge = null;
}
float terrainHeight;
@ -134,7 +116,6 @@ public class BCLBiomeSettings {
float genChance;
int edgeSize;
boolean vertical;
ResourceLocation edge;
/**
@ -181,39 +162,4 @@ public class BCLBiomeSettings {
public int getEdgeSize() {
return edgeSize;
}
/**
* Getter for edge-biome.
*
* @return The assigned edge biome.
*/
public BCLBiome getEdge() {
return BiomeAPI.getBiome(edge);
}
/**
* Load values from Config and apply to the passed Biome. The Default values for the loaded settings
* are derifed from the values store in this object
*
* @param biome {@link BCLBiome} to assign values to
*/
public void applyWithDefaults(BCLBiome biome) {
final String group = biome.configGroup();
biome.genChance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", this.genChance);
if (edge != null) {
biome.edgeSize = Configs.BIOMES_CONFIG.getInt(group, "edge_size", this.edgeSize);
if (edgeSize > 0) {
biome.setEdgeID(edge);
}
}
if (!(this instanceof VanillaBiomeSettings)) {
biome.fogDensity = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", this.fogDensity);
biome.vertical = Configs.BIOMES_CONFIG.getBoolean(group, "vertical", this.vertical);
biome.terrainHeight = Configs.BIOMES_CONFIG.getFloat(group, "terrain_height", this.terrainHeight);
}
Configs.BIOMES_CONFIG.saveChanges();
}
}

View file

@ -155,7 +155,7 @@ public class BiomeAPI {
public static final BiomeType END_CENTER = new BiomeType("END_CENTER", END);
public static final BiomeType END_BARRENS = new BiomeType("END_BARRENS", END);
public static final BiomeType BCL_END_LAND = new BiomeType("BCL_END_LAND", END_LAND, (biome, ignored) -> {
float weight = biome.getGenChance();
float weight = biome.settings.getGenChance();
ResourceKey<Biome> key = biome.getBiomeKey();
if (biome.isEdgeBiome()) {
@ -166,14 +166,14 @@ public class BiomeAPI {
}
});
public static final BiomeType BCL_END_VOID = new BiomeType("BCL_END_VOID", END_VOID, (biome, ignored) -> {
float weight = biome.getGenChance();
float weight = biome.settings.getGenChance();
ResourceKey<Biome> key = biome.getBiomeKey();
if (!biome.isEdgeBiome()) {
TheEndBiomes.addSmallIslandsBiome(key, weight);
}
});
public static final BiomeType BCL_END_CENTER = new BiomeType("BCL_END_CENTER", END_CENTER, (biome, ignored) -> {
float weight = biome.getGenChance();
float weight = biome.settings.getGenChance();
ResourceKey<Biome> key = biome.getBiomeKey();
if (!biome.isEdgeBiome()) {
TheEndBiomes.addMainIslandBiome(key, weight);
@ -184,7 +184,7 @@ public class BiomeAPI {
"BCL_END_BARRENS",
END_BARRENS,
(biome, highlandBiome) -> {
float weight = biome.getGenChance();
float weight = biome.settings.getGenChance();
ResourceKey<Biome> key = biome.getBiomeKey();
if (!biome.isEdgeBiome()) {
ResourceKey<Biome> parentKey = highlandBiome.getBiomeKey();
@ -339,7 +339,7 @@ public class BiomeAPI {
static BCLBiome registerEndLandBiome(BootstapContext<Biome> bootstrapContext, BCLBiome biome) {
registerBuiltinBiomeAndOverrideIntendedDimension(bootstrapContext, biome, BiomeType.BCL_END_LAND);
float weight = biome.getGenChance();
float weight = biome.settings.getGenChance();
ResourceKey<Biome> key = biome.getBiomeKey();
if (biome.isEdgeBiome()) {
@ -363,7 +363,7 @@ public class BiomeAPI {
static BCLBiome registerEndVoidBiome(BootstapContext<Biome> bootstrapContext, BCLBiome biome) {
registerBuiltinBiomeAndOverrideIntendedDimension(bootstrapContext, biome, BiomeType.BCL_END_VOID);
float weight = biome.getGenChance();
float weight = biome.settings.getGenChance();
ResourceKey<Biome> key = biome.getBiomeKey();
if (!biome.isEdgeBiome()) {
TheEndBiomes.addSmallIslandsBiome(key, weight);
@ -382,7 +382,7 @@ public class BiomeAPI {
static BCLBiome registerEndCenterBiome(BootstapContext<Biome> bootstrapContext, BCLBiome biome) {
registerBuiltinBiomeAndOverrideIntendedDimension(bootstrapContext, biome, BiomeType.BCL_END_CENTER);
float weight = biome.getGenChance();
float weight = biome.settings.getGenChance();
ResourceKey<Biome> key = biome.getBiomeKey();
if (!biome.isEdgeBiome()) {
TheEndBiomes.addMainIslandBiome(key, weight);
@ -405,7 +405,7 @@ public class BiomeAPI {
) {
registerBuiltinBiomeAndOverrideIntendedDimension(bootstrapContext, biome, BiomeType.BCL_END_BARRENS);
float weight = biome.getGenChance();
float weight = biome.settings.getGenChance();
ResourceKey<Biome> key = biome.getBiomeKey();
if (!biome.isEdgeBiome()) {
ResourceKey<Biome> parentKey = highlandBiome.getBiomeKey();

View file

@ -223,9 +223,11 @@ public class InternalBiomeAPI {
) {
VanillaBiomeSettings.Builder settings = VanillaBiomeSettings.createVanilla();
if (genChance >= 0) settings.setGenChance(genChance);
settings.setEdge(edgeBiome);
settings.setEdgeSize(edgeBiomeSize);
return wrapBiome(biomeKey, settings.build(), type);
final BCLBiome b = wrapBiome(biomeKey, settings.build(), type);
b._setEdge(edgeBiome);
return b;
}
/**

View file

@ -124,9 +124,9 @@ public class CustomFogRenderer {
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 BCLBiomeRegistry.EMPTY_BIOME.settings.getFogDensity();
}
return renderBiome.getFogDensity();
return renderBiome.settings.getFogDensity();
}
private static float getFogDensity(Level level, double x, double y, double z) {