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]

In Wii Sports Resort, can I have an overview of all my stamps? In Wii Sports Resort, can I have an overview of all my stamps?

Posted On: March 9, 2023
Is there an overview of all stamps for all games somewhere? So far, my only option is to access (and start playing) every single game in order to see what stamps I am missing, which is quite annoying....[More]


Best Hogwarts Legacy Magic Combo Button Layouts Best Hogwarts Legacy Magic Combo Button Layouts

Posted On: June 6, 2023
Just picked up the game on PS5 and loving it. But I’m wondering what people think are the best combos to set up for their magic. I’m about 35% of the way through the game so I have a fair ...[More]


Downloading windows version of steam games on a mac to copy over to a pc Downloading windows version of steam games on a mac to copy over to a pc

Posted On: June 9, 2023
I am sharing an internet connection with a few roommates and have a data cap. I would love to be able to use my MacBook to download games onto it, create Steam backups and install them on Windows. ...[More]


Sunken Bridge Level on Pirates of Dark Water Sunken Bridge Level on Pirates of Dark Water

Posted On: March 24, 2023
How do you get past the sunken bridge level for pirates of dark water on sega genesis? I've been stuck on this level for ages and I can't get past it. Question from user Rakel at gaming.sta...[More]


Does Beaver Woodie get poison damage in Hamlets Gas Rainforest? Does Beaver Woodie get poison damage in Hamlets Gas Rainforest?

Posted On: February 7, 2023
As per the title:. I wonder if Woodie in beaver form takes damage from Hamlet's Gas Rainforest biome? So does it progressively lower the beaver meter? And does the rate of damage change? ...[More]


What's your BG3 take: Hot or Cold What's your BG3 take: Hot or Cold

Posted On: November 20, 2025
Here's mine: This concept art is significantly better then the Soul Vestment we got.Question from user DC_Lark at BaldursGate3 at reddit.com.Answer:Dame Aylin is cool, but I like the original Nightson...[More]


How does Grabby Hand work in Peglin? How does Grabby Hand work in Peglin?

Posted On: August 24, 2023
The description for the Grabby Hand relic states:. Flying enemies are attacked horizontally, allowing for improved targeting. What does "attacked horizontally" mean? How does Grabby Ha...[More]


Where do I sell Specials? Achievement: Arent you Special in Farmville? Where do I sell Specials? Achievement: Arent you Special in Farmville?

Posted On: April 13, 2023
How can I sell the specials? I would like to get the Google Play achievement but my selling board does not have a "special". I am level 52. I understand I may be lacking some requireme...[More]


Why cant I satisfy the Diamond Equipment challenge in Age of Empires 2? Why cant I satisfy the Diamond Equipment challenge in Age of Empires 2?

Posted On: June 30, 2023
I've tried to complete this challenge multiple times, but it never seems to complete. I have tried playing multiple single player skirmishes without cheats and completed all 15 blacksmith upgrades...[More]


What happens to free games obtained through PlayStation Plus after it expires? What happens to free games obtained through PlayStation Plus after it expires?

Posted On: March 3, 2023
I bought a three months membership for PlayStation Plus some time ago. This membership has already expired. While it was active, I got the classic PSOne Resident Evil titles for free. Will I be able t...[More]