How do I set a /kill command on a block?

You can set a /kill command on a command block, I know that, but how do I do it? I am making a map, so please help!


Solution 1:

This is pretty lacking in detail, so I'll give you an overview.

First off, you need a command block (Directly from the wiki):

Command blocks can be obtained by using the pick block control or with various commands, such as /give <player> minecraft:command_block <amount>.

Command blocks are not available in the creative inventory, cannot be broken in survival mode or if you do not have operator permissions (1.9[upcoming]), are not flammable, and have the same blast resistance as bedrock. Command blocks cannot be moved by a piston.

Then enter your desired kill command into the command block, e.g.

  • /kill Name where "Name" is a players name, will kill that player
  • /kill @e To kill everything
  • /kill @e[type=Sheep] To kill all sheep
  • /kill @e[type=!Player] Will kill anything which isn't a player (Including de-spawning dropped items)

You then activate the command block in a normal way, the easiest of which is either directly from a switch/lever, or a redstone current.

Solution 2:

You can't exactly /kill a block (at least I don't think), as blocks are notentities. However there are some exceptions including Item Frames and Minecarts. What you can do as an alternative is /setblock x y z air for example, to set a block to air (basically removing it completely).

With Item Frames, you can do /kill @e[type=ItemFrame]. Same with minecarts (just making the ItemFrame into a MinecartRidable