The capabilities of your player, other players, or mobs are changed when you apply effects to them. Depending on which effect is chosen, you can either add a special power or reduce the health of a player or mob.
In this project we are going to learn how to apply affects to players and mobs. In this tutorial we’ll apply some effects that will give players some super powers!
First, open Minecraft Education Edition, login, create a new world and open the Code Builder.
To create a new Minecraft coding project you will need to follow these steps:
First we are going to apply an effect to your player that makes you run super fast!
An effect applied to your player will last for the number of seconds you tell it to. This is the effect’s duration. You also give a value for the strength of the effect, called the amplifier amount.
Add the following code to make an interaction so that when your player eats an apple, they are nourished and can run with speed for 10 seconds. Amplify the speed effect by 120.
player.onItemInteracted(APPLE, function () { mobs.applyEffect(SPEED, mobs.target(LOCAL_PLAYER), 10, 120) })
You will then need to add some apples to your inventory (press E) and eat an apple. When you do the code will trigger and you will be able to run super fast for 10 seconds!
If you could see in the dark, you could move around without being easily noticed by other players or mobs. You could also keep building when night comes.
Make a chat command that changes the time to night and apply the night vision affect to your player. Set the duration to 10 and amplify the effect by 120.
player.onChat("night", function () { gameplay.timeSet(gameplay.time(MIDNIGHT)) mobs.applyEffect(NIGHT_VISION, mobs.target(LOCAL_PLAYER), 10, 120) })
We’ve all dreamed of being able to fly. Well, make it happen on your command! Create a new chat command called fly. In the chat command, apply the levitation effect to all players and all mobs so that everyone will fly. Set the duration for 5 and use just 2 for the strength of the effect.
player.onChat("fly", function () { mobs.applyEffect(LEVITATION, mobs.target(ALL_ENTITIES), 5, 2) })
Can you take the heat? Well, you can if you’re fireproof. Make a chat command named fireproof. In the command, apply the fire resistance affect to your player and fill in fire all around you. When you use the command, see if you can walk through fire without getting burned!
player.onChat("fireproof", function () { mobs.applyEffect(FIRE_RESISTANCE, mobs.target(LOCAL_PLAYER), 10, 120) blocks.fill(FIRE, pos(-5, 0, -5), pos(5, 0, 5)) })