Minecraft Blogs / Tutorial

Quick Commands

  • 771 views, 3 today
  • 11
  • 9
  • 2
3kh0_'s Avatar 3kh0_
Level 35 : Artisan Fox
61
Basic usage of commands

There are many things players can do with command blocks. Here are examples of some of them:


Cookie announcer
When run in order, such as in a chain of command blocks or functions, these commands will give a random player 5 cookies.

/tag @r add cookie
/give @a[tag=cookie] minecraft:cookie 5
/say @a[tag=cookie] has been given 5 cookies!
/tag @a[tag=cookie] remove cookie
Time Warp
By putting this command inside a repeating command block, the player can make time speed up. Adjust the number to change how fast it goes.

/time add 5
Wireless Redstone
Redstone can wirelessly be 'transmitted' by placing a Redstone block at a certain location. The downside to this method is that the chunks being transmitted must be loaded. This method is often used with Adventure maps to trigger more command blocks.

/setblock <x> <y> <z> redstone_block
/setblock <x> <y> <z> stone

To not require loading chunks, the scoreboard is needed. The second command will only complete successfully if the first has been run. Either a comparator or chained conditional command blocks can detect the success. The second command block should be set to repeat.

/scoreboard objectives add signal dummy
/scoreboard objectives remove signal
Wireless Buttons
The previous is often used in conjunction with buttons. Sometimes, however, there might not be enough room to hide a command block. In that case, the player can use a repeating command block to test if a button on (x, y, z) is pressed.

/execute if block <x1> <y1> <z1> #minecraft:buttons[powered=true] run clone <x1> <y1> <z1> <x2> <y2> <z2> <x3> <y3> <z3>
Starter Kits
Using command blocks users can give starter kits to new players.

/clear @p[tag=!started,distance=..5]
/tag @p add started
/give @p iron_sword
/give @p bread 5
/teleport @p <x> <y> <z>

The problem with this setup is that players can only get the starter kit once, even if they die. To fix this, use these commands. The first command should only be run once, probably by the player rather than a command block.

