Tutorials/Command blocks and functions

Command blocks are used for creating custom maps, automating multiplayer or just as a fun tool to play around with. For more detail, see the command block page. Before you start with this tutorial, it's a good idea to look at coordinates in case you don't know what to set the x, y, and z values to in some commands.

General applications
Command blocks can be used, among many other things, to change the difficulty, change the state of the weather, or give you predesignated items. They are particularly useful for the  and   commands, as they are only available in cheat mode otherwise. The  command is especially useful, as it allows you to change the current time to a preset time at the press of a button.

Command blocks can also be used to make text appear in the person's chat menu. The code to do this is, or. If the @p parameter is present only the nearest person will see the message. If a username was specified, the username will be sent the message. You can also type:  and whenever someone walks over it, it will say: "@ whispers to you: ''.

Changing the difficulty is accomplished by  and x=0 to 3 or the name of the difficulty (ex.  ).

Another way to use command blocks is to use  to teleport between different bases in your world.

Usage of Command Blocks
There are many things you can do with command blocks. Here are examples of some of them:

Give a random player an item and then tell everyone
The Cookie Giver 5000X

This contraption will give a random player 5 cookies, and then post it in the chat, so that all players on that world will see it.

First, make an objective called "cookie".

Now its time to place the command blocks and set them to perform certain commands. The 1st command block should say:

Then, the 2nd and 3rd command blocks should say:

4th command block:

"I" = input.

Teleporting
You can teleport by using the   command, where y is the vertical difference between the upper and lower elevator entrances. The elevator can also be made to tp a player to any x y z coordinate just by leaving out the ~ before the numbers. When ~ is left in the command, the normal x y z is set to 0 0 0 where the command was made, such as standing on a pressure plate or wherever the player is standing when the command block received power. If a pressure plate was at the x y z coordinates of -36 96 -12 that ran to a command block with a command of  it would tp the player to the coordinates of -33 100 -7. The same outcome can be achieved by having the command of  one block must be subtracted from the x and z axis to get to the right coordinates.

Security System for Players
Command blocks can also be used to make a security system. Just put a pressure plate which triggers a command block in front of an iron door, which will be the entrance to your house. Insert the command:. For mobs, a simple fence or lava moat will do.

Moving Sidewalk
A similar concept to the elevator but made to move a player along the x or z coordinates. This can be created by: command_block 1 replace {Command:/tp @p ~-1 ~ ~}
 * Use the /fill command with your coordinates. (/fill x y z x2 y2 z2)
 * For the block you fill it with, use this:
 * Edit the coordinates inside the brackets to change the direction you will move
 * Place pressure plates on top of all the command blocks.
 * Step on it

You might want to turn command block output off....the chat will explode in your face.

Eternal Day


Note: As of 13w24a, there is a gamerule, doDaylightCycle, which can be used to obtain eternal day by typing in the chat,, and then.

By using cobweb and a minecart, you can skip nights using. A minecart takes 31 seconds to fall through a cobweb. Therefore, by using 23 stacked cobweb with a detector rail and several powered rail will keep the sun in the sky.

Alternatively you can use an item de-spawning on a wooden pressure pad. The item de-spawns off of the pad every 5 mins, at this time it triggers a command block reset of the time to 0, also it triggers a dispenser (or dropper) to drop a new item on the wooden pad. 5 Mins is the day cycle and will trigger before mobs spawn. This method however is limited to 64x9 = 576 cycles = 48 IRL hours of gameplay with that chunk loaded. In Minecraft version 1.5 (snapshot 13w01a) and higher, hoppers are added into the game that can pick up items and deposit them into blocks with an inventory. A mob grinder can keep the dispenser full with gunpowder, arrows, and rotten flesh. Another technique is to simply use a command block to create the item out of thin air (e.g.: ). The advantage to this is that it has no 64x9 item limit like using dispensers does.

Both of these methods require the chunk to be loaded to allow the system to work.

Alternatively, you could connect the command block to a repeating redstone pulse, such as a five-clock, some type of loop, or a daylight sensor as seen on the right. To prevent this filling up the chat box, set the gamerule "commandBlockOutput" to false using the command. Note: This method can be used to set a variety of things by using a different command. (I.E. to have eternal sun, add another command block to the loop and use the command )

Also, to make it toggle-able, use one of these designs, but put an AND Gate before the command block, with a lever on one side, and the mechanism on the other side.

Using a daylight sensor is a more direct approach for eternal day.



The sensor deactivates the redstone torch which will activate the Command Block which will set the time to 8000 when there's not enough light for the sensor to power the redstone torch across the far distance. In other words, the command block will set the time to Noon when it's dark enough. The light level when the command will be activated varies with the distance of the redstone wire. The time it sets to varies with the time typed in the command block.



To make it, first, you place the daylight sensor on an open area. Then you place some redstone wire away from it. The distance of the redstone wire depends on your need of precious time. You can only have a max of 15 blocks worth of redstone wire away from the daylight sensor to send the signal to its destination. Next, you put a block on the other end of the redstone. Put a redstone torch on the block's side and a command block on top of the torch. Right click the command block and start with "/time set" and enter a valid time value and the end. The value depends on when you want to set the time to. 14000 is night and 8000 is noon.



This design can be used in maps to keep it a certain time of day/night. This simple contraption can only be used in Creative mode or when you enable cheats.

There is an alternative, more compact design. If you put a comparator facing away from the sunlight detector and a 15 strength redstone line (one redstone with a torch) into the second input. Then set the comparator to subtraction mode. The comparator will activate right after noon.

Easy set day/night
Place a daylight Sensor atop a command block then right-click on it to set it to a night sensor. Add "/time set day" to the command block. Or if you want it to always be night, add a daylight sensor and don't right-click it, then add "/time set night" to the command block.

Wireless redstone
Wireless redstone can be achieved using command blocks and the scoreboard system. The process involves using a scoreboard variable that is searched for by a command block attached to the output of a clock circuit. A comparator is then used on the wireless output command block that will trigger when the variable is found true.

Wireless redstone can also be achieved by using objectives instead of variables. If the output command block is set to try and remove a non-existent objective, a redstone signal can be created by adding said objective via command block or chat command. The advantage to this method over the variable method is that it is not dependent on players.

To do this, place a command block at the input and type the command: /scoreboard objectives add dummy. At the output location, place a command block, type, hook it up to a clock, and put a comparator then a repeater leading out of the command block. Then just use the repeater as an output.

You can also achieve wireless redstone by using the command instead of the scoreboard system. All you have to do is let the command block set a redstone_block to the destination coordinates - together with an air block (or anything that does not output a signal) being set to the same coordinates from a command block connected to the inverted signal.

Wireless Button
You can place a button on a solid block and hide a command block behind. In the command block put, replacing x y z with the coordinates you want, for example next to a note block. As a result you create a pulse at a remote location by pushing a button.

This can be done in reverse with any block, technically, but buttons, levers, and other interchangeable blocks add an interesting effect. It's surprisingly simple, despite the mysteriousness on servers. It uses the 1.8 command. The setup is simply a command block, a comparator to translate the command into a redstone signal, a block to be tested for, and a clock to repeatedly activate the command block. Here's the example for a button:. You use the coordinates and name for the specific block you want to test for, interchangeable for any block that changes data value. The number  after the coordinates corresponds the data value of the button that we want the command block to test for. In this case we want the command block to activate when a button facing west is pushed, so we set the value to.

Note: this value changes depending on which direction the button/lever is facing. The initial value for a button facing west that is not pressed is. When a button is pressed, it adds a value of  to the initial state, so a button facing west when pressed would then have a data value of. Refer to: Button & Lever for the data values.

Starter Kits
By using m=, you can make a kit on a server/custom map that can only be obtained once! First, dig 3 squares down in the ground, then place a row of command blocks (one for each item in the kit). In the GUI, type. Do this for each item you wish to give. Make an extra command block that has the command, then string redstone across all of the command blocks (this can be done easily by sneaking and placing). Fill in the hole and place a pressure plate over it. When players walk over it, they will get the desired kit of items and it will change their gamemode so they cannot receive it anymore (unless cheats are used).

Note: This method can also be done by using the method above only using (First name your kit do ) scoreboard commands! for the row of command blocks giving you the items and  to make it a one time use. Also you can make more than one kit if you repeat the steps and use a different ).

As a replacement for pressure plates
If you don't like the fact that pressure plates only blend in with only gold, iron, stone, oak, spruce, birch, jungle, dark oak and acacia wood planks, you can use command blocks as a replacement. Pressure plates can be replaced with a command block by using the command with a range and a clock circuit. The command  will test to see if any players are within a range of 2 (the command block itself plus 2 more blocks in every direction). Range 2 is the range you want for a command block under a floor. Keep in mind that it will produce a globe shaped trigger area (rather than a cube), so a range of 2 makes an approximately 5x5x5 area and a range of 1 makes a 3x3x3 area (more like a + pattern with an extra block above and below the center). You can get around this by using the dx, dy and dz arguments.

Alternately you can specify xyz coordinates in the code (e.g.  but be warned that you cannot shrink the range to the 1-block point. As with the non-xyz version range means center block plus range number of blocks around it, which makes sense from a command block (where "just the center block" would mean you have to be standing IN the command block) but doesn't make sense here. At any rate a range 1 sphere (+ pattern with an extra block on top and bottom) can be buried underground with just the top sticking out, provided you know no one will be walking through the bottom 2 layers of the globe. Trying this with the non-xyz version of the code would require the command block itself to be embedded in the surface of the floor where it can be seen.

Important note: When writing the code in brackets [], do not put spaces between commas ,

Bad: [x=0, y=0, z=0, r=1]

Bad: [x=0 ,y=0 ,z=0 ,r=1]

Bad: [x=0, y=0 , z=0 , r=1]

Good: [x=0,y=0,z=0,r=1]

Commanding Passwords
You can now create passwords with command blocks, using. Place a command block. This will be the one you put input in. Place another command block, and type in the command. Here's an example:. Place a comparator connected to the second command block, and place a button on or next to it to power the block. Now type "That's Numberwang!" (without quotes). If the second command block properly finds the first, the comparator will activate whatever it's wired to. If you want the first command block to reset so the password isn't used by someone else, also place a command block with  that activates after the.

If you don't want to let people edit your command block, you can test for a sign instead, but this means having to test for the password separately on each of the sign's 4 lines. To add a touch, you can fill the sign with air, but remember to give it back using

The Destroyer
This allows you to destroy a cube of materials around you as you walk, using. The command is. Attach a clock or some sort of repeating device to it, and the cube of air will be created wherever you go. Basically,  takes out a specified amount of space, similar to setblock, but it uses two xyz's and fills the space in between them with the material you choose. In this case, that material would be air. Now, every time you move, it will fill a 3x3 cube of air around you. A destroyer is great for enemy bases, or simply being a crazy griefer.
 * This also deletes water, so you basically become a moving sponge.
 * This works in any game mode, including spectator mode.

Landscaper
This is a reversed version of Destroyer. . This puts a 3x3 grass square under your feet. When using this, make sure not to jump, as this will create many problems.

Spawners
Command blocks can create spawners using the setblock command, e.g.: Anything that counts as an entity can be spawned (except a player), which includes all mobs, as well as minecarts, fireballs, arrows, snowballs, ender pearls, custom thrown potions, fireworks, primed TNT, falling sand, red sand, or gravel, paintings and item frames, experience orbs, and even dropped items of any type.

Pig, cow, or chicken spawners can be placed in the butcher's backyard in a village to create a constant meat supply. E.g.: Note that the spawner in the last code example will spawn a chicken riding a pig. There doesn't seem to be a limit to how many levels of riders you can use. For example, you could create a chicken riding a pig riding a cow riding a horse riding a silverfish riding a villager ("Say, that's a mighty odd hat you have on, Farmer Brown").

Please note that if you want to use the RequiredPlayerRange tag you have to use the MaxNearbyEntities tag as well. The same thing applies to MinSpawnDelay and MaxSpawnDelay. Lastly, note that the y value used in both of those spawner example codes was ~-1, which (assuming you're not flying) will put the spawner in the surface level of the ground at your feet.

If you don't want to target a specific player, you can use,  , or   instead of. Keep in mind that you can use @p (which means "closest player") in player issued commands as an easy to type 2 character replacement for your own name as the closest player to you will always be you.

Booby traps
The most lethal booby trap would be a command block set to teleport someone into the void.

As of 1.8, you can do in a command block below a block with a pressure plate to make a multi-use landmine that kills all nearby entities upon stepping on it (including players, item frames, and paintings)

Note that booby traps that use @p can be dangerous due to the fact that non-player entities could trigger them (if something like a pressure plate is used), resulting in the teleportation of the nearest player, no matter how far away they are and regardless of the fact that they haven't actually stepped on the plate. To get around this, you can either use the command as an invisible pressure plate, or you can do. Hook a clock circuit up to a command block programmed with, with the coordinates changed as appropriate. Note that as of 1.8 a range of zero can now be specified.

Teleporters
It is possible to make teleporters using the command block. (e.g. code: ) Taking it one step further, a teleporting station can be made, with multiple button-activated teleporters that each teleport to different locations. Scouting and testing teleportation destinations first is advisable, to make sure players don't end up stuck inside blocks or in other unintended places. If you appear in ground while testing coordinates, use to get out (may require multiple uses).

If you use the teleport command with the command block, you can use relative coordinates in the destination coordinates by placing an  in front of a Coordinate (e.g. code:  This would teleport the player 8 blocks into the air).

Commands that use coordinates (e.g. or ) add 0.5 to whole numbers when no decimal follows. This is so you appear centered over the block you appear on instead of at the edge or corner of it. For example, the number -33 would execute as -32.5, and 187 as 187.5. To prevent this behavior, add .0 (25.3, 90.0) after them, as these values are executed left as-is.

With the 1.8 update, you can now also teleport minecarts or boats, with you in them. The command is.

Command-Piston-Repeater Fun

 * Command block: /setblock x y z minecraft:sand
 * 1st Piston Front: Showing to set /setblock x y z to that position

Fast Pusher

 * Repeaters are risen by 1 block from 1-3 so you can see them
 * 1(Repeater): Set to 1
 * 2(Repeater): Set to 3
 * 3(2 Repeaters): Set to 4 and 2
 * 4(Repeater): Set to 2(Default)
 * 5(2 Repeaters): Set to 4 and 1
 * 6(2 Repeaters): Set to 4 and 4
 * 7(Repeater): Set to 2
 * 8 and 9(Repeaters): Set to 4 and 4

Slow Pusher

 * 1(Repeater): Set to 4
 * 2(Repeater): Set to 4
 * 3(Repeater): Set to 4
 * 4(Repeater): Set to 1(Default)
 * 5(Repeater): Set to 1
 * 6(Repeater): Set to 1
 * 8(Repeater): Set to 4
 * 9(Repeater): Set to 2
 * 10(Repeater): Set to 2

Using Command Blocks in Single Player Non-Creative Maps
By swapping gamemode it is possible to use command blocks in single player outside of creative mode. Simply swap to creative mode with the /gamemode 1 command, set the command block command to whatever you want, then swap back to /gamemode 0. The command block only needs to be set in creative, but will still function once back in normal.

It can also be used to teleport to certain areas (for ex. a far-away Stronghold, a deep mining operation, or a floating island). If it took you a very long time to get there, and if you don't mind sort-of cheating, then you can set up a teleport system. Make sure that you are on Creative mode while setting it (use the command /gamemode 1. If you don't have cheats enabled, open the LAN and set the cheats on), but you can still activate it in Survival mode. Type this command in when having the Command Block GUI open /tp @p x y z. Then, activate the command block with redstone (including buttons, levers, and pressure plates), and you will be sent to your far-away destination. You can set up multiple different teleports. This can also be used when doing a big project that spans over a very large area or if you are transferring chests to from an old house to a newer house.

Adventure Map Making
If one wishes to create a singleplayer adventure map, do  to allow all other commands (see below) to be used.

Multiplayer applications
This section details the applications of the Command Block in multiplayer.

Through, one can create teleporters for public use on a server. Can be applied to a range of scenarios. For example, one could make a system of portals in a particularly large world in which all portals link to a central hub, which contains portals to all other portal locations creating a sort of "Fast Travel Hub"
 * Teleportation/Transport

By using the /tp command and an external Minecraft world editing program, such as MCEdit, one can copy a landscape, paste it in a faraway location, and alter a few blocks. Wire a pressure plate or tripwire at each site, so that after a short delay to admire the scenery, the player is teleported using the /tp command in the command blocks. If a large amount of these copied and altered locations are wired so that the player teleports to them in sequence with a slight delay in between each, then this creates the illusion that the scenery around the player is moving, similarly to the techniques used in stop-motion animation.
 * "Stop-Motion Animation"

[Note: If you are using 1.8 or its snapshots, you could use /clone with lots of different copies of it, slightly altered bit by bit, and then just clone the areas into one spot in sequence. That way the player doesn't have to be teleported, but the landscape around them can be animated as the clone commands copy the various animation "frames" near the player sequentially.] Through, one can create a lottery. Keep in mind that now,  will directly put items into one's inventory, instead of throwing them on the ground in front of the character.
 * Lottery

As mentioned above one can create a lottery but that lottery is usable by the public. A simple edit can change that... First create a new objective. (For example: ) Then use this command on a command block   to enter players into the lottery then do   to start the lottery and only the players you choose can be in the lottery!
 * LotteryII

By rigging a clock to a command block and using  a whole bunch, you can force a player to stay at a certain place. If you do this it would be advisable to either turn off commands in your chat settings or do. Using the "Range" and "Minimum Range" parameters, you can have it teleport players back only when they're a certain distance away.
 * Jails

Alternatively, giving the player certain status effects at high levels using the  command can mimic the effect of a jail. Use  to keep the player from moving, and   to keep the player from breaking things. If you really want to kick it up a notch, poison the player (use one of the previous two commands, but replace the first number with 19).

By using the parameter, only players in Creative will be affected by the command block.
 * Admin Only

If you place a command block connected to a redstone pulse you can set  for hilarious results. This could be a way to get creative mode people to change to survival and is also really fun to watch.
 * Fun anti-creative mode trap

By using  in a command block one can create announcements that could play even when the admin/owner wasn't there.
 * Announcements

By using, you can scan people for items. If you want to remove certain items, use. For example, on a server that doesn't want griefing you could have a clock connected to a command block set to.
 * Security Scan

Using, the command block can report the nearest player. If the command block is placed after a finish line, it will say the finishers in order. As of patch 1.7, you can also do  and when activated the message "THIS IS A MESSAGE" will come up on the chat system. You can also color the text using "color" at the end of the next command.
 * Race Referee

Creating a "Creative Only" zone is possible through command blocks, but it is complex and more of a case-by-case basis. The basic idea would be to create a "fence" of command block affected zones so that, once a player flies in creative through it, they would be changed to survival or adventure mode. A "World Guard" zone would be a lot simpler, just have a command block do  and when people leave, just have a button to change them to survival.
 * Creative Area/World Guard

You can use  so players cannot steal each other's items. Also, using  and   to help move players around while in PvP competitions.
 * Improving PvP without Plug-Ins

You can easily give people a starter kit with a button without plug-ins:. To prevent people pressing the button a second time and again getting their kit you can make two command blocks activated in order: 1. 2.
 * Starter Kits

Through 1.7, you are now able to create a colored, clickable message you can send to anybody. The command is. Do not confuse with. The basic format is An example would be. Simply place a comma and space with each addition. If you want other players to be able to click it, use. Here's the example:. This means when the player clicks the text, it will give them a stack of cooked pork. If you just want to tell them something without running a command, replace  with   and   with. Then just type the value text as a regular sentence, no slashes. If you want an easier job of it, here are a few McEdits: SethBling's McEdit Filter: ColorCommandBlockText
 * Special Colorful Words

When a player walks over a pressure plate, it can trigger a command block with.
 * Alarm System

Using coordinate and maximum parameters you can teleport everyone within a specific area to another specific area.
 * Remove Players

If a certain player has been very nice, regular, or helpful to the server but not quite meeting the requirements to be promoted to an admin, you could have a room full of buttons connected to Command Blocks with helpful effects, like giving the helpful player a stack of diamonds or a bedrock block, then have it connected to another command block, sending them to the spawn point. (It is VERY important this room is reinforced with bedrock, hidden, and you can only get in by teleporting to its co-ordinates to avoid abuse).
 * Reward Room

(Command:  and   (to start or stop a thunderstorm))  Assuming only admins can get to it, a weather machine can be quite useful, you can turn rain on and off at will. One of the more helpful uses of this technique would be to use a combination of villagers (they run inside when it rains) and some form of redstone machinery to create and automatic rain disabler, this would allow you to shut off the rain almost immediately without needing to use the command, or to have an admin present. It can also be used to create, and/or end, a scenario where it is more advantageous to have rain as opposed to sunlight, and vice versa; such as during a forest fire, or when a thunderstorm is spawning monsters.
 * Weather Machine

with  and , you could make an obstacle course or maze that when finished will give a player a prize, and will teleport them back to spawn or some other area.
 * Obstacle Course prizes

By making two similar places on one map, you can have a button activate a command block to tp you from one to another, while also changing the time of day. This can be used to look like time travel.
 * Time Machine

By using a condition such as  hooked to a short clock and one or more TNT blocks via a comparator, the command block can act as an undetectable proximity mine against all players except the placing player.
 * Proximity Mine

By using a condition such as, the command block can detect a door's owner within a certain radius and open a door for them, and only for them.
 * Secure Doors

By using a trigger objective, you can create commands that players can use on a server.
 * Commands

Warp command example:

First, add the objective:. Place a command block connected to a Redstone clock with the command. Then place another command block connected to the clock with the command. Place a comparator facing away from that command block, activating a command block with the command. When a player uses, they will be teleported to the   coordinates in the command block.

Application in custom maps
This section details the applications of the Command Block in custom maps.

One map that takes advantage of a lot of the features of the Command Block is SethBling's TF2 Map "Dustbowl" in Minecraft.

http://www.youtube.com/watch?v=_f2brU8hBWc&feature=plcp

Another example is the Hypixel's Gladiator Arena in which the fighting system is almost only based on the Command Block.

http://www.youtube.com/watch?v=jryJkWcqmzM

Sometimes it's important in a map to keep the command blocks silent, may it be to keep the magic of the suddenly appearing items in the inventory, or because the channel telling that the player was teleported, it can break the mood of a map. To keep them silent (except when you ask them to speak), just use the.
 * Silent Command Block

Using pressure plates or tripwire, make areas (like a castle for instance) a different difficulty (for this instance I will use peaceful). the doors could have tripwire hooked to a command block that changes ones difficulty to peaceful, creating a sort of "Safe Haven". one could also do it the other way around, creating a more dangerous zone, such as arenas having the difficulty of hard, rather than normal or easy.
 * Safe Haven/Arena Fight Zone

Using parameter, you can affect those who are in Creative, or survival with parameter.
 * Detecting Cheaters

This is a simple one, just have a system of tp-ing command blocks at the entrance/exit of a place, and you can build the interior somewhere else, allowing you to cheat space restriction. (example of use: you want interior walls to be wool, but exterior walls to be wood (normally 2m thick walls). You can make the outside of the house be 8x10 m, and the inside of the house be 8x10 m.) Or, have the inside of the house 20x20m instead! Say hello to a new TARDIS!
 * It's bigger on the inside

By using the  command, one can easily make a button-activated checkpoint.
 * Save game

As said before, there is a command that makes the player able to keep their inventory upon death:. Simply connect this to a pressure pad before a parkour level over lava and you don't have to use any kind of chest minecart (especially useful when the player has it's full inventory, which is bigger than a single chest).
 * Lava parkours

It's true that the  command can be useful because you don't have to wait for the night to create a checkpoint, but sometimes you may want to have a BUD switch connected to the bed or something similar, so that you don't have to type the command in every time. To do this, you just need to have a pressure plate (it's more discreet) connected to a block with the  command, and it will set the time to night so the player can sleep.
 * Still want a bed?

