Command Blocks (CB)

In these instructions you will learn the foundations of using command blocks and connecting them together.

Here you will find their division and a description of individual CBs, how each type of CB works.

Also we are describing here the way to make settings inside command blocks.

The ending of the instructions contains a description of how to copy from command lines into command blocks. 

Smart door with the /execute command

In this tutorial, we’ll look at a simple way of building a smart door that automatically opens when one of the players approach it. The steps in this tutorial can be used for more projects that react to player presence, such as smart lamps.

What you should already know

  1. How to work with command blocks – read about it here
  2. How to use /fill – read about it here
  3. How to work with Minecraft coordinates
  4. How to write block names in commands

Steps

1. Preparing the build

Prepare an area in your world where’d you like to build your smart door. You can frame it with blocks. Dig a hole below the frame, this is where your commands will go.

2. Preparing the /fill command

First, we’ll look at the command we will open and close the door with. It will be the /fill command, which can fill a certain area with a specific block.

Mark the two corners of your door with blocks. What block it is doesn’t matter. To help you understand, the picture below uses two coloured blocks. Fill in their coordinates in the /fill command. Then add the identificator of the block you’d like to use for the closed door’s appearance.

/fill <first corner coordinate> <second corner coordinate> <block identifier>

Try sending the command in chat. The door should “close”, get filled with the block you selected.

Copy the finished command (scroll up with the up arrow and select all with Ctrl + A, and copy with Ctrl + C) and paste it in a command block aside, where it’ll rest for some time.

PRO TIP: You don’t have to use a forward slash in command blocks (/). Your work will be a little easier later on if you delete it now.

3. Detecting when a player is nearby

We can use the /execute command to find out whether a player is nearby. The /execute command allows us to change the way Minecraft commands are run. One of its functions are conditions – such as “Run a command only if someone approaches.”

Place down a command block below your door and open it. When you begin writing the execute command, Minecraft will hint you with some options on how to use execute. Only two options will interest us for now: if and run. We’ll start with the if option.

If modifies the command so that it runs if a condition is fulfilled. In the case of our smart door, we will detect whether a player is nearby. We will tell execute if to check for entities (which also include players).

Then, the command will have to know who to look for. You could write a friend’s username after entity, then you could write a command that would only run if your friend is connected to your world. The door should let everyone in though, so we will use a special placeholder called @a, or all players. But that would mean the command would run if it found any players, and wouldn’t check how far they are. Which is why we’ll have to write a filter.

Type an opening square bracket right after @a without a space, this will open new options. If you don’t know how to write a square bracket, it is best you find it on the internet for the layout you’re using.

A filter in Minecraft can specify what entities we’re looking for. You can think of it as “All players, but only those that…” in Minecraft form. A simple filter that we’ll find quite useful is distance. Write it after the square bracket and let Minecraft autofill an equals sign (=).

Now what remains is to write the range of blocks we’re looking at. This depends on the size of your door. We’ll use 0..5, which means “0 to 5 blocks away”.

IMPORTANT: if you only write one number instead of a range, Minecraft will only look for players exactly 5 blocks away. If you only wrote 5, the command wouldn’t react to players 4 blocks away, 3 blocks away…

/execute if entity @a[distance=0..5]

You can finish the filter by writing a closing square bracket, it should be coloured in blue.

That covers how we check if a player is nearby.

4. Putting our door in service

But what happens when a player actually approaches? You can set this with the run option, which you’ll write after your current command.

Now what’s left to do is to write the command to run when our previous condition is fulfilled. Remember the fill command that we wrote earlier? Now it’s time to make use of it. Save your unfinished command by clicking Done and return to where your fill command is. Copy it from there and paste it back in the command block, right after run.

IMPORTANT: The command written after run doesn’t include a forward slash that is normally used in other commands! If you didn’t remove it earlier, the command will be in red. You can click your mouse near the / and delete it, if you need to.

Our command checks whether someone’s standing at the door. So if someone’s standing there, the door should open. If your fill command is set to fill the area with a block, the door would close! Delete the name of the block from the command and replace it with air. That way you ensure the blocks disappear (become air).

The command is done! Don’t forget to mark the command as repeating (Switch from Impulse to Repeat, it’ll change colour to purple) and always active (Switch from Needs redstone na Always active) to eliminate the need for redstone. Save by clicking Done.

If you now stand at your door and try to build in it, the blocks will disappear. Minecraft knows that someone is standing at the door and is removing the blocks inside (your command is opening the door).

If you walk away from your door, it’ll stay open. We need to create a second command that’ll close the door. Return to your command block and duplicate it (hold Ctrl and press the mouse wheel). A copy of your command block will be placed in your inventory, you can place it somewhere else. Place the second command block next to the first.

Open this new command block. We need to edit two things. Hold the left arrow key and scroll to the beginning of the command. We must change if to unless.

The unless option works as an opposite to if; the command always runs, but not if the condition is fulfilled.

Now go back to the end of the command and change air to any block you want to use to resemble a closed door. We chose oak planks (written as oak_planks). Now, if there’s nobody standing at the door, this command will fill it with blocks.

Save the command. We’re done!

Wrapping up

The execute command is a useful way of automating things. Fill isn’t the only command you can use in /execute. You can create a smart lamp with /setblock, or a teleporter with the /tp command. All you need is an idea. Here’s a few challenges you can try:

  • Can you make a door that reacts to pigs instead of players?
  • Can you change the filter to ignore players in spectator mode?
  • Can you make an area that heals nearby players?

/setblock EN

In this tutorial, we will look at how to use the /setblock command. It is very similar to the /fill command with the difference that /setblock places down or mines exactly one block.

/setblock

  • comand similar to /fill – places only one block

