#Script blocking certain mobs from spawning not working
10 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
everything
it should be something like this
const mobs = []; // your list of mobs that shouldn't spawn
EntityEvents.checkSpawn(event => {
if(mobs.contains(event.type.name())){
event.cancel();
}
});
CLI coding goat btw haha
makes sense, thanks 👍
Ticket closed!
Ok I tested this, here's a working example. event.cancel() doesn't prevent spawn
const mobs = ['minecraft:sheep', 'minecraft:spider', 'minecraft:zombie', 'minecraft:skeleton'];
EntityEvents.checkSpawn(event => {
if(mobs.indexOf(event.entity.type) >= 0){
event.success(false);
}
});
or use for / forEach```js
const mobs = []; // your list of mobs that shouldn't spawn
// for ... of ...
for (let mob of mobs) {
EntityEvents.checkSpawn(mob, event => event.cancel());
}
// forEach
mobs.forEach(mob => {
EntityEvents.checkSpawn(mob, event => event.cancel());
});
Then define a fixed function to optimize the regex to construct an anonymous function with the same functionality.
const mobs = []; // your list of mobs that shouldn't spawn
const blockMobSpawn = event => event.cancel();
// for ... of ...
for (let mob of mobs) EntityEvents.checkSpawn(mob, blockMobSpawn);
// forEach
mobs.forEach(mob => EntityEvents.checkSpawn(mob, blockMobSpawn));