Custom enchantments?

Discussion in 'Plugin Development' started by HeyShibby, Mar 27, 2013.

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

    HeyShibby

    Hey bukkit forums, I need to make this short and sweet so here we go.​
    Basically what i'm trying to do is add a custom enchantment for weapons such as a sword/bow,​
    but what I need to know is it possible without having to have a modified client?​
     
  2. Offline

    Cybermaxke

    It is possible but anvils don't like them, the client crashes if you place items with them in it.
     
  3. Offline

    HeyShibby

    what do you mean?
     
  4. Offline

    Cybermaxke

    You can make custom enchantments. ;)
    But if you use them in a anvil, it will crash your client.
     
  5. Offline

    HeyShibby

    Oh that's okay for what i'm going to be using them for :) any tips on how to do it ;)
     
  6. Offline

    kreashenz

    HeyShibby Last time I asked, I asked for enchantments AND achievements, and I got replied with no for both, but this was for 1.4.6.. Maybe its changed, and now possible. I'm also wondering how to do this, and how to make effects for it, like how sharpness adds more damage.
     
  7. Offline

    Cybermaxke

    I made this some months ago. :)
    Extend this class to make your own, this doesn't add any effects, you should have to do that yourself.
    Code:
    public abstract class EnchantmentCustom extends Enchantment {
     
        public EnchantmentCustom(int id) {
            super(id);
     
            if (id >= 256) {
                throw new IllegalArgumentException("A enchantment id has to be lower then 256!");
            }
     
            try {
                Field f = Enchantment.class.getDeclaredField("acceptingNew");
                f.setAccessible(true);
                   
                boolean b = f.getBoolean(null);
                f.set(null, Boolean.valueOf(true));
       
                Enchantment.registerEnchantment(this);
                f.set(null, b);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
     
        public abstract boolean canEnchantItem(ItemStack itemstack);
     
        public abstract boolean conflictsWith(Enchantment enchantment);
     
        public abstract EnchantmentTarget getItemTarget();
     
        public abstract int getMaxLevel();
     
        public abstract int getStartLevel();
     
        public abstract int getWeight();
     
        @Override
        public String getName() {
            return "EAPIEnchantment" + this.getId();
        }
    }
    Test Enchantment: (For example custom data.)
    Code:
    public class EnchantmentCustomData extends EnchantmentCustom {
     
        public EnchantmentCustomData(int id) {
            super(id);
        }
     
        @Override
        public boolean canEnchantItem(ItemStack itemstack) {
            return false;
        }
     
        @Override
        public boolean conflictsWith(Enchantment enchantment) {
            return false;
        }
     
        @Override
        public EnchantmentTarget getItemTarget() {
            return EnchantmentTarget.ALL;
        }
     
        @Override
        public int getMaxLevel() {
            return 99999;
        }
     
        @Override
        public int getStartLevel() {
            return 0;
        }
     
        @Override
        public int getWeight() {
            return 1000;
        }
    }
    And creating it:
    Code:
    public final EnchantmentCustomData TEST = new EnchantmentCustomData(100);
     
  8. Offline

    HeyShibby

    i'll check it out when i'm at my computer :)
     
  9. Offline

    MrSparkzz

    Cybermaxke
    Can you give some more information on this?
     
Thread Status:
Not open for further replies.

Share This Page