Many times, a player will be building something, and it will start raining or start to get dark, which both can be disturbing to the player. Fortunately, you can use commands to turn off the rain, as well as make the sun go back to sunrise. To toggle rain on and off, just use the  command, replacing the input with whatever you would like to do with the weather. Use  if you want to clear the weather, or   or , if you would like to toggle on rain or a thunderstorm. For example, if you want the weather to be rain but not thunder, type in the  command.
 * Time and weather following the scenario

Along with this, you can also use  with as input a number:   is sunrise,   is midday,   is sunset and   is midnight. So, if you want to set the time to sunrise, type in the chat:.

Note: In the 1.8 you can lock the difficulty for a specific world.
 * Detecting Players who switched to Peaceful

Create a hostile mob (so it disappears when switching to Peaceful) that never despawns if the player is far away. To do so, use a name tag on the mob (or third party software if you are playing in a version previous to 1.5.2) and place it on a pressure plate. Make sure it will keep it pressed infinitely, so make sure surround it with 2 high blocks or fences, so that it can't jump or walk away. Make a redstone circuit that causes a command block to activate when input from pressure plate ceases to exist. Place a message inside the block that informs the player on chat that the map has been broken and must be redownloaded. This way, switching to Peaceful will cause the mob to vanish and activate the message. You can even make a teleportation command block so that a cheater is banished from the map to a small room without a way out as soon as he switches to Peaceful.


 * Talking Adventure Map(featuring an easy Quest System!)

The  command is really useful because it makes a text appear into the chat. It's maybe one of the greatest use of the Command Block as you don't need silly signs or long books to show the game rules. Just put a bunch of command blocks in lines with repeaters set to two or three ticks (so the player isn't spammed) and you can easily remove a chest of books or a lot of signs.

Another use of the command is talking NPCs and other mobs. Imagine you enter a butchery and you want the butcher to say something. Before, you needed to use signs or books, using some room in a butchery and putting objects that sometimes seemed random, but now... You just have to use the  command and the butcher will talk. Maybe a pig behind the counter will even beg for mercy! Let's take another example: you are in a factory and an alarm suddenly rings and says that it's going to explode. Having it in the chat, especially if the text is long, keeps the stressfull mood; the same thing works for bomb timers. The player will get more into the map's mood if the chat displays '10...' '9...' '8...' also.

Last but not least, it makes it easier to create a Quest System. Let's say the player gets in a butchery. He activates through a pressure plate connected to a RS NOR Latch (so it can't be activated twice) and a command block with the  command in which the butcher asks for the player's help: he needs to kill a pig (shame on him). The player gets to the pig that is standing on a stone pressure plate, that turns off when the pig is dead. So, when the player gets back to the butchery, he activates another circuit containing yet another RS NOR Latch and two command blocks with two commands. First, the  command in which the butcher thanks the player, and other one, the   command, so the player gets the reward. Along with that, don't forget to use the @p command so the butcher says the player's name. For example, if the command block is set to do this:, the channel will say: "[@]: Thanks, . You helped me a lot killing that pig." This makes the map way cooler and looks like it's made for the player as it says his/her name! You could also change [@] to [Butcher] by renaming the /say command block using an anvil.

By using  and   you can make a shop system that trades a certain amount of exp for items. For instance, if you made a command block with  and another with   connected to the same redstone current, it will take 5 levels from the player, and in return, give them 64 grass blocks.
 * Making a Store


 * Subtracting xp CAN work as a currency, by using the command   where l (L for level) is subtracted.  The minimum xp for the command to work can be listed inside the brackets, where lm is short for minimum level necessary.


 * Store part 2: Custom Villagers

Custom Villagers selling whatever you want can be created with command blocks. e.g.:. The part labeled "Buy" is what the villager is accepting as payment, the part that says "sell" is what he's giving in return. You can change the maxUses to 1000 if you never want the offer to run out, or to 1 if you want to make it a one-of-a-kind item. Note that the first item there (the gold sword) has an out of range enchantment (sharpness 9). Yes this works, but always research what exactly the enchantment does before making an out of range one as some stuff does nothing or even does negative effects (respiration's "see underwater" side effect makes everything a blinding white at high levels, as if you dove into slush-filled arctic waters). As for that gold sword, keep in mind that gold swords wear out insanely fast (there's a reason people call them butter swords after all). A level 10 Unbreaking enchantment should bring a gold sword up to a decent durability level. Also notice that the other 2 "weapons" are actually a Stick and a Blaze Rod with weapon enchantments on them. Using any non-weapon as a weapon does the same damage as an empty hand (1 damage, aka half a heart) but the enchantments on these ones make them the equal of an unenchanted sword. Why bother? What's the advantage? Because unlike weapons, sticks and blaze rods HAVE NO DURABILITY RATING AND WILL NEVER WEAR OUT! The same trick can be used with mobheads and respiration 3 to make an infinite durability scuba mask.

1.7 uses
In 1.7, the command block gained an expanded potential. Namely, the  and   commands have been added, and can be used to automatically build structures, fill chests, and spawn previously unavailable entities. The syntaxes for the commands are:
 * for setblock
 * for summon

Along with that, the setblock command also makes it possible to make traps with disappearing floors and sudden walls.

MobSpawners pt 1: The Basics
This code will create a zombie spawner 2 blocks from you in the x direction. Note that the name given for mob spawners in this code ("minecraft:mob_spawner") is the long version and you can leave out the "minecraft:" part.

This next code is also pretty basic but it includes the 6 basic parameters that can be set.

Notes: A) All times are in game ticks (20ths of a second). 200-800 is 10–40 seconds. B) Keep in mind that they are in groups of 2 and won't work if their partner is missing. SpawnRange requires RequiredPlayerRange (and vice-versa), MinSpawnDelay requires MaxSpawnDelay, and I assume SpawnCount needs MaxNearbyEntities (although I haven't actually heard confirmation on that last one). C) There is also a parameter called "Delay" which contains the amount of time before next spawn (20 ticks for the first time, whatever random number it picks between MaxSpawnDelay and MinSpawnDelay every other time). D) the coordinates given are ~0 ~-1 ~-3 (so 3 blocks in the negative Z direction from the commandblock's current position and 1 block down). This presumably will imbed it in the surface of the floor. Keep in mind that a spawners "SpawnRange" setting only applies horizontally not vertically. Vertically it will only spawn at the same height or 1 lower or higher, so imbedding it in the surface of the floor cuts the available spawn area by 2/3rds (but can help hide it). Naturally occurring spawners have their height cut by 1/3rd due to appearing 1 block above the floor instead of 2. E) All the values used here are the defaults.

MobSpawners pt 2: Custom monsters
The next thing to do is to modify the spawn data. Spawn data is what tells the spawner you want a non-standard version of a monster, such as a zombie with a diamond sword and a chainmail helmet.

Using ~ without any number after it in the coordinates counts as zero. Because of the fact that none of those 6 parameters from last example are used, they will all be defaults. Note that the 5 equipment slots are: Hand, Boots, Legs, Chest, Helmet. You must even specify empty slots (the { }, parts), unless they're after the last non-empty slot. So, if you want your custom mob to have a helmet, you have to specify all 5 slots, but if it's just a weapon, you can leave off the other 4. Likewise, if you want him to have leg armor. you have to specify weapon and boot slots, but not chest and helmet slots. Remember that creatures that burn in sunlight are safe if they have a helmet on, although it damages the helmet instead.

As for the count tag, most codes can get away with leaving it out; however, it is important. An item without a count tag is a stack of zero, better known in the community as a "Ghost Item". A player trying to use a ghost item will have it disappear out of his hands with its first use (which is a failure). While monsters can use ghost items without problem (hence why codes get away with leaving it out sometimes), if they drop the items the player who picks it up won't be able to use it, so it is highly recommended to use the count tag.

The next example of customized monsters, consists of a skeleton with an enchanted bow (Flame) with a custom mob head (Spider, internet connection required or it's just Steve) with Protection 2 riding a Skeletal Horse.

Technically, the skeleton would just be sitting on a Skeletal Horse, because the lower creature controls the movement and the horse isn't hostile. Don't try to put zombies on horse back, as they just sit there ineffectually while the horse eats grass and snorts. Luckily this is a skeleton and can shoot you from wherever the horse decides to wander. As for the horse itself, it's type 4 (skeletal horse), Tame is set to 1 (yes), and it's got a saddle (and the fact that they make us specify which saddle hints that they may eventually have more than one type). Technically you can have multiple levels of riders, although this gets silly quickly.

MobSpawners pt 3: SpawnPotentials
Using the SpawnPotentials tag, you can create a mob spawner with multiple mobs in it. It will randomly pick one each time when the timer is reset (a second after spawning the previous mobs). Since these codes contain multiple mobs, they tend to be quite long codes. Thanks to a youtuber (Dragnoz), the fact that you can "break up" your code is known (command blocks ignore line breaks, so you can start a new line to clarify where one section ends and another begins and it won't ruin your code). Here's a version of the SpawnPotentials code, that is more easy on the eye:br>

It contains a lot of codes, because of the fact that it is actually 6 separate mobs. In order we have: 0) Before the "SpawnPotentials" tag: The starter, which will never pop up again after the first time. If you want to see him again, you have to include him a second time under SpawnPotentials. His appearance is just a random person in bluejeans (blue dyed leather leg armor), and a cactus green shirt (green dyed leather tunic), with a wooden sword. He's a zombie under that random-dood-mobhead of his of course. They all are. 1) Same thing, only this time his wooden sword is 2 hits away from breaking. 2) The next one has a ninja-like appearance. This one is a skeleton under his mask, but he's been given an iron sword. All of his leather armor is dyed ninja-black. Skeletons with swords close the gap quicker than zombies, so watch out. 3) Zombie with a stone sword and chain armor, with Protection II on his mobhead. 4) The next one has a gold sword, golden armor, a pumpkin on his head, and he's on fire! The pumpkin is enchanted with Protection II and Fire Resistance X (10!) in a desperate attempt to keep him on his feet and threatening the player for more than 5 seconds. It works but if the player plays keepaway then Mr Pumpkinhead does tend to burn to death. Oh his sword has fire aspect too. 5) Iron Sword and Armor guy. Sharpness II on his Sword, Protection II on his mobhead. 6) The final mob, FakeHB, here has highly enchanted Diamond Armor (Boots with Fire Protection IV and Feather Falling IV, Leggings with Blast Protection IV, Chestplate with Protection IV, Mobhead with Protection IV, Fire Protection IV, Blast Protection IV, Respiration III) and a Diamond Pickaxe enchanted with Sharpness IV, Smite IV, Bane of Arthropods IV, Looting III and Unbreaking III. He's also got the previously unseen CustomNameVisible (set to 1 for yes), a CustomName, and PersistenceRequired (set to 1 for yes). That last one will prevent him from ever despawning, although he can be killed normally. If you can get through that Diamond Armor. And level 4 resistances. Luckily he's rarer (see below).

Other than the ninja, it's a straight tour of the 5 tiers of swords and armor. Note that the Weight tag, used right after the mob name in each SpawnPotential. That determines how rarely it's picked. Specific numbers don't mean anything, just the ratios between the numbers. For example if you want all the potentials to have an equal chance just set all the weights to 1. Changing them all to 8 wouldn't do anything different (they're still all the same size as each other), however changing all but one to 8 would make that one 1/8th as likely as the rest. In this code 4 is the default. The ninja only has a weight of 2 (making him half as likely to be picked) and FakeHB has a weight of 1 (making him 1/4th as likely to be picked, and thank god!)

MobSpawners pt 4: Rideable Monsters
Mobs can be ridden by using Minecarts or Boats on their heads. The command is fairly simple Tips:
 * Some mobs simply can't be spawned with a spawner, such as, sadly, bosses and iron golems. Adding a minecart won't affect them either.
 * Hostile mobs with shooting abilities can and will use them against survival players. Watch out.
 * Ghasts cannot be ridden. The minecart becomes stuck in their head, which makes them useless to anyone.
 * Endermen cannot be walked around, but they can be forced to teleport by shooting a projectile at them (e.g.; snowball).
 * Ocelots (Ozelots in the game format) are some of the fastest mobs to ride, seeing they're trying to get away from you. They can also be partially controlled, by pointing away from the place you want to go.
 * Spiders are the only mobs that slow down when ridden.
 * Slimes and their Nether cousins, magma cubes, cannot have their sizes changed.

1.8 uses
New commands There are several new commands and tags added in 1.8. One of the most useful is @e, which allows the player to target entities. You can now perform many more actions using commands, such as teleporting creepers, or killing a minecart. Others include  and. Check out the commands page to see how they work.

Examples

 * The player can make a kind of world guard using the command block. (e.g. code: )
 * Using the radius argument with a teleporter hooked up to a clock circuit can be used to create an exclusion zone ("forcefield") around an x y z coordinate (which should not be centered on the command block itself, otherwise it will be difficult to edit or disable it later). Simply program it to teleport any player within a certain range to a further away point, or just back 10 meters using relative coordinates. Note that such a forcefield wouldn't know which direction you were approaching from, and may result in pulling a player in before pushing them back out the other side.
 * The commands, , and will cause the command block to say user name of the nearest player in the message.
 * You can also clear players inventories, to prevent griefing and/or cheating:

More commands in fewer blocks
There are several ways to combine groups of commands into just one command.


 * will run its command as many times as the number of targets it selects. If it doesn't matter what entity runs a particular command, you can use  to ensure the code always runs 10 times (as long as there are always at least 10 entities in the loaded world).
 * To run multiple commands, /summon a command-block minecart riding another command-block minecart riding another, with the commands in reverse order, on an activator rail. There are also commands called one-command mods that use this tactic. Mr. Garretto makes one-commands and maps here.

Exp Shop
This will allow server owners to sell effects, items, and more to any player, paid using experience. All they have to do is press one button. See this video for en example of how to make one:

Using a map item as a scroll
In his recent videos, Sethbling uses a map as a scroll to perform commands (summon creatures, teleport). He has an empty map in his inventory and when he uses it, it becomes a filled map which immediately disappears and a redstone task is done. In this tutorial I will show you how to build a redstone mechanism to detect the use of a map as a scroll and perform a task (give an effect, open a door,...).

Pros Cons
 * Fast redstone interaction.
 * Compact system.
 * At-will triggered system, just right-click to activate it.
 * Single use : the map disappears during the inventory check, but you can give it back through a /give command
 * There can only be one purpose for the scroll. I.E. you cannot do a scroll of teleporting and a scroll of strength without using complicated data values.
 * You may see the map animation when activating the map before it gets deleted.
 * You cannot use the map item during your playthrough (showing a text message, a path, a drawing,...).

Building the mechanism

You can change the display name of an item to give the player a better understanding of the object and use the tooltip display. Use the following command to give the player a custom named map : /give map 1 0 {display:{Name:"",Lore:[" "]}}
 * player : the player you want to reach (@p, @a[arguments],...).
 * displayName : the name displayed when you scroll in the hotbar or when you hover the item with your mouse.
 * tooltip : the text below the item name when you hover it.

Detecting the activation of the map



/clear filled_map
 * The two hoppers form a redstone clock. You can use other clocks shown here.
 * The Command block 1 contains the /give command described in the section above. It can be dismissed if you don't want the scroll to come back after being activated.
 * The Command block 2 contains the inventory check command :
 * The Command block 3 is the output in case of success. You can do whatever you want : give an effect to the player, teleport him somewhere,... You can also wire this output to a door, a piston,...

Going further The /clear command can check for other interactive items : /clear fishing_rod 2 Note that spamming the reel, or hooking a mob, may damage it more than 2, so make another one of these every 2.
 * check for a glass_bottle if the player just drank a potion.
 * Sethbling also uses a fishing rod which works when the line is reeled in. The /clear syntax involves another argument, the damage value, after the item name:

Further Resources
Feare's Command Block Tutorials

Dragnoz' youtube tutorials to a lot of possibilities using data tags

a text tutorial to data tags