Remove enchantement exclusivity

Discussion in 'Plugin Requests' started by Felina_Lain, Dec 22, 2021.

  1. Offline

    Felina_Lain

    Minecraft version: 1.18+

    Suggested name: Mix any Enchants

    What I want:
    A plugin that would allow players to add any enchantement to any item, and regardless of what other enchantements are already on it. This would allow for exemple to enchant swords with Sharpness and Smite, or a stick with knockback (if my players want to be dumb and add contrary enchantements, or enchant weird stuff and kill themselves with those, then on their head be it). Cost of enchantement would be normal xp wise.

    Ideas for commands:
    None, ideally done through normal anvil enchanting, though if other ways are easier, like crafting table or whatnot, I'm not picky, but no commands.

    Ideas for permissions:
    If it doesn't complicate the work too much, just one to control which players can use that feature. If it adds too much work, then none.

    When I'd like it by:
    No deadline, I'm managing a small friends-only server, and they've been bugging me about it, but they can wait whatever time it takes.


    Thank you very much in advance to anyone that would take an interest in this!


    Side note:
    I looked around, and found an old thread (https://bukkit.org/threads/remove-mutual-exclusivity-in-enchantments.482832/) where a similar thing was asked, but the plugin in it is buggy when we tested it (probably because not up to date) (if this can help, the bugs are: items put in anvil sometimes disappear, items get duplicated at random when pulled out of the anvil, and the bugs mentioned in the thread itself too)
     
  2. Offline

    silkwise

    Hey @Felina_Lain

    This sounds interesting and i will have a look at it! But i will code this plugin for Spigot, is this okay or do you use Bukkit?
     
  3. Offline

    Felina_Lain

    I'm using Paper, but I think it's compatible with spigot and bukkit plugins, so it should be fine :)
    thank you very much!
     
  4. Offline

    silkwise

    Hello @Felina_Lain

    So i have the first version of your requested plugin ready! It was actually pretty challenging, because there are so many edge cases you have to handle that you do not think of if you never worked with this anvil event handlers. This is also the reason that the plugin you mentioned is really buggy, because the developer did not catch all edge cases and fix all bugs (it is not because it's outdated) :D

    Anyway i think the plugin should be pretty stable, i really invested a lot of time into testing to find all possible bugs. But i am sure that you and your friends will encounter maybe some minor bugs when testing it out (but i hope not :D)

    I also recreated the default minecraft Anvil mechanics to calculate the costs for the not allowed enchantment combinations, so it should be the same as for allowed combinations. (https://minecraft.fandom.com/wiki/Anvil_mechanics).

    However, there is still one visual bug which is not my fault and cannot be fixed atm, because it is in the bukkit api (simply because it is not the way the anvil is intended to be used):
    If you combine not allowed enchantments and click in the rename field, the result item is visually disappeared. But it is just a visual bug. The item is still in the result slot of the anvil and you still need the correct amount of experience to take out the item.

    Hope you and your friends are happy with the plugin! If you have some wishes or find some bugs, feel free to contact me!

    Edit: If you want a player to be able to use this features, he needs the "mixanyenchant.use" permission.
     

    Attached Files:

    Last edited: Dec 25, 2021
  5. Offline

    Felina_Lain

    @silkwise

    Whoa, that was... insanely fast!? :eek: I was not expecting it so fast, that's so cool!!! :)
    Thank you very very much, for taking the request. i'm going to upload it on the server, I'm sure everyone'll love it!

    Thank you again, and happy holidays![cake]
     
  6. Offline

    silkwise

    @Felina_Lain no problem! i had a lot of fun working on it. Could you give feedback here if the plugin works and if you encountered some bugs? would be cool to hear!

    happy holidays :)
     
  7. Offline

    H7KZ

    hey @silkwise can I see your source code? I need to know how to display enchanted item on the anvil slot no.3 ... Please?
     
  8. Offline

    silkwise

    Hello @H7KZ

    Sure, i uploaded the project to this repository: https://github.com/si1kwise/mixanyenchants
    It is written in Kotlin. The main logic is in PrepareAnvilEventHandler

    I will explain the basic idea of it:

    You have the PrepareAnvilEvent, which is triggered when the player puts / removes / renames an item in the anvil
    Code:
    fun onAnvilContentChange(event: PrepareAnvilEvent) {
    
    }
    Inside of this method you can get the inventory view, which has all the information about the items. It contains the item in the first slot (which i called target item), the item in the second slot (which i called sacrifice item), the item in the third slot (which is the resulting item) aswell as a lot of other information, but this is all you need atm.
    Code:
    fun onAnvilContentChange(event: PrepareAnvilEvent) {
        val anvilInventory = event.inventory
        val targetItem = anvilInventory.getItem(0)
        val sacrificeItem = anvilInventory.getItem(1)
        var resultItem = event.result
    }
    What you do with this data is really up to you. If you want to create e new item and display it in the third slot (the result item), you have to call 'event.result = <ItemStack>' with <ItemStack> beeing the new item at the end of this method
    Code:
    fun onAnvilContentChange(event: PrepareAnvilEvent) {
        val anvilInventory = event.inventory
        val targetItem = anvilInventory.getItem(0)
        val sacrificeItem = anvilInventory.getItem(1)
        var resultItem = event.result
    
        // here you can write any logic that you want
        // we can for example create a new ItemStack
        val newResultingItem: ItemStack = ItemStack(Material.DIAMOND_BOOTS)
    
    
        // if we want to display this item as a result of the combination, we have to set it as a result of the event
        event.result = newResultingItem
    }
    Hope this helps
     
  9. Offline

    Felina_Lain

    Hey!
    Just to let you know, we've been playing a while, and so far no one had any bug to report, and everyone is super happy with the plugin!
    They're running around with multi-protections armors, and weird enchanted tools, and having loads of fun!
    So thank you again!
     
  10. Offline

    silkwise

    Wow thats really cool! Glad you have fun with it :)
     

Share This Page