SetSpell

Planning
Step 1
In this lesson we are going to make a function which places any wand in our hand

Notice in this video I don't have to craft the wand.

This will make working with spells much cleaner and quicker.

Planning
Step 2
We will achieve this with three steps

You have seen how to do everything in this lesson before. This will be good review

Temp1498254868
  1. Create an export function named setSpell()
  2. Give it a parameter which takes a spell name as a string
  3. Use if-statements to set the player's inventory's itemInMainHand to the correct wand
Step 3
Create an export function named 'setSpell()'
Temp1498255288

I like to place my export functions at the bottom of my code.

Step 4
Give our function a parameter which takes in a string
Temp1498255595

Now if we say:

Temp1498255707

spellName will be equal to "Vanishing"

But if we say:

Temp1498255767

spellName will be equal to "Chicken".

Step 5
Next we need to set the player's itemInMainHand

How can we get to the itemInMainHand property?

Here is a "map"

Temp1498257787
  • We can get the player with self
  • Then we can get self's inventory with self.inventory
  • Lastly we can get self's inventory's item in main hand with self.inventory.itemInMainHand

We'll be using this in the next step

Step 6
Inside our setSpell function we can check the value of the parameter "spellName"

If spellName is equal to "None" the player should get a magicWand in their hand

Temp1498257964
Step 7
Practice by finishing this code for the Vanishing wand
Temp1498258075
Challenge
Step 8
Add to your setSpell function so that it also allows you to switch to the ChickenWand

Typing this command in Minecraft should place the chickenWand into your hand

Temp1498258197
SetSpell Info

Account

MVCode Clubs

Created By

Newprofile jamie

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