Midas Touch Spell

Step 1
In this lesson we are going add a spell called "Midas Touch" that can turn anything into gold!

This lesson will make use of what you learned in these lessons:

Step 2
CHALLENGE: Begin by adding a new wand: Midas Touch

You do not need a crafting recipe for this item.

Give yourself the wand by adding it to your setSpell() function and then calling it in the game.

Step 3
We can break this spell down into three parts

You will be challenged to make this in the next step


Important questions:

  • How do you check if an entity has been damaged by an entity?
  • How do you make an entity disappear?
  • How do you make a block appear at a location?
  • How will you reference the location of the entity?
Step 4
CHALLENGE: Add code to your onEntityDamageByEntity function that allows you to transform entities into gold blocks
  1. Find your EntityDamageByEntity event handler.
  2. Add a new if-statement that checks if the damager is holding a midasWand
  3. Remove the entity
  4. Spawn a gold block at the correct location.
  5. Display a message saying the entity has turned to gold!
Check Your Work
Step 5
The result

If you have completed this challenge successfully you should be able to cast this spell on entities while holding a midasWand

In the next part of the lesson we will learn how to make it work on blocks also!

Step 6
Next we are going to use the PlayerInteract event handler to make the "Midas Touch" spell work on blocks!

We can't use EntityDamageByEntity because blocks aren't entities!

Step 7
Targeting the right block

Remember, only blocks that are in range of the player can be clicked on directly.

For this we can use event.clickedBlock:


Anything out of range we will have to use player.getTargetBlock():

Step 8
Just like for the lightningWand, we need to check if the player is holding the midasWand

in the playerInteract event handler:

Step 9
Now we need to create a reference variable named "target"

If the player left-clicks a block: we can use event.targetBlock.

Step 10
If the player clicks the air, we know they meant to click the out-of-range block they are looking at

So here, we will set target using .getTargetBlock():

Step 11
Now turn the target block into a gold block!

You should be able to do this on your own now.

When you are done you should be able to turn blocks into gold from both touch range:

and from out of touch range

Midas Touch Spell 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