Custom Enchantments

Discussion in 'Plugin Development' started by Ziden, Apr 19, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    Hi there.

    Is it possible to store custom chants into an item , with custom objects in it ?

    Ive hear i would need to add that to that item NBTags so it could be stored, does anyone knows how to do that ?

    The goal of this, is adding data to a specific item (well, w/o using the good old durability)

    Thanks alot for any attention !
  2. Offline


    I hope this is what you're looking for. This is just an example with an itemstack picked up from a player.

    public void BurnBabyBurn(PlayerPickupItemEvent event){
    ItemStack i event.getItem().getItemStack();
  3. Offline


    Im going to have to say use dmg value, easiest way to do it :D.
  4. Offline


    i cant use the dmg value since its a spoutcraft custom item, it would turn the item back to its normal visual etc.

    I can add a unsafeenchant, however, i cant add custom data to it,the only thing i can do is store an integer into its level.

    thanks alot for your help
  5. Offline

    Father Of Time

    Do you need persistence? if not this sounds like one of the situations where the Metadata tags would be useful.
    Ziden likes this.
  6. Offline


    persistence would be needed. Is it possible ?

    Thanks for your attention !
  7. Offline


    Look into using net.minecraft.server.ItemStack directly. It supports arbitrary named binary tags.

    Several mods use NBTs to add additional information to the item. For example, IndustrialCraft^2 stores a "charge" tag on electric tools. Vanilla Minecraft only uses the "ench" tag list, but you can store just about anything, as long as it can be serialized to an NBTTagList.

    So why aren't tons of plugins using this item tagging feature? While the native Minecraft code is fully capable of storing arbitrary tags, the Bukkit API wrappers are not. Compare org.bukkit.inventory.ItemStack to net.minecraft.server.ItemStack for the gory details.

    This limitation manifests itself as data loss when you use plugins interacting with items containing custom tags. For example, using IC2 on modded servers would occasionally cause nanosabers or other items to lose their charge level. Some of these problems have been fixed, but to this day most plugins will lose custom tags on items due to Bukkit's ItemStack not properly representing NBT (it actually has a HashMap for enchantments and levels, which it "rebuilds" into NBT on the fly).

    I've thought about how to fix this, by changing the ItemStack wrapper to store the complete NBT list, instead of its own low-fidelity enchantment map, but haven't got around to it, and it might break encapsulation more than would be desired. I've also considered writing my own ItemStack wrapper addressing this and other design flaws, but it wouldn't solve the problem for other plugins that still rely on Bukkit's implementation.

    Short answer: should be possible, either by fixing Bukkit's wrapper, or bypassing its wrapper so your plugin is not subject to its limitations.

    edit: someone was asking about this on IRC, there is a ticket tracking an API for Item Data:
Thread Status:
Not open for further replies.

Share This Page