Fake enchants

Discussion in 'Plugin Development' started by MaTaMoR_, Apr 16, 2015.

Thread Status:
Not open for further replies.
  1. I was looking for a guide to make fake enchants, until i now i were using lore and other things to do this but know im trying to create fake enchants, so there's any good guide for this ?
     
  2. Offline

    TheDiamond06

    @MaTaMoR_ By fake you mean your own custom enchantments? To make them look real, yes use a lore for that. Have the lore be like default minecraft color and the roman numerals.

    I don't know what you are trying to do but if something is supposed to happen when you break a block make a block break event and test for that lore.

    Since these are not normal enchantments to have a player get them, you could make a certain command to have a shop to get them. You can then add the enchantment name to their lore to their item after they have bought it.

    EXAMPLE:
    So say I want a custom enchantment with the name Fish, and when a player breaks a block it sends them the message "hi".
    Here is how you would do it.
    Code:java
    1.  
    2. @EventHandler
    3. public void Fish(BlockBreakEvent e)
    4. {
    5. Player p = e.getPlayer();
    6. if(p.getInventory().getItemInHand().getType() == null || p.getInventory().getItemInHand().getType() == Material.AIR) return;
    7. if(p.getInventory().getItemInHand().hasItemMeta())
    8. {
    9. if(p.getInventory().getItemInHand().getItemMeta().hasLore())
    10. {
    11. if(p.getInventory().getItemInHand().getItemMeta().getLore().contains(ChatColor.GRAY + "Fish I"))
    12. {
    13. p.sendMessage("hi");
    14. }
    15. }
    16. }
    17. }
    18.  

    Here is how you could give the player the enchantment if you have a shop
    Code:java
    1.  
    2. if(p.getInventory().getItemInHand().getType() == Material.AIR || p.getInventory().getItemInHand().getType == null) return;
    3. ItemStack b = p.getInventory().getItemInHand().getType();
    4. ItemMeta a = p.getInventory().getItemInHand().getItemMeta();
    5. List<String>l = new ArrayList<String>();
    6. l.add(ChatColor.GRAY + "Fish I");
    7. a.setLore(l);
    8. b.setItemMeta(a);
    9. p.getInventory().setItemInHand(b);
    10. p.updateInventory();
    11.  
     
    Last edited: Apr 16, 2015
  3. I know how to do that and i was using this, but now i want to re-code the whole plugin and make it better, and i think do that check whenever a player uses his weapon isn't a good way to do this so instead of having to store anything i wanted to know if i can make my own enchants.
     
  4. Offline

    TheDiamond06

    @MaTaMoR_ Well checking every time a player uses his/her weapon isn't going to slow the server down if you make the code return if it is not what you want, will read a few lines. To make your own enchantment however, I think that is not possible without messing with the Bukkit API and default minecraft. They already have set enchantments and I think if you edit/add anymore it could lead to problems.
     
  5. I saw some time away a way to do this, but now i cant find it, so i think it is really possible .
     
  6. Offline

    nj2miami

    OK, so I came across your request and I just so have an API I created to help handle the heavy lifting for most people. As of this writing I just uploaded v1.2 which is what you will need, so if it is not approved yet, just give it a couple hours.

    http://dev.bukkit.org/bukkit-plugins/itemlib/

    Run it once to build the config.yml. They simply edit it and add in any new Custom Enchants you want.

    For instance, I want to create an Enchantment called 'Tigers Blood':
    tigerblood:
    id: 180
    display: Tiger's Blood
    enable: true
    handle: false
    maxlevel: 10
    cooldown: 0

    'id' should be UNIQUE and I would follow some sequence to be practical. Changing these IDs can cause strange behavior with items that contain the enchants.

    ItemAPI.getCustomEnch(String name)
    returns a CustomEnchantment which extends Enchantment so you can use it as you would any vanilla Enchant. It has some extra stuff built in like a 'Display Name', 'Cooldown', and a 'maxLevel'

    The 1st line defines what the Enchant will be called for Minecraft. So to see if that enchant exists on an item, you just have to call -> someItemStack.containsEnchantment(ItemAPI.getCustomEnch("tigerblood"))

    What level is it? -> someItemStack.getEnchantmentLevel(ItemAPI.getCustomEnch("tigerblood"))

    Add an enchant? -> ItemAPI.addEnchantment(<ItemStack>, "tigerblood");

    'handle' should be FALSE for any custom enchant as ItemAPI handles the included Enchants internally. You can switch those off as well if you would rather handle what they do in an external plugin.

    Tag me if you have questions.
     
  7. How i can modify what does the enchant ?
     
  8. Offline

    nj2miami

    This simply helps you get the Enchant added into MC. You can do with it what you want.

    For instance, in my example of 'Tiger's Blood'.

    Perhaps when I kill something with an Enchanted item with Tiger's Blood I get a Speed Buff and Absorption. So inside EntityDeathEvent I would do some checking for that Enchant on my item.

    It is all up to you. ItemAPI only injects the Enchantments into MC for you so you can do your checks where you need to. ItemAPI also protects Enchants when a player uses an Anvil too!

    Full disclosure: While the enchants are actually on the item, MC will not display them like vanilla enchants. The Enchants you will SEE on the Item are actually Lore. There is no way I have found which will actually DISPLAY the Enchant like a vanilla Enchant. However, ItemAPI seamlessly displays those and works with other Lore plugins discretely.

    You won't even know they are really Lore text. The Enchants ARE applied to the item though. So even if the Lore text were missing, the item is still enchanted. There is just no way I know of to have MC handle custom enchants.
     
Thread Status:
Not open for further replies.

Share This Page