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]

Quidditch Gameplay Help in Hogwarts Legacy Quidditch Gameplay Help in Hogwarts Legacy

Posted On: July 14, 2023
I started playing this amazing game from last 2 days and I remember that when last time I started this game I got to play quidditch match which was amazing. As of now i’m level 12 and still did ...[More]


In SeriousSam, How do I get this body armour located in Tomb Of Ramses III? In SeriousSam, How do I get this body armour located in Tomb Of Ramses III?

Posted On: March 24, 2023
I'm at the Tomb Of Ramses III in Serious Sam HD, and there is some body armour located at the top of an area previously containing an Arachnoid. I'm unable to find anyway up to this area. . ...[More]


I need help naming my Durge I need help naming my Durge

Posted On: December 21, 2024
I’m open to any suggestions y’all may have.Question from user AlarmingAd3090 at BaldursGate3 at reddit.com.Answer:Jennerica Inkhorn.Answer from user No-Bad-463 at BaldursGate3 at reddit.com....[More]


Can you unlock secret stamps before beating the game in Storyteller? Can you unlock secret stamps before beating the game in Storyteller?

Posted On: November 24, 2023
After getting every crown in Storyteller, I unlocked a list of achievements called the Secret Stamp Collection. If I met the requirements for one of these stamps before beating the game, could I unloc...[More]


What's your favorite summoner? What's your favorite summoner?

Posted On: July 23, 2024
The ultimate power fantasy in gaming, getting your summons so strong you don't actually have to play the game. What's your favorite summoner setups? Multi or Mono, curious to see how others enjoy the ...[More]


Gale dropped haste and idk why Gale dropped haste and idk why

Posted On: October 3, 2023
I don’t think this actually has spoilers but it takes place in act 3. Ok so manip cast command, but tav cancelled it with psionic dominance and shadow heart used the backlash. Idk who he was tar...[More]


If you could Avarda Kedavra any person in Hogwarts who would it be? If you could Avarda Kedavra any person in Hogwarts  who would it be?

Posted On: July 5, 2023
I'm going Ignatia Wildsmith. Im so tired of hearing those same 3 lines everytime I floo flame!. Question from user Robj1992 at HogwartsLegacyGaming at reddit. Answer: The b*tch who tries ...[More]


Whats this game with a cyberspace aesthetic featured in a youtube clip? Whats this game with a cyberspace aesthetic featured in a youtube clip?

Posted On: February 7, 2023
This video starts with a montage of game clips and I'm trying to figure out what the game is that appears at 10 seconds in. It features a cyberspace aesthetic and it has a first-person perspective...[More]


Zelda TOTK, What does the blue numbers for my weapon strength indicate? Zelda TOTK, What does the blue numbers for my weapon strength indicate?

Posted On: May 20, 2023
I have a wide selection of fused weapons. Though, I noticed that many of the numbers are colored blue while the rest are white. At first I assumed it was to indicate either fused weapons or weapons...[More]


How do you keep playing in a journey? How do you keep playing in a journey?

Posted On: March 23, 2026
Maybe it’s more a rant than a support request. .I really have a problem with the tons of choices this game has. Actually, the problem isn’t the choices but the fail tests. .Everytime I fail someth...[More]