Minecraft – Determine Minecraft item type from entity or inventory

minecraft-commandsminecraft-java-edition

I have a dropper which can contain, of course, any items. Assuming I can already target this dropper in a command's target selector, how can I determine what item is in the first slot of its inventory and use that item ID for another command? Alternatively, if this dropper is triggered and spits out the item as an entity, is there a way to determine what type of item the entity is and use that?

Basically, I'm trying to use command blocks to turn a certain dropper into a block-placer. But for that to be useful, it should be able to take whatever type of block the player puts in its inventory and place that. How can I determine what type of block is there? The only way I can think of is to check the inventory for literally every type of block in the game, but that would require over a hundred command blocks and be highly inefficient. Is there a better way?

Best Answer

The Command Block Structure

  • In the top left command block: fill ~ ~-1 ~ ~ ~-1 ~ wool 14
  • In the bottom left command block: fill ~ ~1 ~ ~ ~1 ~ redstone_block
  • In the center-left command block: testforblocks ~ ~-1 ~ ~ ~-1 ~ [x2] [y2] [z2] where [x2] [y2] and [z2] are the coordinates of the target dropper.

The dropper on the top is completely unnecessary and is only there because I used this in a tutorial. In the far right command block would be the command you want executed when the two droppers match.