Arqade Asked by Aceplante on January 2, 2021
Let’s make this clear: I’m on 1.12.
I want to know if it is possible to prevent a player from taking certain items out of a chest. I’m trying to fill an entire chest with say, brown panes, except for the 3×3 grid in the center, and the player cannot remove the panes in any way.
You need to use /clear
to remove the items from inventory, and detect whether it succeeds. When in Survival Mode, /clear
only affects the cursor item of players in Survival Mode, not Creative. This will meant that you will need to switch to Survival whenever you want to test it. A bit annoying, but it's what has to be done!
To be able to replenish the item, you will need to check if the /clear
command actually did anything. You can accomplish this through the 1.12 version of /execute store
, which is /stats
.
The first thing you need to do is create a scoreboard objective for the value to be stored in. Here is a sample command:
/scoreboard objectives add tamperedChest
This command will create a scoreboard objective to hold the values in.
Next: Use a fake player to keep track of the score:
/scoreboard players set chest1 tamperedChest 0
Next: Give yourself the item and modify it with custom NBT tags or CustomName
tag to make it identifiable.
Next: Place a 5-block long repeating command chain. (Starting with 1 repeating command block with 4 chain command blocks after. If you don't know how to create a command chain, see this post.) Here are the commands that are supposed to go into each command block:
1. /stats entity @a set AffectedItems chest1 tamperedChest
2. /execute @a ~ ~ ~ clear @s stained_glass_pane 12 1 {TAGS}
3. /stats entity @a clear AffectedItems
Now, the fake player's score in objective tamperedChest
is going to be updated with the number of brown panes. We just need to detect for a 1
in the score and we're home free!
In the 4th command block, insert this command:
4. /scoreboard players test chest1 tamperedChest 1 1
Test for a 1
in chest1
's score.
The 5th command block needs to be set to conditional mode. The command though, is up to you on how you want to do it. Here you'll insert a command that will activate more commands to replenish the glass panes, or other placeholder items. Here are some ways I think of accomplishing this task:
/replaceitem
commands to put those glass panes back./function
command to run it./replaceitem
command, and you need 1 /replaceitem
command for each slot of the chest. But, if you do want to take that road, you most certainly can! Just have it set a redstone block next to a command chain that runs all the /replaceitem
commands!Learn more about these mechanics on the Minecraft Wiki:
/clear
command/stats
commandAnswered by ExpertCoder14 on January 2, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP