How do I, say, make it such that the game will target all levers that have been broken by a stone shovel and make it such that they can be placed on stone and bedrock, but ONLY levers that are currently in entity form - nothing else? For instance, if I were to break a lever and drop a ladder, only the lever would get the tag added to it?

  • 1
    Is it important to only target levers broken by a stone shovel, or is targeting all levers in entity form sufficient?
    – SirBenet
    Mar 11, 2015 at 17:18
  • It's targeting all levers in entity form. Mar 12, 2015 at 14:07

1 Answer 1


You can use the /testfor command and the @e selector. You can do /testfor @e[type=Item] {id:"minecraft:lever"} to get all levers as entities (@e). You can also use /scoreboard if you need to store data for future reference (which is what I usually do, since detecting an entity and doing nothing with it is basically useless). To setup, you can create an objective (/scoreboard objectives add objectiveName dummy Objective Name Here) then use /scoreboard players set @e[type=Item] objectiveName 1 {Item:{id:"minecraft:lever"}} or something like that (using add instead of set or likewise).

You could then edit the NBT data of the lever to have {CanPlaceOn:["minecraft:stone","minecraft:bedrock"]}. You'd also have to be in /gamemode 2 a.k.a Adventure mode for CanPlaceOn to work.

  • When I do this, it says that the item does not match the required data structure. I then tested it by having it detect all levers in a radius of 2, and I get "item.item.lever did not match the required data structure" when I run "/testfor @e[type=Item,r=2] {id:"minecraft:lever"}". What am I doing incorrectly? If I remove the tag and just have it search for items, it works, but it seems I'm not using the correct tag. Is it supposed to be "{Item:{id:"minecraft:lever"}} instead? Mar 13, 2015 at 14:24
  • If the answer is correct, consider accepting it. Click the checkmark next to the vote count.
    – RetroCraft
    Mar 13, 2015 at 15:13
  • It didn't entirely solve it, though. I can't seem to be able to get it to edit the nbt data of levers with this information. I have two command blocks. First one is /scoreboard players set @e[type=Item] lever 1 {Item:{id:"minecraft:lever"}} and the second is /execute @e[type=Item,score_lever_min=1] {Item:{id:"minecraft:lever"}} entitydata @e[type=Item,score_lever_min=1] {CanPlaceOn:["minecraft:stone","minecraft:bedrock"]}. Nothing happens when a lever entity is detected. Mar 13, 2015 at 15:33
  • You got /execute wrong. You can't use NBT tags in /execute. You can just do /entitydata @e[type=Item,score_lever_min=1] {CanPlaceOn:["minecraft:stone","minecraft:bedrock"]}
    – RetroCraft
    Mar 13, 2015 at 18:54
  • The command block says that it worked, however, the item itself does not display any tags in the tooltip and does not allow me to place it in adventure mode. Here's the commands and their outputs: /scoreboard players set @e[type=Item] lever 1 {Item:{id:"minecraft:lever"}} [10:19:38] The dataTag does not match for 33db6695-d7eb-4e7c-bba7-ffe8e3a57fe0 (It's obviously just stating that for other entities; the following output shows that the previous block is in fact interacting with the lever) /entitydata @e[type=Item,score_lever_min=1] {CanPlaceOn:["minecraft:stone","minecraft:bedrock"]} (CONT.) Mar 16, 2015 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .