Changes related to Biome-Holders and Features
This commit is contained in:
parent
86a3480ce0
commit
ff70a2b1a8
30 changed files with 200 additions and 222 deletions
|
@ -2,6 +2,7 @@ package ru.bclib.world.biomes;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
@ -31,9 +32,9 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
private final ResourceLocation biomeID;
|
||||
private final Biome biome;
|
||||
|
||||
private Consumer<Biome> surfaceInit;
|
||||
private Consumer<Holder<Biome>> surfaceInit;
|
||||
private BCLBiome biomeParent;
|
||||
private Biome actualBiome;
|
||||
private Holder<Biome> actualBiome;
|
||||
|
||||
/**
|
||||
* Create wrapper for existing biome using its {@link ResourceLocation} identifier.
|
||||
|
@ -65,7 +66,7 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
* @param settings The Settings for this Biome or {@code null} if you want to apply default settings
|
||||
*/
|
||||
public BCLBiome(Biome biome, VanillaBiomeSettings settings) {
|
||||
this(BuiltinRegistries.BIOME.getKey(biome), biome, settings);
|
||||
this(BiomeAPI.getBiomeID(biome), biome, settings);
|
||||
}
|
||||
|
||||
public BCLBiome(ResourceLocation biomeID, Biome biome) {
|
||||
|
@ -164,7 +165,10 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
return biomeID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Holder<Biome> getBiomeHolder() {
|
||||
return BuiltinRegistries.BIOME.getOrCreateHolder(BiomeAPI.getBiomeKey(biome));
|
||||
}
|
||||
/**
|
||||
* Getter for biome from buil-in registry. For datapack biomes will be same as actual biome.
|
||||
* @return {@link Biome}.
|
||||
|
@ -177,7 +181,7 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
* Getter for actual biome (biome from current world registry with same {@link ResourceLocation} id).
|
||||
* @return {@link Biome}.
|
||||
*/
|
||||
public Biome getActualBiome() {
|
||||
public Holder<Biome> getActualBiome() {
|
||||
return this.actualBiome;
|
||||
}
|
||||
|
||||
|
@ -196,7 +200,7 @@ public class BCLBiome extends BCLBiomeSettings {
|
|||
if (edge != null && edge != this) {
|
||||
edge.updateActualBiomes(biomeRegistry);
|
||||
}
|
||||
this.actualBiome = biomeRegistry.get(biomeID);
|
||||
this.actualBiome = biomeRegistry.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID)).orElse(null);
|
||||
if (actualBiome==null) {
|
||||
BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID);
|
||||
}
|
||||
|
|
|
@ -5,32 +5,25 @@ import net.minecraft.core.Registry;
|
|||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.VerticalAnchor;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.placement.HeightRangePlacement;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
|
||||
import ru.bclib.api.features.BCLCommonFeatures;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BCLFeature {
|
||||
private PlacedFeature placedFeature;
|
||||
private Holder<PlacedFeature> placedFeature;
|
||||
private Decoration featureStep;
|
||||
private Feature<?> feature;
|
||||
|
||||
public BCLFeature(ResourceLocation id, Feature<?> feature, Decoration featureStep, PlacedFeature placedFeature) {
|
||||
public BCLFeature(ResourceLocation id, Feature<?> feature, Decoration featureStep, Holder<PlacedFeature> placedFeature) {
|
||||
this.placedFeature = placedFeature;
|
||||
this.featureStep = featureStep;
|
||||
this.feature = feature;
|
||||
|
||||
if (!BuiltinRegistries.PLACED_FEATURE.containsKey(id)) {
|
||||
Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature);
|
||||
Registry.register(BuiltinRegistries.PLACED_FEATURE, id, placedFeature.value());
|
||||
}
|
||||
if (!Registry.FEATURE.containsKey(id) && !containsObj(Registry.FEATURE, feature)) {
|
||||
Registry.register(Registry.FEATURE, id, feature);
|
||||
|
@ -58,7 +51,7 @@ public class BCLFeature {
|
|||
* Get configured feature.
|
||||
* @return {@link PlacedFeature}.
|
||||
*/
|
||||
public PlacedFeature getPlacedFeature() {
|
||||
public Holder<PlacedFeature> getPlacedFeature() {
|
||||
return placedFeature;
|
||||
}
|
||||
|
||||
|
@ -69,92 +62,4 @@ public class BCLFeature {
|
|||
public Decoration getDecoration() {
|
||||
return featureStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use function from {@link BCLCommonFeatures} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density) {
|
||||
return BCLCommonFeatures.makeVegetationFeature(id, feature, density);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use function from {@link BCLCommonFeatures} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density, boolean allHeight) {
|
||||
return BCLCommonFeatures.makeVegetationFeature(id, feature, density, allHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, moved to {@link BCLCommonFeatures}. Will be completely removed.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, float airDiscardChance, VerticalAnchor minY, VerticalAnchor maxY, boolean rare) {
|
||||
return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, airDiscardChance, HeightRangePlacement.uniform(minY, maxY), rare);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, moved to {@link BCLCommonFeatures}. Will be completely removed.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, VerticalAnchor minY, VerticalAnchor maxY, boolean rare) {
|
||||
return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, 0.0f, HeightRangePlacement.uniform(minY, maxY), rare);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use function from {@link BCLCommonFeatures} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, float airDiscardChance, PlacementModifier placement, boolean rare) {
|
||||
return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, airDiscardChance, placement, rare);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use function from {@link BCLCommonFeatures} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, Block hostBlock, int veins, int veinSize, PlacementModifier placement, boolean rare) {
|
||||
return BCLCommonFeatures.makeOreFeature(id, blockOre, hostBlock, veins, veinSize, 0.0f, placement, rare);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use function from {@link BCLCommonFeatures} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeChunkFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature) {
|
||||
return BCLCommonFeatures.makeChunkFeature(id, step, feature);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use function from {@link BCLCommonFeatures} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeChancedFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature, int chance) {
|
||||
return BCLCommonFeatures.makeChancedFeature(id, step, feature, chance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use function from {@link BCLCommonFeatures} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeCountFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature, int count) {
|
||||
return BCLCommonFeatures.makeCountFeature(id, step, feature, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated, use {@link ru.bclib.api.features.BCLFeatureBuilder} instead.
|
||||
*
|
||||
* Creates and configures new BCLib feature.
|
||||
* @param id {@link ResourceLocation} feature ID.
|
||||
* @param step {@link Decoration} feature step.
|
||||
* @param feature {@link Feature} with {@link NoneFeatureConfiguration} config.
|
||||
* @param placementModifiers array of {@link PlacementModifier}
|
||||
* @return new BCLFeature instance.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public static BCLFeature makeFeature(ResourceLocation id, Decoration step, Feature<NoneFeatureConfiguration> feature, PlacementModifier... placementModifiers) {
|
||||
PlacedFeature configured = feature.configured(FeatureConfiguration.NONE).placed(placementModifiers);
|
||||
return new BCLFeature(id, feature, step, configured);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package ru.bclib.world.features;
|
|||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtIo;
|
||||
|
@ -50,7 +51,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
protected abstract void addStructureData(StructurePlaceSettings data);
|
||||
|
||||
protected BlockPos getGround(WorldGenLevel world, BlockPos center) {
|
||||
Biome biome = world.getBiome(center);
|
||||
Holder<Biome> biome = world.getBiome(center);
|
||||
ResourceLocation id = BiomeAPI.getBiomeID(biome);
|
||||
if (id.getNamespace().contains("moutain") || id.getNamespace().contains("lake")) {
|
||||
int y = getAverageY(world, center);
|
||||
|
@ -148,7 +149,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
if (!isTerrain(stateSt)) {
|
||||
if (merge == TerrainMerge.SURFACE) {
|
||||
boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking();
|
||||
Biome b = world.getBiome(mut);
|
||||
Holder<Biome> b = world.getBiome(mut);
|
||||
BlockState top = (isTop ? BiomeAPI.findTopMaterial(b) : BiomeAPI.findUnderMaterial(b)).orElse(defaultBlock);
|
||||
BlocksHelper.setWithoutUpdate(world, mut, top);
|
||||
}
|
||||
|
@ -159,7 +160,7 @@ public abstract class NBTStructureFeature extends DefaultFeature {
|
|||
else {
|
||||
if (isTerrain(state) && state.getMaterial().isSolidBlocking()) {
|
||||
if (merge == TerrainMerge.SURFACE) {
|
||||
Biome b = world.getBiome(mut);
|
||||
Holder<Biome> b = world.getBiome(mut);
|
||||
BlockState bottom = BiomeAPI.findUnderMaterial(b).orElse(defaultBlock);
|
||||
BlocksHelper.setWithoutUpdate(world, mut, bottom);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ru.bclib.world.generator;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
|
@ -8,15 +9,15 @@ import ru.bclib.api.biomes.BiomeAPI;
|
|||
import java.util.List;
|
||||
|
||||
public abstract class BCLBiomeSource extends BiomeSource {
|
||||
protected final Registry<Biome> biomeRegistry;
|
||||
protected final Registry<Holder<Biome>> biomeRegistry;
|
||||
protected final long seed;
|
||||
|
||||
private static List<Biome> preInit(Registry<Biome> biomeRegistry, List<Biome> biomes){
|
||||
private static List<Holder<Biome>> preInit(Registry<Holder<Biome>> biomeRegistry, List<Holder<Biome>> biomes){
|
||||
biomes.forEach(biome -> BiomeAPI.sortBiomeFeatures(biome));
|
||||
return biomes;
|
||||
}
|
||||
|
||||
protected BCLBiomeSource(Registry<Biome> biomeRegistry, long seed, List<Biome> list) {
|
||||
protected BCLBiomeSource(Registry<Holder<Biome>> biomeRegistry, long seed, List<Holder<Biome>> list) {
|
||||
super(preInit(biomeRegistry, list));
|
||||
|
||||
this.seed = seed;
|
||||
|
|
|
@ -2,6 +2,7 @@ package ru.bclib.world.generator;
|
|||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -19,6 +20,7 @@ import ru.bclib.api.biomes.BiomeAPI;
|
|||
import ru.bclib.config.ConfigKeeper.StringArrayEntry;
|
||||
import ru.bclib.config.Configs;
|
||||
import ru.bclib.interfaces.BiomeMap;
|
||||
import ru.bclib.mixin.common.BiomeAccessor;
|
||||
import ru.bclib.noise.OpenSimplexNoise;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
import ru.bclib.world.generator.map.hex.HexBiomeMap;
|
||||
|
@ -29,14 +31,14 @@ import java.util.List;
|
|||
import java.util.function.Function;
|
||||
|
||||
public class BCLibEndBiomeSource extends BCLBiomeSource {
|
||||
public static final Codec<BCLibEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps
|
||||
public static Codec<BCLibEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps
|
||||
.retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> theEndBiomeSource.biomeRegistry), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new)));
|
||||
private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324);
|
||||
private Function<Point, Boolean> endLandFunction;
|
||||
|
||||
private final SimplexNoise noise;
|
||||
private final Biome centerBiome;
|
||||
private final Biome barrens;
|
||||
private final Holder<Biome> centerBiome;
|
||||
private final Holder<Biome> barrens;
|
||||
private BiomeMap mapLand;
|
||||
private BiomeMap mapVoid;
|
||||
private final Point pos;
|
||||
|
@ -49,7 +51,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
|
||||
List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue();
|
||||
this.possibleBiomes().forEach(biome -> {
|
||||
ResourceLocation key = biomeRegistry.getKey(biome);
|
||||
ResourceLocation key = biomeRegistry.getKey(biome.value());
|
||||
String group = key.getNamespace() + "." + key.getPath();
|
||||
|
||||
if (!BiomeAPI.hasBiome(key)) {
|
||||
|
@ -94,8 +96,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER);
|
||||
}
|
||||
|
||||
this.centerBiome = biomeRegistry.getOrThrow(Biomes.THE_END);
|
||||
this.barrens = biomeRegistry.getOrThrow(Biomes.END_BARRENS);
|
||||
this.centerBiome = biomeRegistry.getHolderOrThrow(Biomes.THE_END);
|
||||
this.barrens = biomeRegistry.getHolderOrThrow(Biomes.END_BARRENS);
|
||||
|
||||
WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed));
|
||||
chunkRandom.consumeCount(17292);
|
||||
|
@ -115,9 +117,15 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (GeneratorOptions.addEndBiomesByCategory() && biome.getBiomeCategory() == BiomeCategory.THEEND) {
|
||||
return true;
|
||||
|
||||
final boolean isEndBiome;
|
||||
if ((Object)biome instanceof BiomeAccessor bacc) {
|
||||
isEndBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.THEEND;
|
||||
if (GeneratorOptions.addEndBiomesByCategory() && isEndBiome) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
isEndBiome = false;
|
||||
}
|
||||
|
||||
BCLBiome bclBiome = BiomeAPI.getBiome(key);
|
||||
|
@ -127,12 +135,12 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
|
|||
}
|
||||
key = bclBiome.getID();
|
||||
}
|
||||
return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (biome.getBiomeCategory() == BiomeCategory.THEEND && BiomeAPI.isDatapackBiome(key));
|
||||
return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (isEndBiome && BiomeAPI.isDatapackBiome(key));
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) {
|
||||
public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler sampler) {
|
||||
long posX = biomeX << 2;
|
||||
long posZ = biomeZ << 2;
|
||||
long farEndBiomes = GeneratorOptions.getFarEndBiomes();
|
||||
|
|
|
@ -71,7 +71,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
|
|||
BiomeAPI.NETHER_BIOME_PICKER.clearMutables();
|
||||
|
||||
this.possibleBiomes().forEach(biome -> {
|
||||
ResourceLocation key = biomeRegistry.getKey(biome);
|
||||
ResourceLocation key = biomeRegistry.getKey(biome.value());
|
||||
|
||||
if (!BiomeAPI.hasBiome(key)) {
|
||||
BCLBiome bclBiome = new BCLBiome(key, biome);
|
||||
|
|
|
@ -94,7 +94,7 @@ public class BCLStructureFeature {
|
|||
return structure;
|
||||
}
|
||||
|
||||
public ConfiguredStructureFeature<?, ?> getFeatureConfigured() {
|
||||
public Holder<ConfiguredStructureFeature<?, ?>> getFeatureConfigured() {
|
||||
return featureConfigured;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue