diff --git a/src/main/java/ru/bclib/api/BiomeAPI.java b/src/main/java/ru/bclib/api/BiomeAPI.java index 5c664ce0..3950f754 100644 --- a/src/main/java/ru/bclib/api/BiomeAPI.java +++ b/src/main/java/ru/bclib/api/BiomeAPI.java @@ -45,7 +45,7 @@ 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. * Have {@code Biomes.THE_VOID} as the reference biome. */ - public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location(), BuiltinRegistries.BIOME.get(Biomes.THE_VOID), 1, 0); + 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 END_LAND_BIOME_PICKER = new BiomePicker(); @@ -100,9 +100,8 @@ public class BiomeAPI { return subBiome; } - public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float chance) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome subBiome = new BCLBiome(key.location(), biome, 1, chance); + public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) { + BCLBiome subBiome = new BCLBiome(biome).setGenChance(genChance); return registerSubBiome(parent, subBiome); } @@ -122,8 +121,8 @@ public class BiomeAPI { Climate.ParameterPoint parameters = Climate.parameters( MHelper.randRange(-1.5F, 1.5F, random), MHelper.randRange(-1.5F, 1.5F, random), - 0.0f, //new in 1.18 - 0.0f, //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), random.nextFloat() @@ -140,8 +139,7 @@ public class BiomeAPI { * @return {@link BCLBiome} */ public static BCLBiome registerNetherBiome(Biome biome) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(biome); NETHER_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -170,8 +168,7 @@ public class BiomeAPI { * @return {@link BCLBiome} */ public static BCLBiome registerEndLandBiome(Biome biome) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(biome); END_LAND_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -181,12 +178,11 @@ public class BiomeAPI { * 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}; - * @param weight float generation chance. + * @param genChance float generation chance. * @return {@link BCLBiome} */ - public static BCLBiome registerEndLandBiome(Biome biome, float weight) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, weight); + public static BCLBiome registerEndLandBiome(Biome biome, float genChance) { + BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); END_LAND_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -214,8 +210,7 @@ public class BiomeAPI { * @return {@link BCLBiome} */ public static BCLBiome registerEndVoidBiome(Biome biome) { - ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(biome); END_VOID_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -224,13 +219,13 @@ public class BiomeAPI { /** * 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}; - * @param weight float generation chance. + * @param biome {@link BCLBiome}. + * @param genChance float generation chance. * @return {@link BCLBiome} */ - public static BCLBiome registerEndVoidBiome(Biome biome, float weight) { + public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { ResourceKey key = BuiltinRegistries.BIOME.getResourceKey(biome).get(); - BCLBiome bclBiome = new BCLBiome(key.location(), biome, 1, weight); + BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); END_VOID_BIOME_PICKER.addBiome(bclBiome); registerBiome(bclBiome); return bclBiome; @@ -238,7 +233,6 @@ public class BiomeAPI { /** * Get {@link BCLBiome} from {@link Biome} instance on server. Used to convert world biomes to BCLBiomes. - * * @param biome - {@link Biome} from world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ @@ -251,7 +245,6 @@ public class BiomeAPI { /** * Get {@link BCLBiome} from biome on client. Used in fog rendering. - * * @param biome - {@link Biome} from client world. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ @@ -269,7 +262,6 @@ public class BiomeAPI { /** * Get biome {@link ResourceLocation} from given {@link Biome}. - * * @param biome - {@link Biome} from server world. * @return biome {@link ResourceLocation}. */ @@ -280,7 +272,6 @@ public class BiomeAPI { /** * Get {@link BCLBiome} from given {@link ResourceLocation}. - * * @param biomeID - biome {@link ResourceLocation}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. */ @@ -290,7 +281,6 @@ public class BiomeAPI { /** * Check if biome with {@link ResourceLocation} exists in API registry. - * * @param biomeID - biome {@link ResourceLocation}. * @return {@code true} if biome exists in API registry and {@code false} if not. */ @@ -455,12 +445,9 @@ public class BiomeAPI { * @param structure {@link ConfiguredStructureFeature} to add. */ public static void addBiomeStructure(Biome biome, ConfiguredStructureFeature structure) { - BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE.getResourceKey(structure) - .ifPresent((key)-> - BiomeModifications.addStructure( - (ctx)-> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), - key - )); + BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE + .getResourceKey(structure) + .ifPresent(key -> BiomeModifications.addStructure(ctx -> ctx.getBiomeKey().location().equals(BuiltinRegistries.BIOME.getKey(biome)), key)); } /** * Adds new structure feature to existing biome. diff --git a/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java b/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java index 3d21990e..663ca0dd 100644 --- a/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java +++ b/src/main/java/ru/bclib/gui/gridlayout/GridScreen.java @@ -18,7 +18,6 @@ import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; import ru.bclib.gui.gridlayout.GridLayout.Alignment; -import ru.bclib.util.Pair; @Environment(EnvType.CLIENT) diff --git a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java index 91c2c4d2..b9ae402c 100644 --- a/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java +++ b/src/main/java/ru/bclib/mixin/common/ServerLevelMixin.java @@ -1,9 +1,5 @@ package ru.bclib.mixin.common; -import java.util.List; -import java.util.concurrent.Executor; -import java.util.function.Supplier; - import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -23,6 +19,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import ru.bclib.api.BiomeAPI; import ru.bclib.api.LifeCycleAPI; +import java.util.List; +import java.util.concurrent.Executor; +import java.util.function.Supplier; + @Mixin(ServerLevel.class) public abstract class ServerLevelMixin extends Level { private static String bclib_lastWorld = null; diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiome.java b/src/main/java/ru/bclib/world/biomes/BCLBiome.java index 00db3a40..39c851a9 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiome.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiome.java @@ -1,26 +1,13 @@ package ru.bclib.world.biomes; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import net.minecraft.core.Registry; +import net.minecraft.data.BuiltinRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.biome.Biome; -import net.minecraft.world.level.biome.Biomes; -import net.minecraft.world.level.levelgen.GenerationStep.Decoration; import org.jetbrains.annotations.Nullable; -import ru.bclib.config.Configs; -import ru.bclib.util.JsonFactory; -import ru.bclib.util.StructureHelper; import ru.bclib.util.WeightedList; -import ru.bclib.world.features.BCLFeature; -import ru.bclib.world.features.ListFeature; -import ru.bclib.world.features.ListFeature.StructureInfo; -import ru.bclib.world.features.NBTStructureFeature.TerrainMerge; -import java.io.InputStream; -import java.util.List; import java.util.Map; import java.util.Random; @@ -39,6 +26,22 @@ public class BCLBiome { private float genChance = 1.0F; private float edgeSize = 0.0F; + /** + * Create wrapper for existing biome using its {@link ResourceLocation} identifier. + * @param biomeID {@link ResourceLocation} biome ID. + */ + public BCLBiome(ResourceLocation biomeID) { + this(biomeID, BuiltinRegistries.BIOME.get(biomeID)); + } + + /** + * Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}. + * @param biome {@link Biome} to wrap. + */ + public BCLBiome(Biome biome) { + this(BuiltinRegistries.BIOME.getKey(biome), biome); + } + public BCLBiome(ResourceLocation biomeID, Biome biome) { this.biomeID = biomeID; this.biome = biome; @@ -56,10 +59,12 @@ public class BCLBiome { /** * Set biome edge for this biome instance. * @param edge {@link BCLBiome} as the edge biome. + * @return same {@link BCLBiome}. */ - public void setEdge(BCLBiome edge) { + public BCLBiome setEdge(BCLBiome edge) { this.edge = edge; edge.biomeParent = this; + return this; } /** @@ -73,19 +78,23 @@ public class BCLBiome { /** * Set edges size for this biome. Size is in relative units to work fine with biome scale. * @param size as a float value. + * @return same {@link BCLBiome}. */ - public void setEdgeSize(float size) { + public BCLBiome setEdgeSize(float size) { edgeSize = size; + return this; } /** * Adds sub-biome into this biome instance. Biome chance will be interpreted as a sub-biome generation chance. * Biome itself has chance 1.0 compared to all its sub-biomes. * @param biome {@link Random} to be added. + * @return same {@link BCLBiome}. */ - public void addSubBiome(BCLBiome biome) { + public BCLBiome addSubBiome(BCLBiome biome) { biome.biomeParent = this; subbiomes.add(biome, biome.getGenChance()); + return this; } /** @@ -115,32 +124,13 @@ public class BCLBiome { return this.biomeParent; } - /** - * Checks if this biome has edge biome. - * @return true if it has edge. - */ - @Deprecated(forRemoval = true) - public boolean hasEdge() { - return edge != null; - } - - /** - * Checks if this biome has parent biome. - * @return true if it has parent. - */ - @Deprecated(forRemoval = true) - public boolean hasParentBiome() { - return biomeParent != null; - } - /** * Compares biome instances (directly) and their parents. Used in custom world generator. * @param biome {@link BCLBiome} * @return true if biome or its parent is same. */ - @Deprecated(forRemoval = true) public boolean isSame(BCLBiome biome) { - return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this); + return biome == this || (biome.biomeParent != null && biome.biomeParent == this); } /** @@ -183,6 +173,16 @@ public class BCLBiome { return this.genChance; } + /** + * Set gen chance for this biome, default value is 1.0. + * @param genChance chance of this biome to be generated. + * @return same {@link BCLBiome}. + */ + public BCLBiome setGenChance(float genChance) { + this.genChance = genChance; + return this; + } + /** * Recursively update biomes to correct world biome registry instances, for internal usage only. * @param biomeRegistry {@link Registry} for {@link Biome}. @@ -225,17 +225,21 @@ public class BCLBiome { * Adds custom data object to this biome instance. * @param name {@link String} name of data object. * @param obj any data to add. + * @return same {@link BCLBiome}. */ - public void addCustomData(String name, Object obj) { + public BCLBiome addCustomData(String name, Object obj) { customData.put(name, obj); + return this; } /** * Adds custom data object to this biome instance. * @param data a {@link Map} with custom data. + * @return same {@link BCLBiome}. */ - public void addCustomData(Map data) { + public BCLBiome addCustomData(Map data) { customData.putAll(data); + return this; } /** diff --git a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java b/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java index f9659e69..df7400d7 100644 --- a/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java +++ b/src/main/java/ru/bclib/world/biomes/BCLBiomeBuilder.java @@ -1,13 +1,23 @@ package ru.bclib.world.biomes; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.level.biome.Biome.BiomeBuilder; import net.minecraft.world.level.biome.Biome.BiomeCategory; import net.minecraft.world.level.biome.Biome.Precipitation; +import net.minecraft.world.level.biome.BiomeSpecialEffects; +import net.minecraft.world.level.biome.MobSpawnSettings; +import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData; + +import java.util.ArrayList; +import java.util.List; public class BCLBiomeBuilder { private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); + private List mobs = new ArrayList<>(32); + private BiomeSpecialEffects.Builder effectsBuilder; private Precipitation precipitation; private ResourceLocation biomeID; private BiomeCategory category; @@ -23,7 +33,9 @@ public class BCLBiomeBuilder { INSTANCE.biomeID = biomeID; INSTANCE.precipitation = Precipitation.NONE; INSTANCE.category = BiomeCategory.NONE; + INSTANCE.effectsBuilder = null; INSTANCE.temperature = 1.0F; + INSTANCE.mobs.clear(); return INSTANCE; } @@ -67,17 +79,46 @@ public class BCLBiomeBuilder { return this; } + /** + * Adds mob spawning to biome. + * @param entityType {@link EntityType} mob type. + * @param weight spawn weight. + * @param minGroupCount minimum mobs in group. + * @param maxGroupCount maximum mobs in group. + * @return + */ + public BCLBiomeBuilder spawn(EntityType entityType, int weight, int minGroupCount, int maxGroupCount) { + mobs.add(new SpawnerData(entityType, weight, minGroupCount, maxGroupCount)); + return this; + } + public BCLBiome build() { - Biome biome = new Biome.BiomeBuilder() + BiomeBuilder builder = new BiomeBuilder() .precipitation(precipitation) .biomeCategory(category) .temperature(temperature) - .downfall(downfall) + .downfall(downfall); /* - .specialEffects(effects.build()) - .mobSpawnSettings(spawnSettings.build()) .generationSettings(generationSettings.build())*/ - .build(); - return new BCLBiome(biomeID, biome); + //.build(); + + if (!mobs.isEmpty()) { + MobSpawnSettings.Builder spawnSettings = new MobSpawnSettings.Builder(); + mobs.forEach(spawn -> spawnSettings.addSpawn(spawn.type.getCategory(), spawn)); + builder.mobSpawnSettings(spawnSettings.build()); + } + + if (effectsBuilder != null) { + builder.specialEffects(effectsBuilder.build()); + } + + return new BCLBiome(biomeID, builder.build()); + } + + private BiomeSpecialEffects.Builder getEffects() { + if (effectsBuilder == null) { + effectsBuilder = new BiomeSpecialEffects.Builder(); + } + return effectsBuilder; } } diff --git a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java index 5a2d283d..89fc2c53 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibEndBiomeSource.java @@ -53,12 +53,12 @@ public class BCLibEndBiomeSource extends BiomeSource { this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { - BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(key, biome); BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); } else { BCLBiome bclBiome = BiomeAPI.getBiome(key); - if (bclBiome != BiomeAPI.EMPTY_BIOME && !bclBiome.hasParentBiome()) { + if (bclBiome != BiomeAPI.EMPTY_BIOME && bclBiome.getParentBiome() == null) { if (!BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) && !BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key)) { BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome); } @@ -105,7 +105,7 @@ public class BCLibEndBiomeSource extends BiomeSource { BCLBiome bclBiome = BiomeAPI.getBiome(key); if (bclBiome != BiomeAPI.EMPTY_BIOME) { - if (bclBiome.hasParentBiome()) { + if (bclBiome.getParentBiome() != null) { bclBiome = bclBiome.getParentBiome(); } key = bclBiome.getID(); diff --git a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java index ad4c7b96..fefbdc91 100644 --- a/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/ru/bclib/world/generator/BCLibNetherBiomeSource.java @@ -42,12 +42,12 @@ public class BCLibNetherBiomeSource extends BiomeSource { this.possibleBiomes().forEach(biome -> { ResourceLocation key = biomeRegistry.getKey(biome); if (!BiomeAPI.hasBiome(key)) { - BCLBiome bclBiome = new BCLBiome(key, biome, 1, 1); + BCLBiome bclBiome = new BCLBiome(key, biome); BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); } else { BCLBiome bclBiome = BiomeAPI.getBiome(key); - if (bclBiome != BiomeAPI.EMPTY_BIOME && !bclBiome.hasParentBiome()) { + if (bclBiome != BiomeAPI.EMPTY_BIOME && bclBiome.getParentBiome() == null) { if (!BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key)) { BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); } @@ -82,7 +82,7 @@ public class BCLibNetherBiomeSource extends BiomeSource { BCLBiome bclBiome = BiomeAPI.getBiome(key); if (bclBiome != BiomeAPI.EMPTY_BIOME) { - if (bclBiome.hasParentBiome()) { + if (bclBiome.getParentBiome() != null) { bclBiome = bclBiome.getParentBiome(); } key = bclBiome.getID(); diff --git a/src/main/java/ru/bclib/world/generator/BiomeMap.java b/src/main/java/ru/bclib/world/generator/BiomeMap.java index 078bac1f..34251623 100644 --- a/src/main/java/ru/bclib/world/generator/BiomeMap.java +++ b/src/main/java/ru/bclib/world/generator/BiomeMap.java @@ -87,9 +87,9 @@ public class BiomeMap { public BCLBiome getBiome(int x, int z) { BCLBiome biome = getRawBiome(x, z); - if (biome.hasEdge() || (biome.hasParentBiome() && biome.getParentBiome().hasEdge())) { + if (biome.getEdge() != null || (biome.getParentBiome() != null && biome.getParentBiome().getEdge() != null)) { BCLBiome search = biome; - if (biome.hasParentBiome()) { + if (biome.getParentBiome() != null) { search = biome.getParentBiome(); } int d = (int) Math.ceil(search.getEdgeSize() / 4F) << 2;