1
Help with testfor (@e)
I tried to use /testfor to detect if a specific block was dropped on the ground. Here is my command:
This command doesnt work and I dont know why.
Other possibility could be to have a custom name and testfor it instead (but I don't know if I can testfor a custom name for an item on the ground). Also, I didn't know if the custom name should go in the data tag or between the square brackets after the selector.
My item also have custom echantment.
Basicaly, I would like to know if it is possible to detect these data tags for an item on the ground: id (i know I can check the id, but it doesn't work for some reasons :/ ), name, ench.
Thanks for reading
/testfor @e[type=Item] {id:"minecraft:firework_charge"}
This command doesnt work and I dont know why.
Other possibility could be to have a custom name and testfor it instead (but I don't know if I can testfor a custom name for an item on the ground). Also, I didn't know if the custom name should go in the data tag or between the square brackets after the selector.
My item also have custom echantment.
Basicaly, I would like to know if it is possible to detect these data tags for an item on the ground: id (i know I can check the id, but it doesn't work for some reasons :/ ), name, ench.
Thanks for reading
Create an account or sign in to comment.
7
1
I found the solution! Thanks for the help, I jsut didnt remember that when you write a data tag of an item entity, it's writen like so:
Edit: You can also test for id, custom name and ench that way! You can also just use /testfor
{Item:{data}}
Edit: You can also test for id, custom name and ench that way! You can also just use /testfor
/testfor @e[type=Item] {Item:{id:"minecraft:firework_charge",tag:{display:{Name:"TEST"},ench:[{id:1,lvl:1}]}}}
1
I was not aware that you can test for a datatag! When was that added?
1
Hum I think the one of the 1.8 snapshot
1
I tought about using scoreboard but I supposed that using id:"minecraft:firework_charge" in the data tag of my testfor should work. Before it worked...
And my item is a firework charge, not just a normal firework.
Thanks for the answer, really, I just wanted to know if it was possible so I'm gonna use scoreboard probaly.
And my item is a firework charge, not just a normal firework.
Thanks for the answer, really, I just wanted to know if it was possible so I'm gonna use scoreboard probaly.
1
Sadly, you can't check for a custom name even if you do rename it because the item entity doesn't retain this bit of information. This method is a bit more complicated than you might like, but it works.
First add an objective. It can have any name, for example, "fireworkItem".
Next, you want to make a redstone clock (any kind is fine really, just Google "hopper clock" if you want an efficient one). Connected to this clock should be a command block with the following command:
Then, attach another command block to the same clock with the following command:
That's it! If you have any issues, feel free to ask me.
First add an objective. It can have any name, for example, "fireworkItem".
/scoreboard objectives add fireworkItem dummy
Next, you want to make a redstone clock (any kind is fine really, just Google "hopper clock" if you want an efficient one). Connected to this clock should be a command block with the following command:
/scoreboard players set @e[type=Item] fireworkItem 1 {id:minecraft:fireworks}
Then, attach another command block to the same clock with the following command:
/testfor @e[type=Item,score_fireworkItem_min=1]
That's it! If you have any issues, feel free to ask me.
1
As of 14w21a, most entities will accept the "CustomName" tag, which includes item entities. As well, the syntax is incorrect: item entities store its item data within the "Item" compound tag:
/testfor would be used if you merely want to detect the presence, while /scoreboard would be used to both detect it and manipulate it via /execute and other commands.
EDIT: modified the item ID to match above post.
/testfor @e[type=Item] {Item:{id:minecraft:firework_charge}}
/scoreboard players set @e[type=Item] OBJECTIVE 1 {Item:{id:minecraft:firework_charge}}
/testfor would be used if you merely want to detect the presence, while /scoreboard would be used to both detect it and manipulate it via /execute and other commands.
EDIT: modified the item ID to match above post.
1
I think its minecraft:firework, not sure. (I suck at redstone/commandblocks)