From 7e36ac4159a5d2bfe78356ff725251e5e0c35208 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sat, 14 Aug 2021 01:32:25 +0300 Subject: [PATCH] Crash fixes --- src/main/java/ru/bclib/api/BiomeAPI.java | 25 +++++++++------- .../world/generator/BCLibEndBiomeSource.java | 30 +++++++++++++++---- .../generator/BCLibNetherBiomeSource.java | 26 ++++++++++++---- .../ru/bclib/world/generator/BiomePicker.java | 18 ++++++----- .../world/generator/GeneratorOptions.java | 2 +- 5 files changed, 71 insertions(+), 30 deletions(-) diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index e9f821e6..b2ed8666 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -41,15 +41,15 @@ public class BiomeAPI { private static final Map CLIENT = Maps.newHashMap(); private static Registry biomeRegistry; - public static final BCLBiome NETHER_WASTES_BIOME = registerNetherBiome(getFromRegistry(new ResourceLocation("nether_wastes"))); - public static final BCLBiome CRIMSON_FOREST_BIOME = registerNetherBiome(getFromRegistry(new ResourceLocation("crimson_forest"))); - public static final BCLBiome WARPED_FOREST_BIOME = registerNetherBiome(getFromRegistry(new ResourceLocation("warped_forest"))); - public static final BCLBiome SOUL_SAND_VALLEY_BIOME = registerNetherBiome(getFromRegistry(new ResourceLocation("soul_sand_valley"))); - public static final BCLBiome BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(new ResourceLocation("basalt_deltas"))); + 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 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 BASALT_DELTAS_BIOME = registerNetherBiome(getFromRegistry(Biomes.BASALT_DELTAS)); - public static final BCLBiome THE_END = registerEndLandBiome(getFromRegistry(new ResourceLocation("the_end"))); - public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(new ResourceLocation("end_midlands")), 0.5F); - public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(new ResourceLocation("end_highlands")), 0.5F); + 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_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 SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands"))); @@ -330,8 +330,13 @@ public class BiomeAPI { } @Nullable - public static Biome getFromRegistry(ResourceLocation biomeID) { - return BuiltinRegistries.BIOME.get(biomeID); + public static Biome getFromRegistry(ResourceLocation key) { + return BuiltinRegistries.BIOME.get(key); + } + + @Nullable + public static Biome getFromRegistry(ResourceKey key) { + return BuiltinRegistries.BIOME.get(key); } public static boolean isDatapackBiome(ResourceLocation biomeID) { diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index df8168e6..4fdb9731 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -2,6 +2,7 @@ package ru.bclib.world.generator; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryLookupCodec; import net.minecraft.resources.ResourceLocation; @@ -45,14 +46,26 @@ public class BCLibEndBiomeSource extends BiomeSource { BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); BiomeAPI.END_VOID_BIOME_PICKER.clearMutables(); + this.possibleBiomes.forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); - BCLBiome bclBiome = BiomeAPI.getBiome(key); - bclBiome.updateActualBiomes(biomeRegistry); - if (!BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key)) { + if (!BiomeAPI.hasBiome(key)) { + BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); } + else { + BCLBiome bclBiome = BiomeAPI.getBiome(key); + if (bclBiome != BiomeAPI.EMPTY_BIOME && !bclBiome.hasParentBiome()) { + if (!BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) && !BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key)) { + BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); + } + } + } }); + + BiomeAPI.END_LAND_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); + BiomeAPI.END_VOID_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); + BiomeAPI.END_LAND_BIOME_PICKER.rebuild(); BiomeAPI.END_VOID_BIOME_PICKER.rebuild(); @@ -74,9 +87,14 @@ public class BCLibEndBiomeSource extends BiomeSource { private static List getBiomes(Registry biomeRegistry) { return biomeRegistry.stream().filter(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); - return BiomeAPI.END_LAND_BIOME_PICKER.contains(key) || - BiomeAPI.END_VOID_BIOME_PICKER.contains(key) || - (BiomeAPI.isDatapackBiome(key) && biome.getBiomeCategory() == BiomeCategory.THEEND); + BCLBiome bclBiome = BiomeAPI.getBiome(key); + if (bclBiome != BiomeAPI.EMPTY_BIOME) { + if (bclBiome.hasParentBiome()) { + bclBiome = bclBiome.getParentBiome(); + } + 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)); }).toList(); } diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index cad86fce..62ced1da 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -30,14 +30,24 @@ public class BCLibNetherBiomeSource extends BiomeSource { super(getBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); + this.possibleBiomes.forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); - BCLBiome bclBiome = BiomeAPI.getBiome(key); - bclBiome.updateActualBiomes(biomeRegistry); - if (!BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key)) { + if (!BiomeAPI.hasBiome(key)) { + BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); } + else { + BCLBiome bclBiome = BiomeAPI.getBiome(key); + if (bclBiome != BiomeAPI.EMPTY_BIOME && !bclBiome.hasParentBiome()) { + if (!BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key)) { + BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); + } + } + } }); + + BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry)); BiomeAPI.NETHER_BIOME_PICKER.rebuild(); this.biomeMap = new BiomeMap(seed, GeneratorOptions.getBiomeSizeNether(), BiomeAPI.NETHER_BIOME_PICKER); @@ -48,8 +58,14 @@ public class BCLibNetherBiomeSource extends BiomeSource { private static List getBiomes(Registry biomeRegistry) { return biomeRegistry.stream().filter(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); - return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || - (BiomeAPI.isDatapackBiome(key) && biome.getBiomeCategory() == BiomeCategory.NETHER); + BCLBiome bclBiome = BiomeAPI.getBiome(key); + if (bclBiome != BiomeAPI.EMPTY_BIOME) { + if (bclBiome.hasParentBiome()) { + bclBiome = bclBiome.getParentBiome(); + } + key = bclBiome.getID(); + } + return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || (biome.getBiomeCategory() == BiomeCategory.NETHER && BiomeAPI.isDatapackBiome(key)); }).toList(); } diff --git a/src/main/java/ru/bclib/world/generator/BiomePicker.java b/src/main/java/ru/bclib/world/generator/BiomePicker.java index c4337102..99eae8df 100644 --- a/src/main/java/ru/bclib/world/generator/BiomePicker.java +++ b/src/main/java/ru/bclib/world/generator/BiomePicker.java @@ -14,16 +14,22 @@ import java.util.Set; public class BiomePicker { private final Set immutableIDs = Sets.newHashSet(); private final List biomes = Lists.newArrayList(); - private int biomeCount = 0; private WeighTree tree; + private int biomeCount = 0; public void addBiome(BCLBiome biome) { + if (immutableIDs.contains(biome.getID())) { + return; + } immutableIDs.add(biome.getID()); biomes.add(biome); biomeCount++; } public void addBiomeMutable(BCLBiome biome) { + if (immutableIDs.contains(biome.getID())) { + return; + } biomes.add(biome); } @@ -45,10 +51,6 @@ public class BiomePicker { return immutableIDs.contains(id); } - public boolean contains(ResourceLocation id) { - return biomes.contains(id); - } - public void removeMutableBiome(ResourceLocation id) { for (int i = biomeCount; i < biomes.size(); i++) { BCLBiome biome = biomes.get(i); @@ -63,10 +65,10 @@ public class BiomePicker { if (biomes.isEmpty()) { return; } - WeightedList list = new WeightedList(); - biomes.forEach((biome) -> { + WeightedList list = new WeightedList<>(); + biomes.forEach(biome -> { list.add(biome, biome.getGenChance()); }); - tree = new WeighTree(list); + tree = new WeighTree<>(list); } } diff --git a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java index d7bbc22a..7137ad2b 100644 --- a/src/main/java/ru/bclib/world/generator/GeneratorOptions.java +++ b/src/main/java/ru/bclib/world/generator/GeneratorOptions.java @@ -11,7 +11,7 @@ public class GeneratorOptions { private static int biomeSizeEndLand; private static int biomeSizeEndVoid; private static Function endLandFunction; - private static boolean farEndBiomes; + private static boolean farEndBiomes = true; public static void init() { biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256);