1

Help with testfor (@e)

TheRedSkorpion's Avatar TheRedSkorpion7/6/14 3:16 pm
1 emeralds 1.9k 7
7/6/2014 4:15 pm
TheRedSkorpion's Avatar TheRedSkorpion
I tried to use /testfor to detect if a specific block was dropped on the ground. Here is my command:
/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
Posted by TheRedSkorpion's Avatar
TheRedSkorpion
Level 20 : Expert Engineer
10

Create an account or sign in to comment.

7

1
07/06/2014 4:14 pm
Level 20 : Expert Engineer
TheRedSkorpion
TheRedSkorpion's Avatar
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:
{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
07/06/2014 4:10 pm
Level 9 : Apprentice Engineer
HawkpathAS
HawkpathAS's Avatar
I was not aware that you can test for a datatag! When was that added?
1
07/06/2014 4:15 pm
Level 20 : Expert Engineer
TheRedSkorpion
TheRedSkorpion's Avatar
Hum I think the one of the 1.8 snapshot
1
07/06/2014 3:46 pm
Level 20 : Expert Engineer
TheRedSkorpion
TheRedSkorpion's Avatar
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.
1
07/06/2014 3:31 pm
Level 9 : Apprentice Engineer
HawkpathAS
HawkpathAS's Avatar
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".

/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
07/06/2014 3:47 pm
Level 16 : Journeyman Engineer
Skylinerw
Skylinerw's Avatar
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 @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
07/06/2014 3:21 pm
Level 15 : Journeyman Unicorn
TBGPrison
TBGPrison's Avatar
I think its minecraft:firework, not sure. (I suck at redstone/commandblocks)
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome