An interesting workaround to change NBT of a custom item is to copy it to a chest, modify it in the chest (where it can be modified) and then use `/loot` in `replace` mode to replace the item slot.

**Note:** Once 1.17 fully comes out, you can replace this method with the `/item` command.
# Outside preparation #
You'll need a special loot table to make this happen. [Click this link](https://github.com/MinecraftPhi/MinecraftPhi-modules/blob/master/phi.modifyinv/src/datapack/data/minecraft/loot_tables/blocks/yellow_shulker_box.json) to access a data pack with the loot table that you'll need.

This loot table will cause a yellow shulker box to drop its contents instead of itself when broken with a tool with the custom tag `{drop_contents:1b}`.

# Minecraft preparation #
You'll need to first place down a yellow shulker box, and place a temporary item (like a piece of dirt) in slot 0 (upper-left corner).

**Important:** Ensure the shulker box is otherwise empty, and always write to it with the NBT path `Items[0]`.
# Commands #
The first step is to copy the item to the shulker box:

    data modify block (x) (y) (z) Items[0] merge from entity (selector) SelectedItem

(Note, if your copy source includes the `Slot` tag, you'll need to use three separate commands to copy `ID`, `Count`, and `tag` separately.)

The second step is to modify that item, use whatever commands you want here to reference the shulker box. Here are some sample commands. Try these ones out for your first try. These commands will set the Sharpness enchantment level to the scoreboard value you specify.

    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 FakePlayer myObjective
Once the modification is complete, here's the magic: use `/loot` to replace the item in the specified slot.

    /loot replace entity (selector) weapon.mainhand 1 mine block (x) (y) (z) stick{dropContents:1b}

<!--
You have to copy the selected item to a container like a chest.  Modify the container's item (the item from the player's hand) to what you want.  Then use the loot command to loot the container to the player's hand.  You need a datapack for this so if you cant use datapacks this wont work for you.  This method requires a loot table for destroying a specific block.  The loot table has to drop the contents of the container and not the block plus the contents like a chest does.
You can copy the item from a player's hand to the container with the following command.

data modify block &lt;cords&gt; Items[0] set from entity entity selector SelectedItem[0]

Below is a video I made to show how you could do it.  I forgot to put in how to copy the item to the container.  You can do that with the above command.  I put it on YouTube since I didn't know how to put it in my question without a link.  The video's description has a video on how the loot command works.
https://youtu.be/3-7tH2aET0o
For that you need the following loot table for shulker boxes in a datapack [here][1]
I hope this helped.


  [1]: https://pastebin.com/80r3YePi

-->