Custom enchantments?

Discussion in 'Plugin Development' started by AbeJ, Jan 23, 2012.

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

    AbeJ

    Would it be possible to add custom enchantments? I need to add an enchantment to a "magic" item. It wouldn't have to actually do anything, I just need the item to glow like enchanted ones do.
    Is this possible? CB code is fine, as I would guess it's the only way.

    I tried registerEnchantment, but I just get NPEs when I apply the enchantment.
     
    mushroomhostage likes this.
  2. Offline

    mushroomhostage

    You might try using net.minecraft.server.ItemStack, adding your own id and lvl tags to the 'ench' NBT tag list.

    I'm curious if you can get this to work. Both CraftItemStack and org.bukkit.inventory.ItemStack seem to not be very tolerant of custom enchantments or other tags, but it would be very cool if this were possible.
     
  3. Offline

    ArcheCane

    If this is possible, I'ma die of epicness.
     
    mushroomhostage likes this.
  4. Offline

    mushroomhostage

    I looked into this some more.

    12w04a snapshot version history: "Anything can be placed in an Enchanting Table" - not sure what to make of this

    It is possible to make items glow with no enchantments, by adding "ench" to the NBTTagList in net.minecraft.server.ItemStack, without any id/lvl pairs. However this is not possible using org.bukkit.inventory.ItemStack, as of BUKKIT-24.

    The protocol slot data and client allows any item with a damage bar to be enchanted (even hoes, flint & steel, fishing rods, and shears). Tested on 1.1 with addUnsafeEnchantment(), works great - the glow and tooltips appear as you would expect:

    [​IMG]

    Non-durable items can be enchanted, and the data is retained (it is how SilkSpawners and creaturebox store the creature type on mob spawner items, since the damage value is lost - BUKKIT-329). Unfortunately there is no shimmering glow effect on the clients - I'd guess you need a client mod to do this.

    There is an EnchantmentTable API in Bukkit, but the "enchantments are added safely to the item", I take to mean no custom enchantments from enchantment tables. Nonetheless, you could allow enchanted items to be obtainable in other ways, such as item spawning commands or crafting (crafting recipes with enchanted outputs are broken in org.bukkit.craftbukkit, BUKKIT-602, but this can be worked around in 1.1-R1 by calling into net.minecraft.server.CraftingManager yourself, see SilkSpawners source where I add a recipe for crafting mob spawners from monster eggs for an example).

    I played around with "custom" enchantments (rather, custom enchantment/item combinations not legitimately obtainable, I didn't explore adding brand new enchantment names) a bit, here is the result: EnchantMore - 36 new item/enchantment effects, on hoes, shears, fishing rods, and a few more.
     
    Father Of Time and ArcheCane like this.
  5. Offline

    AbeJ

    Wow, thanks!
    I looked through the client source a bit. It seems that it uses the translateToLocal function to get the enchantment's name for display. It all seemed fine at this point, because translateToLocal will just return the original text if no translation was found. Then, I saw that it actually appends "enchantment." to the beginning of your enchantment name. So even if you got it to recognize that your enchantment was called "Bane of Big Black Dragons", it would be called "enchantment.Bane of Big Black Dragons". This looks like a good use case for the plugin message packet, and a simple client mod to add enchantments when it gets the correct packet.
     
    mushroomhostage likes this.
  6. Offline

    madyoda

    Is there a plugin for this? xD
     
Thread Status:
Not open for further replies.

Share This Page