Minecraft
Normal
30 mins
115 points
What you need:
  • Computer/laptop
  • Minecraft Education Edition

Zombie Pigs

Did you know pigs turn into zombie's in Minecraft when they're struck by lightning? Let's code it!

This message will be visible to everyone. Send

    This code along has finished! ⌚

    You can watch it back by playing the video!

    The code along is open for everyone to join in but if you would like to earn the points and badges please join our club!

    1 - Open Minecraft

    In this project we are going to learn what a Minecraft mob is and how you can interact with them in Minecraft.

    First, open Minecraft Education Edition, login, create a new world and open the Code Builder.

    2 - What is a mob?

    Mobs are beings, or entities, in a Minecraft world. They are the players, the monsters, the villagers, etc. Mobs can be spawned, killed, teleported, enchanted, and given items.

    Types
    A mob type is identified by a unique number. There are various types of mobs like animal or monster and you can use these to help you craft the mob you want.

    Selectors
    Selectors allow you to describe and select a group of mobs at once. For example, you can decide to select all players or select all chickens. Selection can be made by mob type, distance and other criteria. 


    3 - Create an event

    Did you know that pigs turn into zombie pigmen when they're struck by lightning in Minecraft? 

    Let's create an event to trigger some code to run. Create an event for when your player swings an Iron Pickaxe.

    player.onItemInteracted(IRON_PICKAXE, function () {
    	
    })

    4 - Spawn a pig mob

    Now put a spawn block into the event block, like below, to spawn a pig 7 blocks away from your player.

    player.onItemInteracted(IRON_PICKAXE, function () {
        mobs.spawn(PIG, pos(7, 0, 0))
    })

    Once you've added the new code, go back to the game and add the Iron Pickaxe to your equipment (press E on your keyboard and search for 'Iron Pickaxe'). Then swing the pickaxe by clicking the right mouse button. A pig should be spawned each time you swing it.


    5 - Spawn a lightning bolt

    Next let's add some code to spawn a lightning bolt to hit the same location that the pig was spawned in. 

    player.onItemInteracted(IRON_PICKAXE, function () {
        mobs.spawn(PIG, pos(7, 0, 0))
        mobs.spawn(LIGHTNING_BOLT, pos(7, 0, 0))
    })

    Run your code and swing the pickaxe, the pig should be created and then hit by lightning, turning it into a zombie pigman!



    Join our club 😃

    Create your profile, earn points & badges and learn how to code!

    Copyright Notice
    This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more