Pig Stacking Plugin

About this lesson

Use loops to place a pile of entities atop one another.

Concepts Reviewed:

While Loops
Planning
Step 1
In this lesson, we will use loops to create a tower of pigs
Planning
Step 2
First we will use loops to make a simple function

This function will be used to display many blank lines in chat.

Step 3
Create our function

exports.name turns that name into a function you can call in chat

Step 4
Create an empty line in chat

Add this code into your clearChat function

Step 5
Create a variable to control how many times we want to do this.

linesToClear is a variable that will keep track of how many times we want to echo

Step 6
Create a While loop

This while loop should be around your echo, but beneath the linesToClear variable

Step 7
Decrease linesToClear after you clear a line
Check Your Work
Step 8
This is the code you should now have
Challenge
Step 9
More lines!

Make your function clear all visible lines from chat

Planning
Step 10
It's pig stacking time

The rest of the lesson will walk you through creating a stack of pigs.

Step 11
Spawning a single pig

This is the code to spawn a pig.
In order to use it, we need a world and a location

Type the following two lines into chat to set up these variables.

Now we can use the above command to spawn a pig at that location in that world

Note that every time we reset the world we will need to recreate these variables

Step 12
Set up what we just did in game as its own function

Create pigStack as a new function at the bottom of our code
This will let us call /js pigStack() to spawn a pig at our location

Check Your Work
Step 13
Pig!
Challenge
Step 14
Pigs!

Make a loop like we did above to create more pigs!

Planning
Step 15
Return types

when you call the world.spawnEntity(location, entityType.pig) function in chat, it returns to you CraftPig
CraftPig is the pig we just spawned

we can store this return in a variable to further affect our pig

Step 16
Store Pigs being spawned in variables

Add this to our pigStack function.
This will allow us to reference the pigs we are creating.

Lets give them names to better keep track of them

Step 17
Now to stack them!

add this after you give them custom names

Step 18
More Pig Stacking!

update your while loop so we make a new upper pig each time.

This stacks all of the pigs on top of one pig

Step 19
Taller Stacks!

make the old upperPig the new lowerPig

Challenge
Step 20
Different Creatures

change the entityType to your favorite creature

Pig Stacking Plugin Info

Account

MVCode Clubs

Created By

jake wheaton

Course:

Fundamentals in Minecraft

Access Level

premium

For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach