Moved biome API to all other APIs

This commit is contained in:
paulevsGitch 2021-12-01 12:35:39 +03:00
parent e1e09c4efa
commit 6895d705f8
11 changed files with 502 additions and 500 deletions

View file

@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.blocks.BaseBarrelBlock; import ru.bclib.blocks.BaseBarrelBlock;
import ru.bclib.blocks.BaseChestBlock; import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.blocks.BaseFurnaceBlock; import ru.bclib.blocks.BaseFurnaceBlock;

View file

@ -1,4 +1,4 @@
package ru.bclib.world.biomes; package ru.bclib.api.biomes;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
@ -9,6 +9,7 @@ import net.minecraft.world.level.biome.Biome.Precipitation;
import net.minecraft.world.level.biome.BiomeSpecialEffects; import net.minecraft.world.level.biome.BiomeSpecialEffects;
import net.minecraft.world.level.biome.MobSpawnSettings; import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
import ru.bclib.world.biomes.BCLBiome;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View file

@ -1,491 +1,491 @@
package ru.bclib.api; package ru.bclib.api.biomes;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications; import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.impl.biome.NetherBiomeData; import net.fabricmc.fabric.impl.biome.NetherBiomeData;
import net.fabricmc.fabric.impl.biome.TheEndBiomeData; import net.fabricmc.fabric.impl.biome.TheEndBiomeData;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries; import net.minecraft.data.BuiltinRegistries;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.Mob;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Biomes; import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.Climate;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.biomes.FabricBiomesData; import ru.bclib.world.biomes.FabricBiomesData;
import ru.bclib.world.features.BCLFeature; import ru.bclib.world.features.BCLFeature;
import ru.bclib.world.generator.BiomePicker; import ru.bclib.world.generator.BiomePicker;
import ru.bclib.world.structures.BCLStructureFeature; import ru.bclib.world.structures.BCLStructureFeature;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
public class BiomeAPI { public class BiomeAPI {
/** /**
* Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs. * Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs.
* Have {@code Biomes.THE_VOID} as the reference biome. * Have {@code Biomes.THE_VOID} as the reference biome.
*/ */
public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location()); public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location());
public static final BiomePicker NETHER_BIOME_PICKER = new BiomePicker(); public static final BiomePicker NETHER_BIOME_PICKER = new BiomePicker();
public static final BiomePicker END_LAND_BIOME_PICKER = new BiomePicker(); public static final BiomePicker END_LAND_BIOME_PICKER = new BiomePicker();
public static final BiomePicker END_VOID_BIOME_PICKER = new BiomePicker(); public static final BiomePicker END_VOID_BIOME_PICKER = new BiomePicker();
private static final Map<ResourceLocation, BCLBiome> ID_MAP = Maps.newHashMap(); private static final Map<ResourceLocation, BCLBiome> ID_MAP = Maps.newHashMap();
private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap(); private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap();
private static Registry<Biome> biomeRegistry; private static Registry<Biome> biomeRegistry;
private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Biome>>> MODIFICATIONS = Maps.newHashMap(); private static final Map<ResourceKey, List<BiConsumer<ResourceLocation, Biome>>> MODIFICATIONS = Maps.newHashMap();
private static final Set<ResourceLocation> MODIFIED_BIOMES = Sets.newHashSet(); private static final Set<ResourceLocation> MODIFIED_BIOMES = Sets.newHashSet();
public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES)); public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(Biomes.NETHER_WASTES));
public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST)); public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.CRIMSON_FOREST));
public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.WARPED_FOREST)); public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(Biomes.WARPED_FOREST));
public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY)); public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(Biomes.SOUL_SAND_VALLEY));
public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS)); public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS));
public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END)); public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(Biomes.THE_END));
public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS), 0.5F); public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS), 0.5F);
public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS), 0.5F); public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS), 0.5F);
public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens"))); public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")));
public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands"))); public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")));
/** /**
* Initialize registry for current server. * Initialize registry for current server.
* *
* @param server - {@link MinecraftServer} * @param server - {@link MinecraftServer}
*/ */
public static void initRegistry(MinecraftServer server) { public static void initRegistry(MinecraftServer server) {
biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY); biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
CLIENT.clear(); CLIENT.clear();
} }
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* @param biome {@link BCLBiome} * @param biome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerBiome(BCLBiome biome) { public static BCLBiome registerBiome(BCLBiome biome) {
if (BuiltinRegistries.BIOME.get(biome.getID()) == null) { if (BuiltinRegistries.BIOME.get(biome.getID()) == null) {
Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome()); Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome());
} }
ID_MAP.put(biome.getID(), biome); ID_MAP.put(biome.getID(), biome);
return biome; return biome;
} }
public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) { public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) {
registerBiome(subBiome); registerBiome(subBiome);
parent.addSubBiome(subBiome); parent.addSubBiome(subBiome);
return subBiome; return subBiome;
} }
public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) { public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) {
BCLBiome subBiome = new BCLBiome(biome).setGenChance(genChance); BCLBiome subBiome = new BCLBiome(biome).setGenChance(genChance);
return registerSubBiome(parent, subBiome); return registerSubBiome(parent, subBiome);
} }
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* After that biome will be added to BCLib Nether Biome Generator and into Fabric Biome API. * After that biome will be added to BCLib Nether Biome Generator and into Fabric Biome API.
* @param biome {@link BCLBiome} * @param biome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerNetherBiome(BCLBiome biome) { public static BCLBiome registerNetherBiome(BCLBiome biome) {
registerBiome(biome); registerBiome(biome);
NETHER_BIOME_PICKER.addBiome(biome); NETHER_BIOME_PICKER.addBiome(biome);
Random random = new Random(biome.getID().hashCode()); Random random = new Random(biome.getID().hashCode());
//TODO: 1.18 Check parameters, depth was previously called altitude //TODO: 1.18 Check parameters, depth was previously called altitude
//temperature, humidity, continentalness, erosion, depth, weirdness, offset //temperature, humidity, continentalness, erosion, depth, weirdness, offset
Climate.ParameterPoint parameters = Climate.parameters( Climate.ParameterPoint parameters = Climate.parameters(
MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random),
MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random),
MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18 MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18
MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18 MHelper.randRange(-1.5F, 1.5F, random), //new in 1.18
MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random),
MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random),
random.nextFloat() random.nextFloat()
); );
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
NetherBiomeData.addNetherBiome(key, parameters); NetherBiomeData.addNetherBiome(key, parameters);
return biome; return biome;
} }
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* After that biome will be added to BCLib Nether Biome Generator and into Fabric Biome API. * After that biome will be added to BCLib Nether Biome Generator and into Fabric Biome API.
* @param biome {@link BCLBiome} * @param biome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerNetherBiome(Biome biome) { public static BCLBiome registerNetherBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome); BCLBiome bclBiome = new BCLBiome(biome);
NETHER_BIOME_PICKER.addBiome(bclBiome); NETHER_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
} }
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands).
* @param biome {@link BCLBiome} * @param biome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndLandBiome(BCLBiome biome) { public static BCLBiome registerEndLandBiome(BCLBiome biome) {
registerBiome(biome); registerBiome(biome);
END_LAND_BIOME_PICKER.addBiome(biome); END_LAND_BIOME_PICKER.addBiome(biome);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight); TheEndBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight);
TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight); TheEndBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight);
return biome; return biome;
} }
/** /**
* Register {@link BCLBiome} wrapper for {@link Biome}. * Register {@link BCLBiome} wrapper for {@link Biome}.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands).
* @param biome {@link BCLBiome} * @param biome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndLandBiome(Biome biome) { public static BCLBiome registerEndLandBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome); BCLBiome bclBiome = new BCLBiome(biome);
END_LAND_BIOME_PICKER.addBiome(bclBiome); END_LAND_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
} }
/** /**
* Register {@link BCLBiome} wrapper for {@link Biome}. * Register {@link BCLBiome} wrapper for {@link Biome}.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands).
* @param biome {@link BCLBiome}; * @param biome {@link BCLBiome};
* @param genChance float generation chance. * @param genChance float generation chance.
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndLandBiome(Biome biome, float genChance) { public static BCLBiome registerEndLandBiome(Biome biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance);
END_LAND_BIOME_PICKER.addBiome(bclBiome); END_LAND_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
} }
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands).
* @param biome {@link BCLBiome} * @param biome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndVoidBiome(BCLBiome biome) { public static BCLBiome registerEndVoidBiome(BCLBiome biome) {
registerBiome(biome); registerBiome(biome);
END_VOID_BIOME_PICKER.addBiome(biome); END_VOID_BIOME_PICKER.addBiome(biome);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get(); ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight); TheEndBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight);
return biome; return biome;
} }
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands).
* @param biome {@link BCLBiome} * @param biome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndVoidBiome(Biome biome) { public static BCLBiome registerEndVoidBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome); BCLBiome bclBiome = new BCLBiome(biome);
END_VOID_BIOME_PICKER.addBiome(bclBiome); END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
} }
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a void biome (will generate only in the End void - between islands).
* @param biome {@link BCLBiome}. * @param biome {@link BCLBiome}.
* @param genChance float generation chance. * @param genChance float generation chance.
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) {
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance);
END_VOID_BIOME_PICKER.addBiome(bclBiome); END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
} }
/** /**
* Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes. * Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes.
* @param biome - {@link Biome} from world. * @param biome - {@link Biome} from world.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/ */
public static BCLBiome getFromBiome(Biome biome) { public static BCLBiome getFromBiome(Biome biome) {
if (biomeRegistry == null) { if (biomeRegistry == null) {
return EMPTY_BIOME; return EMPTY_BIOME;
} }
return ID_MAP.getOrDefault(biomeRegistry.getKey(biome), EMPTY_BIOME); return ID_MAP.getOrDefault(biomeRegistry.getKey(biome), EMPTY_BIOME);
} }
/** /**
* Get {@link BCLBiome} from biome on client. Used in fog rendering. * Get {@link BCLBiome} from biome on client. Used in fog rendering.
* @param biome - {@link Biome} from client world. * @param biome - {@link Biome} from client world.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/ */
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public static BCLBiome getRenderBiome(Biome biome) { public static BCLBiome getRenderBiome(Biome biome) {
BCLBiome endBiome = CLIENT.get(biome); BCLBiome endBiome = CLIENT.get(biome);
if (endBiome == null) { if (endBiome == null) {
Minecraft minecraft = Minecraft.getInstance(); Minecraft minecraft = Minecraft.getInstance();
ResourceLocation id = minecraft.level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome); ResourceLocation id = minecraft.level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome);
endBiome = id == null ? EMPTY_BIOME : ID_MAP.getOrDefault(id, EMPTY_BIOME); endBiome = id == null ? EMPTY_BIOME : ID_MAP.getOrDefault(id, EMPTY_BIOME);
CLIENT.put(biome, endBiome); CLIENT.put(biome, endBiome);
} }
return endBiome; return endBiome;
} }
/** /**
* Get biome {@link ResourceLocation} from given {@link Biome}. * Get biome {@link ResourceLocation} from given {@link Biome}.
* @param biome - {@link Biome} from server world. * @param biome - {@link Biome} from server world.
* @return biome {@link ResourceLocation}. * @return biome {@link ResourceLocation}.
*/ */
public static ResourceLocation getBiomeID(Biome biome) { public static ResourceLocation getBiomeID(Biome biome) {
ResourceLocation id = biomeRegistry.getKey(biome); ResourceLocation id = biomeRegistry.getKey(biome);
return id == null ? EMPTY_BIOME.getID() : id; return id == null ? EMPTY_BIOME.getID() : id;
} }
/** /**
* Get {@link BCLBiome} from given {@link ResourceLocation}. * Get {@link BCLBiome} from given {@link ResourceLocation}.
* @param biomeID - biome {@link ResourceLocation}. * @param biomeID - biome {@link ResourceLocation}.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/ */
public static BCLBiome getBiome(ResourceLocation biomeID) { public static BCLBiome getBiome(ResourceLocation biomeID) {
return ID_MAP.getOrDefault(biomeID, EMPTY_BIOME); return ID_MAP.getOrDefault(biomeID, EMPTY_BIOME);
} }
/** /**
* Check if biome with {@link ResourceLocation} exists in API registry. * Check if biome with {@link ResourceLocation} exists in API registry.
* @param biomeID - biome {@link ResourceLocation}. * @param biomeID - biome {@link ResourceLocation}.
* @return {@code true} if biome exists in API registry and {@code false} if not. * @return {@code true} if biome exists in API registry and {@code false} if not.
*/ */
public static boolean hasBiome(ResourceLocation biomeID) { public static boolean hasBiome(ResourceLocation biomeID) {
return ID_MAP.containsKey(biomeID); return ID_MAP.containsKey(biomeID);
} }
/** /**
* Load biomes from Fabric API. For internal usage only. * Load biomes from Fabric API. For internal usage only.
*/ */
public static void loadFabricAPIBiomes() { public static void loadFabricAPIBiomes() {
FabricBiomesData.NETHER_BIOMES.forEach((key) -> { FabricBiomesData.NETHER_BIOMES.forEach((key) -> {
if (!hasBiome(key.location())) { if (!hasBiome(key.location())) {
registerNetherBiome(BuiltinRegistries.BIOME.get(key.location())); registerNetherBiome(BuiltinRegistries.BIOME.get(key.location()));
} }
}); });
FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> { FabricBiomesData.END_LAND_BIOMES.forEach((key, weight) -> {
if (!hasBiome(key.location())) { if (!hasBiome(key.location())) {
registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location()), weight); registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location()), weight);
} }
}); });
FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> { FabricBiomesData.END_VOID_BIOMES.forEach((key, weight) -> {
if (!hasBiome(key.location())) { if (!hasBiome(key.location())) {
registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location()), weight); registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location()), weight);
} }
}); });
} }
@Nullable @Nullable
public static Biome getFromRegistry(ResourceLocation key) { public static Biome getFromRegistry(ResourceLocation key) {
return BuiltinRegistries.BIOME.get(key); return BuiltinRegistries.BIOME.get(key);
} }
@Nullable @Nullable
public static Biome getFromRegistry(ResourceKey<Biome> key) { public static Biome getFromRegistry(ResourceKey<Biome> key) {
return BuiltinRegistries.BIOME.get(key); return BuiltinRegistries.BIOME.get(key);
} }
public static boolean isDatapackBiome(ResourceLocation biomeID) { public static boolean isDatapackBiome(ResourceLocation biomeID) {
return getFromRegistry(biomeID) == null; return getFromRegistry(biomeID) == null;
} }
public static boolean isNetherBiome(ResourceLocation biomeID) { public static boolean isNetherBiome(ResourceLocation biomeID) {
return pickerHasBiome(NETHER_BIOME_PICKER, biomeID); return pickerHasBiome(NETHER_BIOME_PICKER, biomeID);
} }
public static boolean isEndBiome(ResourceLocation biomeID) { public static boolean isEndBiome(ResourceLocation biomeID) {
return pickerHasBiome(END_LAND_BIOME_PICKER, biomeID) || pickerHasBiome(END_VOID_BIOME_PICKER, biomeID); return pickerHasBiome(END_LAND_BIOME_PICKER, biomeID) || pickerHasBiome(END_VOID_BIOME_PICKER, biomeID);
} }
private static boolean pickerHasBiome(BiomePicker picker, ResourceLocation key) { private static boolean pickerHasBiome(BiomePicker picker, ResourceLocation key) {
return picker.getBiomes().stream().filter(biome -> biome.getID().equals(key)).findFirst().isPresent(); return picker.getBiomes().stream().filter(biome -> biome.getID().equals(key)).findFirst().isPresent();
} }
/** /**
* Registers new biome modification for specified dimension. Will work both for mod and datapack biomes. * Registers new biome modification for specified dimension. Will work both for mod and datapack biomes.
* @param dimensionID {@link ResourceLocation} dimension ID, example: Level.OVERWORLD or "minecraft:overworld". * @param dimensionID {@link ResourceLocation} dimension ID, example: Level.OVERWORLD or "minecraft:overworld".
* @param modification {@link BiConsumer} with {@link ResourceKey} biome ID and {@link Biome} parameters. * @param modification {@link BiConsumer} with {@link ResourceKey} biome ID and {@link Biome} parameters.
*/ */
public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer<ResourceLocation, Biome> modification) { public static void registerBiomeModification(ResourceKey dimensionID, BiConsumer<ResourceLocation, Biome> modification) {
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(dimensionID); List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(dimensionID);
if (modifications == null) { if (modifications == null) {
modifications = Lists.newArrayList(); modifications = Lists.newArrayList();
MODIFICATIONS.put(dimensionID, modifications); MODIFICATIONS.put(dimensionID, modifications);
} }
modifications.add(modification); modifications.add(modification);
} }
/** /**
* Registers new biome modification for the Overworld. Will work both for mod and datapack biomes. * Registers new biome modification for the Overworld. Will work both for mod and datapack biomes.
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
*/ */
public static void registerOverworldBiomeModification(BiConsumer<ResourceLocation, Biome> modification) { public static void registerOverworldBiomeModification(BiConsumer<ResourceLocation, Biome> modification) {
registerBiomeModification(Level.OVERWORLD, modification); registerBiomeModification(Level.OVERWORLD, modification);
} }
/** /**
* Registers new biome modification for the Nether. Will work both for mod and datapack biomes. * Registers new biome modification for the Nether. Will work both for mod and datapack biomes.
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
*/ */
public static void registerNetherBiomeModification(BiConsumer<ResourceLocation, Biome> modification) { public static void registerNetherBiomeModification(BiConsumer<ResourceLocation, Biome> modification) {
registerBiomeModification(Level.NETHER, modification); registerBiomeModification(Level.NETHER, modification);
} }
/** /**
* Registers new biome modification for the End. Will work both for mod and datapack biomes. * Registers new biome modification for the End. Will work both for mod and datapack biomes.
* @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters. * @param modification {@link BiConsumer} with {@link ResourceLocation} biome ID and {@link Biome} parameters.
*/ */
public static void registerEndBiomeModification(BiConsumer<ResourceLocation, Biome> modification) { public static void registerEndBiomeModification(BiConsumer<ResourceLocation, Biome> modification) {
registerBiomeModification(Level.END, modification); registerBiomeModification(Level.END, modification);
} }
/** /**
* Will apply biome modifications to world, internal usage only. * Will apply biome modifications to world, internal usage only.
* @param level * @param level
*/ */
public static void applyModifications(ServerLevel level) { public static void applyModifications(ServerLevel level) {
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension()); List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension());
if (modifications == null) { if (modifications == null) {
return; return;
} }
BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource(); BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource();
Set<Biome> biomes = source.possibleBiomes(); Set<Biome> biomes = source.possibleBiomes();
biomes.forEach(biome -> { biomes.forEach(biome -> {
ResourceLocation biomeID = getBiomeID(biome); ResourceLocation biomeID = getBiomeID(biome);
boolean modify = isDatapackBiome(biomeID); boolean modify = isDatapackBiome(biomeID);
if (biome != BuiltinRegistries.BIOME.get(biomeID)) { if (biome != BuiltinRegistries.BIOME.get(biomeID)) {
modify = true; modify = true;
} }
else if (!modify && !MODIFIED_BIOMES.contains(biomeID)) { else if (!modify && !MODIFIED_BIOMES.contains(biomeID)) {
MODIFIED_BIOMES.add(biomeID); MODIFIED_BIOMES.add(biomeID);
modify = true; modify = true;
} }
if (modify) { if (modify) {
modifications.forEach(consumer -> { modifications.forEach(consumer -> {
consumer.accept(biomeID, biome); consumer.accept(biomeID, biome);
}); });
} }
}); });
} }
/** /**
* Adds new features to existing biome. * Adds new features to existing biome.
* @param biome {@link Biome} to add features in. * @param biome {@link Biome} to add features in.
* @param feature {@link ConfiguredFeature} to add. * @param feature {@link ConfiguredFeature} to add.
* *
*/ */
public static void addBiomeFeature(Biome biome, BCLFeature feature) { public static void addBiomeFeature(Biome biome, BCLFeature feature) {
addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep());
} }
/** /**
* Adds new features to existing biome. * Adds new features to existing biome.
* @param biome {@link Biome} to add features in. * @param biome {@link Biome} to add features in.
* @param feature {@link ConfiguredFeature} to add. * @param feature {@link ConfiguredFeature} to add.
* @param step a {@link Decoration} step for the feature. * @param step a {@link Decoration} step for the feature.
*/ */
public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) { public static void addBiomeFeature(Biome biome, PlacedFeature feature, Decoration step) {
BuiltinRegistries.PLACED_FEATURE BuiltinRegistries.PLACED_FEATURE
.getResourceKey(feature) .getResourceKey(feature)
.ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), step, key)); .ifPresent(key -> BiomeModifications.addFeature(ctx -> ctx.getBiomeKey().equals(BuiltinRegistries.BIOME.getKey(biome)), step, key));
} }
/** /**
* Adds new features to existing biome. * Adds new features to existing biome.
* @param biome {@link Biome} to add features in. * @param biome {@link Biome} to add features in.
* @param features array of {@link BCLFeature} to add. * @param features array of {@link BCLFeature} to add.
*/ */
public static void addBiomeFeatures(Biome biome, BCLFeature... features) { public static void addBiomeFeatures(Biome biome, BCLFeature... features) {
for (BCLFeature feature: features) { for (BCLFeature feature: features) {
addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep()); addBiomeFeature(biome, feature.getPlacedFeature(), feature.getFeatureStep());
} }
} }
// TODO: 1.18 There are no more StructureFeatures in the Biomes, they are in a separate registry now // TODO: 1.18 There are no more StructureFeatures in the Biomes, they are in a separate registry now
/** /**
* Adds new structure feature to existing biome. * Adds new structure feature to existing biome.
* @param biome {@link Biome} to add structure feature in. * @param biome {@link Biome} to add structure feature in.
* @param structure {@link ConfiguredStructureFeature} to add. * @param structure {@link ConfiguredStructureFeature} to add.
*/ */
public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) {
BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE
.getResourceKey(structure) .getResourceKey(structure)
.ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), key)); .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), key));
} }
/** /**
* Adds new structure feature to existing biome. * Adds new structure feature to existing biome.
* @param biome {@link Biome} to add structure feature in. * @param biome {@link Biome} to add structure feature in.
* @param structure {@link BCLStructureFeature} to add. * @param structure {@link BCLStructureFeature} to add.
*/ */
public static void addBiomeStructure(Biome biome, BCLStructureFeature structure) { public static void addBiomeStructure(Biome biome, BCLStructureFeature structure) {
addBiomeStructure(biome, structure.getFeatureConfigured()); addBiomeStructure(biome, structure.getFeatureConfigured());
} }
/** /**
* Adds new structure features to existing biome. * Adds new structure features to existing biome.
* @param biome {@link Biome} to add structure features in. * @param biome {@link Biome} to add structure features in.
* @param structures array of {@link BCLStructureFeature} to add. * @param structures array of {@link BCLStructureFeature} to add.
*/ */
public static void addBiomeStructures(Biome biome, BCLStructureFeature... structures) { public static void addBiomeStructures(Biome biome, BCLStructureFeature... structures) {
for (BCLStructureFeature structure: structures) { for (BCLStructureFeature structure: structures) {
addBiomeStructure(biome, structure.getFeatureConfigured()); addBiomeStructure(biome, structure.getFeatureConfigured());
} }
} }
/** /**
* Adds mob spawning to specified biome. * Adds mob spawning to specified biome.
* @param biome {@link Biome} to add mob spawning. * @param biome {@link Biome} to add mob spawning.
* @param entityType {@link EntityType} mob type. * @param entityType {@link EntityType} mob type.
* @param weight spawn weight. * @param weight spawn weight.
* @param minGroupCount minimum mobs in group. * @param minGroupCount minimum mobs in group.
* @param maxGroupCount maximum mobs in group. * @param maxGroupCount maximum mobs in group.
*/ */
public static <M extends Mob> void addBiomeMobSpawn(Biome biome, EntityType<M> entityType, int weight, int minGroupCount, int maxGroupCount) { public static <M extends Mob> void addBiomeMobSpawn(Biome biome, EntityType<M> entityType, int weight, int minGroupCount, int maxGroupCount) {
ResourceLocation biomeKey = BuiltinRegistries.BIOME.getKey(biome); ResourceLocation biomeKey = BuiltinRegistries.BIOME.getKey(biome);
BiomeModifications.addSpawn( BiomeModifications.addSpawn(
ctx -> ctx.getBiomeKey().equals(biomeKey), ctx -> ctx.getBiomeKey().equals(biomeKey),
entityType.getCategory(), entityType.getCategory(),
entityType, entityType,
weight, weight,
minGroupCount, minGroupCount,
maxGroupCount maxGroupCount
); );
} }
} }

