Moved Biome classes
This commit is contained in:
parent
51ec0596da
commit
f70db44ffd
10 changed files with 41 additions and 23 deletions
|
@ -18,7 +18,10 @@ import org.betterx.bclib.api.surface.SurfaceRuleUtil;
|
|||
import org.betterx.bclib.api.tag.TagAPI;
|
||||
import org.betterx.bclib.util.WeightedList;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -183,10 +186,6 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
}
|
||||
|
||||
|
||||
public Holder<Biome> getBiomeHolder() {
|
||||
return BuiltinRegistries.BIOME.getOrCreateHolderOrThrow(BiomeAPI.getBiomeKey(biome));
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for biome from buil-in registry. For datapack biomes will be same as actual biome.
|
||||
*
|
||||
|
|
|
@ -35,8 +35,6 @@ import org.betterx.bclib.util.CollectionsUtil;
|
|||
import org.betterx.bclib.util.ColorUtil;
|
||||
import org.betterx.bclib.util.Pair;
|
||||
import org.betterx.bclib.util.TriFunction;
|
||||
import org.betterx.bclib.world.biomes.BCLBiome;
|
||||
import org.betterx.bclib.world.biomes.BCLBiomeSettings;
|
||||
import org.betterx.bclib.world.features.BCLFeature;
|
||||
import org.betterx.bclib.world.structures.BCLStructure;
|
||||
|
||||
|
@ -56,7 +54,8 @@ public class BCLBiomeBuilder {
|
|||
-0.012);
|
||||
|
||||
private final List<TagKey<Biome>> structureTags = new ArrayList<>(8);
|
||||
private final List<Pair<GenerationStep.Carving, Holder<? extends ConfiguredWorldCarver<?>>>> carvers = new ArrayList<>(1);
|
||||
private final List<Pair<GenerationStep.Carving, Holder<? extends ConfiguredWorldCarver<?>>>> carvers = new ArrayList<>(
|
||||
1);
|
||||
private BiomeGenerationSettings.Builder generationSettings;
|
||||
private BiomeSpecialEffects.Builder effectsBuilder;
|
||||
private MobSpawnSettings.Builder spawnSettings;
|
||||
|
|
202
src/main/java/org/betterx/bclib/api/biomes/BCLBiomeSettings.java
Normal file
202
src/main/java/org/betterx/bclib/api/biomes/BCLBiomeSettings.java
Normal file
|
@ -0,0 +1,202 @@
|
|||
package org.betterx.bclib.api.biomes;
|
||||
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.world.generator.BiomePicker;
|
||||
|
||||
public class BCLBiomeSettings {
|
||||
public static Builder createBCL() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder extends CommonBuilder<BCLBiomeSettings, Builder> {
|
||||
public Builder() {
|
||||
super(new BCLBiomeSettings());
|
||||
}
|
||||
}
|
||||
|
||||
public static class CommonBuilder<T extends BCLBiomeSettings, R extends CommonBuilder> {
|
||||
private final T storage;
|
||||
|
||||
CommonBuilder(T storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public T build() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set gen chance for this biome, default value is 1.0.
|
||||
*
|
||||
* @param genChance chance of this biome to be generated.
|
||||
* @return same {@link BCLBiomeSettings}.
|
||||
*/
|
||||
public R setGenChance(float genChance) {
|
||||
storage.genChance = genChance;
|
||||
return (R) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for terrain height, can be used in custom terrain generator.
|
||||
*
|
||||
* @param terrainHeight a relative float terrain height value.
|
||||
* @return same {@link Builder}.
|
||||
*/
|
||||
public R setTerrainHeight(float terrainHeight) {
|
||||
storage.terrainHeight = terrainHeight;
|
||||
return (R) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set biome vertical distribution (for tall Nether only).
|
||||
*
|
||||
* @return same {@link Builder}.
|
||||
*/
|
||||
public R setVertical() {
|
||||
return setVertical(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set biome vertical distribution (for tall Nether only).
|
||||
*
|
||||
* @param vertical {@code boolean} value.
|
||||
* @return same {@link Builder}.
|
||||
*/
|
||||
public R setVertical(boolean vertical) {
|
||||
storage.vertical = vertical;
|
||||
return (R) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set edges size for this biome. Size is in blocks.
|
||||
*
|
||||
* @param size as a float value.
|
||||
* @return same {@link Builder}.
|
||||
*/
|
||||
public R setEdgeSize(int size) {
|
||||
storage.edgeSize = size;
|
||||
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;
|
||||
return (R) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets fog density for this biome.
|
||||
*
|
||||
* @param fogDensity
|
||||
* @return same {@link Builder}.
|
||||
*/
|
||||
public R setFogDensity(float fogDensity) {
|
||||
storage.fogDensity = fogDensity;
|
||||
return (R) this;
|
||||
}
|
||||
}
|
||||
|
||||
protected BCLBiomeSettings() {
|
||||
this.terrainHeight = 0.1F;
|
||||
this.fogDensity = 1.0F;
|
||||
this.genChance = 1.0F;
|
||||
this.edgeSize = 0;
|
||||
this.vertical = false;
|
||||
this.edge = null;
|
||||
}
|
||||
|
||||
float terrainHeight;
|
||||
float fogDensity;
|
||||
float genChance;
|
||||
int edgeSize;
|
||||
boolean vertical;
|
||||
BCLBiome edge;
|
||||
|
||||
|
||||
/**
|
||||
* Getter for biome generation chance, used in {@link BiomePicker} and in custom generators.
|
||||
*
|
||||
* @return biome generation chance as float.
|
||||
*/
|
||||
public float getGenChance() {
|
||||
return this.genChance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if biome is vertical, for tall Nether only (or for custom generators).
|
||||
*
|
||||
* @return is biome vertical or not.
|
||||
*/
|
||||
public boolean isVertical() {
|
||||
return vertical;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for terrain height, can be used in custom terrain generator.
|
||||
*
|
||||
* @return terrain height.
|
||||
*/
|
||||
public float getTerrainHeight() {
|
||||
return terrainHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for fog density, used in custom for renderer.
|
||||
*
|
||||
* @return fog density as a float.
|
||||
*/
|
||||
public float getFogDensity() {
|
||||
return fogDensity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for biome edge size.
|
||||
*
|
||||
* @return edge size in blocks.
|
||||
*/
|
||||
public int getEdgeSize() {
|
||||
return edgeSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for edge-biome.
|
||||
*
|
||||
* @return The assigned edge biome.
|
||||
*/
|
||||
public BCLBiome getEdge() {
|
||||
return 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.setEdge(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();
|
||||
}
|
||||
}
|
|
@ -52,9 +52,6 @@ import org.betterx.bclib.interfaces.SurfaceRuleProvider;
|
|||
import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
||||
import org.betterx.bclib.mixin.common.MobSpawnSettingsAccessor;
|
||||
import org.betterx.bclib.util.CollectionsUtil;
|
||||
import org.betterx.bclib.world.biomes.BCLBiome;
|
||||
import org.betterx.bclib.world.biomes.FabricBiomesData;
|
||||
import org.betterx.bclib.world.biomes.VanillaBiomeSettings;
|
||||
import org.betterx.bclib.world.features.BCLFeature;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -249,7 +246,7 @@ public class BiomeAPI {
|
|||
public static BCLBiome registerNetherBiome(BCLBiome bclBiome) {
|
||||
registerBiome(bclBiome, BiomeType.BCL_NETHER);
|
||||
|
||||
ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(bclBiome.getBiomeHolder());
|
||||
ResourceKey<Biome> key = BiomeAPI.getBiomeKey(bclBiome.getBiome());
|
||||
if (bclBiome.allowFabricRegistration()) {
|
||||
bclBiome.forEachClimateParameter(p -> NetherBiomeData.addNetherBiome(key, p));
|
||||
}
|
||||
|
@ -329,7 +326,7 @@ public class BiomeAPI {
|
|||
registerBiome(biome, BiomeType.END_VOID);
|
||||
|
||||
float weight = biome.getGenChance();
|
||||
ResourceKey<Biome> key = BiomeAPI.getBiomeKeyOrThrow(biome.getBiomeHolder());
|
||||
ResourceKey<Biome> key = BiomeAPI.getBiomeKey(biome.getBiome());
|
||||
if (biome.allowFabricRegistration()) {
|
||||
TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight);
|
||||
}
|
||||
|
@ -407,9 +404,13 @@ public class BiomeAPI {
|
|||
*/
|
||||
@Nullable
|
||||
public static ResourceKey getBiomeKey(Biome biome) {
|
||||
if (biomeRegistry != null) {
|
||||
Optional<ResourceKey<Biome>> key = biomeRegistry.getResourceKey(biome);
|
||||
if (key.isPresent()) return key.get();
|
||||
}
|
||||
return BuiltinRegistries.BIOME
|
||||
.getResourceKey(biome)
|
||||
.orElseGet(() -> biomeRegistry != null ? biomeRegistry.getResourceKey(biome).orElse(null) : null);
|
||||
.orElseGet(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -448,6 +449,26 @@ public class BiomeAPI {
|
|||
return biome.unwrapKey().orElseThrow();
|
||||
}
|
||||
|
||||
public static Holder<Biome> getBiomeHolder(BCLBiome biome) {
|
||||
return getBiomeHolder(biome.getBiome());
|
||||
}
|
||||
|
||||
public static Holder<Biome> getBiomeHolder(Biome biome) {
|
||||
if (biomeRegistry != null) {
|
||||
Optional<ResourceKey<Biome>> key = biomeRegistry.getResourceKey(biome);
|
||||
if (key.isPresent()) return biomeRegistry.getOrCreateHolderOrThrow(key.get());
|
||||
}
|
||||
|
||||
return BuiltinRegistries.BIOME.getOrCreateHolderOrThrow(BiomeAPI.getBiomeKey(biome));
|
||||
}
|
||||
|
||||
public static Holder<Biome> getBiomeHolder(ResourceLocation biome) {
|
||||
if (biomeRegistry != null) {
|
||||
return getBiomeHolder(biomeRegistry.get(biome));
|
||||
}
|
||||
return getBiomeHolder(BuiltinRegistries.BIOME.get(biome));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link BCLBiome} from given {@link ResourceLocation}.
|
||||
*
|
||||
|
@ -607,8 +628,7 @@ public class BiomeAPI {
|
|||
.map(e -> e.getKey());
|
||||
if (s != null) {
|
||||
s.forEach(id -> {
|
||||
BCLBiome b = BiomeAPI.getBiome(id);
|
||||
Holder<Biome> biomeHolder = b.getBiomeHolder();
|
||||
Holder<Biome> biomeHolder = BiomeAPI.getBiomeHolder(id);
|
||||
if (biomeHolder.isBound()) {
|
||||
mod.getValue().forEach(c -> c.accept(id, biomeHolder));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.betterx.bclib.api.biomes;
|
||||
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class FabricBiomesData {
|
||||
public static final Map<ResourceKey<Biome>, Float> END_LAND_BIOMES = Maps.newHashMap();
|
||||
public static final Map<ResourceKey<Biome>, Float> END_VOID_BIOMES = Maps.newHashMap();
|
||||
public static final Set<ResourceKey<Biome>> NETHER_BIOMES = Sets.newHashSet();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package org.betterx.bclib.api.biomes;
|
||||
|
||||
|
||||
public class VanillaBiomeSettings extends BCLBiomeSettings {
|
||||
public static class Builder extends BCLBiomeSettings.CommonBuilder<VanillaBiomeSettings, VanillaBiomeSettings.Builder> {
|
||||
public Builder() {
|
||||
super(new VanillaBiomeSettings());
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder createVanilla() {
|
||||
return new Builder();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue