Need help with skript-mirror (about NBT of an item)

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

aeim

Member
Feb 21, 2017
38
5
8
27
Hey, i try since some days to make an hotfix for skStuff in 1.12 for item's NBT support (this unofficial fork does not allow NBT interaction for items https://github.com/Tuke-Nuke/SkStuff )

Spigot 1.12
Skript 2.2-dev35b
skript-mirror 0.14.1

The part of the *GET* works fine, now i need help for the part *SET*, i can maybe do *ADD* + *REMOVE* + *DELETE* if i learn how to SET.

exemple of final syntax (Unbreakable is an exemple !!! it will be other NBT after):
code_language.skript:
add "{Unbreakable:1b}" to item nbt of tool
set item nbt "Unbreakable" of tool to "1b"
set item nbt of tool to "{Unbreakable:1b}"   >>> This is equal to an ADD
remove "Unbreakable" to nbt of tool
delete nbt of tool



code_language.skript:
import:
    net.minecraft.server.v1_12_R1.NBTBase
    net.minecraft.server.v1_12_R1.NBTTagString
    net.minecraft.server.v1_12_R1.NBTTagCompound
    org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack
    net.minecraft.server.v1_12_R1.Item
    net.minecraft.server.v1_12_R1.ItemStack
    net.minecraft.server.v1_12_R1.Items

item property item[stack] nbt [%-string%]:
 
    #GET work, need help in SET
    get:
        set {_object} to expression-1
     
        #Return "{}" and not "<none>" if the item does not have any nbt
        #set {_nbt} to new NBTTagCompound()
     
        if {_object} is an item:
            if expression-2 is not set:
                set {_nbt} to CraftItemStack.asNMSCopy({_object}).getTag()
            else:
                set {_nbt} to CraftItemStack.asNMSCopy({_object}).getTag().get(expression-2)
        return {_nbt}

    set:
        set {_object} to expression-1
     
        if {_object} is an item:
            set {_key} to expression-2
            set {_nmsItem} to CraftItemStack.asNMSCopy({_object})
            set {_comp} to {_nmsItem}.getTag()
            set {_tag} to new NBTTagString(change value)
         
            # Upward it's fine, need help below
            # I had try to get the current NBT of an item, add/change the new NBT to the current, then save the result.
         
         
            {_comp}.set({_key}, {_tag})         #Break the code
            broadcast "1"                       #Not show , cause of break
            {_nmsItem}.setTag({_comp})          #Break the code
            {_nmsItem}.save({_comp})            #I had try something but he need to be parsed as NBTTagCompound
            broadcast "2"                       #Not show , cause of break
         
         
            # idk if i need the code below
            set {_meta} to CraftItemStack.getItemMeta({_nmsItem})
            {_object}.setItemMeta({_meta})



Some help : https://github.com/Tuke-Nuke/SkStuff/blob/master/src/me/TheBukor/SkStuff/util/NMS_v1_12_R1.java

https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/NBTTagCompound.java

https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/ItemStack.java


https://bukkit.org/threads/adding-multiple-nbt-tags-to-item.465371/

Thx for help
 
Last edited:
Yes it's just an example, i will use it for set a lot of NBT in the same time like this :
code_language.skript:
execute console command "/replaceitem entity %{_p}% slot.armor.head minecraft:diamond_sword 1 %{_id}% {AttributeModifiers:[{AttributeName:""generic.attackDamage"",Name:""generic.attackDamage"",Slot:""mainhand"",Amount:0,Operation:2,UUIDMost:43467,UUIDLeast:126563}],HideFlags:63,Unbreakable:1}"
Vanilla Command it's temporary if i don't found a solution


before with skStuff 1.10.2 I had use :
code_language.skript:
add "{AttributeModifiers:[{AttributeName:""generic.armor"",Name:""generic.armor"",Slot:""chest"",Amount:00,Operation:2,UUIDMost:78299,UUIDLeast:156778}],HideFlags:63,Unbreakable:1,display:{color:%{_dye}%}}" to nbt of {_p}'s chestplate
 
is your unbreakable example just an arbitrary example or do you actually need it because you can do that without nbt.
code_language.skript:
{_item}.setItemMeta({_item}.getItemMeta().setUnbreakable(true));
[doublepost=1528221663,1528221558][/doublepost]you actually dont even need skript mirror, skellet has it https://docs.skunity.com/syntax/expressions/Itemstack unbreakable
you don't even need skellett, vanilla has the same unbreakable %itemstack%
[doublepost=1528224289][/doublepost]
Hey, i try since some days to make an hotfix for skStuff in 1.12 for item's NBT support (this unofficial fork does not allow NBT interaction for items https://github.com/Tuke-Nuke/SkStuff )

Spigot 1.12
Skript 2.2-dev35b
skript-mirror 0.14.1

The part of the *GET* works fine, now i need help for the part *SET*, i can maybe do *ADD* + *REMOVE* + *DELETE* if i learn how to SET.

exemple of final syntax :
code_language.skript:
add "{Unbreakable:1b}" to item nbt of tool
set item nbt "Unbreakable" of tool to "1b"
set item nbt of tool to "{Unbreakable:1b}"   >>> This is equal to an ADD
remove "Unbreakable" to nbt of tool
delete nbt of tool



code_language.skript:
import:
    net.minecraft.server.v1_12_R1.NBTBase
    net.minecraft.server.v1_12_R1.NBTTagString
    net.minecraft.server.v1_12_R1.NBTTagCompound
    org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack
    net.minecraft.server.v1_12_R1.Item
    net.minecraft.server.v1_12_R1.ItemStack
    net.minecraft.server.v1_12_R1.Items

