The Wand

Step 1
In this lesson we are going to create a magic wand item that we can use to cast spells!
Step 2
We're going to start by creating a new item, called magic wand

First create a variable, this will need to contain all the item data about our wand

Step 3
Items need a lot of data in order to work, so it's easiest to duplicate and edit an already existing item

Here we start our wand out as a single stick.

Step 4
We've taken object data from an existing item in the game, and copied it into a new object "magicWand"
Step 5
Our magicWand item currently has the exact same properties as a regular stick

The properties are stored in the itemMeta

Step 6
Create a new variable and set it equal to the magic wand's itemMeta

This will allow us to edit the itemMeta

Step 7
First let's change the display name

Here we are using . (dot notation) to access object properties.

You can think of this sequence as saying:
magicWand's itemMeta's displayName

Step 8
Set the display name to "Magic Wand"

The displayName property...
of the itemMeta property...
of the magicWand object

Step 9
Just for fun, let's make the display name text blue!

You can add one of these colors to any string.

The .aqua() method willturn our string aqua

Step 10
We can use the lore property to give our item a description

Lore is stored as an array where each element of the array is a new line of text.

Start by setting lore to an empty array:

Step 11
The first line of text will show the user the current wand spell

We'll have "Current Spell:" in blue and "None" in yellow

Step 12
Add a second element to the array to make a new line of text

Use a comma to separate the two elements

Step 13
Add the customized ItemMeta to the wand

Now that we've modified the magicWandMeta we need to set our magicWands itemMeta to magicWandMeta.

Check Your Work
Step 15
We've now set the displayName and lore of our magic wand

We aren't ready to deploy this plugin yet, so you won't be able to see this just yet.

Take a moment to see what our code does for us so far:

Step 16
Next we need a way to get a magic wand in game. For this we will create a new recipe

In the next few steps we will make a recipe for a magic wand consisting of diamond, obsidian, and a stick

Step 17
Before we make a recipe, let's make some variables to hole our ingredients

Technically this is not necessary, but it will make our code easier to read and to write

Step 18
We're going to use the "add" method of the Recipes module

We type the keyword recipes to pull up the Recipes module.
Then we type .add() to call the add method

Step 19
Recipes are stored as a special type of data called an "Object"

Add a pair of curly braces to begin writing an Object


Press enter to add a newline inside the object:

This is for readability.

Step 20
Recipe Objects have three properties: ingredients, shape, and a result

This is a visual model of what our data needs to define:


In the next step we'll write these one at a time.

Step 21
First add the ingredients property

Here we are assigning a symbol for each ingredient:

D -> diamond
O -> obsidian
S -> stick


The ingredients list is also an object

Step 22
Add a comma and start the next property "shape" on a newline
Step 23
The shape is an array and it looks like this

We can use the letter keys from the ingredients object in the shape array

Step 24
How the shape array works

Do not type this in, this is an illustration for you to know when you start making your own recipes:


Each element of the array corresponds to a row in the crafting table

Step 25
You may want to write you array like this if it helps you



this way it looks more like the crafting table:

Step 26
The last property of the recipe is the result

We want our recipe to result in a magicWand

Add a property named result whose value is magicWand.

Check Your Work
Step 27
Deploy your plugin and make sure the recipe you added can be used to craft the Magic Wand
Step 28
Let's make the wand look a bit more interesting

Right now the magic want just looks like a regular stick. Let's make it a bit more magical by adding a hidden enchantment that will make it glow!

Step 29
Since you normally cannot enchant sticks in Minecraft, any enchantment you add will be considered an "unsafeEnchantment"

This code must go after setting the magicWand's item meta


We'll use the .addUnsafeEnchantment() method to add an enchantment to the stick.

Step 30
As part of the itemMeta we add to our `magicWand`, we'll add an itemFlag which makes enchantments invisible

We'll use .addItemFlags() to add the itemFlag.hideEnchants flag to our magic wand's itemMeta.

Check Your Work
Step 31
Make sure everything is working properly

You should be able to craft the magic wand complete with custom display name and lore.

The wand should appear enchanted, but without showing any enchantment text on the item (e.g. Unbreaking II)

Try one of these lessons next:

The Wand Info


MVCode Clubs

Created By

Mvcc logo new aaron


Wand World

Access Level


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