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

Craft What wrong ?

Discussion in 'Development' started by Marabou, Jan 21, 2017.

  1. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    Hello, I tried to update my item but I do not see the problem because it always gives me the original item. I dont have error console
    PHP:
    <?php

    namespace UL\Events;

    use 
    pocketmine\block\Block;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\event\inventory\CraftItemEvent;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\item\Tool;
    use 
    pocketmine\item\WoodenPickaxe;

    use 
    UL\Main;


    class 
    EventListener Implements Listener{
       

    public function 
    onCraft(CraftItemEvent $event)
        {
            
    $item $event->getRecipe()->getResult();
            
    $player $event->getPlayer();
            if (
    $item instanceof Tool) {
                
    $newitem $this->getNextTier($item);
                    
    $newitem->addEnchantment(Enchantment::getEnchantment(Enchantment::TYPE_MINING_EFFICIENCY)->setLevel(3));
                    
    $newitem->addEnchantment(Enchantment::getEnchantment(Enchantment::TYPE_MINING_DURABILITY)->setLevel(3));
                     
    $event->setCancelled();
                     
    $player->getInventory()->addItem($newitem);
                     
    $player->getInventory()->sendContents($player);
            }
       }

        
    /**
         * @param Tool $item
         * @return Item|void
         */
        
    public function getNextTier(Tool $item)
        {
            
    $i 0;
            switch (
    $item->getId()) {
                case 
    Tool::WOODEN_PICKAXE:
                    
    $i Item::STONE_PICKAXE;
                    break;
                case 
    Tool::GOLD_PICKAXE:
                    
    $i Item::STONE_PICKAXE;
                    break;
                case 
    Tool::STONE_PICKAXE:
                    
    $i Item::IRON_PICKAXE;
                    break;
                case 
    Tool::IRON_PICKAXE:
                    
    $i Item::DIAMOND_PICKAXE;
                    break;
                case 
    Tool::WOODEN_AXE:
                    
    $i Item::STONE_AXE;
                    break;
                case 
    Tool::GOLD_AXE:
                    
    $i Item::STONE_AXE;
                    break;
                case 
    Tool::STONE_AXE:
                    
    $i Item::IRON_AXE;
                    break;
                case 
    Tool::IRON_AXE:
                    
    $i Item::DIAMOND_AXE;
                    break;
                case 
    Tool::WOODEN_SHOVEL:
                    
    $i Item::STONE_SHOVEL;
                    break;
                case 
    Tool::GOLD_SHOVEL:
                    
    $i Item::STONE_SHOVEL;
                    break;
                case 
    Tool::STONE_SHOVEL:
                    
    $i Item::IRON_SHOVEL;
                    break;
                case 
    Tool::IRON_SHOVEL:
                    
    $i Item::DIAMOND_SHOVEL;
                    break;
            }
            return 
    Item::get($i);
        }
    }
     
    Last edited: Jan 21, 2017
  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.