More biome API changes

This commit is contained in:
paulevsGitch 2021-12-01 12:31:25 +03:00
parent 548cedcffe
commit e1e09c4efa
8 changed files with 121 additions and 90 deletions

View file

@ -1,26 +1,13 @@
package ru.bclib.world.biomes;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import org.jetbrains.annotations.Nullable;
import ru.bclib.config.Configs;
import ru.bclib.util.JsonFactory;
import ru.bclib.util.StructureHelper;
import ru.bclib.util.WeightedList;
import ru.bclib.world.features.BCLFeature;
import ru.bclib.world.features.ListFeature;
import ru.bclib.world.features.ListFeature.StructureInfo;
import ru.bclib.world.features.NBTStructureFeature.TerrainMerge;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Random;
@ -39,6 +26,22 @@ public class BCLBiome {
private float genChance = 1.0F;
private float edgeSize = 0.0F;
/**
* Create wrapper for existing biome using its {@link ResourceLocation} identifier.
* @param biomeID {@link ResourceLocation} biome ID.
*/
public BCLBiome(ResourceLocation biomeID) {
this(biomeID, BuiltinRegistries.BIOME.get(biomeID));
}
/**
* Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}.
* @param biome {@link Biome} to wrap.
*/
public BCLBiome(Biome biome) {
this(BuiltinRegistries.BIOME.getKey(biome), biome);
}
public BCLBiome(ResourceLocation biomeID, Biome biome) {
this.biomeID = biomeID;
this.biome = biome;
@ -56,10 +59,12 @@ public class BCLBiome {
/**
* Set biome edge for this biome instance.
* @param edge {@link BCLBiome} as the edge biome.
* @return same {@link BCLBiome}.
*/
public void setEdge(BCLBiome edge) {
public BCLBiome setEdge(BCLBiome edge) {
this.edge = edge;
edge.biomeParent = this;
return this;
}
/**
@ -73,19 +78,23 @@ public class BCLBiome {
/**
* Set edges size for this biome. Size is in relative units to work fine with biome scale.
* @param size as a float value.
* @return same {@link BCLBiome}.
*/
public void setEdgeSize(float size) {
public BCLBiome setEdgeSize(float size) {
edgeSize = size;
return this;
}
/**
* Adds sub-biome into this biome instance. Biome chance will be interpreted as a sub-biome generation chance.
* Biome itself has chance 1.0 compared to all its sub-biomes.
* @param biome {@link Random} to be added.
* @return same {@link BCLBiome}.
*/
public void addSubBiome(BCLBiome biome) {
public BCLBiome addSubBiome(BCLBiome biome) {
biome.biomeParent = this;
subbiomes.add(biome, biome.getGenChance());
return this;
}
/**
@ -115,32 +124,13 @@ public class BCLBiome {
return this.biomeParent;
}
/**
* Checks if this biome has edge biome.
* @return true if it has edge.
*/
@Deprecated(forRemoval = true)
public boolean hasEdge() {
return edge != null;
}
/**
* Checks if this biome has parent biome.
* @return true if it has parent.
*/
@Deprecated(forRemoval = true)
public boolean hasParentBiome() {
return biomeParent != null;
}
/**
* Compares biome instances (directly) and their parents. Used in custom world generator.
* @param biome {@link BCLBiome}
* @return true if biome or its parent is same.
*/
@Deprecated(forRemoval = true)
public boolean isSame(BCLBiome biome) {
return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this);
return biome == this || (biome.biomeParent != null && biome.biomeParent == this);
}
/**
@ -183,6 +173,16 @@ public class BCLBiome {
return this.genChance;
}
/**
* Set gen chance for this biome, default value is 1.0.
* @param genChance chance of this biome to be generated.
* @return same {@link BCLBiome}.
*/
public BCLBiome setGenChance(float genChance) {
this.genChance = genChance;
return this;
}
/**
* Recursively update biomes to correct world biome registry instances, for internal usage only.
* @param biomeRegistry {@link Registry} for {@link Biome}.
@ -225,17 +225,21 @@ public class BCLBiome {
* Adds custom data object to this biome instance.
* @param name {@link String} name of data object.
* @param obj any data to add.
* @return same {@link BCLBiome}.
*/
public void addCustomData(String name, Object obj) {
public BCLBiome addCustomData(String name, Object obj) {
customData.put(name, obj);
return this;
}
/**
* Adds custom data object to this biome instance.
* @param data a {@link Map} with custom data.
* @return same {@link BCLBiome}.
*/
public void addCustomData(Map<String, Object> data) {
public BCLBiome addCustomData(Map<String, Object> data) {
customData.putAll(data);
return this;
}
/**

View file

@ -1,13 +1,23 @@
package ru.bclib.world.biomes;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.biome.Biome.BiomeBuilder;
import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.biome.Biome.Precipitation;
import net.minecraft.world.level.biome.BiomeSpecialEffects;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
import java.util.ArrayList;
import java.util.List;
public class BCLBiomeBuilder {
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
private List<SpawnerData> mobs = new ArrayList<>(32);
private BiomeSpecialEffects.Builder effectsBuilder;
private Precipitation precipitation;
private ResourceLocation biomeID;
private BiomeCategory category;
@ -23,7 +33,9 @@ public class BCLBiomeBuilder {
INSTANCE.biomeID = biomeID;
INSTANCE.precipitation = Precipitation.NONE;
INSTANCE.category = BiomeCategory.NONE;
INSTANCE.effectsBuilder = null;
INSTANCE.temperature = 1.0F;
INSTANCE.mobs.clear();
return INSTANCE;
}
@ -67,17 +79,46 @@ public class BCLBiomeBuilder {
return this;
}
/**
* Adds mob spawning to biome.
* @param entityType {@link EntityType} mob type.
* @param weight spawn weight.
* @param minGroupCount minimum mobs in group.
* @param maxGroupCount maximum mobs in group.
* @return
*/
public <M extends Mob> BCLBiomeBuilder spawn(EntityType<M> entityType, int weight, int minGroupCount, int maxGroupCount) {
mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount));
return this;
}
public BCLBiome build() {
Biome biome = new Biome.BiomeBuilder()
BiomeBuilder builder = new BiomeBuilder()
.precipitation(precipitation)
.biomeCategory(category)
.temperature(temperature)
.downfall(downfall)
.downfall(downfall);
/*
.specialEffects(effects.build())
.mobSpawnSettings(spawnSettings.build())
.generationSettings(generationSettings.build())*/
.build();
return new BCLBiome(biomeID, biome);
//.build();
if (!mobs.isEmpty()) {
MobSpawnSettings.Builder spawnSettings = new MobSpawnSettings.Builder();
mobs.forEach(spawn -> spawnSettings.addSpawn(spawn.type.getCategory(), spawn));
builder.mobSpawnSettings(spawnSettings.build());
}
if (effectsBuilder != null) {
builder.specialEffects(effectsBuilder.build());
}
return new BCLBiome(biomeID, builder.build());
}
private BiomeSpecialEffects.Builder getEffects() {
if (effectsBuilder == null) {
effectsBuilder = new BiomeSpecialEffects.Builder();
}
return effectsBuilder;
}
}