1

/testfor help 6

TSchweibz 3/26/15 7:03 pm
1.2k
3/29/2015 10:56 am
How do I /testfor if a player has an item that is enchanted?
Posted by
TSchweibz
Level 2 : Apprentice Miner
0

  Have something to say?

JoinSign in

20

TSchweibz
03/29/2015 10:56 am
Level 2 : Apprentice Miner
I got it to work!
testfor @p {Inventory:[{id:"minecraft:wooden_sword",tag:{ench:[{id:16,lvl:1}]},tag:{RepairCost:1}}]}

I just used the data tag from the nbt editor and it worked beautifully, thanks everyone for all your help!
1
TSchweibz
03/29/2015 10:53 am
Level 2 : Apprentice Miner
In the NBT Editor it says ench: 1 entry and also RepairCost: 1, but i don't think NBT tags are the issue because if you /enchant a wooden sword it says it has 1 NBT tag and the command won't work for it. It seems to only work with the /give command (the scoreboard command works too). Is there any way it could testfor it how it is after used by the anvil because in the map the player has to get the book from one place and the sword from another and then combine them using the anvil. any ideas?
1
TSchweibz
03/28/2015 9:07 pm
Level 2 : Apprentice Miner
oh ok thank you!
1
Jmal116
03/28/2015 9:06 pm
Level 34 : Artisan System
Ah, well I found the reason for the error, but not what's causing it. See, when I was doing my testing, I gave myself an enchanted sword with this command:give @p wooden_sword 1 0 {ench:[{id:16,lvl:1}]}And the tested for it with the command above. When I got this sword, it had 1 nbt tag. However the one in your video (and when I tried using a book myself) had 2 tags. I'm not sure what the difference is or how I could figure it out, but that's probably what's causing the error. I'd suggest going in with an nbt editor and actually figuring out what tags the game thinks are there, and check to see if enchanting the sword normally does the same thing.
1
TSchweibz
03/28/2015 7:59 pm
Level 2 : Apprentice Miner
Here's a video where i use the command, maybe someone can figure out what I'm doing wrong

http://youtu.be/SLHh5FS71SE
1
TSchweibz
03/28/2015 6:39 pm
Level 2 : Apprentice Miner
It is still not working on my end, do you have it in a certain inventory slot?
1
Jmal116
03/28/2015 6:12 pm
Level 34 : Artisan System
Strange, it looks like the data structure's correct. Let me try it myself, see if I can figure it out.

Oh also, since you can testfor data tags, you don't have to use the scoreboard command if you don't need to target that player for anything else, If you do, then you might as well keep it.

EDIT I got it to work with this command:testfor @p {Inventory:[{id:"minecraft:wooden_sword",tag:{ench:[{id:16,lvl:1}]}}]}I literally copy/pasted the data directly from Skitto's comment, so if you can't get it to work it's likely something on your side.
1
TSchweibz
03/28/2015 6:02 pm
Level 2 : Apprentice Miner
?
1
TSchweibz
03/28/2015 2:32 pm
Level 2 : Apprentice Miner
any ideas anyone?
1
TSchweibz
03/28/2015 12:47 pm
Level 2 : Apprentice Miner
it works without the enchantment tag, how can i get it to work with the tag
1
TSchweibz
03/28/2015 12:41 pm
Level 2 : Apprentice Miner
It says that the data tag does not match for me
1
TSchweibz
03/27/2015 9:48 pm
Level 2 : Apprentice Miner
Thank you so much!
1
Skitto493
03/27/2015 9:29 pm
Level 55 : Grandmaster Dragon
Alright, first, create a scoreboard objective. I'll name it HasSword. Make it a dummy objective.

Now: have a command block that has /scoreboard players set @a HasSword 1 {Inventory:[{id:"minecraft:wooden_sword",tag:{ench:[{id:16,lvl:1}]}}]}

Now, have a command block with:
/testfor @a[score_HasSword_min=1]

If you want it to reset, you can have a command block setting the HasSword score to 0 happening on the same tick first in the redstone sequence.
1
TSchweibz
03/27/2015 8:28 pm
Level 2 : Apprentice Miner
I just need a command that will test for a sharpness 1 wooden sword anywhere in the players inventory please
1
TSchweibz
03/27/2015 7:07 pm
Level 2 : Apprentice Miner
Jmall116, could you give me a command because i cannot get this to work, thanks.
1
TheArchitect_95
03/27/2015 5:11 pm
Level 32 : Artisan Architect
Dragnoz seems to know his stuff, this video may help.
https://youtube.com/watch?v=OC-fbKL7G2E
1
Jmal116
03/27/2015 4:18 pm
Level 34 : Artisan System
When I use enchantments, I usually use the enchantment number instead of the enchantment name. I'm not sure if it's required to do this or not, but the wiki says it's a short tag, so it's at least worth trying. If that doesn't work, also try adding the slot tag to define a certain inventory slot. I think it should work without it, but sometimes this stuff surprises me.
1
TSchweibz
03/27/2015 2:54 pm
Level 2 : Apprentice Miner
no sorry it didn't work. Anyone else?
1
TheArchitect_95
03/27/2015 3:54 am
Level 32 : Artisan Architect
I believe you need to insert a tag parameter.
/testfor @p {Inventory:[{id:"wooden_sword",tag:{ench:[{id:sharpness,lvl:1}]}]}
Or something along these lines. I'm not brilliant with data tags myself so don't be surprised if this doesn't work.
1
TSchweibz
03/26/2015 8:39 pm
Level 2 : Apprentice Miner
/testfor @p {Inventory:[{id:"minecraft:wooden_sword",ench:[{id:sharpness,lvl:1}]}]}

this is what I have come up with so far, but it says that i did not match the required data structure, any ideas?
1

Welcome