There is a faster way to create three similar blocks. Do you know how? This is introduced in detail later in this activity.
Activity: Minecraft Moving Company
If you’ve ever built the perfect house in Minecraft but wished you had done it in a different location, now you can! You can use coordinates and some of the block operations in the ||blocks:BLOCKS||
Toolbox drawer to copy and paste entire portions of the Minecraft landscape. You can copy hillsides, lakes, and even entire buildings! Let’s create a way to specify an area of the world, then copy it somewhere else.
In this project, you will use three different ||player:on chat command||
commands:
"start"
: This sets one corner of the area to be copied."stop"
: This sets the opposite corner of the area to be copied."copy"
: This creates an exact copy of everything between the start and stop points, placing it at your current position.
Do the activity
Make the chat commands
Create a new MakeCode project called “Move Me” or something similar.
Drag three
||player:on chat command||
blocks into the coding Workspace.Change the name of these
||player:on chat command||
blocks to"start"
,"stop"
, and"copy"
.
player.onChat("start", function () { })
player.onChat("stop", function () { })
player.onChat("copy", function () { })
Create the variables
Let’s create some variables that you’ll use to store the starting and stopping positions. Variables are covered in detail in Lesson 4, but for now just note that you will use one variable to store the (X, Y, Z) location for the bottom corner of the box and a second variable to store the location of the top corner.
- Open
||variables:VARIABLES||
and click the Make a Variable button.
- Name the variable start, and click Ok.
Make another variable
Click the Make a Variable button again.
Name the second variable stop, and click Ok.
Set the variables
Now let’s set the value of these variables based on the player’s current world position.
From
||variables:VARIABLES||
, place a||variables:set||
variable block into||player:on chat command||
forstart
.Use the drop-down menu and adjust this to say
||variables:set start||
to0
.Adjust
0
to||player:player world position||
. From||player:PLAYER||
, drag||player:player world position||
into||variables:set start||
and replace the0
.
let start: Position = null
player.onChat("start", function () {
start = player.position()
})
Print messages
Let’s print out a message that displays the coordinates you saved as the starting position.
- Open
||player:PLAYER||
, and add||player:say||
after||variables:set start||
.
let start: Position = null
player.onChat("start", function () {
start = player.position()
player.say("Hi!")
})
- Click the Advanced tab in the Toolbox to expand the Toolbox categories.
Open
||text:TEXT||
, and place||text:join||
into the||player:say||
block, replacing"Hi!"
.In the first slot of
||text:join||
, enter “Starting Point Set: “.Next, open
||variables:VARIABLES||
, and drag||variables:start||
into the second slot of the||text:join||
block.
let start: Position = null
player.onChat("start", function () {
start = player.position()
player.say("Starting Point Set: " + start)
})
Repeat for the stop command
The code for the stop position is very similar, so to create this you will duplicate the blocks inside start
and just change the new copy a little. This will save you a lot of time. You can right-click any block and select Duplicate to copy blocks. This is a good strategy that speeds up your workflow when you are creating large blocks of similar code!
- Right-click
||player:on chat command||
"start"
and duplicate it.
Now you might be able to see that you could have started this activity in a completely different way. Because you can duplicate, you did not really need to drag three ||player:on chat command||
blocks to the Workspace as step 2 instructed. You could have just waited and duplicated. Let’s try this a different way.
- Delete the empty
||player:on chat command||
blocks for"stop"
and"copy"
.
Let’s just duplicate "start"
two times and change things as needed. "stop"
will be very similar to "start"
, so just change the inside blocks of the duplicate as necessary.
let stop: Position = null
player.onChat("stop", function () {
stop = player.position()
player.say("Stopping Point Set: " + stop)
})
For "copy"
, you can delete the inside blocks and rename the duplicate. In the end, you should get something that looks like the blocks shown here:
let start: Position = null
let stop: Position = null
player.onChat("start", function () {
start = player.position()
player.say("Starting point set" + start)
})
player.onChat("stop", function () {
stop = player.position()
player.say("Stopping point set" + stop)
})
player.onChat("copy", function () {
})
Build the copy command
Now that you’ve set the starting and stopping points, you will create the ability to copy the area in between these points.
- Open
||blocks:BLOCKS||
, and drag the first||blocks:clone||
block (the one with the mask property) into"copy"
. This block clones, or copies, the area from the first set of coordinates to the second set of coordinates. It also copies it into the third set of coordinates.
player.onChat("copy", function () {
blocks.clone(
pos(0, 0, 0),
pos(0, 0, 0),
pos(0, 0, 0),
CloneMask.Replace,
CloneMode.Normal
)
})
From
||variables:VARIABLES||
, drag||variables:start||
into the first slot in||blocks:clone||
. Your block should now readclone from start
.From
||variables:VARIABLES||
, drag||variables:stop||
into the second slot in||blocks:clone||
. Your block should now readclone from start to stop
.
let start: Position = null
let stop: Position = null
player.onChat("copy", function () {
blocks.clone(
start,
stop,
pos(0, 0, 0),
CloneMask.Replace,
CloneMode.Normal
)
})
Test the code
Now let’s test out the code.
- Enter into a Minecraft world where you have a house or some other structure you want to copy.
- Move your player to one of the bottom corners of the structure, and in the chat window, type the command “start”.
- Move your player diagonally to the top corner from the start. In the chat window, type the command “stop”.
- Move your player to an open space in the world where you want to copy the structure, and in the chat window, type the command “copy”.
Did it copy your house or structure correctly?
Complete program
let stop: Position = null
let start: Position = null
player.onChat("start", function () {
start = player.position()
player.say("Starting Point Set: " + start)
})
player.onChat("copy", function () {
blocks.clone(
start,
stop,
pos(0, 0, 0),
CloneMask.Replace,
CloneMode.Normal
)
})
player.onChat("stop", function () {
stop = player.position()
player.say("Stopping Point Set: " + stop)
})
Shared Program: https://makecode.com/_dHhhCoW85JAJ
Copy the wagon from the Oregon Trail World:
Set the starting point at the lower-left corner.
Set the stopping point at the upper-right corner.
Copy somewhere else!
Challenges
Now you can change some things to make your own different and unique situations!
Challenge 1 - Cut and Paste Structures
How would you move something instead of copying it? Play around with the settings of the ||blocks:clone||
block to make this possible. Then rename your ||player:on chat command||
to "cut_paste"
.
Challenge 2 - Move Only the Tree Trunk
How would you implement a cut and paste special? Is there a way to cut only certain blocks from an area?
Let’s try to cut only the trunk from a tree.
Can any of the settings in ||blocks:clone||
help you? See if you can figure out how!
Experiments
Here there are no rules… Copy the code for the experiments and change things around to see what kind of results you can create. Suggestions are given, but do as you like!
Experiment 1 - Walk Through Walls
Can you identify the coordinates in this code?
As a challenge, replace blocks around your character with air blocks. This will make it look as if things around you are disappearing. You can walk through things!!! The air blocks should be four blocks wide, three blocks high, and two blocks in front and behind the player. Try to walk through massive structures, like mountains! You could replace some blocks with air and some with diamonds to create a diamond tunnel everywhere you walk. What other ideas can you come up with?
By playing with the coordinates, you can come up with some pretty interesting situations.