Is there any way in Minecraft to detect who deposited a diamond into a chest using command blocks?

[BACK]
Is there any way in Minecraft to detect who deposited a diamond into a chest using command blocks?
Posted On: April 26, 2024

So far, I've been able to detect when a diamond is placed into a chest's inventory but how can I detect who placed that diamond?


I'd prefer not to use the nearest player because someone else could potentially be falsely identified. (I have a command chain that trades players emeralds in exchange for experience levels and it also sometimes robs random nearby players.).


Some context: I'm making a race to be the first to deposit a diamond. I could constrain the player accessing the chest and just check who is standing on a block, but if I did that, I could also just test the player's inventory directly. But that seems boring. Adding the chest adds to the drama, I feel. Like, if someone fumbles last minute and deposits dirt on accident, someone else could easily win, which is fun.


My command chain is currently:.


if block x y z chest{Items:[{id:"minecraft:diamond"}]}.


say Diamond Detected.


Edit: The diamonds are mined and as such, I will not necessarily be able to tag them for each player. Another user suggested I could scan the inventories of the users at every tick and tag the diamonds in their inventory with their name. I don't know how to do this, though I believe this is the direction where I will find my answer.


Question from user Robert Talada at gaming.stackexchange.com.


Answer:

If you don't know who has each diamond.


Minecraft 1.20.5 changed the syntax of some of the commands a bit but the concept behind this answer should still be valid.


Step one.


Give each player a unique scoreboard ID. See this related question for how to do that.


Step two.


Run the following command in a repeating, always active command block:.


execute as @e[type=item,nbt={Item:{id:"minecraft:diamond"}}] run data merge entity @s {Item:{tag:{Unclaimed:1b}}.


This gives each diamond item on the ground a custom Unclaimed tag, allowing you implement Step 3 without 30+ command blocks per player.


Step three.


Once for each player who could be playing the map, run in a repeating command block:.


clear @a[scores={Id=1}] diamond{Unclaimed:1b} 1.


and then, in a conditional chain command block that the repeating command block is pointing to.


give @a[scores={Id=1}] diamond{PlayerOwns:1b} 1.


Repeat this for each player, using scores={Id=2} and PlayerOwns:2b for the second player and so on.


Step four.


Now that each diamond has a tag describing whose it is, you can use the technique described in ExpertCoder14's answer to determine who put a diamond in the chest.


This has a known bug that if Alice puts a diamond in a container, and then Bob takes the diamond out of the container (and never drops and picks it up again), the diamond is still interpreted as belonging to Alice -- but I actually like that if I understand what you're doing correctly; if you stole someone else's diamond from a chest instead of mining your own, that means you're trying to cheat… karma!.


If you want a more seamless experience, you may want to interest yourself in player inventory modification. With the method above, the diamond is visibly replaced by a different one, you can use this to make a seamless replacement.


Answer from user pppery at gaming.stackexchange.com.


[BACK]
Is there any way in Minecraft to detect who deposited a diamond into a chest using command blocks?
Posted On: April 26, 2024

So far, I've been able to detect when a diamond is placed into a chest's inventory but how can I detect who placed that diamond?


I'd prefer not to use the nearest player because someone else could potentially be falsely identified. (I have a command chain that trades players emeralds in exchange for experience levels and it also sometimes robs random nearby players.).


Some context: I'm making a race to be the first to deposit a diamond. I could constrain the player accessing the chest and just check who is standing on a block, but if I did that, I could also just test the player's inventory directly. But that seems boring. Adding the chest adds to the drama, I feel. Like, if someone fumbles last minute and deposits dirt on accident, someone else could easily win, which is fun.


My command chain is currently:.


if block x y z chest{Items:[{id:"minecraft:diamond"}]}.


say Diamond Detected.


Edit: The diamonds are mined and as such, I will not necessarily be able to tag them for each player. Another user suggested I could scan the inventories of the users at every tick and tag the diamonds in their inventory with their name. I don't know how to do this, though I believe this is the direction where I will find my answer.


Question from user Robert Talada at gaming.stackexchange.com.


Answer:

If you don't know who has each diamond.


Minecraft 1.20.5 changed the syntax of some of the commands a bit but the concept behind this answer should still be valid.


Step one.


Give each player a unique scoreboard ID. See this related question for how to do that.


Step two.


Run the following command in a repeating, always active command block:.


execute as @e[type=item,nbt={Item:{id:"minecraft:diamond"}}] run data merge entity @s {Item:{tag:{Unclaimed:1b}}.


This gives each diamond item on the ground a custom Unclaimed tag, allowing you implement Step 3 without 30+ command blocks per player.


Step three.


Once for each player who could be playing the map, run in a repeating command block:.


clear @a[scores={Id=1}] diamond{Unclaimed:1b} 1.


and then, in a conditional chain command block that the repeating command block is pointing to.


give @a[scores={Id=1}] diamond{PlayerOwns:1b} 1.


Repeat this for each player, using scores={Id=2} and PlayerOwns:2b for the second player and so on.


Step four.


Now that each diamond has a tag describing whose it is, you can use the technique described in ExpertCoder14's answer to determine who put a diamond in the chest.


This has a known bug that if Alice puts a diamond in a container, and then Bob takes the diamond out of the container (and never drops and picks it up again), the diamond is still interpreted as belonging to Alice -- but I actually like that if I understand what you're doing correctly; if you stole someone else's diamond from a chest instead of mining your own, that means you're trying to cheat… karma!.


If you want a more seamless experience, you may want to interest yourself in player inventory modification. With the method above, the diamond is visibly replaced by a different one, you can use this to make a seamless replacement.


Answer from user pppery at gaming.stackexchange.com.


[BACK]

Is there any difference between a TV and a monitor in regard to input latency? Is there any difference between a TV and a monitor in regard to input latency?

Posted On: June 11, 2023
Is there any difference between a TV and a monitor in regard to input latency (for high-speed online games such as fighting games, sports simulators, and FPS) when connected to a PS/Xbox via HDMI cabl...[More]


XBox 360 storage device issue with Darksiders XBox 360 storage device issue with Darksiders

Posted On: April 16, 2024
I've been playing Darksiders now for some time now and I've noticed that when I start the game, in the main menu where it says "Press Start", it always triggers me to select a storage device. Why does...[More]


Where is Anduin actually? Where is Anduin actually?

Posted On: July 29, 2023
I played Shadowlands a little bit at the end so I am not familiar with much that happend in that expansion. I am now leveling my second character in Dragonflight. I am at the Stormwind docks and sa...[More]


Besides practicing, what are some great ways to become a better player? Besides practicing, what are some great ways to become a better player?

Posted On: January 20, 2018
Besides practicing, what are some great ways to become a better StarCraft II player? Off the top of my head I can think of:. Watching replays with commentary from youtube.com/hdstarcraft and you...[More]


Does Lore Bard get good at later levels? Does Lore Bard get good at later levels?

Posted On: September 25, 2023
Hey all, I know basically all straight classes end up good enough, but I am trying to decide between a pure sorcerer or pure bard. I have a paladin/warlock sitting at the start of ACT 3 and just got b...[More]


In Path of Exile, Whats the intended purpose of the Book of Regression? In Path of Exile, Whats the intended purpose of the Book of Regression?

Posted On: March 30, 2023
The Book of Regression, an item you get by vendoring an Orb of Scouring with 1x Scroll of Wisdom, apparently downlevels your character by 1 and resets all exp to 0. What I want to understand is, fo...[More]


Man spoke nothing but facts and truth Man spoke nothing but facts and truth

Posted On: December 13, 2024
Question from user ScarHydreigon87 at BaldursGate3 at reddit.com.Answer:Is it even legal for one man to be this based?Answer from user Roland1232 at BaldursGate3 at reddit.com....[More]


Whats the most efficient Minecraft mining strategy? Whats the most efficient Minecraft mining strategy?

Posted On: December 28, 2022
When I'm not exploring fresh caves or lands in minecraft, I'm busy trying to find deposits of diamond, gold and iron deep in the earth. So far I've just been digging around just above bedrock on a whi...[More]


Am I doing this Durge thing right? About to hit act 2 Am I doing this Durge thing right? About to hit act 2

Posted On: June 24, 2025
Question from user Smiley_707 at BaldursGate3 at reddit.com.Answer:Umm… I think you may have an IRL dark urge.Answer from user TheMediumEagle at BaldursGate3 at reddit.com....[More]


How much grain can a giant node produce with the production per 25 perk? How much grain can a giant node produce with the production per 25 perk?

Posted On: June 13, 2023
The total amount of stuff from a node can be increased by getting perks. Here are two such perks;. Mold supply: Increase the production of grain by +1 (or +2). Grain harvest: Increase the produc...[More]