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]

Why am I not getting anything when I break blocks? Why am I not getting anything when I break blocks?

Posted On: February 6, 2023
I can break blocks but they give me nothing in one world. And I don't want to restart because I'm creating an adventure map.Question from user CrazyOlHoboJoe at gaming.stackexchange.com.Answer:If I we...[More]


How to solve the electric box riddle in Ace Ventura Game? How to solve the electric box riddle in Ace Ventura Game?

Posted On: February 14, 2023
In the game AceVentura there is an electric box. One has to press green/red + hand gear and red/blue + hand gear (see minute 55:14):. How are you supposed to know as a player that you have to hi...[More]


I have just discovered the devs gave Scratch his own tent I have just discovered the devs gave Scratch his own tent

Posted On: April 28, 2024
Question from user SmartTransformingAce at BaldursGate3 at reddit.com.Answer:I have well over 1000 hours in this game - and have only just discovered this.Answer from user SmartTransformingAce at Bald...[More]


How can I obtain Final Fantasy Adventure for a Mobile phone in the US? How can I obtain Final Fantasy Adventure for a Mobile phone in the US?

Posted On: March 20, 2023
A little back story. The first (quasi) RPG I ever played was Final Fantasy Adventure. At that time, I was quite the platformer fan and NES Zelda games, although moderately fun, never caught my attenti...[More]


Is there any way I can give myself 360° vision in game? Is there any way I can give myself 360° vision in game?

Posted On: March 15, 2024
A key gameplay mechanic in Project Zomboid is that your character can only see what's in front of them, even though the game has an isometric perspective. Anything behind becomes shrouded. That's fine...[More]


What is the equivalent to the blood moon when in the depths? What is the equivalent to the blood moon when in the depths?

Posted On: June 13, 2023
I've run around the depths for quite a while (100%-ed the lightroots) and I realized. I never saw a blood moon in the depths. The blood moon is essential because it causes enemies/ores to respa...[More]


Am I the only one with a light crush on Hogwarts Legacy Rookwood? Am I the only one with a light crush on Hogwarts Legacy Rookwood?

Posted On: June 5, 2023
Question from user PaletteSizeQueen at HogwartsLegacyGaming at reddit.com. Answer: no you’re not alone. i also find him a tad attractive lol. Answer from user itzclara_ at HogwartsLegac...[More]


How do I backup my Minecraft world on Xbox to a flash drive without realms? How do I backup my Minecraft world on Xbox to a flash drive without realms?

Posted On: June 10, 2023
How do I backup my Minecraft Bedrock world from my Xbox to a flash drive?. I don’t have realms and don’t want to get realms to backup my world. I want to keep it on a drive separate ...[More]


How does Skyrim determine if a dungeon is cleared? How does Skyrim determine if a dungeon is cleared?

Posted On: July 19, 2022
Skyrim adds an awesome feature, that lets you know if you have cleared a dungeon or not. This saves a lot of time and effort, because you do not have to revisit every dungeon you have been through lik...[More]


In Yakuza 0, How do I fight the 3rd to last opponent in the Colosseum? In Yakuza 0, How do I fight the 3rd to last opponent in the Colosseum?

Posted On: March 28, 2023
I have fought every opponent at the Bed of Styx colosseum except for one. Even after repeating every tournament multiple times, I haven't met the third to last person in the opponent list. Is t...[More]