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 boxinventory to modify their properties. This is otherwise empty, and always writethe easiest way to it withmodify item properties, whether they are within the NBT path Items[0]player's inventory or not.
The standard location for this shulker boxHere is (-30000000, 0, 1602).a sample item modifier for the example in the question post:
Commands
{
"function": "minecraft:set_attributes",
"modifiers": [
{
"attribute": "minecraft:generic.attack_damage",
"name": "",
"amount": 5,
"operation": "addition",
"id": "fffe27a9-0000-04d5-0002-50b6fffff656",
"slot": "mainhand"
}
]
}
With 1Item modifiers are placed at the folder /data/<namespace>/item_modifiers/<modifier_name>.json.17 out, you It can usethen be invoked upon any item slot in any container block or entity's inventory, using /item to copy the item to the shulker box.like so:
item replace block -30000000 0 1602 container.0 frommodify entity @s weapon.mainhand <modifier_reference>
Thenwhere <modifier_reference> is your reference to the data pack file containing your item modifier's data. For example, you can modifyif your item as muchmodifier'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 want insidecan 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 using any commands you likeplaced at the coordinates (-30000000, 0, 1602). For example
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:
dataitem modifyreplace block (x) (y) (z)<block> Items[0]<slot> mergefrom valueentity {tag:{Enchantments:[{id:"minecraft:sharpness",<player> lvl:1s}]}}<slot>
execute store result block (x) (y) (z) Items[0].tag.Enchantments[0].lvlitem shortreplace 1.0entity run<entity> scoreboard<slot> playersfrom getentity FakePlayer<player> myObjective<slot>
FinallyThe left side block or entity and slot refers to the location where the item(s) will be copied to, replaceand the right hand side refers to where the item with(s) are coming /item:from. Therefore, the command can be reversed to copy the item(s) back to the player.
item replace entity @s weapon.mainhand from block -30000000 0 1602 container.0
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.