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

hey, i've created a custom craft item and it works, except that when we take it and try to put it on

Discussion in 'Development' started by Flow, Apr 16, 2019.

  1. Flow

    Flow Silverfish

    Messages:
    22
    <?php

    namespace CM;

    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\block\Block;
    use pocketmine\item\Item;
    use pocketmine\math\Vector3;
    use pocketmine\item\enchantment\Enchantment;
    use pocketmine\item\enchantment\EnchantmentInstance;
    use pocketmine\inventory\ShapedRecipe;


    class Main extends PluginBase implements Listener{


    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $i = Item::get(Item::BONE);
    $i->setCustomName("Hyru-Sword");
    $ench = new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::SHARPNESS));
    $ench->setLevel(3);
    $i->addEnchantment($ench);
    $sword = new ShapedRecipe([" A "," A "," B "],["A"=>Item::get(Item::EMERALD),"B"=>Item::get(Item::STICK)],[$i]);
    $sword->registerToCraftingManager($this->getServer()->getCraftingManager());
    }

    public function onDisable(){
    $this->getLogger()->info("Desactiver");
    }
    }
     
  2. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    You made a sword why are you trying to put it on ?
     
  3. Flow

    Flow Silverfish

    Messages:
    22
    I made a craft of a custom epee and I can not take the item in hand: /
     
  4. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    epee = sword for anyone who wonders
     
    KielKing likes this.
  5. Swourire

    Swourire Spider Jockey

    Messages:
    49
    GitHub:
    swourire
    upload_2019-4-16_16-25-59.png It does work. Tried with your code.
     
  6. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    No it doesn't work. I just tried,
    If I am right, it's because you use BONE, change
    PHP:
    $i Item::get(Item::BONE);
    for
    PHP:
    $i Item::get(352,2,1);
    With this code, you can take it in your hand and use it. For the rest, everything works well.

    EDIT : Do not use magical ID's since they may change at any moments. Read comments below.
     
    Last edited: Apr 17, 2019
  7. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    I had the same error haha, I've been working on a lot of new items. Always use ID, never the name, for kits, crafting or whatever you want, for real, its less trouble.. Little trick :p
     
  8. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    no, please do not do this...

    if you use custom "damage" values on items, your code WILL break in future updates when those magic values no longer work. They are not supported by the game in any official capacity, and as such their behaviour is subject to change.

    Consider using an NBT tag instead, which is less likely to catch fire.
     
  9. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    please don't do this either...

    you clearly haven't realized what an enormous headache it will create for anyone who has to maintain your code in the future. Those magic numbers will cease to work in a future update, and if you hardcoded numeric IDs everywhere your code is going to be very difficult to update.
     
    Muqsit, radondev and HimbeersaftLP like this.
  10. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    oops, I didn't even notice that I used 2 for the damage typing error.
     
  11. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    not stupid, lol.
     
  12. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    really? then why are you recommending it.
     
  13. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    I didn't think about it..You are right.
     
  14. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    using the item constants is the same as ids if you have ever took the time to look, for example
    PHP:
    BlockIds::GRASS 2;
    (ItemIds implements BlockIds, Item implements ItemIds)
     
  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.