1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved 1.12.2 Modifying Item Attributes

Discussion in 'Skript' started by Flajakay, Jun 13, 2019 at 7:25 AM.

  1. F

    Flajakay Well-Known Member

    Joined:
    Jul 29, 2018
    Messages:
    47
    Likes Received:
    1
    How can I modify item attributes using skript-mirror?
    --- Double Post Merged, Jun 14, 2019 at 11:20 AM, Original Post Date: Jun 13, 2019 at 7:25 AM ---
    Solved by myself.

    Code (Text):
    1.  
    2. import:
    3.     java.lang.Object
    4.     java.util.List
    5.     java.util.Arrays
    6.     java.util.ArrayList
    7.     org.bukkit.inventory.ItemFlag
    8.     org.bukkit.enchantments.Enchantment
    9.     org.bukkit.inventory.meta.ItemMeta
    10.  
    11. import:
    12.  
    13.     java.lang.String
    14.     java.util.regex.Pattern
    15.  
    16.     org.bukkit.Bukkit
    17.     org.bukkit.entity.Entity
    18.     org.bukkit.inventory.ItemStack
    19.  
    20.     ch.njol.skript.Skript
    21.     ch.njol.skript.util.Version
    22.     ch.njol.skript.aliases.ItemType
    23.  
    24.  
    25. option nms-version:
    26.     get:
    27.         return Bukkit.getServer().getClass().getPackage().getName().split("\.")[3]
    28.  
    29.  
    30. import:
    31.  
    32.     org.bukkit.craftbukkit.{@nms-version}.inventory.CraftItemStack
    33.     org.bukkit.craftbukkit.{@nms-version}.block.CraftBlock
    34.  
    35.     net.minecraft.server.{@nms-version}.ItemStack as NMSItemStack
    36.     net.minecraft.server.{@nms-version}.NBTTagCompound
    37.     net.minecraft.server.{@nms-version}.NBTTagList
    38.     net.minecraft.server.{@nms-version}.MojangsonParser
    39.     net.minecraft.server.{@nms-version}.BlockPosition
    40.     net.minecraft.server.{@nms-version}.NBTTagString
    41.     net.minecraft.server.{@nms-version}.Item
    42.     net.minecraft.server.{@nms-version}.Items
    43.  
    44. local itemtypes property item NBT:
    45.   get:
    46.     set {_item} to CraftItemStack.asNMSCopy(expression-1.getRandom())
    47.     set {_nbt} to {_item}.getTag() if {_item}.hasTag() is true, else new NBTTagCompound()
    48.     return {_nbt}
    49.  
    50.   add string:
    51.     set {_appended-nbt} to MojangsonParser.parse(change value)
    52.  
    53.     loop expressions-1:
    54.       set {_item} to CraftItemStack.asNMSCopy(loop-value.getRandom())
    55.  
    56.       if {_appended-nbt} is set:
    57.  
    58.         if {_item}.hasTag() is true:
    59.           {_item}.a({_appended-nbt})
    60.         else:
    61.           {_item}.setTag({_appended-nbt})
    62.  
    63.         set {_meta} to CraftItemStack.getItemMeta({_item})
    64.         loop-value.setItemMeta({_meta})
    65.    
    66.   remove string:
    67.     set {_removed-nbt} to MojangsonParser.parse(change value)
    68.  
    69.     loop expressions-1:
    70.       set {_item} to CraftItemStack.asNMSCopy(expression-1.getRandom())
    71.  
    72.       if {_removed-nbt} is set:
    73.         {_item}.hasTag() is true
    74.         {_item}.remove({_removed-nbt})
    75.  
    76.         set {_meta} to CraftItemStack.getItemMeta({_item})
    77.         loop-value.setItemMeta({_meta})
    78.  
    79.   set string:
    80.     set {_new-nbt} to MojangsonParser.parse(change value)
    81.  
    82.     loop expressions-1:
    83.       set {_item} to CraftItemStack.asNMSCopy(loop-value.getRandom())
    84.  
    85.       if {_new-nbt} is set:
    86.         {_item}.setTag({_new-nbt})
    87.  
    88.         set {_meta} to CraftItemStack.getItemMeta({_item})
    89.         loop-value.setItemMeta({_meta})
    90.  
    91.  
    92. expression %itemtype% with nbt %string%:
    93.   get:
    94.     set {_item} to expression-1
    95.     set item nbt of {_item} to expression-2
    96.     return {_item}
    97.  
    98. command /adt:
    99.     trigger:
    100.         set player's tool to player's tool with nbt "{AttributeModifiers:[{Operation:0,UUIDLeast:1,UUIDMost:1,Amount:999999,AttributeName:generic.attackDamage,Name:Barrier}]}"
    101.  
     
Loading...