why does this command block code not work

why does this command block code not work - Close Up Photo of Computer Codes

This: /testforblock ~ ~+1 ~ minecraft:chest {Items:[{id: @p{SelectedItem {id:minecraft:stick}}}]}

Command block output: {Items:[{id:' is not a valid number

Please help.

info i have only tried this i want to know why this code does not work



Best Answer

The format for your command is off, and you're trying to combine two commands in one. First you try to detect certain items in the chest, then you suddenly switch to trying to detect a player holding a certain item. I'll explain the parts of the command in order for detecting a chest with certain items.

You first need to start off your command with /testforblock ~ ~-1 ~ minecraft:chest. This part shows that you are testing for a chest directly under your feet.

Next you have to specify the data value of the chest; in this case, which way the chest is pointing. If the lock on the chest is facing North, the data value is 2. If it's facing South, it's 3. West is 4, and East is 5. A wildcard is -1, which doesn't require any specific direction. So far, your command is /testforblock ~ ~-1 ~ minecraft:chest -1.

Your next step is to specify the data tag, or what items you want to test for in the chest. To test for any amount of sticks (I'm assuming this is what you want as you put it in the original post) the data tag would be {Items:[{id:minecraft:stick}]}.

If we combine all the parts, your new command is:

/testforblock ~ ~-1 ~ minecraft:chest -1 {Items:[{id:minecraft:stick}]}



Pictures about "why does this command block code not work"

why does this command block code not work - Black and Gray Laptop Computer Turned on Doing Computer Codes
why does this command block code not work - PHP Screengrab
why does this command block code not work - Computer Codes



How do you get command blocks to work?

To activate the command block, just activate the redstone device that is attached to the command block. In this example, the redstone device is a lever. So you would activate the command block by toggling the lever.

How do you use a command block code?

You forgot to give the player argument leading to a syntax error. This is the programming term for a grammar error. The unexpected " is related to the internal representation of the item name you supplied.



5 reasons why your command block invention is not working




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Markus Spiske, Christina Morillo, Pixabay, Pixabay