#I need help in replacing mob spawns

9 messages · Page 1 of 1 (latest)

muted talon
#

I need it so that everytime a specific mob spawns (ex. valarian_conquest:valarian_villager) I need to be replaced with another mob (in this instance mca:male_villager) heres my same code (doesnt work)

entity.onSpawned(event => {
  const entity = event.getEntity();
  const level = event.getLevel();

  // Check if the spawned entity is a zombie
  if (entity.getType().equals('valarian_conquest:valarian_villager')) {
    // Cancel the original zombie's spawn
    event.cancel();

    // Spawn a skeleton at the same location
    level.addEntity('mca:male_villager', entity.getX(), entity.getY(), entity.getZ());
    console.log('did it work?????');
  }
});
azure mulchBOT
#

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

young jay
#

1.20 or 1.19? The code syntax is for 1.19

muted talon
silver flower
#

@muted talon the correct syntax would be like so and you would cancel the event at the very end because when you event.cancel() it fails to run the rest of the code inside the event and exits immediately js EntityEvents.spawned(event => { let { entity, server, level } = event })

muted talon
# silver flower <@678069455523282965> the correct syntax would be like so and you would cancel t...

I tried but I dont I always get confused on the layout of things when it comes to different versions....I used this and it didnt work


EntityEvents.spawned(event => {
    let { entity, level } = event


    if (entity.type == 'valarian_conquest:valarian_villager') {


        level.spawnEntity('mca:male_villager', entity.x, entity.y, entity.z)

        console.log('[KubeJS] Replaced valarian villager with MCA male villager')

         event.cancel()
    }
})


silver flower
# muted talon I tried but I dont I always get confused on the layout of things when it comes t...

spawnEntity with those parameters is not an existing method, to spawn a new entity you have the block.createEntity method which will create an entity in memory and then you have to use the .spawn() method to add it to the world. One more thing, you can put your detected entity type up in the spawned event's optional first parameter to filter by only that entity for the whole event. its optional but cleaner looking if you are only working with one entity. js EntityEvents.spawned('valarian_conquest:valarian_villager', event => { let { entity, level } = event let newVillager = entity.block.createEntity("mca:male_villager") newVillager.spawn() console.log('[KubeJS] Replaced valarian villager with MCA male villager') event.cancel() })

muted talon