Store additional spawn-information along with an entity
This commit is contained in:
parent
7292c3cf3a
commit
5be62802e8
5 changed files with 58 additions and 0 deletions
|
@ -30,6 +30,7 @@ import net.minecraft.world.level.levelgen.SurfaceRules;
|
|||
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import ru.bclib.entity.BCLEntityWrapper;
|
||||
import ru.bclib.util.ColorUtil;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
import ru.bclib.world.features.BCLFeature;
|
||||
|
@ -131,6 +132,22 @@ public class BCLBiomeBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds mob spawning to biome.
|
||||
* @param wrapper {@link BCLEntityWrapper} mob type.
|
||||
* @param weight spawn weight.
|
||||
* @param minGroupCount minimum mobs in group.
|
||||
* @param maxGroupCount maximum mobs in group.
|
||||
* @return same {@link BCLBiomeBuilder} instance.
|
||||
*/
|
||||
public <M extends Mob> BCLBiomeBuilder spawn(BCLEntityWrapper<M> wrapper, int weight, int minGroupCount, int maxGroupCount) {
|
||||
if (wrapper.canSpawn()) {
|
||||
return spawn(wrapper.type(), weight, minGroupCount, maxGroupCount);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds ambient particles to thr biome.
|
||||
* @param particle {@link ParticleOptions} particles (or {@link net.minecraft.core.particles.ParticleType}).
|
||||
|
|
|
@ -61,6 +61,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
|||
import org.apache.commons.lang3.mutable.MutableInt;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.config.Configs;
|
||||
import ru.bclib.entity.BCLEntityWrapper;
|
||||
import ru.bclib.interfaces.SurfaceMaterialProvider;
|
||||
import ru.bclib.interfaces.SurfaceProvider;
|
||||
import ru.bclib.interfaces.SurfaceRuleProvider;
|
||||
|
@ -626,6 +627,10 @@ public class BiomeAPI {
|
|||
* @param structure {@link ConfiguredStructureFeature} to add.
|
||||
*/
|
||||
public static void addBiomeStructure(ResourceKey biomeKey, ConfiguredStructureFeature structure) {
|
||||
if (biomeKey==null){
|
||||
BCLib.LOGGER.error("null is not a valid biomeKey for " + structure);
|
||||
return;
|
||||
}
|
||||
changeStructureStarts(structureMap -> {
|
||||
Multimap<ConfiguredStructureFeature<?, ?>, ResourceKey<Biome>> configuredMap = structureMap.computeIfAbsent(structure.feature, k -> HashMultimap.create());
|
||||
|
||||
|
@ -699,6 +704,20 @@ public class BiomeAPI {
|
|||
return SURFACE_RULES.get(biomeID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds mob spawning to specified biome.
|
||||
* @param biome {@link Biome} to add mob spawning.
|
||||
* @param entityType {@link BCLEntityWrapper} mob type.
|
||||
* @param weight spawn weight.
|
||||
* @param minGroupCount minimum mobs in group.
|
||||
* @param maxGroupCount maximum mobs in group.
|
||||
*/
|
||||
public static <M extends Mob> void addBiomeMobSpawn(Biome biome, BCLEntityWrapper<M> entityType, int weight, int minGroupCount, int maxGroupCount) {
|
||||
if (entityType.canSpawn()){
|
||||
addBiomeMobSpawn(biome, entityType.type(), weight, minGroupCount, maxGroupCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds mob spawning to specified biome.
|
||||
* @param biome {@link Biome} to add mob spawning.
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.world.entity.SpawnPlacements.Type;
|
|||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.levelgen.Heightmap.Types;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import ru.bclib.entity.BCLEntityWrapper;
|
||||
import ru.bclib.interfaces.SpawnRule;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -33,6 +34,7 @@ public class SpawnRuleBuilder<M extends Mob> {
|
|||
|
||||
/**
|
||||
* Starts new rule building process.
|
||||
* @param entityType The entity you want to build a rule for
|
||||
* @return prepared {@link SpawnRuleBuilder} instance.
|
||||
*/
|
||||
public static SpawnRuleBuilder start(EntityType<? extends Mob> entityType) {
|
||||
|
@ -41,6 +43,15 @@ public class SpawnRuleBuilder<M extends Mob> {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts new rule building process.
|
||||
* @param entityType The entity you want to build a rule for
|
||||
* @return prepared {@link SpawnRuleBuilder} instance.
|
||||
*/
|
||||
public static SpawnRuleBuilder start(BCLEntityWrapper<? extends Mob> entityType) {
|
||||
return start(entityType.type());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop entity spawn on peaceful {@link Difficulty}
|
||||
* @return same {@link SpawnRuleBuilder} instance.
|
||||
|
|
7
src/main/java/ru/bclib/entity/BCLEntityWrapper.java
Normal file
7
src/main/java/ru/bclib/entity/BCLEntityWrapper.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package ru.bclib.entity;
|
||||
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
|
||||
public record BCLEntityWrapper<T extends Entity>(EntityType<T> type, boolean canSpawn) {
|
||||
}
|
|
@ -11,6 +11,7 @@ import net.minecraft.world.level.levelgen.SurfaceRules;
|
|||
import net.minecraft.world.level.levelgen.SurfaceRules.RuleSource;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.api.biomes.BiomeAPI;
|
||||
import ru.bclib.util.WeightedList;
|
||||
|
||||
|
@ -226,6 +227,9 @@ public class BCLBiome {
|
|||
edge.updateActualBiomes(biomeRegistry);
|
||||
}
|
||||
this.actualBiome = biomeRegistry.get(biomeID);
|
||||
if (actualBiome==null) {
|
||||
BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID);
|
||||
}
|
||||
|
||||
if (!this.structures.isEmpty()) {
|
||||
structures.forEach(s -> BiomeAPI.addBiomeStructure(BiomeAPI.getBiomeKey(actualBiome), s));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue