Chance spawning rule
This commit is contained in:
parent
45216cdab5
commit
e0443a7a13
1 changed files with 16 additions and 3 deletions
|
@ -82,6 +82,19 @@ public class SpawnRuleBulder<M extends Mob> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will spawn entity with 1 / chance probability (randomly).
|
||||||
|
* @param chance probability limit.
|
||||||
|
* @return same {@link SpawnRuleBulder} instance
|
||||||
|
*/
|
||||||
|
public SpawnRuleBulder withChance(int chance) {
|
||||||
|
entryInstance = getFromCache("with_chance_" + chance, () -> {
|
||||||
|
return new SpawnRuleEntry(1, (type, world, spawnReason, pos, random) -> random.nextInt(chance) == 0);
|
||||||
|
});
|
||||||
|
rules.add(entryInstance);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will spawn entity only below specified brightness value.
|
* Will spawn entity only below specified brightness value.
|
||||||
* @param lightLevel light level upper limit.
|
* @param lightLevel light level upper limit.
|
||||||
|
@ -89,7 +102,7 @@ public class SpawnRuleBulder<M extends Mob> {
|
||||||
*/
|
*/
|
||||||
public SpawnRuleBulder belowBrightness(int lightLevel) {
|
public SpawnRuleBulder belowBrightness(int lightLevel) {
|
||||||
entryInstance = getFromCache("below_brightness_" + lightLevel, () -> {
|
entryInstance = getFromCache("below_brightness_" + lightLevel, () -> {
|
||||||
return new SpawnRuleEntry(1, (type, world, spawnReason, pos, random) -> world.getMaxLocalRawBrightness(pos) <= lightLevel);
|
return new SpawnRuleEntry(2, (type, world, spawnReason, pos, random) -> world.getMaxLocalRawBrightness(pos) <= lightLevel);
|
||||||
});
|
});
|
||||||
rules.add(entryInstance);
|
rules.add(entryInstance);
|
||||||
return this;
|
return this;
|
||||||
|
@ -102,7 +115,7 @@ public class SpawnRuleBulder<M extends Mob> {
|
||||||
*/
|
*/
|
||||||
public SpawnRuleBulder aboveBrightness(int lightLevel) {
|
public SpawnRuleBulder aboveBrightness(int lightLevel) {
|
||||||
entryInstance = getFromCache("above_brightness_" + lightLevel, () -> {
|
entryInstance = getFromCache("above_brightness_" + lightLevel, () -> {
|
||||||
return new SpawnRuleEntry(1, (type, world, spawnReason, pos, random) -> world.getMaxLocalRawBrightness(pos) >= lightLevel);
|
return new SpawnRuleEntry(2, (type, world, spawnReason, pos, random) -> world.getMaxLocalRawBrightness(pos) >= lightLevel);
|
||||||
});
|
});
|
||||||
rules.add(entryInstance);
|
rules.add(entryInstance);
|
||||||
return this;
|
return this;
|
||||||
|
@ -135,7 +148,7 @@ public class SpawnRuleBulder<M extends Mob> {
|
||||||
public SpawnRuleBulder maxNearby(EntityType<?> selectorType, int count, int side) {
|
public SpawnRuleBulder maxNearby(EntityType<?> selectorType, int count, int side) {
|
||||||
final Class<? extends Entity> baseClass = selectorType.getBaseClass();
|
final Class<? extends Entity> baseClass = selectorType.getBaseClass();
|
||||||
entryInstance = getFromCache("max_nearby_" + selectorType.getDescriptionId(), () -> {
|
entryInstance = getFromCache("max_nearby_" + selectorType.getDescriptionId(), () -> {
|
||||||
return new SpawnRuleEntry(2, (type, world, spawnReason, pos, random) -> {
|
return new SpawnRuleEntry(3, (type, world, spawnReason, pos, random) -> {
|
||||||
try {
|
try {
|
||||||
final AABB box = new AABB(pos).inflate(side, world.getHeight(), side);
|
final AABB box = new AABB(pos).inflate(side, world.getHeight(), side);
|
||||||
final List<?> list = world.getEntitiesOfClass(baseClass, box, (entity) -> true);
|
final List<?> list = world.getEntitiesOfClass(baseClass, box, (entity) -> true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue