End biome source (WIP)
This commit is contained in:
parent
0e0944ba51
commit
34ecbb3f14
8 changed files with 300 additions and 7 deletions
|
@ -1,10 +1,11 @@
|
|||
package ru.bclib.api;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.impl.biome.InternalBiomeData;
|
||||
import net.fabricmc.fabric.impl.biome.WeightedBiomePicker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
|
@ -14,13 +15,15 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.ClimateParameters;
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
import ru.bclib.interfaces.BiomeListProvider;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
import ru.bclib.world.generator.BiomePicker;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class BiomeAPI {
|
||||
/**
|
||||
|
@ -29,9 +32,13 @@ public class BiomeAPI {
|
|||
*/
|
||||
public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location(), BuiltinRegistries.BIOME.get(Biomes.THE_VOID), 1, 0);
|
||||
|
||||
private static final Set<BCLBiome> NETHER_BIOMES = Sets.newHashSet();
|
||||
private static final Set<BCLBiome> END_LAND_BIOMES = Sets.newHashSet();
|
||||
private static final Set<BCLBiome> END_VOID_BIOMES = Sets.newHashSet();
|
||||
private static final Map<ResourceLocation, BCLBiome> NETHER_BIOMES = Maps.newHashMap();
|
||||
private static final Map<ResourceLocation, BCLBiome> END_LAND_BIOMES = Maps.newHashMap();
|
||||
private static final Map<ResourceLocation, BCLBiome> END_VOID_BIOMES = Maps.newHashMap();
|
||||
|
||||
public static final BiomePicker NETHER_BIOME_PICKER = new BiomePicker();
|
||||
public static final BiomePicker END_LAND_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<Biome, BCLBiome> CLIENT = Maps.newHashMap();
|
||||
|
@ -65,6 +72,7 @@ public class BiomeAPI {
|
|||
*/
|
||||
public static void registerNetherBiome(BCLBiome biome) {
|
||||
registerBiome(biome);
|
||||
NETHER_BIOME_PICKER.addBiome(biome);
|
||||
Random random = new Random(biome.getID().hashCode());
|
||||
ClimateParameters parameters = new ClimateParameters(
|
||||
MHelper.randRange(-1.5F, 1.5F, random),
|
||||
|
@ -77,6 +85,18 @@ public class BiomeAPI {
|
|||
InternalBiomeData.addNetherBiome(key, parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param biome {@link BCLBiome}
|
||||
*/
|
||||
public static void registerNetherBiome(Biome biome) {
|
||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
|
||||
BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1);
|
||||
NETHER_BIOME_PICKER.addBiome(bclBiome);
|
||||
registerBiome(bclBiome);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
|
@ -84,12 +104,25 @@ public class BiomeAPI {
|
|||
*/
|
||||
public static void registerEndLandBiome(BCLBiome biome) {
|
||||
registerBiome(biome);
|
||||
END_LAND_BIOME_PICKER.addBiome(biome);
|
||||
float weight = biome.getGenChance();
|
||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
|
||||
InternalBiomeData.addEndBiomeReplacement(Biomes.END_HIGHLANDS, key, weight);
|
||||
InternalBiomeData.addEndBiomeReplacement(Biomes.END_MIDLANDS, key, weight);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
* @param biome {@link BCLBiome}
|
||||
*/
|
||||
public static void registerEndLandBiome(Biome biome) {
|
||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
|
||||
BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1);
|
||||
END_LAND_BIOME_PICKER.addBiome(bclBiome);
|
||||
registerBiome(bclBiome);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
|
@ -97,11 +130,24 @@ public class BiomeAPI {
|
|||
*/
|
||||
public static void registerEndVoidBiome(BCLBiome biome) {
|
||||
registerBiome(biome);
|
||||
END_VOID_BIOME_PICKER.addBiome(biome);
|
||||
float weight = biome.getGenChance();
|
||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
|
||||
InternalBiomeData.addEndBiomeReplacement(Biomes.SMALL_END_ISLANDS, key, weight);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
* @param biome {@link BCLBiome}
|
||||
*/
|
||||
public static void registerEndVoidBiome(Biome biome) {
|
||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome).get();
|
||||
BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1);
|
||||
END_VOID_BIOME_PICKER.addBiome(bclBiome);
|
||||
registerBiome(bclBiome);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds {@link BCLBiome} to FabricAPI biomes as the Nether biome (with random {@link ClimateParameters}).
|
||||
*
|
||||
|
@ -116,7 +162,7 @@ public class BiomeAPI {
|
|||
MHelper.randRange(-2F, 2F, random),
|
||||
MHelper.randRange(-2F, 2F, random),
|
||||
MHelper.randRange(-2F, 2F, random),
|
||||
MHelper.randRange(-2F, 2F, random)
|
||||
random.nextFloat()
|
||||
);
|
||||
InternalBiomeData.addNetherBiome(key, parameters);
|
||||
}
|
||||
|
@ -226,4 +272,32 @@ public class BiomeAPI {
|
|||
public static boolean hasBiome(ResourceLocation biomeID) {
|
||||
return ID_MAP.containsKey(biomeID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load biomes from Fabric API. For internal usage only.
|
||||
*/
|
||||
public static void loadFabricAPIBiomes() {
|
||||
List<ResourceKey<Biome>> biomes = Lists.newArrayList();
|
||||
biomes.addAll(getBiomes(InternalBiomeData.getEndBiomesMap().get(Biomes.SMALL_END_ISLANDS)));
|
||||
biomes.addAll(getBiomes(InternalBiomeData.getEndBarrensMap().get(Biomes.END_BARRENS)));
|
||||
biomes.forEach((key) -> registerEndVoidBiome(BuiltinRegistries.BIOME.get(key.location())));
|
||||
|
||||
biomes.clear();
|
||||
biomes.addAll(getBiomes(InternalBiomeData.getEndBiomesMap().get(Biomes.END_MIDLANDS)));
|
||||
biomes.addAll(getBiomes(InternalBiomeData.getEndBiomesMap().get(Biomes.END_HIGHLANDS)));
|
||||
biomes.forEach((key) -> registerEndLandBiome(BuiltinRegistries.BIOME.get(key.location())));
|
||||
}
|
||||
|
||||
private static List<ResourceKey<Biome>> getBiomes(WeightedBiomePicker picker) {
|
||||
BiomeListProvider biomeList = (BiomeListProvider) (Object) picker;
|
||||
return biomeList == null ? Collections.emptyList() : biomeList.getBiomes();
|
||||
}
|
||||
|
||||
public static boolean isNetherBiome(ResourceLocation biomeID) {
|
||||
return NETHER_BIOMES.containsKey(biomeID);
|
||||
}
|
||||
|
||||
public static boolean isEndBiome(ResourceLocation biomeID) {
|
||||
return END_LAND_BIOMES.containsKey(biomeID) || END_VOID_BIOMES.containsKey(biomeID);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue