1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

CustomEnchantments

Discussion in 'Development' started by Junkdude, Dec 19, 2016.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Is there a way to register a new enchantment? Im trying to make a customenchantment and I dont want to use getCustomName().
     
  2. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    To register a new one you'd have to edit Enchantment.php from PMMP SRC. I would prefer using setCustomName() and then let EntityDamageEvent to act according to your need!
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Well the only problem with getCustomName, it requires so much code just to check if the item has/doesnt have a custom name then the enchant
     
  4. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Is this hard?
    PHP:
    $item->setCustomName("Killer\n50% nausea chance"); // EG
    On EntityDamageEvent
    $h 
    $player->getInventory()->getItemInHand();
    if(
    $h->getCustomName("Killer\n50% nausea chance")) { // Just copy and paste
    //code 
    }
     
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Yes, because im setting up a system where players can add any enchant to there item name no matter what the name,
     
  6. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
  7. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  8. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Yes. It gets whatever name the Item has.
     
  9. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Well this thread just became useless
     
  10. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Let's wait for others to share their thoughts!
     
  11. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    This isnt working yikes, no errors though

    if($it->getName() == $it->getName()."\nTest1"){
     
  12. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Maybe it's really better if you just define the name without unnecessary codes.
    PHP:
    if($it->getName() === "\nTest1") {
    }
     
  13. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    no this doesnt work causeit thinks the name is just "\nTest1", so if it had another name, it would work :p
     
  14. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Ok. I think you know that New Enchantments adds its identity below "\nTest1"
     
    Last edited: Dec 19, 2016
  15. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Facepalm, i just want t check if the item has a name on the first lin THEN the \nTest1 name
     
  16. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  17. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Because it is not systematic to change the names properly?
    And what the **** is that `if($h->getCustomName("blah"))`?
     
  18. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What about using reflections and modifying the Enchantment::$enchantments in the plugin onLoad?
     
  19. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    How'd this work? Any example?
     
  20. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Hacks :p
    Hacks :p not gonna talk about it to somebody who doesn't know what it exactly is to prevent misuse, but if you really want that to happen, take a look at http://PHP.net/reflections
     
    Legoboy0215 likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.