Prevent entities from spawning if disabled

This commit is contained in:
Frank 2021-12-10 00:36:18 +01:00
parent 5be62802e8
commit 358c0099dd

View file

@ -45,11 +45,27 @@ public class SpawnRuleBuilder<M extends Mob> {
/**
* Starts new rule building process.
* @param entityType The entity you want to build a rule for
* @param wrapper 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());
public static SpawnRuleBuilder start(BCLEntityWrapper<? extends Mob> wrapper) {
SpawnRuleBuilder builder = start(wrapper.type());
if (!wrapper.canSpawn()){
builder.preventSpawn();
}
return builder;
}
/**
* Stop entity spawn entierly
* @return same {@link SpawnRuleBuilder} instance.
*/
public SpawnRuleBuilder preventSpawn() {
entryInstance = getFromCache("prevent", () -> {
return new SpawnRuleEntry(-1, (type, world, spawnReason, pos, random) -> false);
});
rules.add(entryInstance);
return this;
}
/**