I would like to use command blocks to swap the contents of two specific inventory slots dynamically, while retaining the item, data value, and stack size. I know it is possible to set a slot to contain a specific item, but I am unsure as to whether or not it is possible to switch them (without a ridiculous amount of command blocks, accounting for every possible item in the game). Is this possible?
Minecraft – How to swap two inventory slots dynamically
minecraft-commandsminecraft-java-edition
Related Topic
- Minecraft – Give player item(s) when player hits X amount of deaths
- Minecraft – How to make a rain of arrows in vanilla Minecraft using command blocks
- Minecraft – Decrease Stack Size in Chest
- Minecraft – Making crafted items usable in adventure mode
- Minecraft – Setting a damage value on to a slot
- Minecraft – Clearing just one item in a specific hotbar slot
- Minecraft – how would I refill an items durability over time with commands
Best Answer
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 theSlot
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.