3

I am working on the project I've seen mentioned everywhere: farm every farmable item and put it all in one central storage system. I was wondering if there was an easy way to reset all chest and hopper inventories in an area, so I don't have random items in all my shulkers and none of them ever get popped off and go into the storage because they aren't completely full. Kind of like what /data does, but on a much larger scale. Below are pictures of the sorter, if it helps.

The top is the standard item sorter. The middle is the shulker loader. The bottom is chest minecart output (for crafting, smelting, and brewing). The whole thing is 2-wide tileable.

1 Answer 1

1

I made a simple command chain that will empty any block with items in it. It doesn't work for entities such as Minecraft with chest. I could also make that work, but it would be a bit more trouble.

Anyway, I made an armor stand that checks and removes the Items path of any block in the same block as the armor stand, and then I moved it based on a few scoreboards.

Setup:

Summon the Armor stands:

/summon armor_stand ~ ~ ~ {Marker:1b,CustomName:'{"text":"ClearChest"}',Tags:["Clear"]}

and also another with the tag GPS instead of Clear.

Add the scoreboards:

scoreboard objectives add ClearChestX dummy

and ClearChestZ and ClearChestY as well the same way.

Give the armor stand and fake players a score:

/execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s run scoreboard players set @s ClearChestX 0

Then the same command two more times but change the X to Z and Y.

Fake players:

scoreboard players set Max.X ClearChestX 0
scoreboard players set Max.Z ClearChestZ 0
scoreboard players set Max.Y ClearChestY 0

Here I have 3 fake players that all get a score of 0 on separate scores. Make sure the name matches up with the score name. The fake players have a . in the name, so no actual player can have the same name.

ClearMachine:

Because there are so many commands I will simply list them all and explain a bit afterward. (All in one chain command line)

Command 1:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s if score @s ClearChestX < Max.X ClearChestX run data remove block ~ ~ ~ Items

Command 2:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s if score @s ClearChestX < Max.X ClearChestX run tp @s ~1 ~ ~

Command 3:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s if score @s ClearChestX < Max.X ClearChestX run scoreboard players add @s ClearChestX 1

Command 4:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX run data modify entity @s Pos[0] set from entity @e[limit=1,type=minecraft:armor_stand,name=ClearChest,tag=GPS] Pos[0]

Command 5:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX if score @s ClearChestZ < Max.Z ClearChestZ run tp @s ~ ~ ~1

Command 6:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX if score @s ClearChestZ < Max.Z ClearChestZ run scoreboard players add @s ClearChestZ 1

Command 7:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX unless score @s ClearChestZ < Max.Z ClearChestZ if score @s ClearChestY < Max.Y ClearChestY run data modify entity @s Pos[2] set from entity @e[limit=1,type=minecraft:armor_stand,name=ClearChest,tag=GPS] Pos[2]

Command 8:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX unless score @s ClearChestZ < Max.Z ClearChestZ if score @s ClearChestY < Max.Y ClearChestY run tp @s ~ ~1 ~

Command 9:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX unless score @s ClearChestZ < Max.Z ClearChestZ if score @s ClearChestY < Max.Y ClearChestY run scoreboard players add @s ClearChestY 1

Command 10:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX unless score @s ClearChestZ < Max.Z ClearChestZ if score @s ClearChestY < Max.Y ClearChestY run scoreboard players set @s ClearChestZ 0

Command 11:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX if score @s ClearChestZ < Max.Z ClearChestZ if score @s ClearChestY < Max.Y ClearChestY run scoreboard players set @s ClearChestX 0

Command 12:

execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=Clear] at @s unless score @s ClearChestX < Max.X ClearChestX unless score @s ClearChestZ < Max.Z ClearChestZ unless score @s ClearChestY < Max.Y ClearChestY run data modify entity @s Pos set from entity @e[limit=1,type=minecraft:armor_stand,name=ClearChest,tag=GPS] Pos

Okay, so:

Command 1: Clears any data in the Items path for any block that the armor stand with the Clear tag is at.

Command 2: Teleports the Clear tag armor stand in the X direction by 1, as long as the Clear tag armor stands ClearChestX score is smaller than Max.X score.

Command 3: Adds 1 to the Clear tag armor stands ClearChestX score, as long as the score is smaller than Max.X.

Command 4: Unless the ClearChestX score of the Clear tag armor stand is smaller than Max.X, so if it is equal or bigger. It modifies the X position data of the Clear tag armor stand from the GPS tag armor stand. Basically: tp to start location without the need for coordinates.

Command 5: Teleporst the Clear tag armor stand 1 in the Z direction if X score is equal to Max.X and as long as the Z score of the armor stand is smaller than Max.Z.

Command 6: Adds 1 score to the Clear tag armor stands Z score, if same as above.

Command 7: tp to start, using the GPS tag armor stands Z Pos data, as long as X score of Clear tag armor stands is equal to Max.X and Z score also is equal to Max.Z and as long as Y score is smaller than Max.Y.

Command 8: Same conditions as above and then tp 1 in the Y direction.

Command 9: Same conditions again then add 1 Y score to Clear tag armor stand.

Command 10: Same conditions again then reset the Z score for Clear tag armor stand.

Command 11: Almost same conditions again, but as long as Z is smaller than Max.Z, reset the X score for Clear tag armor stand.

Command 12: If the X, Z, and Y scores of the Clear tag armor stand is all equal to the respective fake players, then the Clear tag armor stand will get the same position data as the GPS tag armor stand i.e. tp to start.

Use:

Now to set the size of your area you have to set the scores of the fake players. By using the commands I showed in the setup part, you can change your area size.

The scores should be set as equal to the area. Even if the armor stand starts at 0. So if you have a 5x5x2 area, you would run these commands:

scoreboard players set Max.X ClearChestX 5
scoreboard players set Max.Z ClearChestZ 2
scoreboard players set Max.Y ClearChestY 5

Note that I have arranged the names as X Z Y, because that is the order it operates in. As long as you can make sure you have entered the correct numbers it will be fine.

Then it's important that you place the GPS tag armor stand on the correct place. The GPS will need to be placed in the smallest coordinate block that is inside of your area. So if you have x from -5 to 3, it will be at -5. If you have y from 56 to 60, it will be at 56, and if you have z from 5 to 10, it will be at 5: [-5,56,5].

This command can be used to teleport the GPS:

/execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=GPS] run tp @s -6 56 10

Make sure you use whole numbers so it is nicely in the center of the block.

The armor stands are Marker so they can't be destroyed unless you use the kill command. Then this would work:

/execute as @e[type=minecraft:armor_stand,name=ClearChest,tag=GPS] run kill @s

Just change the tag= to GPS or Clear.

You can always spawn another one.


Also to make it a bit easier to implement I saved some structures:

clearchest - the main chain command block line.

clearchestsetup - the scoreboard commands.

clearchestarmorstands - the two commands to summon the armor stands.

clearchestreset - the command to reset the scores of the Clear tag armor stand, this will make it run again if the main line is powered.

If you run these in the order they are here, you shouldn't need anything more.

Place a continuous source of Redstone on the main chain line, all the outers just require a single input. You can activate the reset line to restart the operation. Try to not do it while it runs, I don't know what could break.

Here is the download link to the structures:

structures.zip

You'll have to unzip the zip file and then add all the structure files in %appdata%\.minecraft\saves\<Your world name>\generated\minecraft\structures, just remember to put the correct world name for you.

If you have any questions just put it in a comment and I'll come back to you as fast as I can.

2
  • Ok, thanks, how do I mark this question as answered?
    – Ekipsogel
    Commented Feb 23 at 1:00
  • There should be a check mark at the top of the answer. Commented Feb 25 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .