forum Forumsplay_arrow Minecraft fiber_manual_record Redstone

1

Item ID detection with command blocks

1 emerald3 replies7,160 views
created 04/03/2013 11:26 pm by Willsr71
last reply 01/03/2014 4:28 pm
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 avatar
Willsr71
Level 52 : Grandmaster Programmer
196

comment Login or register to post a reply.

3 replies

01/03/2014 4:28 pm
Level 31 : Artisan Geek
pikminiac92
do /clear then do /give to give it back then do what you want to do.
04/10/2013 2:42 am
Level 37 : Artisan Engineer
Steve_OH
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?
04/07/2013 9:11 am
Level 28 : Expert Architect
Falconblade99
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

Browse

Site

© 2010 - 2019
planetminecraft.com

Welcome