How do I /testfor if a player has an item that is enchanted?
Create an account or sign in to comment.
20
1
I got it to work!
I just used the data tag from the nbt editor and it worked beautifully, thanks everyone for all your help!
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
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
oh ok thank you!
1
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
Here's a video where i use the command, maybe someone can figure out what I'm doing wrong
http://youtu.be/SLHh5FS71SE
http://youtu.be/SLHh5FS71SE
1
It is still not working on my end, do you have it in a certain inventory slot?
1
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:
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
?
1
any ideas anyone?
1
it works without the enchantment tag, how can i get it to work with the tag
1
It says that the data tag does not match for me
1
Thank you so much!
1
Alright, first, create a scoreboard objective. I'll name it HasSword. Make it a dummy objective.
Now: have a command block that has
Now, have a command block with:
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.
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
I just need a command that will test for a sharpness 1 wooden sword anywhere in the players inventory please
1
Jmall116, could you give me a command because i cannot get this to work, thanks.
1
Dragnoz seems to know his stuff, this video may help.
https://youtube.com/watch?v=OC-fbKL7G2E
https://youtube.com/watch?v=OC-fbKL7G2E
1
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
no sorry it didn't work. Anyone else?
1
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.
/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
/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?
this is what I have come up with so far, but it says that i did not match the required data structure, any ideas?