Command Block

From Better Than Wolves Wiki
Jump to: navigation, search
Command Block


Type

Solid Block

Requirements

None

Physics

No

Transparency

No

Luminance

No

Blast resistance

0

Tool

A wooden pickaxe or better is required to mine this block

Renewable

No

Stackable

Yes (64)

Flammable

No

First appearance

Template:Version link

Tile Entity ID

Control

Data value

dec: 137 hex: 89

The Command Block is a block made with the intent to support Adventure mode and allows mapmakers to expand the interaction with the player through server commands. The block can run specified server commands when activated by a redstone current. Considering its great power and possibilities, it can't be normally crafted. Currently, it is not available in the creative mode inventory either. Only players with sufficient privileges to use the 'give' command: /give <player_name> 137 can obtain the block. Furthermore, only players which are in Creative mode and are also an operator on the server are able to edit and successfully save the command of the block. To be able to use this block in multiplayer, you have to set the value of enable-command-block to true in the server.properties file. If this line doesn't exist, you'll have to add it. In survival mode, command blocks can be broken instantly, even without a tool, but will only drop as an item when mined with a pickaxe. They can't be pushed by pistons, as they have tile entities. The maximum command length is limited to 254 characters.

Usage

The Command Block will execute some useful commands like giving items or experience to a player.<ref>jebtweet:228830318398959617</ref>

To change the command executed by the block, simply right-click it, and the GUI will open.

In place of player names, it is possible to use multiple different variables:

Variable Function
@p Nearest player
@r Random player
@a All players

When using commands, treat them as if entered from the console - you always need to specify the target, so it is not possible to use commands such as "kill" which do not take a player argument. For example, to change the mode to Survival for the nearest player type: /gamemode survival @p. Note that you will have to be in Creative mode to change the command associated with the block.

The command block sends commands through the console in singleplayer and multiplayer, though commands can still be prefixed with a "/". If you want to give the nearest player stone, you can enter /give @p 1 or give @p 1.

For innovative, practical uses of the Command Block, view Tutorials/Command Block.

Examples

  • It is possible to make teleporters using the command block. (e.g. code: /tp @p[r=3] x y z)
  • 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: /tp @p ~0 ~8 ~0 This would teleport the player 8 blocks into the air).
  • Commands using coordinates (eg. "/tp" or "/spawnpoint") add 0.5 to integers, like usual. To clarify, the number -33 would be interpreted as -32.5, and the number 187 would be interpreted as 187.5.
  • The player can make a kind of world guard using the command block. (e.g. code: /gamemode <gamemode> @a[r=<radius>])
  • The commandBlockOutput gamerule does not affect the command block using the Template:Cmd and Template:Cmd, and Template:Cmdcommands.
  • The commands /say Hello, @p and /tell @p Hello, @p will cause the command block to say user name of the nearest player in the message, however /me Hello, @p just causes it to say "Hello, @p".

Game Rules

Game Rules allow players and command blocks to adjust several base settings.

Usage: /gamerule <gamerule> <true/false>

Gamerule Effect
commandBlockOutput Enables/disables text output of command block commands to console
doFireTick Enables/disables fire spread
doMobLoot Enables/disables mob drops
doMobSpawning Enables/disables the spawning of mobs unless you want them to ex: eggs and mob spawners will still spawn mobs
doTileDrops Enables/disables blocks dropping items when broken (includes TNT destroying blocks)
keepInventory Enables/disables keeping inventory on death
mobGriefing Enables/disables creepers, ghasts, and Wither blowing up blocks, endermen picking up blocks and zombies breaking doors

Disabled or Unavailable commands

The following commands cannot be used in a command block for various reasons:

Category Reason for Unavailability Commands
Disabled for server security These commands are likely disabled due to limited use in command blocks and the potential for severe, unintended consequences on servers. ban, ban-ip, deop, kick, op, pardon, pardon-ip, save-all, save-off, save-on, stop, whitelist add/remove/on/off/reload, debug, publish
Unavailable to console These commands require a player to be the executor*. kill
Available, but no apparent effect These commands output messages to their user only, not to public chat. help, seed, list, scoreboard objectives/players/teams, list, banlist, whitelist list

*Some commands, such as /me, /tell, and /say would be expected to require a player as the executor, but work in command blocks and the server console. The command block's "name" defaults to "@", but can be renamed with an anvil.

Arguments

After using a target (@a, @p or @r) you can optionally use arguments. This is how you use the arguments: @<selector>[<argument>=<value>,<argument>=<value>]
NOTE: Make sure you do NOT add a space between arguments or commas.

Argument Function
x X coordinate for the search center.
y Y coordinate for the search center.
z Z coordinate for the search center.
r Maximum search radius.
rm Minimum search radius.
m A player's game mode. 0=Survival, 1=Creative, 2=Adventure
c Number of players. If negative, uses players from the end of the list first. When outputting through a comparator, the signal strength is equal to the number of players it locates.
l Maximum experience level of players.
lm Minimum experience level of players.
score_name For the objective "name", the maximum score this player has.
score_name_min For the objective "name", the minimum score this player has.
team Checks if player is in the specified team. Inserting an '!' before the team name checks only for players *not* on this team. Providing no team name allows for checking for all players without a team.
name Checks for players with this name. Inserting an '!' before the name checks only for players who do not have this name.

Example: @p[x=1,y=30,z=26,r=10,rm=2,m=1,c=3,l=25,lm=3]

Alternatively, the coordinates and maximum (but not minimum!) radius can be provided more concisely as long as they're the first (up to four) arguments without keys, for instance:

@p[1,30,26,10,rm=2,m=1,c=3,l=25,lm=3,score_Kills_min=1,score_Deaths=2,team=Red]

is identical to the previous example.

Because the argument 'c' uses players from the end of a list first when negative, @p[c=-1] may be used to select the farthest player instead of the nearest one.

History

Template:History Template:History Template:History Template:History Template:History Template:History Template:History Template:History Template:History Template:History

Issues

Template:Issue list

Gallery

References

Template:Reflist

Template:Redstone Template:Blocks