#Script blocking certain mobs from spawning not working

10 messages · Page 1 of 1 (latest)

gloomy trout
#

This script is located in server_scripts and doesn't seem to have any issues, but the mobs I'm trying to block keep spawning anyway. What am I doing wrong?

quartz mantleBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

tranquil pewter
#

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

tranquil pewter
# gloomy trout makes sense, thanks 👍

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);
    }
});
zenith bay
#

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));