This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Ashton's profile picture

Detect item a player is right-clicking with?

Started by Ashton, 12 December 2013 - 05:18 PM
Ashton #1
Posted 12 December 2013 - 06:18 PM
Is ther a way to detect what Item a player is right-clicking with? I want to make a map where your trying to find a specific component, then you right-click a button, a hidden PC runs and IF-Then program, and if the item is the one required it takes the item from you, swaps out a block for a model nearby to "complete the machine" (done using the AGI from immibirs' peripherals) and after some "animation" (blocks replaceing and moving) the player goes on to the next part of the puzzle — but if they right-click with an item OTHER than the one they are supposed to, it will make a sound or /tell them that it needs a different item…

Any way to do this? I have no problem installing peripheral packs if I need to.
gezepi #2
Posted 12 December 2013 - 07:30 PM
OpenCCSensors can detect players and gives a lot of information about them. You could use it to check what the user is holding when they right-click on the screen.
Otherwise you could have the player put the item into a chest, then check the chest for the correct type.
theoriginalbit #3
Posted 12 December 2013 - 07:49 PM
Nope, there is no way that I know of that you can; well no way to do it as easy as you want it to.

You can however use the PIM from OpenPeripheral. When a player stands on that you can gain access to their entire inventory and even remove and place items in it from adjacent inventories.
Ashton #4
Posted 12 December 2013 - 09:46 PM
OpenCCSensors can detect players and gives a lot of information about them. You could use it to check what the user is holding when they right-click on the screen.
Otherwise you could have the player put the item into a chest, then check the chest for the correct type.

Not what I was wanting, but it gave me an idea - there is a "dropped item sensor" so I could set up a chute the player drops the item into, and if the sensor detects it to be the correct one, it activates the "clear puzzle" code, and if it's not the right item, it just drops it back to the player (or for humor drops it into a hopper connected to a dispenser and fires it at the player's face like a canon) Or I could make it even more "cutscene-like" and when they drop the item a turtle collects it and puts it in a disguised chest, then the sensor detects if it's the correct item… and if not the turtle is given the item back and it then drops the item down a chute to the player…


Nope, there is no way that I know of that you can; well no way to do it as easy as you want it to.

You can however use the PIM from OpenPeripheral. When a player stands on that you can gain access to their entire inventory and even remove and place items in it from adjacent inventories.

That gives me a fun idea for an unscruplous NPC who requests an item and when you talk to him again he says "…your not holding out on me, are you?" and the PIM checks to see if your holding the item he wants…
Mark100 #5
Posted 14 December 2013 - 01:28 PM
For a dropped item sensor, use a hopper and run a co mparator out of it. Then in your computer you can detect whether a redstone signal from the comparator is there. That uses redstone, though.