Cats vs Dogs

Introduction

The weather changed and it’s raining cats and dogs! Cats and dogs fall from the sky with the rain!

Cats and dogs dropping from the sky

Swing a shovel

Add an ||player:on item used|| event to run code when the iron shovel is used.

player.onItemInteracted(IRON_SHOVEL, function () {

})

Make it rain

In the event, add code to ||gameplay:set the weather|| to rain. Make sure your world has weather enabled!

player.onItemInteracted(IRON_SHOVEL, function () {
    // @highlight
    gameplay.setWeather(RAIN)
})

Add a ‘repeat’ loop

Now, add in a loop to ||loops:repeat|| code 10 times.

player.onItemInteracted(IRON_SHOVEL, function () {
    gameplay.setWeather(RAIN)
    // @highlight
    for (let index = 0; index < 10; index++) {
    }
})

Spawn some mobs

Put in some code to ||mobs:spawn|| an ocelot, 5 blocks above the player and 10 blocks randomly around it.

player.onItemInteracted(IRON_SHOVEL, function () {
    gameplay.setWeather(RAIN)
    for (let index = 0; index < 10; index++) {
        // @highlight
        mobs.spawn(OCELOT, randpos(
        pos(10, 5, 10),
        pos(-10, 5, -10)
        ))
    }
})

Spawn different mobs

Add more code to ||mobs:spawn|| a wolf, 5 blocks above the player and 10 blocks randomly around it.

player.onItemInteracted(IRON_SHOVEL, function () {
    gameplay.setWeather(RAIN)
    for (let index = 0; index < 10; index++) {
        mobs.spawn(OCELOT, randpos(
        pos(10, 5, 10),
        pos(-10, 5, -10)
        ))
        // @highlight
        mobs.spawn(WOLF, randpos(
        pos(10, 5, 10),
        pos(-10, 5, -10)
        ))
    }
})

Give it a try!

Go to Minecraft and swing an iron shovel to “rain cats and dogs!”