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

Custom Crafting cancels crafting and returns items

Discussion in 'Development' started by Swyrene, Jun 25, 2020.

  1. Swyrene

    Swyrene Creeper

    Messages:
    3
    GitHub:
    swyrene
    So, what I found out was when I used excessive enchants (over than vanilla max level). Or say, I added Custom Lore, etc. the error happens again, and I'm getting frustrated, I tried debugging by using many different recipes and checking on CraftItemEvent, and it doesn't seem to work except for the custom name only, this can be a big issue I think.

    Here's my entire code, I had a bunch of Dummies to test if the enchantments, or lore, or whatever works, but it seemed to me that only setCustomName() works. Might want to look into this. The CustomCraft plugin is still active in my server and I don't see any errors in the code, if you were able to use it in your server then, please test it in mine http://mps.uhc.us.to because it doesn't seem to be working. And if you guys find an issue in my server on in my code, please help me, thanks.

    PHP:
    <?php
    declare(strict_types=1);
    # MADE BY:
    #   ______
    #  /      \                                                        
    # /$$$$$$  | __   __   __  __    __   ______    ______   _______    ______
    # $$ \__$$/ /  | /  | /  |/  |  /  | /      \  /      \ /       \  /      \
    # $$      \ $$ | $$ | $$ |$$ |  $$ |/$$$$$$  |/$$$$$$  |$$$$$$$  |/$$$$$$  |
    #  $$$$$$  |$$ | $$ | $$ |$$ |  $$ |$$ |  $$/ $$    $$ |$$ |  $$ |$$    $$ |
    # /  \__$$ |$$ \_$$ \_$$ |$$ \__$$ |$$ |      $$$$$$$$/ $$ |  $$ |$$$$$$$$/
    # $$    $$/ $$   $$   $$/ $$    $$ |$$ |      $$       |$$ |  $$ |$$       |
    #  $$$$$$/   $$$$$/$$$$/   $$$$$$$ |$$/        $$$$$$$/ $$/   $$/  $$$$$$$/
    #                        /  \__$$ |                              
    #                        $$    $$/                                
    #                         $$$$$$/                                

    namespace Swyrene\CustomCraft;

    use 
    pocketmine\block\Block;
    use 
    pocketmine\block\BlockFactory;
    use 
    pocketmine\command\{CommandCommandSender};
    use 
    pocketmine\event\block\BlockFormEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\sound\FizzSound;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\{ConfigTextFormat as TF};
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\item\enchantment\EnchantmentInstance;
    use 
    pocketmine\inventory\ShapedRecipe;
    use 
    pocketmine\event\inventory\CraftItemEvent;

    class 
    CustomCraft extends PluginBase implements Listener {

        public function 
    onEnable(){

            
    $this->getServer()->getPluginManager()->registerEvents($this$this);

            
    # Obsidian Pickaxe
            
    $lp Item::get(Item::DIAMOND_PICKAXE);
            
    $lp->setCustomName(TF::RESET.TF::RED."Obsidian Pickaxe");
            
    $lpeff = new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::EFFICIENCY));
            
    $lpeff->setLevel(100);
            
    $lpunb = new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::UNBREAKING));
            
    $lpunb->setLevel(100);
            
    $lp->addEnchantment($lpeff);
            
    $lp->setLore([
                   
    TF::RESET.TF::LIGHT_PURPLE."Made with extereme heat, lava, iron, water, and sticks...",
                
    TF::RESET.TF::RED."The Obsidian Pickaxe".TF::RESET.TF::LIGHT_PURPLE." Destroys down anything it touches in an instant!",
                
    TF::RESET.TF::YELLOW."\nGives a 5 second haste upon breaking a block!"
            
    ]);
            
    $lpr = new ShapedRecipe(["AAA"," B "," B "],["A"=>Item::get(Item::OBSIDIAN),"B"=>Item::get(Item::STICK)],[$lp]);
            
    $lpr->registerToCraftingManager($this->getServer()->getCraftingManager());

            
    #Dummy Item A
            
    $dummy Item::get(Item::STONE);
            
    $dummy->setCustomName(TF::RESET.TF::LIGHT_PURPLE."Dummy");
            
    $dummyr = new ShapedRecipe(["AAA","AAA","AAA"],["A"=>Item::get(Item::DIRT)],[$dummy]);
            
    $dummyr->registerToCraftingManager($this->getServer()->getCraftingManager());

            
    # Dummy Item B
            
    $dummyb Item::get(Item::STONE);
            
    $dummyb->setCustomName(TF::RESET.TF::LIGHT_PURPLE."Dummy");
            
    $dummybeff = new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::EFFICIENCY));
            
    $dummybeff->setLevel(100);
            
    $dummyb->addEnchantment($dummybeff);
            
    $dummybr = new ShapedRecipe(["AAA","AAA","AAA"],["A"=>Item::get(Item::STONE)],[$dummyb]);
            
    $dummybr->registerToCraftingManager($this->getServer()->getCraftingManager());

            
    # Dummy Item C
            
    $dummyc Item::get(Item::STONE);
            
    $dummyc->setCustomName(TF::RESET.TF::LIGHT_PURPLE."Dummy");
            
    $dummyc->setLore([
                
    TF::RESET.TF::LIGHT_PURPLE."Dummy Item, Dispose of this..."
            
    ]);
            
    $dummycr = new ShapedRecipe(["AAA","AAA","AAA"],["A"=>Item::get(Item::STICK)],[$dummyc]);
            
    $dummycr->registerToCraftingManager($this->getServer()->getCraftingManager());

            
    # Dummy Item D
            
    $dummyd Item::get(Item::STONE);
            
    $dummyd->setCustomName(TF::RESET.TF::LIGHT_PURPLE."Dummy");
            
    $dummydeff = new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::EFFICIENCY));
            
    $dummydeff->setLevel(100);
            
    $dummyd->addEnchantment($dummydeff);
            
    $dummyd->setLore([
                
    TF::RESET.TF::LIGHT_PURPLE."Dummy Item, Dispose of this..."
            
    ]);
            
    $dummydr = new ShapedRecipe(["AAA","AAA","AAA"],["A"=>Item::get(Item::COAL)],[$dummyd]);
            
    $dummydr->registerToCraftingManager($this->getServer()->getCraftingManager());

        }

        public function 
    onCraft(CraftItemEvent $event){

            
    $event->getLogger()->info(TF::YELLOW "[Debug]" TF::LIGHT_PURPLE "CraftItemEvent Confirmed, crafted item: " $event->getOutputs());

        }

    }
    This post was previously posted in Main Forums->General discussion->Crafting Error by @DANRULEZ123. Since I feel that it doesn't belong in there, I have created another thread here, please help both of us considering this issue is a bit critical to servers.
     
  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.