Minecraft Blogs / Article

All About Command Blocks!

  • 12,237 views, 1 today
  • 36
  • 14
  • 45
Frostystorm1
Level 39 : Artisan Narwhal
17
Command Blocks are a powerful block, they can be used for a variety of tasks that I will be explaining today.

If you would like my texture pack, please download and leave a diamond here.

If you would like my lego skin, please download and leave a diamond here.

I WILL ADD A SECTION WITH FUN COMMANDS IF WE CAN GET TO 10 DIAMONDS!

ADDED! √

I WILL ADD EVEN MORE FUN COMMANDS IF WE CAN GET TO 20 DIAMONDS!

ADDED! √


undefined

Start
Command blocks can not be obtained in regular creative mode, you must type a special command to get one.
Click on the spoiler to show the command.

Click to reveal command
/give [USERNAME] minecraft:command_block

You must be in creative, and cheats must be enabled. If you are on a multiplayer server, the admin must set the enable-command-block value to true.

The Basics
Right clicking a command block will bring up a menu with a space for a command. In this space you can put any command. Commands in a command block can be executed by powering the command block with redstone.

Target Selectors
Selectors are used to target certain entities and players in a command. Instead of using /give minecraftman530 137, you can use /give @p 137. This will give a command block to the nearest player instead of just one specific person.
Click to reveal selectors
@p - The nearest player.
@a - All players.
@r - A random player
@f - The farthest player.
@e - All entities. (ONLY IN MINECRAFT SNAPSHOT 1.8)

The Commands
There is a wide variety of commands available for use in a command block.

/give - Will give a player an item.
/clear - Will clear a player's inventory or items from a player's inventory.
/difficulty - Changes the game's difficulty.
/gamemode - Changes a player's gamemode.
/effect - Will give a potion effect to a player.
/gamerule - Changes a rule or property of the game.
/setblock - Sets a certain block at given coordinates.
/summon - Summons an entity.
/time - Sets the world's time.
/toggledownfall - Toggles rain and clear weather in the world.
/xp - Gives a certain amount of xp to a player.

There are more commands but these are the ones I will be focusing on.

/give
The full command arguments are: /give [player] [item] [amount] [dataTag]
The first part of the command is [player]. This can be a player name or a selector.
The second part of the command is [item]. This can be a numerical item id, or it can be stated in words by using minecraft:ITEMNAME. 
The third part of the command is [amount]. This is simply the amount of the item you want to give.
The last part is [dataTag]. This part can be used to contain information about the item. You can give the item a custom name, lore, and enchantment here.

Click the spoiler below for an example command on how to give yourself a custom sword:
Click to reveal command
/give @p minecraft:diamond_sword 1 0 {ench:[{id:16,lvl:5}],display:{Name:"Sword of Death",Lore:[This sword is very dangerous!]}}

/clear
The clear command can be used to clear certain items out of a player's inventory, or to clear all the items from an inventory.
The full command arguments are: /clear [player] [item]
The first part of the command is [player]. This can be any player or selector and this can also be left blank to mean yourself.
The second part of the command is [item]. In this part of the command you can put an item id or name. This will clear that certain item from the player's inventory. Sadly there is no support to clear a certain amount of that item, but this can still be a useful command.

Example: 
I have a bank and I need to keep it secure. I can put a pressure plate with a command block under it with the command of /clear @p minecraft:tnt. This will clear all tnt from an entering player's inventory, so no one can blow up my bank.

/difficulty
The difficulty command can be used to change the game's difficulty. 
The full command arguments are: /difficulty [difficulty]
This is a simple command where the only argument is [difficulty]. In this spot you have to put a number which corresponds to a difficulty.
Click to reveal difficulties
0 - Peaceful, no hostile mobs can spawn. Players regen health.
1 - Easy, hostile mobs spawn, but don't deal a great amount of damage.
2 - Normal, hostile mobs spawn and deal the standard amount of damage.
3 - Hard, hostile mobs spawn and deal a greater amount of damage than normal, mobs get special abilities (zombies break through doors, spiders get potion effects, etc)

/gamemode
The gamemode command changes a player's gamemode.
The full command arguments are: /gamemode [gamemode] [player]
The first argument is [gamemode]. This is a number or word that corresponds to a gamemode.
Click to reveal gamemodes
Survival (Gamemode 0) - Players gather resources throughout the world to survive. Player has health.
Creative (Gamemode 1) - Player has no health, can fly, has infinite blocks, and can destroy blocks instantly.
Adventure (Gamemode 2) - Player can interact with objects like levers and buttons, as well as mobs, but can not destroy blocks unless they are using the correct tools.
Hardcore - The same as survival, except you only have one set of hearts, and the difficulty is permanently set to hard. The map must be deleted on the player's death.
Spectator (Gamemode 3) - Player can noclip through blocks, are invisible to everyone except other spectators, and... this is a fun one... players can left-click on entities to spectate them! This means you can view life from a creeper's eyes!! Players in spectator can also teleport to other players. (ONLY IN MINECRAFT SNAPSHOT 1.8)

/effect
The effect command applies a potion effect to a player (or entity with @e) for a certain amount of time (default 30 seconds).
The full command arguments are: /effect [player] [effect] [seconds] [amplifier].
The [player] argument specifies who the potion effect will be targeted at. This can be an entity in minecraft 1.8 or later.
The [effect] argument is a number that specifies what the potion effect will be. Click the spoiler to show all the effects.
Click to reveal effects
1 - Speed
2 - Slowness
3 - Haste
4 - Mining Fatigue
5 - Strength
6 - Instant Health
7 - Instant Damage
8 - Jump Boost
9 - Nausea
10 - Regeneration
11 - Resistance
12 - Fire Resistance
13 - Water Breathing
14 - Invisibility
15 - Blindness
16 - Night Vision
17 - Hunger
18 - Weakness
19 - Poison
20 - Wither
21 - Health Boost
22 - Absorption
23 - Saturation
The [seconds] argument specifies how long the effect should last. Default is 30 seconds.
The [amplifier] argument boosts the effect, the higher it is, the stronger the effect. Max is 255.

This fun command will give an INSANE jump boost for 5 minutes! WARNING: Dont use in survival!
Click to reveal command
/effect @p 8 300 50

/gamerule
The gamerule command allows us to change the properties of the game. 
The full arguments of the command are: /gamerule [rule name] [value]
The first argument is the name of the gamerule. 
The second argument is a value you want to assign to that gamerule. This part can be left out, if you just want to see the current value of the gamerule.
Click on the spoiler to show a list of gamerules:
Click to reveal gamerules
commandBlockOutput - Whether command blocks should notify admins when they perform commands
doDaylightCycle - Whether time progresses
doFireTick - Whether fire should spread and naturally extinguish
doMobLoot - Whether mobs should drop items
doMobSpawning - Whether mobs should naturally spawn
doTileDrops - Whether blocks should have drops
keepInventory - Whether the player should keep items in their inventory after death
mobGriefing - Whether Creepers, Endermen, Ghasts, Withers and Villagers should be able to change blocks or zombies, skeletons, and Zombie Pigmen can pick up items
naturalRegeneration - Whether the player can regenerate health naturally if their hunger is full enough



The following rules will be added in 1.8 and are currently available only in the snapshots:
logAdminCommands - Whether to log admin commands to server log
randomTickSpeed - How often a random tick occurs, such as plant growth, leaf decay, etc. Can be 0 to disable random updates
sendCommandFeedback - Whether the feedback from commands executed by a player should show up in chat
showDeathMessages - Whether a message appears in chat when a player dies


From: minecraft.gamepedia.com/Commands
Valid value for all gamerules are true or false, except randomTickSpeed which can be any non-negative integer.