item property item[stack] nbt [%-string%]:
 
    #GET work, need help in SET
    get:
        set {_object} to expression-1
     
        #Return "{}" and not "<none>" if the item does not have any nbt
        #set {_nbt} to new NBTTagCompound()
     
        if {_object} is an item:
            if expression-2 is not set:
                set {_nbt} to CraftItemStack.asNMSCopy({_object}).getTag()
            else:
                set {_nbt} to CraftItemStack.asNMSCopy({_object}).getTag().get(expression-2)
        return {_nbt}

    set:
        set {_object} to expression-1
     
        if {_object} is an item:
            set {_key} to expression-2
            set {_nmsItem} to CraftItemStack.asNMSCopy({_object})
            set {_comp} to {_nmsItem}.getTag()
            set {_tag} to new NBTTagString(change value)
         
            # Upward it's fine, need help below
            # I had try to get the current NBT of an item, add/change the new NBT to the current, then save the result.
         
         
            {_comp}.set({_key}, {_tag})         #Break the code
            broadcast "1"                       #Not show , cause of break
            {_nmsItem}.setTag({_comp})          #Break the code
            {_nmsItem}.save({_comp})            #I had try something but he need to be parsed as NBTTagCompound
            broadcast "2"                       #Not show , cause of break
         
         
            # idk if i need the code below
            set {_meta} to CraftItemStack.getItemMeta({_nmsItem})
            {_object}.setItemMeta({_meta})



Some help : https://github.com/Tuke-Nuke/SkStuff/blob/master/src/me/TheBukor/SkStuff/util/NMS_v1_12_R1.java

https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/NBTTagCompound.java

https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/ItemStack.java


https://bukkit.org/threads/adding-multiple-nbt-tags-to-item.465371/

Thx for help
you need to use semicolons when using java calls as effects
 
Thx for help,

code_language.skript:
set:
        set {_object} to expression-1
      
        if {_object} is an item:
            set {_key} to expression-2
            set {_nmsItem} to CraftItemStack.asNMSCopy({_object})
            set {_comp} to new NBTTagCompound()
            set {_comp} to {_nmsItem}.getTag()
            set {_tag} to new NBTTagString(change value)        #return a bad NBT format
            broadcast "tag: %{_tag}%"

            {_comp}.set({_key}, {_tag});
            broadcast "actual : %{_comp}%"
            {_nmsItem}.setTag({_comp});
            broadcast "setTag : %{_comp}%"
            {_nmsItem}.save({_comp});

            set {_meta} to CraftItemStack.getItemMeta({_nmsItem})
            {_object}.setItemMeta({_meta});
This work (= i can set NBT) but I can a bug:

for my exemple : !set item nbt "Unbreakable" of tool to "1b"
The final NBT is {Unbreakable:"1b"} and not {Unbreakable:1b} cause of > new NBTTagString() which does not parse correctly

It allow to add CUSTOM NBT (i don't need custom, i need existing ^^)

And I don't know why but it take 0.5 second before saving the NBT in my tool :/
 
Last edited:
Thx for help,

code_language.skript:
set:
        set {_object} to expression-1
       
        if {_object} is an item:
            set {_key} to expression-2
            set {_nmsItem} to CraftItemStack.asNMSCopy({_object})
            set {_comp} to new NBTTagCompound()
            set {_comp} to {_nmsItem}.getTag()
            set {_tag} to new NBTTagString(change value)        #return a bad NBT format
            broadcast "tag: %{_tag}%"

            {_comp}.set({_key}, {_tag});
            broadcast "actual : %{_comp}%"
            {_nmsItem}.setTag({_comp});
            broadcast "setTag : %{_comp}%"
            {_nmsItem}.save({_comp});

            set {_meta} to CraftItemStack.getItemMeta({_nmsItem})
            {_object}.setItemMeta({_meta});
This work (= i can set NBT) but I can see a bug:

for my exemple : !set item nbt "Unbreakable" of tool to "1b"
The final NBT is {Unbreakable:"1b"} and not {Unbreakable:1b} cause of > new NBTTagString() which does not parse correctly

It allow to add CUSTOM NBT (i don't need custom, i need real ^^)

And I don't know why but it take 0.5 second before saving the NBT in my tool :/
what do you even need nbt fot
 
what do you even need nbt fot
like i said :
code_language.skript:
execute console command "/replaceitem entity %{_p}% slot.armor.head minecraft:diamond_sword 1 %{_id}% {AttributeModifiers:[{AttributeName:""generic.attackDamage"",Name:""generic.attackDamage"",Slot:""mainhand"",Amount:0,Operation:2,UUIDMost:43467,UUIDLeast:126563}],HideFlags:63,Unbreakable:1}"
Vanilla command turn into skript,
(and other stuff like this)

I'm just trying to make an hotfix of skStuff for item NBT in 1.12

In 1.10.2 I was able to interact with item NBT, not now.
(I can only interact with Entity NBT)

code_language.skript:
add %NBT% to nbt of %itemstack% (=skStuff's syntax exemple)

Extra info ; If my memory is good : It was never be possible to change NBT of an item in a variable in any version of spigot : add "{Unbreakable:1b}" to nbt of {_item} never worked, but if we replace {_item} with an existing item like player's chestplate or player's tool, it work (1.10.2) ... just a bug noticed




EDIT:

I progress (this work but it's not usefull for now):
code_language.skript:
    set:
        set {_object} to expression-1
        if {_object} is an item:
            set {_key} to expression-2
            set {_nmsItem} to CraftItemStack.asNMSCopy({_object})
            set {_meta} to CraftItemStack.getItemMeta({_nmsItem})
            
            
            #Just a test, need to transform rawNBT to meta
            {_meta}.setDisplayName("test2");

            {_object}.setItemMeta({_meta});
 
Last edited:
Status
Not open for further replies.