/scoreboard objectives add died deathCount
/tag remove @p[scores={died=0..}] started
/scoreboard players set @p died 0
Teleporting
The player can teleport by using the /teleport teleport or tp commands, 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 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 coordinates of (-36,96,-12) that ran to a command block with a command of /teleport @p ~3 ~4 ~5 it would tp the player to the coordinates of (-33,100,-7). The same outcome can be achieved by having the command of /teleport @p -33 100 -7 one block must be subtracted from the x and z-axis to get to the right coordinates. Using @p, @s, @a @e.
Security System for Mobs or Players
Command blocks can also be used to make a security system. Just put a pressure plate that triggers a command block in front of an iron door, which will be the entrance to the house. Insert the command: kill @e[​type=(mob)] and hook it up with chain command blocks to kill different mobs. this is to not kill you or other players. do this second command in a command block to teleport all things in the vicinity: tp @e[​r=2] ~(any distance) ~(any distance) ~(any distance
Title of Expandable Spoiler
A similar concept to the elevator but made to move a player along the x or z coordinates. This can be created by:

Use the /fill command.
/fill <x1> <y1> <z1> <x2> <y2> <z2> command_block{Command:"/execute as @p at @s run teleport @s ~-1 ~ ~"}
> Edit the coordinates inside the brackets to change the direction the player will move
> Place pressure plates on top of all the command blocks.
> Step on it.

Users might want to turn command block output off since the chat will keep spamming command block output. You can use this command:

/gamerule Commandoutput false
Replacement for pressure plates
Pressure plates only blend in with only gold, iron, stone, and wood planks, but cannot be concealed in any other floor; command blocks can be used instead. Pressure plates can be replaced with a command block by using the if the argument in the command /execute with a range and a clock circuit. The command /execute if @p[​distance=..2] 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 a player wants 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 5×5×5 area and a range of 1 makes a 3×3×3 area (more like a + pattern with an extra block above and below the center). The player can get around this by using the dx, dy, and dz arguments.

Alternately the player can specify the x, y, and z coordinates in the command (e.g. /execute if @p[​x=50,y=64,z=46,distance=..1] but be warned that the range cannot be shrunk 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 the player knows no one will be walking through the bottom 2 layers of the globe. Trying this with the non-XYZ version of the command 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 , : Do not add / during coding unless instructed to.

Bad: [x=0, y=0, z=0, distance=..1]Bad: [x=0 ,y=0 ,z=0 ,distance=..1]Bad: [x=0 , y=0 , z=0 , distance=..1]Good: [x=0,y=0,z=0,distance=..1]
Commanding Passwords
Players can now create passwords with command blocks, using the if block argument on /execute. Place a command block. This will be the one you put input in. Place another command block, and type in the following command:
/execute if block <x, y, z coordinates of first command block> command_block{Command:"<input>"}Example:
/execute if block ~2 ~ ~ command_block{Command:"That's Numberwang!"}
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 /setblock that activates after /execute.

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 /give @p sign.
The Destroyer
This allows the player to destroy a cube of materials around them as they walk, using /execute. The command is
/execute as @p at @s run fill ~1 ~2 ~1 ~-1 ~0 ~-1 air
Use the repeating command block with the "Always Active" option selected, and the cube of air will be created wherever a player go. Basically, /fill takes out a specified amount of space, similar to /setblock, but it uses two coordinates and fills the space in between them with the material of the players choosing. In this case, that material would be air. Now, every time a player moves, it will fill a 3×3 cube of air around the player. A destroyer is great for enemy bases, or simply being a crazy griefer. If you are playing on 1.12.2, then it is: /execute @p ~ ~ ~ fill ~1 ~2 ~1 ~-1 ~0 ~-1 air
This also deletes water, so the player basically becomes a moving sponge. To not remove water, use
/execute as @p at @s run fill ~1 ~2 ~1 ~-1 ~0 ~-1 air keep water instead.
This works in any game mode, including spectator mode.
Landscaper
This is a reversed version of Destroyer.
/execute as @p at @s run fill ~1 ~-1 ~1 ~-1 ~-1 ~-1 grass_blockThis puts a 3×3 grass square under a player.

The 1.12.2 version is
/execute @p ~ ~ ~ fill ~1 ~-1 ~1 ~-1 ~-1 ~-1 grass
Booby Traps

An extremely lethal booby trap would be a command block set to teleport someone into the void.

The player can do/kill @e[distance=..2] 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, players can either use the /execute if entity command as an invisible pressure plate, or they can do /teleport @p[distance=..<radius>] x y z rot<x> rot<y>Hook a clock circuit up to a command block programmed with /execute if entity @p[x=1, y=2, z=3, distance=..<radius>]with the coordinates changed as appropriate.

Note that as of Java Edition 1.8 a range of zero can now be specified.
Teleporters

It is possible to make teleporters using the command block. (e.g. /teleport @p <x> <y> <z>) 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 players appear in ground while testing coordinates, use /teleport @p ~ ~8 ~ to get out (may require multiple uses).



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



Commands that use coordinates (e.g. /teleport or /spawnpoint) 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.

It is also possible to teleport minecarts or boats, with players in them. The command is /teleport @e[type=boat] <x> <y> <z>


Multiplayer applications


This section details the applications of the command block in multiplayer.

Command-based flying
Commands can also be used for flying entities or structures. Most commands based flying machines use command blocks so that when the player turns on an input, it activates certain command blocks. Unlike piston based technologies, however, these cannot be legitimately made in survival as command blocks require set up by an operator in creative mode.

/tp
Using the /tp command, entities can be teleported in a specific direction in small repeated increments, to exhibit a smooth flying. With clever command usage, movement can be controlled by various means such as holding a specific item
/clone
Using the /clone command, it is possible to more easily move structures by cloning them and teleporting entities in it with /tp. It can be accomplished by cloning a structure relative to an entity with /execute. The entity, in turn, can be controlled by some other means.
/summon
Using the /summon command, it is possible to lift an entity with explosions, somewhat similar to real life rockets. This can be done by spawning instantly detonating creepers or TNT below an entity. However, there is a multitude of disadvantages, including:

> It is noisy and potentially laggy compared to most other types of flying.
> This method is destructive to the terrain. Using creepers without mobgriefing enabled could solve this.
> Damage to the entity being flown. This can be partially solved with Blast Protection, status effects or the Invulnerable NBT Tag.


/data (merge/modify) [entity] command
Using the /data command (1.13+), it is possible to change the velocities applied to an entity rideable by the player, such as a minecart or boat.

The equivalent command for versions below 1.13 is the /entitydata command.
Teleportation/Transport
Through /teleport, one can create teleporters for public use on a server. It 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" using <X> <Y> <Z>
Stop-Motion Animation
By using the /clone command 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.
Lottery
Through /give @r, one can create a lottery. Keep in mind that now, /give will directly put items into one's inventory, instead of throwing them on the ground in front of the character.
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: /scoreboard objectives add lottery dummyThen use this command on a command block /scoreboard players add <playerName> lottery 1 to enter players into the lottery then do /give @r[score={lottery=1..}] to start the lottery and only the players chosen can be in the lottery.
Jails

By rigging a fast clock to a command block executing /teleport, they can force a player to stay at a certain place. If they do this it would be advisable to either turn off commands in their chat settings or do /gamerule commandBlockOutput falseUsing the "Range" and "Minimum Range" parameters, they can have it teleport players back only when they're a certain distance away.

Alternatively, giving the player certain status effects at high levels using the /effect command can mimic the effect of a jail. Use /effect give @p minecraft:slowness <insert duration of effect> 127 to keep the player from moving, and /effect give @p minecraft:mining_fatigue <insert duration of effect> 127 to keep the player from breaking things. If a player really wants to kick it up a notch, poison the player (use one of the previous two commands, but replace the first number with 19).
Creative Only
By using the parameter [gamemode=creative]only players in Creative will be affected by the command block.
Fun anti-creative mode trap
If a player places a repeating command block with the "Always Active" option, they can set /teleport @a[gamemode=creative] ~0 ~1 ~0 for hilarious (like really hilarious) results. This could be a way to get creative mode people to change to Survival and is also really fun to watch.
Announcements
By using /me in a command block one can create announcements that could play even when the admin or owner wasn't there.
Title of Expandable Spoiler
By using /clear, players can scan people for items. If they want to remove certain items, use /clear <playername> <itemid>. For example, on a server that doesn't want griefing, players could have a clock connected to a command block set to /clear @a minecraft:flint_and_steelThis command will remove the flint and steel from everyone's inventories.
Improving PvP without Plugins
Players can use /gamerule keepInventory true so players cannot steal each other's items. Also, using /spawnpoint <x> <y> <z> and /teleport <x> <y> <z> to help move players around while in PvP competitions.
Starter Kits
Players can easily give people a starter kit with a button without plugins: /give @p[distance=2]. To prevent people pressing the button a second time and again getting their kit, players can make two command blocks activated in order: /give @p[distance=2,m=2] minecraft:stone_pickaxe
/gamemode @p[distance=2] survival

Title of Expandable Spoiler
It is possible to create colored, clickable messages players can send to anybody. The command is /tellraw. Not to be confused with /tell. The basic format is:/tellraw @a {text:"", color:<color>} An example would be :/tellraw @a {text:"Hello, Steve", color:blue, italic:true, obfuscated:true}Simply place a comma and space with each addition. If you want other players to be able to click it, use clickEvent. Here's the example: /tellraw @p {text:"Run Coward! I hunger!", clickEvent:{action:run_command, value:"/give @p minecraft:cooked_porkchop 64"}}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 clickEvent with hoverEvent and run_command with show_text. Then just type the value text as a regular sentence, no slashes. If you want an easier job of it, here we have tellraw generators:

minecraft.tools
minecraftjson.com
Minecraft Forums
Alarm System
When a player walks over a pressure plate, it can trigger a command block with /say <message> or /title <player> title <message>@p can be used within the message to display the player closest to the command block upon triggering.
Reward Room
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, players 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).
Weather Machine

Command: /weather <weather>

Assuming only admins can get to it, a weather machine can be quite useful, players can turn the 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 an 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.
Obstacle Course Prizes

With /teleport @p <x> <y> <z> and /give @p <item>Players 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.
Time Machine
By making two similar places on one map, players can have a button activate a command block to teleport them from one to another, while also changing the time of day. This can be used to look like time travel.
Proximity Mine
By using a condition such as /execute if entity @p[distance=..5,name=!<placing player>] run <command> 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.
Secure Doors
By using a condition such as /execute if entity @p[distance=..5,name=<owner>] run <command>TThe command block can detect a door's owner within a certain radius and open a door for them, and only for them.

Thank you so much for reading my tutorial. I really hope you enjoyed it. I will add more if this tutorial get 5 diamonds.

I would like to thank Alex for helping me.

Please subscribe!
CreditMy friend Alex
Tags

Create an account or sign in to comment.

1
03/21/2021 5:24 am
Level 1 : New Miner
th1rtyv1rus
th1rtyv1rus's Avatar
Why is the picture so low quality?

Nice job tho!
2
03/19/2021 1:22 pm
Level 1 : New Network
Bongs237
Bongs237's Avatar
Thank you for making these! they are so helpful
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome