Solved [1.13-1.16] Is there a way to set NBT data with the same code on 1.13-1.16 versions?

Discussion in 'Spigot Plugin Development' started by TurtlesAreHot, Jan 8, 2021.

  1. What I want to do:
    Currently, I am working on a plugin that will give you items that you are not allowed to craft with. I want to set NBT tag data to the item (that works on 1.13-1.16) in order to check if it is able to be used or not in the PrepareItemCraftEvent.

    My Question:
    I have figured out how I can do this for one version of Minecraft but have now found that between different versions it does not work. This is because of how the original ItemStack must be created in order to set and get NBT data (net.minecraft.server.**version**.ItemStack). Is there a simple way (without adding other APIs or plugins) to do this between multiple versions with the same code? Would I have to just check for the version the server is on and based upon the version create the ItemStack object with different imports of ItemStack (net.minecraft.server.**version**.ItemStack)? I felt that what I just asked isn't really a good way to do it, though if it is the actual solution I would like to know.

    Example:
    Code (Java):
    ItemStack item = new ItemStack(Material.BRICK, 1);
    net.minecraft.server.v1_15_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item);


    The second line of code of what I just presented is exactly why it does not work for multiple versions and I want a way around that without APIs or plugins.

    Any help with this would be greatly appreciated, thanks :)
     
  2. drives_a_ford

    Moderator

    For 1.14+ you can simply use the Persistent data API.

    If you do need 1.13 support, you can check for that and use abstraction to provide that for the specific version.
     
    • Like Like x 1