Minecraft Mod Recipes
This page contains a list of ideas for things you can try with your new coding knowledge!
You can combine these ideas with other concepts you learned in your missions. For example, you can use the
postToChat()
function to allow the user to invoke or enable one of these features. You can also use
pollBlockHits()
or
pollProjectileHits()
to trigger an event.
Finally, try to build on these ideas using your imagination!
Contents
Super powers
Instant fire extinguisher
Create a
postToChat
command that instantly spawns a water block over your head. Replace the water block with air after a few seconds so you don't flood the area! Of course, if you're a troublemaker and like flooding things, have at it. It's your world!
Excavator
Write a magic sword or arrow spell that clears a large area of blocks in front of or underneath you.
Construction recipes
Stairway to Heaven
You can use the
range()
to make a
list
of numbers from 0 to any number. We'll use this to build a stairway that goes as high as we want!
- Refresh your memory on lists and for loops in your Python reference.
-
Store the player's current coordinates in
x
,y
,z
variables. -
Create a
for loop
with
range()
to loop through every number from 0 to 30, usingstep
to store the current step:for step in range(30):
-
Inside the loop, use
mc.setBlock()
to set the stair block (id #53) atx + step
,y + step
, andz
.
Run the script and climb away!
Pyramid
Here's how you can create an algorithm you can use to spawn a pyramid of any size on command. We do this by using
range()
to make a
list
of "levels" and then looping through each level in reverse. For example, if we want a 10-block-high pyramid, we start with 10 for the base level, then 9 for the next, then 8, etc.
- Refresh your memory on lists and for loops in your Python reference.
-
Store the player's current coordinates in
x
,y
,z
variables. -
Create a variable called
height
to define how many levels your pyramid will have. For example,10
would give you a pyramid 10 blocks high. -
Use the
range
function to create a list of numbers that represent each level (you can read more aboutrange()
in your Python reference). Assign this value to a variable calledlevels
. -
Create a
for loop
to loop through each level, but use
reversed()
to reverse the list so we start from the largest number and move to the smallest:for level in reversed(levels):
-
Inside the loop, use
mc.setBlocks()
to make a 1 block high cuboid around your position using thelevel
variable:mc.setBlocks(x - level, y, z - level, x + level, y, z + level, block_id)
-
On the next line inside the loop,
increment
y
by 1 usingy += 1
- Set the player's position to the current x, y, z variables so you don't get buried inside the pyramid!
Mini-games
Keeping score
If you want to keep score in a mini-game, simply create a variable at the top of your script and set it to
0
. Then, add points using an
assignment operator
, for example to increase by 1:
score += 1
.
Using game data inside custom functions:
If you need to access the score variable within a custom function in your script, you should store your game data inside another object (such as a dictionary , for example). You can then pass that variable as an argument to any function that needs to modify the data inside.
To try this out, create a
dictionary
at the top of your script called
game_data
and a key called
score
set to
0
. :
game_data = {
'score': 0
}
def add_points(game_data, points):
game_data['points'] += points
# score 5 points
add_points(game_data, 5)
Random teleportation world tour
You can generate random numbers for x, y, z coordinates, and teleport the user to that location. But, you'll need to make sure you don't teleport them underground or too high up ion the air. You can use the
mc.getHeight()
function to get a "safe" Y coordinate. See your
Minecraft API Reference
for details.
Find the treasure
Generate a random x, y, z coordinate and place a special item at that position. Randomly place a treasure within a radius of a few hundred meters (Use google to learn how to calculate distance in a 3D coordinate system). Print variations of "hot" or " cold" depending on how far the player is from a randomly placed treasure, eg: "freezing", "cold", "warm", "boiling", or "on fire!". When the user finds the treasure, print "found it!"
Offer a gift to the gods
Write a script where the player must find a specific item and place that item on a pedestal somewhere in the world. If they place the right item, the pedestal disappears and the player is rewarded with a special item. You could also grant the player the ability to perform a special power. Use a boolean variable to keep track of whether or not the player should has the power.