AnswerBun.com

How do I prevent some items from being removed from a chest? [1.12−]

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.

Arqade Asked by Aceplante on January 2, 2021

1 Answers

One Answer

Main answer for 1.12 players

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.

Setup

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:

  • Running a function. This is probably the best way, as you'll need a bunch of /replaceitem commands to put those glass panes back.
    Functions do require a little extra setup, but it's worth it, compared to having 54 command blocks (you need 1 command for each slot of the chest). See how to setup functions using the links below.
    As for running the function, use the /function command to run it.
  • Placing a redstone block. Using this method is ill-advised, as it will require you to place 54 command blocks in a row, because you need 1 command block for each /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:

Answered by ExpertCoder14 on January 2, 2021

Add your own answers!

Related Questions

Level 6 – Getting past the drone

3  Asked on September 24, 2020

 

Riot Police crashing on Mission 14

0  Asked on September 23, 2020 by mohamed-ennahdi-el-idrissi

 

Valorant shows no internet connection

0  Asked on September 23, 2020 by sheersh-jindal

   

How do I fix these graphics in Pokemon X using the Citra emulator?

1  Asked on September 23, 2020 by mafnankhattak260

   

Why can’t I buy any games in Uplay after linking Steam account?

1  Asked on September 22, 2020 by frotz16

     

Download stuck at 100 mb every time

1  Asked on September 22, 2020 by yash-tekade

 

What are non-periodic heals in world of warcraft?

1  Asked on September 21, 2020 by djangoblockchain

 

What is the weapon damage range formula?

0  Asked on September 21, 2020 by khrounose

 

Xbox 360 apps cannot connect to Xbox Live

1  Asked on September 21, 2020 by user462455

   

What’s special ammo in Destiny 2?

2  Asked on September 21, 2020 by drfish

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.