Minecraft – /blockdata ~ ~ ~ {Items:[]} does not work at a certain distance away from the player

minecraft-commandsminecraft-java-edition

I have an adventure map with restocking chests. The cycle I have them on are activated by a daylight sensor which is connected to a series of command blocks. The following will be my command example:

Redstone trail leads to first command block with the command:

/blockdata -54 135 191 {Items:[]}

Restone trail continues to next command block after a redstone repeater delay. The next command is:

 /setblock -54 135 191 minecraft:air 0 destroy

Restone circuit finishes at a final command block after yet another redstone repeater delay. The final command is:

 /setblock -54 135 191 chest 0 replace
{LootTable:"mctools:chests/overworld lvl 1"}

(this is a custom loot table I created)

Also, here is a visual of my circuit. The current flows from right to left: enter image description here

So, what happens is the chest that was previously placed has its items destroyed, then the chest itself is destroyed, and finally a new chest with new loot is placed. This is what I want. The problem here is that this only works when my character is relatively close to the chest targeted when the commands are activated. If I back away, and then come back, the loot that was in the chest before the new chest was placed is all over the ground! I want the items to be destroyed not on the ground. It appears /blockdata ~ ~ ~ {Items:[]} doesn't work if the player is a distance away from the targeted chest. Like the items won't delete at a distance. Please explain this problem and how to fix it.

Best Answer

When the oldBlockHandlingValue on the /setblock command is destroy, the block will drop itself and its contents (Unless gamerules prohibit it). However, if you use replace instead, the chest will drop neither itself nor its contents.

Also, using redstone with command blocks is an excellent way to start learning command blocks. You'll eventually want to learn about chain and repeating command blocks and functions, and certainly use functions for anything large scale, but using just normal command blocks for small things, learning and experimenting is fine.