Possible as of 1.14, which allows you to use the new /data modify
command to copy NBT between sources.
You need to have three commands per slot: one to copy the ID, one to copy the Count, and one to copy the tag
compound (which stores the item's other data). You don't want to copy the Slot
tag because it'll mess things up. Instead, you'll rely on it for selecting which slots to modify.
It won't be this easy though. Coding practice says you need a third temporary location when you swap two values. So free up a third slot in the block you want to modify as a utility slot. In this case, I'm going to swap slots 0 and 1 of the chest at coordinates (12, 23, 34) with my utility slot at slot 0 of block (0, 0, 0). Make sure to place one piece of dirt in the utility slot.
data modify block 0 0 0 Items[0].id set from block 12 23 34 Items[{Slot:0b}].id
data modify block 0 0 0 Items[0].Count set from block 12 23 34 Items[{Slot:0b}].Count
data modify block 0 0 0 Items[0].tag set from block 12 23 34 Items[{Slot:0b}].tag
data modify block 12 23 34 Items[{Slot:0b}].id set from block 12 23 34 Items[{Slot:1b}].id
data modify block 12 23 34 Items[{Slot:0b}].Count set from block 12 23 34 Items[{Slot:1b}].Count
data modify block 12 23 34 Items[{Slot:0b}].tag set from block 12 23 34 Items[{Slot:1b}].tag
data modify block 12 23 34 Items[{Slot:1b}].id set from block 0 0 0 Items[0].id
data modify block 12 23 34 Items[{Slot:1b}].Count set from block 0 0 0 Items[0].Count
data modify block 12 23 34 Items[{Slot:1b}].tag set from block 0 0 0 Items[0].tag
This is possible somewhat easily since 1.13 thanks to /execute store
.
As a preparation, you need some scoreboard:
/scoreboard objectives add temp dummy
Then you need the value 1 somewhere. Here I set it for the dummy player #1
(which can't be a real player name and does not appear in scoreboard displays):
/scoreboard players set #1 temp 1
When you actually want to decrease the item count, first store the amount in a scoreboard:
/execute store result score @s temp run data get block ~ ~ ~ Items[{Slot:0b}].Count
I specifically check for Slot:0b
instead of simply using the index (Items[0]
) as a workaround of a bug.
Now you need to subtract 1:
/scoreboard players operation @s temp -= #1 temp
And store it back to the chest's NBT.
/execute store result block ~ ~ ~ Items[{Slot:0b}].Count byte 1 run scoreboard players get #1 temp
Best Answer
This command prevents items from stacking. If you put it into a repeating command block, then items should no longer stack, as soon as they were dropped at least once (it will not break stacks that already exist as stacks)
Note: I use Minecraft 1.14.2 and this command may not work in older versions