As of 1.17, a loot table is no longer required, butthere are two ways to modify items while they are inside of the shulker box still isplayer's inventory.
Preparation
Item modifiers
You'll need to first place down a yellow shulker box, and place a temporary item1.17 introduced (like a piece of dirt)item modifiers, data pack files that can be invoked upon items in slot 0 (upper-left corner).
Important: Ensure the shulker box is otherwise empty, and always writeinventory to it with the NBT path Items[0]
modify their properties.
The standard location for this shulker box This is (-30000000, 0the easiest way to modify item properties, 1602)whether they are within the player's inventory or not.
Commands
With 1.17 out, you can use /item
to copy theHere is a sample item tomodifier for the shulker box.example in the question post:
item{
replace block"function": -30000000"minecraft:set_attributes",
0 1602"modifiers": container.0[
from entity @s weapon.mainhand{
Then, you can modify your item as much as you want inside the shulker box using any commands you like. For example:
data modify block (x) (y) (z) Items[0]"attribute": merge"minecraft:generic.attack_damage",
value {tag:{Enchantments:[{id "name":"minecraft "",
"amount":sharpness" 5,
lvl "operation":1s}]}} "addition",
execute store result block (x) (y) (z)"id": Items[0].tag.Enchantments[0].lvl"fffe27a9-0000-04d5-0002-50b6fffff656",
short 1.0 run scoreboard players get"slot": FakePlayer"mainhand"
myObjective }
]
}
Finally, replaceItem modifiers are placed at the folder /data/<namespace>/item_modifiers/<modifier_name>.json
. It can then be invoked upon any item withslot in any container block or entity's inventory, using /item
like so:
item replacemodify entity @s weapon.mainhand from<modifier_reference>
where <modifier_reference>
is your reference to the data pack file containing your item modifier's data. For example, if your item modifier's location is /data/special_enchants/item_modifiers/add_attributes.json
, then your modifier reference would be special_enchants:add_attributes
.
You can generate item modifier files using a generator such as misode.github.io, and you can read more about these changes on the relevant Minecraft Wiki page.
Commands only
With commands and command blocks only, /item
still allows us to cut down on the number of commands we run. However, we cannot take advantage of the performance benefit of item modifiers, given that /data
(the only other alternative) has a high impact on performance and is considered an expensive operation. This is why data packs are recommended for larger projects.
This method uses a temporary slot to store items while they are being modified. Usually, the standard location for this purpose is a yellow shulker box placed at the coordinates (-30000000, 0, 1602).
To copy an item from the player's main hand to an inventory slot of another block or entity, one of the following commands can be used:
item replace block -30000000<block> 0<slot> 1602from container.0entity <player> <slot>
item replace entity <entity> <slot> from entity <player> <slot>
The left side block or entity and slot refers to the location where the item(s) will be copied to, and the right hand side refers to where the item(s) are coming from. Therefore, the command can be reversed to copy the item(s) back to the player.
Example
The following example adds the Sharpness enchantment to the item in the player's main hand, and sets the level of this enchantment to one of the player's score values.
-
item replace block -30000000 0 1602 container.0 from entity @s weapon.mainhand
-
data modify block (x) (y) (z) Items[0] merge value {tag:{Enchantments:[{id:"minecraft:sharpness", lvl:1s}]}}
-
execute store result block (x) (y) (z) Items[0].tag.Enchantments[0].lvl short 1.0 run scoreboard players get @s sharpnesslvl
-
item replace entity @s weapon.mainhand from block -30000000 0 1602 container.0
Explanation
- Copies the item from the player's main hand to the shulker box.
- Accesses the item's data, and adds a temporary enchantment of Sharpness. Currently it has level I, but this will be changed by command #3.
- This command runs a
/scoreboard players get
to get the player's sharpnesslvl
score. Whatever number is retrieved gets set as the level on the enchantment as per the /execute store
part.
- This is the reverse of command #1, to copy the modified item and overwrite the old item in the mainhand.