Alright lets take a little break from commands. I am going to explain relative coordinates.

Relative coordinates
Instead of using the coordinates obtained from pressing F3, command blocks can use relative coordinates. Relative coordinates are relative to the command block. Basically they mean how many blocks away from the command block. For example I could say 1 block above the command block instead of actually writing out the coordinates. We do this by using a ~. For example if I want to teleport 10 blocks above the command block, I could use the command /tp @p ~ ~10 ~. The first ~ is for the x position, since I am teleporting up I only need the y position, so I can leave the x and z positions alone by putting a ~. Since I want to teleport up, I put a 10 after the ~ for the y position. 

/setblock
This command will set a block at give coordinates.
The full command arguments are: /setblock [x] [y] [z] [tilename] [datavalue] [method] [datatag]
This is a fairly long command but bear with me.
The x y and z arguments specify coordinates for the command, these can be relative coordinates.
The [tilename] argument is the name or id of the block you will be setting.
The [datavalue] argument is something I wont really get into, but if you are setting a solid full normal block, the datavalue is usually 0. You can read more about each block's specific datavalues here. Datavalues can be used to set orientation, color, damage, and much much more.
The [method] argument specifies what to do if there is a block at the given coordinates.
There are currently 3 methods:
  1. replace - Will replace an existing block without particles and item drops.
  2. keep - Will keep an exisiting block if setblock specifies coordinates where tere is already a block.
  3. destroy - Physically destroys the block and then drops the existing block and then replaces it with the new block.
The last argument is [dataTag], to specify any data for that block.

undefined
I made a command block with the following command in it: /setblock ~ ~1 ~ minecraft:glowstone 0 replace

When I flipped the lever the block above the command block turned to glowstone.

undefined

If you like my skin and texture pack, see the link at the top of this article and leave a diamond!

/summon
This command summons an entity. 
The full command arguments are: /summon [EntityName] [x] [y] [z] [dataTag]
The first argument is the [EntityName]. Entity names can be the name of an animal, or entity such as FallingSand, PrimedTnt, or EnderCrystal. A list can be found here.
The [x] [y] and [z] arguments specify a location.
The [dataTag] argument is a data tag for the entity. For example, Fuse for primed tnt. A list of tags can be found here.

/time
In minecraft, one full day cycle is 24,000 ticks, which is 20 minutes in real life. With the /time command, you can set the time of the world.
The full arguments are: /time set [value], or /time add [value].
If you use /time set [value], it will set the time to the value. If you use /time add [value], it will add to the current time.
The only argument in this command is [value]. This can be from 0 to 24,000, day, or night. So you can use /time set day, if you want to set it to day but you don't want to use the numbers.

Below is an image of the minecraft times, look below the bigger numbers for the ticks that you should use in the /time command:
undefined
/toggledownfall
This is a very simple command that toggles the rain and snow. If it is raining, and you use this command, it will turn the weather to clear. If it is clear and you use this command, it will make it rain/snow.

This is the last command!

/xp
The /xp command gives a target player xp, or xp levels.
The full arguments are: /xp [amount] [player], or /xp [amount]L [player].
The first command will give only the little segments, while the second command will give levels of xp.
The first argument is [amount] for both commands. In the first command, this is how many segments of xp to give. It can be a maximum of 2,147,483,647 per command. You can not use negative numbers. In the second command, the [amount] argument is how many levels of xp to give/take. You may use negative numbers, the minimum is -2,147,483,647 and the maximum is 2,147,483,647.
The [player] argument is which player is recieving or losing the xp.
The only difference between the two xp commands is the L after the amount.

Executing these commands with a command block
To execute these commands, you can type them or paste them into the console command space in the command block. To run a command, you must power the block with redstone. You can power them in a variety of ways. Especially useful for adventure maps, you can power command blocks with a pressure plate. You can also power them with levers, buttons, redstone torches, redstone blocks, detector rails, and a daylight sensor. For the best effect in adventure maps, you may want to put the command blocks out of view from the player.

Alright its the moment you have all been waiting for! FUN COMMANDS!

Fun Commands
These are some fun commands to use in game. I recommend using them in creative. I will use spoilers because some commands get quite large.

Slime Tornado - Summon a giant slime tornado!
/summon Slime ~ ~2 ~ {Size:4, Riding:{id:"Slime", Size:3, Riding:{id:"Slime", Size:2, Riding:{id:"Slime", Size:1, Riding:{id:"Slime", Size:0, Riding:{id:"Bat", ActiveEffects:[{Id:14,Amplifier:0,Duration:100000000}]}}}}}}

Skeleton Riding A Skeleton Horse - Summon a skeleton on a cool horse that doesn't naturally spawn.
/summon Skeleton ~ ~ ~ {Riding:{id:"EntityHorse",Type:4,Tame:1}}

Charged Creeper - Will spawn a charged creeper with a HUGE explosion radius.
/summon Creeper ~ ~ ~ {powered:1,ExplosionRadius:100}

Baby Zombie Riding Chicken - Will spawn a funny baby zombie on a chicken!
/summon Zombie ~ ~1 ~ {IsBaby:1,Riding:{id:Chicken}}

Troll Diamond Block - Will spawn a diamond block that can't be picked up!
/summon Item ~ ~1 ~ {Item:{id:57,Count:0}}
You can change the id from 57 to whatever id you want.

Custom Player Head - Will give you notch's head!
/give @p minecraft:skull 1 3 {SkullOwner:Notch}

You can change notch to any player name!

Summon primed tnt - Will summon primed tnt 8 blocks above the command block.

[code]/summon PrimedTnt ~ ~8 ~ {Fuse:0.1}[/code]
You can change fuse to as long as you want the tnt to be ignited for.

Summon items with gravity - Will summon an item with the physics of falling sand.
/summon FallingSand ~ ~10 ~ {TileID:[ITEM ID HERE],Time:1}
You can change the tileid to whatever you want. Once the entity hits a block, it will turn into a solid block. You must keep the Time:1 tag. 
The launcher - Will guve you a sword that launches mobs SUPER.
/give @p minecraft:diamond_sword 1 0 {ench:[{id:19,lvl:100}],display:{Name:"The Launcher",Lore:[This sword will knockback mobs so far, they will never haunt you again!]}}
MORE FUN COMMANDS COMING!
Tags

Create an account or sign in to comment.

agent_waddles
02/26/2016 6:16 pm
Level 1 : New Explorer
You will be amazing if you can add Enchantment numbers! <3
1
redfox_pw
10/08/2015 4:16 pm
Level 30 : Artisan Toast
Great tutorial!
1
Frostystorm1
10/08/2015 8:08 pm
Level 39 : Artisan Narwhal
Thanks! :D
1
Luportex MC
09/10/2015 2:55 am
Level 17 : Journeyman Architect
also how do i do the fake diamond it just says cant summon object
1
Frostystorm1
10/08/2015 8:08 pm
Level 39 : Artisan Narwhal
Not really sure it works for me, try replacing item ids with minecraft:diamond if there are any
1
Luportex MC
10/08/2015 8:18 pm
Level 17 : Journeyman Architect
hey r u online now
1
Luportex MC
09/10/2015 2:47 am
Level 17 : Journeyman Architect
hey how do i color the name to my things with command blocks
1
Blow_Bob
08/31/2015 8:40 am
Level 1 : New Explorer
1.8 won't let you use negative numbers.
1
Frostystorm1
09/05/2015 12:47 pm
Level 39 : Artisan Narwhal
For which command?
1
HHTheMelon
07/15/2014 11:31 am
Level 15 : Journeyman Engineer
Thank you so much! Now I know what the command is to spawn peoples heads! /give @p minecraft:skull 1 3 {SkullOwner:[Username]}
1

Welcome