Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Custom enchantments

Comments in 'Plugin Development' started by JonsMC, Aug 20, 2016.

  1. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Is it really possible that we can create custom enchantment with custom name? If so, can i have an example?
    Legoboy0215 likes this.
  2. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
  3. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
  4. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    The only hard part is about showing the enchantment name to the player. The rest can be handled server-side without even calling it an enchantment.
  5. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    If you want to do this via a plugin, you can extend \pocketmine\item\enchantment\Enchantment class.
    But there's no way of NAMING the enchant. But you can still register it tho!
  6. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    If you want it only that it displays as an entchantment without action do $item->setCustomName("Iron Sword\n §7Coolnes 1"); [IDK how an enchantment lore looks]
  7. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Can i use getCustomName() in EntityDamageByEntity event? To get the item's name
  8. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Yeah
  9. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Eg:
    Custom Enchantment name is: Poison
    $enchantment = ...(poison)
    $name = $item->getCustomName();
    $item->setCustomName($name."/n"."Poison ".$enchantment->getLevel());
  10. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Umm.....example at $enchantment = ...(poison)? I don't understand it :p, what should ... Contain?
  11. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    PHP:
    Enchantment Enchantment::getEnchantment(10); //If you wanna use the enchantment id 10.
  12. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    well, then actually we don't have Enchantment name poison :/, why did you put it there tho?
  13. Muqsit
    Offline

    Muqsit Active Member

    Joined:
    Sep 9, 2015
    Posts:
    175
    Minecraft User:
    Muqsit
    Register a new enchantment. I just gave an example.
  14. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    :eek:Wow, i though Enchantment::getEnchantment() only getting an exist enchantment, not creating one :eek:
  15. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    Seems like i have to extract the PocketMine-MP.phar and edit the enchentment file :/, idk about it
  16. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    You can still hack it into PocketMine using reflections. However, you must properly manage the ID, because it must not duplicate an existing one (to be compatible with the existing enchantments), and it must not be a nonexisting one (because it may crash the client).
  17. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    So hard for a beginner like me :p
  18. jojoe77777
    Offline

    jojoe77777 Notable Member Plugin Developer

    Joined:
    May 28, 2015
    Posts:
    653
    Plugins:
    1
    Minecraft User:
    jojoe77777
    How I would do it:
    Enchant the item with an enchantment like fire protection, that does nothing
    Name the item "§fItem Name\n§7Custom Enchant Name\n\n\n\n\n"
    The reason I have lots of new lines at the end is so "Fire Protection I" is pushed down so far you can't see it.
    So to the client it's shining, and all the client can see of the name is:

    Item Name
    Custom Enchant Name
  19. JonsMC
    Offline

    JonsMC Active Member

    Joined:
    Jul 26, 2016
    Posts:
    107
    Minecraft User:
    JonsMC
    This would work? :p
    Added this constant in Enchantment.php
    PHP:
    const TYPE_WEAPON_COOL;
    And this in init() function :3
    PHP:
    self::$enchantments[self::TYPE_WEAPON_COOL] = new Enchantment(self::TYPE_WEAPON_COOL"Cool enchantment"self::RARITY_UNCOMMONself::ACTIVATION_EQUIPself::SLOT_SWORD);
  20. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    And what's going to be the value you're using for the constant (enchantment ID)?

Share This Page

Advertisement