1

Item ID detection with command blocks

Willsr71's Avatar Willsr714/3/13 11:26 pm
1 emeralds 7.5k 3
1/3/2014 4:28 pm
pikminiac92's Avatar pikminiac92
I am working on a map and I would like to know if it is possible to detect weather a player has a certain item in their inventory by using the /testfor command. I personally dont think there is a way other then doing /clear @a 18 and having a comparator pointing out that activates when it clears someone with that. But I want to keep the item so that I can identify the player that had he item. Btw ID 18 is leaves.
Posted by Willsr71's Avatar
Willsr71
Level 53 : Grandmaster Programmer
197

Create an account or sign in to comment.

3

1
01/03/2014 4:28 pm
Level 34 : Artisan Geek
pikminiac92
pikminiac92's Avatar
do /clear then do /give to give it back then do what you want to do.
1
04/10/2013 2:42 am
Level 40 : Master Engineer
Steve_OH
Steve_OH's Avatar
Willsr71I am working on a map and I would like to know if it is possible to detect weather a player has a certain item in their inventory by using the /testfor command. I personally dont think there is a way other then doing /clear @a 18 and having a comparator pointing out that activates when it clears someone with that. But I want to keep the item so that I can identify the player that had he item. Btw ID 18 is leaves.


You mind giving a larger context? It is possible there are other avenues. I assume in order to get leaves they would need shears/silk touch, or is this an adventure map?

I have worked extensively with command blocks and have not found any test for commands that allow you to detect a certain type of item.

Alternatively, having them deposit the item into a hopper, which shoots it back at them when it's through 'counting' the leaves.

What will be the outcome of the test? Is this to unlock a feature?
1
04/07/2013 9:11 am
Level 31 : Artisan Architect
Falconblade99
Falconblade99's Avatar
I had this idea in the snapshots and it didn't work, but now i tested it and it does work , thanks for reminding me about it. As for giving the player the leaves back, I have an idea, although I'm a bit tired while writing this so it might be quite over-complicated.

Firstly I would set up a dummy scoreboard objective and give each player a different score on the scoreboard. eg Player 1 has 1 'dummy' point, player 2 has 2 'dummy' points etc. Once you do that you can target each player individually. So then you clear player 1 and if that is successful(test with comparator) then you give the player leaves.
As for giving them the right amount back that would be very difficult. You could clog up their inventory(with golden axes for example), teleport them to a room with a hopper on the floor and constantly give them leaves until their stack fills up and the leaves drop on the floor and into the hopper picks it up and tells you that they have filled up the stack. That would take quite a while though and be really annoying to keep track of if players had a small amount of leaves in their inventory, as you might have to run the /give command 63 times just to determine that the player had 1 leaf block in their inventory. Then you would also need a counter that could count to 63 quickly.
So all in all my system would probably work, but it would be nowhere near worth looking into because of its impracticality, but maybe I gave you an idea that would be practical.
I hope I helped at least a bit.
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome