I've been using command blocks for a long time in Minecraft, and I was wondering if anyone knows of a way to make it so that the level of enchantment on an item can be a scoreboard score.
Something like this would be ideal:
give @p diamond_pickaxe{Enchantments:[{id:"efficiency",lvl:["score":{"name":"ench","objective":"level"}]}]}
Effectively, that command (if executed how I would intend for it to be) would give the nearest player a Diamond Pickaxe with the Efficiency enchantment -- the level of the enchantment being equal to ench's score in the objective named "level."
I've been using command blocks for a long time in Minecraft, and I was wondering if anyone knows of a way to make it so that the level of enchantment on an item can be a scoreboard score.
Something like this would be ideal:
give @p diamond_pickaxe{Enchantments:[{id:"efficiency",lvl:["score":{"name":"ench","objective":"level"}]}]}
Effectively, that command (if executed how I would intend for it to be) would give the nearest player a Diamond Pickaxe with the Efficiency enchantment -- the level of the enchantment being equal to ench's score in the objective named "level."
Thanks in advance,
Sammy
I never rly try to do this, cuz I don't think it's ever necessary (I don't know your objective exactly, but ain't gonna question it).
Let's assume the pickaxe:
1) is custom (i.e. not by mining diamonds, crafting one and enchanted)
2) always have Efficiency as the 1st enchantment
3) will only be executed if the player holds it
4) MUST have that enchantment, even with 0 lvl
Then, congratulations, your dream of using using scoreboard score as a tag variable comes true!
I tested this:
/execute as @a store result entity @s SelectedItem.tag.Enchantments[0].lvl short 1 run scoreboard players get @s <scoreboard>
I never rly try to do this, cuz I don't think it's ever necessary (I don't know your objective exactly, but ain't gonna question it).
Let's assume the pickaxe:
1) is custom (i.e. not by mining diamonds, crafting one and enchanted)
2) always have Efficiency as the 1st enchantment
3) will only be executed if the player holds it
4) MUST have that enchantment, even with 0 lvl
Then, congratulations, your dream of using using scoreboard score as a tag variable comes true!
I tested this:
/execute as @a store result entity @s SelectedItem.tag.Enchantments[0].lvl short 1 run scoreboard players get @s <scoreboard>
And it worked!
Hi there!
I was able to fiddle with this to get it how I needed it. Thanks a ton!
When (and if) I publish the project, then I'll be sure to credit you as you asked for it. I may also have some special plans to credit you within the project that aren't just a sign or a "head stuck to a wall" because you basically just gave me what I needed in order finish it in a timely and convenient manner. Finally, if you'd like, then I'll get back to you whenever I finish the project if you would like a copy of it prior to my releasing of it!
I was able to fiddle with this to get it how I needed it. Thanks a ton!
When (and if) I publish the project, then I'll be sure to credit you as you asked for it. I may also have some special plans to credit you within the project that aren't just a sign or a "head stuck to a wall" because you basically just gave me what I needed in order finish it in a timely and convenient manner. Finally, if you'd like, then I'll get back to you whenever I finish the project if you would like a copy of it prior to my releasing of it!
Thank you so much,
Sammy
Noted, thank you for actually reading my signature tho : p
(And how will you plan to place it? I mean, we can talk in Private Chat, but just giving you the question)
I never rly try to do this, cuz I don't think it's ever necessary (I don't know your objective exactly, but ain't gonna question it).
Let's assume the pickaxe:
1) is custom (i.e. not by mining diamonds, crafting one and enchanted)
2) always have Efficiency as the 1st enchantment
3) will only be executed if the player holds it
4) MUST have that enchantment, even with 0 lvl
Then, congratulations, your dream of using using scoreboard score as a tag variable comes true!
I tested this:
/execute as @a store result entity @s SelectedItem.tag.Enchantments[0].lvl short 1 run scoreboard players get @s <scoreboard>
And it worked!
I copied this command, but no matter what it will not apply the enchantment level to the item.
Instead of applying the enchantment level to the item, it displays a chat message saying that the player has # for <scoreboard>.
This, for some reason, does work if I do block instead of entity and pick a chest, but I would prefer it to be for the player's SelectedItem like how you did. This does not display the chat message like the last one. I do not know why though. /execute store result block <x> <y> <z> Items[0].tag.Enchantments[0].lvl short 1 run scoreboard players get @s <scoreboard>
I copied this command, but no matter what it will not apply the enchantment level to the item.
Instead of applying the enchantment level to the item, it displays a chat message saying that the player has # for <scoreboard>.
This, for some reason, does work if I do block instead of entity and pick a chest, but I would prefer it to be for the player's SelectedItem like how you did. This does not display the chat message like the last one. I do not know why though. /execute store result block <x> <y> <z> Items[0].tag.Enchantments[0].lvl short 1 run scoreboard players get @s <scoreboard>
Any way to make it so SelectedItem works?
Oh. Due to that ANNOYING patch in 1.15, you can no longer modify ANY single data on the player, including the enchantments on an item a player is holding.
Displaying the score in chat is just a by-product of using the command in chat.
Long story short, the command no longer works in 1.15+
The Meaning of Life, the Universe, and Everything.
Join Date:
7/19/2013
Posts:
94
Minecraft:
TimmyCheeseburgr
Member Details
I see, that's really unfortunate. Alright, well my original plans for what I was wanting to do are out now, but I do have a different idea of doing something similar with /data that involves other entities and containers. Thanks for notifying, I didn't realize that they made this change. I see that if I try to use /data on myself to modify my data, it says that I cannot modify player data, while for this, it only displayed the score value and not the error.
I see, that's really unfortunate. Alright, well my original plans for what I was wanting to do are out now, but I do have a different idea of doing something similar with /data that involves other entities and containers. Thanks for notifying, I didn't realize that they made this change. I see that if I try to use /data on myself to modify my data, it says that I cannot modify player data, while for this, it only displayed the score value and not the error.
Of course, there's a way where you modify an item in a shulker box, then you change the loot table of the shulker box to make it drop the content via /loot. But I personally haven't done that, and it sound inconvenient.
In case the pick has efficiency but not as the first enchant, you can replace "Enchantments[0]" by "Enchantments[{id:"minecraft:efficiency"}]", which automatically leads to the efficiency enchantment index.
Well as YMbrothers said, the only way to modify an item into player's inventory without changing its slot is the shulker box method. I used it some times, and I could say this is pretty effective.
Here's how it works :
Modify the shulker loot table. Here's what you want it to do :
-First, choose an item players can't have (barrier/structure void/...), I think you can set specific nbt as well
-If shulker box is broken, but not with [chosen item], it drops its normal loot
-If shulker box is broken using [custom item], it drops only its content, as if the shulker was a chest, but without dropping the chest item
When you want to set enchantment level from score value (Selected item for following example) :
-Setblock a shulker box at ~ 0 ~ from the targetted player, containing one item (like 1 stone)
-Copy player's SelectedItem tag into shulker's Item[0] (So it gets in the shulker)
-Change shulker item's tag.Enchantments[{id:"minecraft:efficiency"}].lvl to score value using /data modify
-Use /loot to copy Shulker's Items[0] into player's SelectedItem tag
-Remove the shulker : Replace the shulker by an adjacent block from it at y=0 using /clone (so will fill the shulker using the same block as layer 0, no matter what block layer 0 is made of)
If you want visuals, my favorite is CloudWolf's video here about modifying SelectedItem using shulker box.
This looks complicated, but I would say by my current experience, it's between easy/medium level, hard being vanilla chest GUI systems, as a reference.
I got into chiptune music composition.
You can listen to them on my Youtube channel : https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
If you want to modify left hand, you can not move player's Inventory[{Slot:-106b}] into shulker's Items[0].
This is because Inventory[{Slot:-106b}] data also contains a Slot tag of -106b
As a result, copying directly player's Inventory[{Slot:-106b}] into shulker's Items[0]will move the item into shulker's -106th slot, which doesn't exist, so item won't be copied.
The solution is pretty simple :
-Put any item into the shulker box (like 1 stone)
-Copy player's Inventory[{Slot:-106b}].id into shulker's Items[0].id
-Copy player's Inventory[{Slot:-106b}].Count into shulker's Items[0].Count
-Copy player's Inventory[{Slot:-106b}].tag into shulker's Items[0].tag
And so, the item willl keep the same "Slot" value as the stone item had.
I got into chiptune music composition.
You can listen to them on my Youtube channel : https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
The Meaning of Life, the Universe, and Everything.
Join Date:
7/19/2013
Posts:
94
Minecraft:
TimmyCheeseburgr
Member Details
I've been using something similar except only with Item Frames. You can simply replace Items[]with Item, and it should work out perfectly.
For example, I set whatever item in an Invulnerable Item Frame's CustomModelData to 1. Here is the command:
/data modify entity @e[type=minecraft:item_frame,limit=1,sort=nearest,distance=..3,nbt={Invulnerable:1b}] Item.tag.CustomModelData set value 1
Once I have done this, because you can't remove an Invulnerable Item Frame's contents in survival, I copy the frame's data to a barrel above it, then purge the Item Frame's contents (the carets are really helpful in this scenario). Here are my commands:
-Copy Item Frame data to Barrel above frame:
/execute as @e[type=minecraft:item_frame,nbt={Invulnerable:1b},distance=..3] at @s run data modify block ^ ^1 ^-1 Items[{Slot:13b}] merge from entity @s Item
-Erase Item Frame's item:
/execute as @e[type=minecraft:item_frame,nbt={Invulnerable:1b},distance=..3] at @s run data merge entity @s {Item:{id:""}}
While I would've liked this to be done via the player's inventory, this still works quite well. I felt like I didn't understand the /data command when I tried to modify player data as I felt like I was doing something wrong, but now that I can actually use the command, I feel like I am really understanding how it works.
Hi there folks,
I've been using command blocks for a long time in Minecraft, and I was wondering if anyone knows of a way to make it so that the level of enchantment on an item can be a scoreboard score.
Something like this would be ideal:
Effectively, that command (if executed how I would intend for it to be) would give the nearest player a Diamond Pickaxe with the Efficiency enchantment -- the level of the enchantment being equal to ench's score in the objective named "level."
Thanks in advance,
Sammy
I never rly try to do this, cuz I don't think it's ever necessary (I don't know your objective exactly, but ain't gonna question it).
Let's assume the pickaxe:
1) is custom (i.e. not by mining diamonds, crafting one and enchanted)
2) always have Efficiency as the 1st enchantment
3) will only be executed if the player holds it
4) MUST have that enchantment, even with 0 lvl
Then, congratulations, your dream of using using scoreboard score as a tag variable comes true!
I tested this:
/execute as @a store result entity @s SelectedItem.tag.Enchantments[0].lvl short 1 run scoreboard players get @s <scoreboard>
And it worked!
Hi there!
I was able to fiddle with this to get it how I needed it. Thanks a ton!
When (and if) I publish the project, then I'll be sure to credit you as you asked for it. I may also have some special plans to credit you within the project that aren't just a sign or a "head stuck to a wall" because you basically just gave me what I needed in order finish it in a timely and convenient manner. Finally, if you'd like, then I'll get back to you whenever I finish the project if you would like a copy of it prior to my releasing of it!
Thank you so much,
Sammy
Noted, thank you for actually reading my signature tho : p
(And how will you plan to place it? I mean, we can talk in Private Chat, but just giving you the question)
Private messaging sounds great. Let's keep talking in there
I copied this command, but no matter what it will not apply the enchantment level to the item.
Instead of applying the enchantment level to the item, it displays a chat message saying that the player has # for <scoreboard>.
This, for some reason, does work if I do block instead of entity and pick a chest, but I would prefer it to be for the player's SelectedItem like how you did. This does not display the chat message like the last one. I do not know why though.
/execute store result block <x> <y> <z> Items[0].tag.Enchantments[0].lvl short 1 run scoreboard players get @s <scoreboard>
Any way to make it so SelectedItem works?
Oh. Due to that ANNOYING patch in 1.15, you can no longer modify ANY single data on the player, including the enchantments on an item a player is holding.
Displaying the score in chat is just a by-product of using the command in chat.
Long story short, the command no longer works in 1.15+
I see, that's really unfortunate. Alright, well my original plans for what I was wanting to do are out now, but I do have a different idea of doing something similar with /data that involves other entities and containers. Thanks for notifying, I didn't realize that they made this change. I see that if I try to use /data on myself to modify my data, it says that I cannot modify player data, while for this, it only displayed the score value and not the error.
Of course, there's a way where you modify an item in a shulker box, then you change the loot table of the shulker box to make it drop the content via /loot. But I personally haven't done that, and it sound inconvenient.
Just passing by, here's a little tip :
In case the pick has efficiency but not as the first enchant, you can replace "Enchantments[0]" by "Enchantments[{id:"minecraft:efficiency"}]", which automatically leads to the efficiency enchantment index.
Well as YMbrothers said, the only way to modify an item into player's inventory without changing its slot is the shulker box method. I used it some times, and I could say this is pretty effective.
Here's how it works :
-If shulker box is broken, but not with [chosen item], it drops its normal loot
-If shulker box is broken using [custom item], it drops only its content, as if the shulker was a chest, but without dropping the chest item
-Copy player's SelectedItem tag into shulker's Item[0] (So it gets in the shulker)
-Change shulker item's tag.Enchantments[{id:"minecraft:efficiency"}].lvl to score value using /data modify
-Use /loot to copy Shulker's Items[0] into player's SelectedItem tag
-Remove the shulker : Replace the shulker by an adjacent block from it at y=0 using /clone (so will fill the shulker using the same block as layer 0, no matter what block layer 0 is made of)
If you want visuals, my favorite is CloudWolf's video here about modifying SelectedItem using shulker box.
This looks complicated, but I would say by my current experience, it's between easy/medium level, hard being vanilla chest GUI systems, as a reference.
Also, this is the loot table for shulker box (Source : my own "potion stacker datapack" ) :
This loot table makes shulker boxes drop their content instead of themselves if they are broken using a barrier item
I got into chiptune music composition.
You can listen to them on my Youtube channel :
https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
-------------------------↑
Dude I missed this one!
Thank you for correcting me, I modified it!
Well while I'm there, here's another tip :
If you want to modify left hand, you can not move player's Inventory[{Slot:-106b}] into shulker's Items[0].
This is because Inventory[{Slot:-106b}] data also contains a Slot tag of -106b
As a result, copying directly player's Inventory[{Slot:-106b}] into shulker's Items[0] will move the item into shulker's -106th slot, which doesn't exist, so item won't be copied.
The solution is pretty simple :
-Put any item into the shulker box (like 1 stone)
-Copy player's Inventory[{Slot:-106b}].id into shulker's Items[0].id
-Copy player's Inventory[{Slot:-106b}].Count into shulker's Items[0].Count
-Copy player's Inventory[{Slot:-106b}].tag into shulker's Items[0].tag
And so, the item willl keep the same "Slot" value as the stone item had.
I got into chiptune music composition.
You can listen to them on my Youtube channel :
https://www.youtube.com/channel/UCjWYbJGk7nvNDbnCvMlZGkw
Descriptions are in french, you'd just need some google translation copy-paste...
Also made some more or less complicated datapacks, shared here (planetminecraft).
I've been using something similar except only with Item Frames. You can simply replace Items[] with Item, and it should work out perfectly.
For example, I set whatever item in an Invulnerable Item Frame's CustomModelData to 1. Here is the command:
/data modify entity @e[type=minecraft:item_frame,limit=1,sort=nearest,distance=..3,nbt={Invulnerable:1b}] Item.tag.CustomModelData set value 1
Once I have done this, because you can't remove an Invulnerable Item Frame's contents in survival, I copy the frame's data to a barrel above it, then purge the Item Frame's contents (the carets are really helpful in this scenario). Here are my commands:
-Copy Item Frame data to Barrel above frame:
/execute as @e[type=minecraft:item_frame,nbt={Invulnerable:1b},distance=..3] at @s run data modify block ^ ^1 ^-1 Items[{Slot:13b}] merge from entity @s Item
-Erase Item Frame's item:
/execute as @e[type=minecraft:item_frame,nbt={Invulnerable:1b},distance=..3] at @s run data merge entity @s {Item:{id:""}}
While I would've liked this to be done via the player's inventory, this still works quite well. I felt like I didn't understand the /data command when I tried to modify player data as I felt like I was doing something wrong, but now that I can actually use the command, I feel like I am really understanding how it works.