Moved Biome classes

This commit is contained in:
Frank 2022-05-27 16:34:32 +02:00
parent 51ec0596da
commit f70db44ffd
10 changed files with 41 additions and 23 deletions

View file

@ -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.
*

View file

@ -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;

View file

@ -1,4 +1,4 @@
package org.betterx.bclib.world.biomes;
package org.betterx.bclib.api.biomes;
import net.minecraft.world.level.biome.Biome;

View file

@ -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));
}

View file

@ -1,4 +1,4 @@
package org.betterx.bclib.world.biomes;
package org.betterx.bclib.api.biomes;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;

View file

@ -1,4 +1,4 @@
package org.betterx.bclib.world.biomes;
package org.betterx.bclib.api.biomes;
public class VanillaBiomeSettings extends BCLBiomeSettings {

View file

@ -12,11 +12,11 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.material.FogType;
import com.mojang.blaze3d.systems.RenderSystem;
import org.betterx.bclib.api.biomes.BCLBiome;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.util.BackgroundInfo;
import org.betterx.bclib.util.MHelper;
import org.betterx.bclib.world.biomes.BCLBiome;
public class CustomFogRenderer {
private static final MutableBlockPos LAST_POS = new MutableBlockPos(0, -100, 0);

View file

@ -19,13 +19,13 @@ import net.fabricmc.fabric.impl.biome.TheEndBiomeData;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.biomes.BCLBiome;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.interfaces.BiomeMap;
import org.betterx.bclib.interfaces.TheEndBiomeDataAccessor;
import org.betterx.bclib.noise.OpenSimplexNoise;
import org.betterx.bclib.world.biomes.BCLBiome;
import org.betterx.bclib.world.generator.map.hex.HexBiomeMap;
import org.betterx.bclib.world.generator.map.square.SquareBiomeMap;

View file

@ -15,11 +15,11 @@ import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import org.apache.commons.lang3.function.TriFunction;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.biomes.BCLBiome;
import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.config.ConfigKeeper.StringArrayEntry;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.interfaces.BiomeMap;
import org.betterx.bclib.world.biomes.BCLBiome;
import org.betterx.bclib.world.generator.map.MapStack;
import org.betterx.bclib.world.generator.map.hex.HexBiomeMap;
import org.betterx.bclib.world.generator.map.square.SquareBiomeMap;

View file

@ -7,9 +7,9 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import com.google.common.collect.Lists;
import org.betterx.bclib.api.biomes.BCLBiome;
import org.betterx.bclib.util.WeighTree;
import org.betterx.bclib.util.WeightedList;
import org.betterx.bclib.world.biomes.BCLBiome;
import java.util.HashMap;
import java.util.List;