Rabbit Invasion

Introduction

Make a rabbit and try to get rid of it. Won’t happen, two more new rabbits appear each time one gets killed!

Rabbits multiplying

Iron shovel event

Add an event to run code when the iron shovel is ||player:swinged||.

player.onItemInteracted(IRON_SHOVEL, function () {

})

Spawn a rabbit mob

In the event, add code to ||mobs:spawn|| a rabbit at the player position when the shovel is swinged.

player.onItemInteracted(IRON_SHOVEL, function () {
    mobs.spawn(RABBIT, pos(0, 0, 0))    
})

Check for mob event

Add another event to run code when a rabbit is ||mobs:killed||.

mobs.onMobKilled(RABBIT, function () {
})

Add a ‘repeat’ loop

Put a loop in to ||loops:repeat|| code 2 times.

mobs.onMobKilled(RABBIT, function () {
    // @highlight
    for (let i = 0; i < 2; i++) {
    }
})

Multiply the rabbits

Add code to ||mobs:spawn|| a rabbit ||positions:randomly|| near the player.

mobs.onMobKilled(RABBIT, function () {
    for (let i = 0; i < 2; i++) {
        // @highlight
        mobs.spawn(RABBIT, randpos(
        pos(-5, 0, -5),
        pos(5, 0, 5)
        ))
    }
})

See what happens!

Go to Minecraft, swing an iron shovel to spawn a rabbit. Try killing a rabbit and see how they multiply!