/setblock <coordinate> <material> <optional_attribute>

/setblock 132 76 -904 minecraft:redstone_block

/setblock 132 76 -904 air destroy (can be used to mine a block at a coordinate)

  • coordinate – relative or absolute coordinate
  • material – any block in Minecraft (including air)
  • optional_attribute – one of three options (usually not necessary, can be left out)
    • keep – places a block only if the current block at the given position is air
    • replace – always replaces the block at the given position, this is the default if the attribute is left out
    • destroy – if there is a block at the position it is mined as if it was destroyed by a player and replaced with the given block

If you want to build in the air, you can use this command to place a block at your feet (no need for a huge pillar) /setblock ~ ~ ~ stone

Conveyor belt

finished build

In this tutorial, we will look at the easiest way of building a conveyor belt for your factory.

The build itself is very simple, but requires knowledge of the following:

  1. /setblock – read about it here
  2. /clone – tutorial to be added
  3. basic work with command blocks – read about it here
  4. creating a redstone clock – tutorial to be added

If you are familiar with these, you can read further.

Steps:

1.

Prepare a basic build, it should look like a long conveyor belt. If you don’t want others to see blocks appear and disappear, you can cover the first and last two blocks. In this picture, only one side is covered.

basic build

2.

Mark the first two coordinates for the /clone command. Select an area above the belt so that one block on the belt is not included (see the picture below). This is because we will move the selected area forward by one block, and this block will be replaced.

Then, we will start typing the /clone command and use these two coordinates, the resulting command will look like this:

/clone <orange_block_coordinates> <green_block_coordinates> (the order doesn’t matter here)

/clone -197 5 -165 -209 5 -165 (example command, notice how only one number changes – the first one, which resembles the X axis)

the two coordinates of the command
the yellow area plus the blue block resemble the area we’ve selected, the blue block is the most negative block of the area

3.

The third coordinate is next – we will find the most negative coordinate in the area, and move this most negative block by one space in the direction we want our belt to move in – this is our third coordinate.
In the picture with the area in yellow, the blue block shows where the most negative coordinate is. In the next picture with the area in orange (which displays how the area will look after we’ve moved it), the blue block shows where our third coordinate is.

area after moving – the blue block resembles the third coordinate

4.

Now we will finish the /clone command. Because the source and destination areas overlap, we must add two optional attributes:

replace – clone the entire area including air blocks

move – the area is cloned to the selected coordinate and the source blocks are replaced with air

The resulting command should look like this

/clone <orange_block_coordinate> <green_block_coordinate> <third_coordinate> replace move

/clone -197 5 -165 -209 5 -165 -208 5 -165 replace move

(notice that the third coordinate differs by exactly 1)

5.

We still need a way to place blocks at the start of the belt, we can do this using the simple /setblock command.
Select the coordinate of the belt’s start (it’s the orange block in the first picture)

/setblock <belt_start_coordinate> <selected_material>

/setblock -209 5 -165 minecraft:coal_block

6.

We are almost finished, now we need to build a simple redstone clock that follows these rules:

  1. it will alternate between redstone and command blocks
  2. the delay between any two command blocks has to be the same, for instance, two repeaters with a delay of one tick = one repeater with a delay of two ticks
  3. the number of command blocks in the clock will be one more than the gap between individual blocks on the belt

These rules may sound complicated, but they’re easy to understand with a picture. Below you can see a clock prepared for a belt that has a 3 block wide gap between the moved blocks. The blue numbers show the repeater delays.

example clock, blue numbers show the delays of the repeaters

7.

Paste the /clone command we’ve previously written into the command blocks.

PRO TIP: You can also only prepare one command block and paste the command there, and then copy the command block with the command already inside by using CTRL + scroll wheel click. You can then place the remaining command blocks to finish the clock.

8.

The belt should work now (you can try it out by activating the clock and placing blocks on the belt), but we still need to spawn blocks on it. We can do this by placing a chain command block (the green one) on any command block in the sequence and pasting the /setblock command inside.

Know that the chain command block must be set to always active for this to work.

correctly placed chain command block – it is important that the arrow points at the chain CB

Done!

You only have to activate the clock now, and your belt will work.

All used commands:

/clone -197 5 -165 -209 5 -165 -208 5 -165 replace move

/setblock -209 5 -165 minecraft:coal_block

Couple of tips to finish off:

  1. You can make your belt turn by placing another one perpendicular to the first, just make sure their areas in /clone overlap
  2. We recomment making the gap between blocks at least two blocks wide, so that the belt actually looks like it is moving (instead of alternating between two states)
  3. You can also move more complex builds on a belt, the belt’s width can even span across multiple blocks. To generate complex builds at the start of the belt, it is best you first build it elsewhere and clone it, replacing the single /setblock command

Minecraft Foundations

This first post is the complete foundation of how to play, move and build in Minecraft.

Here you will find useful things, such as instructions on how to fly and what the inventory contains.

 

Basics of game Minecraft

Movement + Building

 

  • Forward        key W
  • Back              key S
  • Left                key L
  • Right              key D
  • Rotating character   Myš nebo Touchpad
  • Skok                 klávesa Mezerník
  • Skrčení         klávesa Shift
  • Sprint                klávesa Ctrl nebo dvojité kliknutí na klávesu W

Ničení bloků = Levé tlačítko myši
Stavba bloků = Pravé tlačítko myši

Létání

Aby postavička vzlétla musíme mít zapnutý creative mode (/gamemode creative @plepší způsob přepínání zde 

  • Vzlétnutí         dvojité kliknutí na klávesu Mezerník
  • Klesání dolů        klávesa Shift
  • Pohyb ve vzduchu je pak stejný jako pohyb na zemi (kapitola Pohyb)