From 8439528e8ec278514fa65d45f5dfebcc16e001cd Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Sun, 28 Nov 2021 06:16:52 +0300 Subject: [PATCH] Custom spawning rule --- .../bclib/api/spawning/SpawnRuleBulder.java | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/bclib/api/spawning/SpawnRuleBulder.java b/src/main/java/ru/bclib/api/spawning/SpawnRuleBulder.java index 4d040412..27819b2c 100644 --- a/src/main/java/ru/bclib/api/spawning/SpawnRuleBulder.java +++ b/src/main/java/ru/bclib/api/spawning/SpawnRuleBulder.java @@ -14,6 +14,7 @@ import net.minecraft.world.entity.SpawnPlacements.Type; import net.minecraft.world.level.ServerLevelAccessor; import net.minecraft.world.level.levelgen.Heightmap.Types; import net.minecraft.world.phys.AABB; +import ru.bclib.interfaces.SpawnRule; import java.util.Collections; import java.util.List; @@ -32,7 +33,7 @@ public class SpawnRuleBulder { /** * Starts new rule building process. - * @return prepared {@link SpawnRuleBulder} instance + * @return prepared {@link SpawnRuleBulder} instance. */ public static SpawnRuleBulder start(EntityType entityType) { INSTANCE.entityType = entityType; @@ -42,7 +43,7 @@ public class SpawnRuleBulder { /** * Stop entity spawn on peaceful {@link Difficulty} - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder notPeaceful() { entryInstance = getFromCache("not_peaceful", () -> { @@ -55,7 +56,7 @@ public class SpawnRuleBulder { /** * Restricts entity spawn above world surface (flying mobs). * @param minHeight minimal spawn height. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder aboveGround(int minHeight) { entryInstance = getFromCache("above_ground", () -> { @@ -72,7 +73,7 @@ public class SpawnRuleBulder { /** * Restricts entity spawn below world logical height (useful for Nether mobs). - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder belowMaxHeight() { entryInstance = getFromCache("below_max_height", () -> { @@ -85,7 +86,7 @@ public class SpawnRuleBulder { /** * Will spawn entity with 1 / chance probability (randomly). * @param chance probability limit. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder withChance(int chance) { entryInstance = getFromCache("with_chance_" + chance, () -> { @@ -98,7 +99,7 @@ public class SpawnRuleBulder { /** * Will spawn entity only below specified brightness value. * @param lightLevel light level upper limit. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder belowBrightness(int lightLevel) { entryInstance = getFromCache("below_brightness_" + lightLevel, () -> { @@ -111,7 +112,7 @@ public class SpawnRuleBulder { /** * Will spawn entity only above specified brightness value. * @param lightLevel light level lower limit. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder aboveBrightness(int lightLevel) { entryInstance = getFromCache("above_brightness_" + lightLevel, () -> { @@ -124,7 +125,7 @@ public class SpawnRuleBulder { /** * Entity spawn will follow common vanilla spawn rules - spawn in darkness and not on peaceful level. * @param lightLevel light level upper limit. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder hostile(int lightLevel) { return notPeaceful().belowBrightness(lightLevel); @@ -132,7 +133,7 @@ public class SpawnRuleBulder { /** * Entity spawn will follow common vanilla spawn rules - spawn in darkness (below light level 7) and not on peaceful level. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder vanillaHostile() { return hostile(7); @@ -143,7 +144,7 @@ public class SpawnRuleBulder { * @param selectorType selector {@link EntityType} to search. * @param count max entity count. * @param side side of box to search in. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder maxNearby(EntityType selectorType, int count, int side) { final Class baseClass = selectorType.getBaseClass(); @@ -167,7 +168,7 @@ public class SpawnRuleBulder { * Will spawn entity only if count of nearby entities with same type will be lower than specified. * @param count max entity count. * @param side side of box to search in. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder maxNearby(int count, int side) { return maxNearby(entityType, count, side); @@ -176,12 +177,22 @@ public class SpawnRuleBulder { /** * Will spawn entity only if count of nearby entities with same type will be lower than specified. * @param count max entity count. - * @return same {@link SpawnRuleBulder} instance + * @return same {@link SpawnRuleBulder} instance. */ public SpawnRuleBulder maxNearby(int count) { return maxNearby(entityType, count, 256); } + /** + * Allows to add custom spawning rule for specific entities. + * @param rule {@SpawnRule} rule, can be a lambda expression. + * @return same {@link SpawnRuleBulder} instance. + */ + public SpawnRuleBulder customRule(SpawnRule rule) { + rules.add(new SpawnRuleEntry(7, rule)); + return this; + } + /** * Finalize spawning rule creation. * @param spawnType {@link Type} of spawn.