View file

@ -13,7 +13,7 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.material.FogType; import net.minecraft.world.level.material.FogType;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.util.BackgroundInfo; import ru.bclib.util.BackgroundInfo;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;

View file

@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.api.BonemealAPI; import ru.bclib.api.BonemealAPI;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;

View file

@ -21,7 +21,7 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.api.dataexchange.DataExchangeAPI; import ru.bclib.api.dataexchange.DataExchangeAPI;
import ru.bclib.recipes.BCLRecipeManager; import ru.bclib.recipes.BCLRecipeManager;

View file

@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.api.LifeCycleAPI; import ru.bclib.api.LifeCycleAPI;
import java.util.List; import java.util.List;

View file

@ -27,7 +27,7 @@ import net.minecraft.world.level.levelgen.carver.CarverConfiguration;
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver; import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature; import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.config.IdConfig; import ru.bclib.config.IdConfig;
import ru.bclib.config.PathConfig; import ru.bclib.config.PathConfig;
import ru.bclib.util.ColorUtil; import ru.bclib.util.ColorUtil;

View file

@ -19,7 +19,7 @@ import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConf
import net.minecraft.world.level.levelgen.structure.BoundingBox; import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings; import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.api.TagAPI; import ru.bclib.api.TagAPI;
import ru.bclib.util.BlocksHelper; import ru.bclib.util.BlocksHelper;
import ru.bclib.world.processors.DestructionStructureProcessor; import ru.bclib.world.processors.DestructionStructureProcessor;

View file

@ -15,7 +15,7 @@ import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.WorldgenRandom; import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.synth.SimplexNoise; import net.minecraft.world.level.levelgen.synth.SimplexNoise;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import ru.bclib.config.Configs; import ru.bclib.config.Configs;
import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.noise.OpenSimplexNoise;

View file

@ -10,7 +10,7 @@ import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate; import net.minecraft.world.level.biome.Climate;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.config.ConfigKeeper.StringArrayEntry; import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import ru.bclib.config.Configs; import ru.bclib.config.Configs;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;