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

Custom Recipes?

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

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I'm trying to define a custom recipe, but when I go to use it, nothing happens! I have the right name for the book to.
    PHP:
    public function registerRecipe() {
            
            
    //TEST
          
    $name "TEST";
            
    $this->getServer()->getCraftingManager()->registerRecipe((new ShapedRecipe(Item::get(Item::DIAMOND_BOOTS01)->setCustomName("§r§4test"),
                    
    "AAA",
                    
    "APA",
                    
    "AGA"))->setIngredient("G"Item::get(Item::BOOK01)->getCustomName($name))->setIngredient("P"Item::get(Item::APPLE01))->setIngredient("A"Item::get(Item::AIR01)));
      }
    }
    Code:
     
  2. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Full code! So basically I'm not getting errors but the recipe dont work either, any idea?
    PHP:
    <?php

    namespace CustomItemsEnchantments;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    CustomItemsEnchantments\Commands;
    use 
    pocketmine\event\entity\EntitySpawnEvent;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\inventory\BigShapedRecipe;
    use 
    pocketmine\inventory\ShapedRecipe;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\item\Emerald;
    class 
    Loader extends PluginBase implements Listener,CommandExecutor{

        public function 
    onEnable(){
            
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getPluginManager()->registerEvents(new ZaRocDamageEvent($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Commands($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new WizardsStaff($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new BookOfKnowledge($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Combiner($this), $this);
            
    $this->getCommand("test")->setExecutor(new Commands($this));
            
    $this->getCommand("buy_zaroc")->setExecutor(new Commands($this));
            
    $this->getCommand("buy_wizards_staff")->setExecutor(new Commands($this));
            
    $this->getCommand("buy_ball_of_energy")->setExecutor(new Commands($this));
            
    $this->getCommand("ce")->setExecutor(new Commands($this));
            
    $this->getLogger()->info(TextFormat::GREEN."CustomItemsRewrite Enabled!");
            
        }
     
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."CustomItemsRewrite Disabled!");
        }

        public function 
    OnJoin(PlayerJoinEvent $event){
            
    $this->getServer()->sendRecipeList($event->getPlayer());
        }

        public function 
    registerRecipes(Item $item){
    $item Item::get(31001);
    $item->setCustomName("§8Obsidian Helmet");
    $item->addEnchantment(Enchantment::getEnchantment(0)->setLevel(10));
        
    $this->getServer()->getCraftingManager()->registerRecipe((new BigShapedRecipe($item,
          
    "XXX",
          
    "XYX",
          
    "YYY"
        
    ))->addIngredient("X"Item::get(Item::OBSIDIAN05))->addIngredient("Y"Item::get(Item::AIR02)));
    $item Item::get(31101);
    $item->setCustomName("§8Obsidian Chestplate");
    $item->addEnchantment(Enchantment::getEnchantment(0)->setLevel(10));
        
    $this->getServer()->getCraftingManager()->registerRecipe((new BigShapedRecipe($item,
          
    "XYX",
          
    "XXX",
          
    "XXX"
        
    ))->addIngredient("X"Item::get(Item::OBSIDIAN07))->addIngredient("Y"Item::get(Item::AIR02)));
    $item Item::get(31201);
    $item->setCustomName("§8Obsidian Leggings");
    $item->addEnchantment(Enchantment::getEnchantment(0)->setLevel(10));
        
    $this->getServer()->getCraftingManager()->registerRecipe((new BigShapedRecipe($item,
          
    "XXX",
          
    "XYX",
          
    "XYX"
        
    ))->addIngredient("X"Item::get(Item::OBSIDIAN05))->addIngredient("Y"Item::get(Item::AIR02)));
    $item Item::get(31301);
    $item->setCustomName("§8Obsidian Boots");
    $item->addEnchantment(Enchantment::getEnchantment(0)->setLevel(10));
        
    $this->getServer()->getCraftingManager()->registerRecipe((new BigShapedRecipe($item,
          
    "YYY",
          
    "XYX",
          
    "XYX"
        
    ))->addIngredient("X"Item::get(Item::OBSIDIAN05))->addIngredient("Y"Item::get(Item::AIR02)));
    $item Item::get(27601);
    $item->setCustomName("§8Obsidian Sword");
    $item->addEnchantment(Enchantment::getEnchantment(9)->setLevel(5));
        
    $this->getServer()->getCraftingManager()->registerRecipe((new BigShapedRecipe($item,
          
    "GXG",
          
    "GXG",
          
    "GYG"
        
    ))->addIngredient("X"Item::get(Item::OBSIDIAN05))->addIngredient("G"Item::get(Item::AIR05))->addIngredient("Y"Item::get(Item:: STICK02)));
            }
    }
     
  4. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  5. Aviv

    Aviv Baby Zombie

    Messages:
    156
    PHP:
    public function onJoin(PlayerJoinEvent $event){
      
    $this->getServer()->sendRecipeList($event->getPlayer());
    }
    try that
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Actually, PluginBase implements Plugin extends CommandExecutor. Yo udon't need to explicitly implement CommandExecutor.
     
    applqpak likes this.
  7. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I did that because i have mutliple classes, with commands
     
  8. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I did do that...look at my code
     
  9. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  10. XShockinFireX

    XShockinFireX Creeper

    Messages:
    4
    GitHub:
    xshockinfirex
    Change
    PHP:
    public function registerRecipes(Item $item) {
    to
    PHP:
    public function registerRecipes() {
    And add
    PHP:
    $this->registerRecipes();
    to the onEnable() function.
     
    Last edited: Dec 16, 2016
  11. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    "Argument 3 passed to pocketmine\inventory\ShapedRecipe::addIngredient() must be an instance of pocketmine\item\Item, none given, called in C:\Users\Conner\Documents\OFFICIAL-PM\plugins\CustomItemsEnchantments\src\ArchonEnchants\Loader.php on line 42" (EXCEPTION) in "/src/pocketmine/inventory/ShapedRecipe" at line 85
     
  12. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    The error is the a debugging tool for developer of beginner or advance
    learn to read it, master to read it, it WILL help you in the long run
    i will help you with this time:
    (Error) called in (location) on line (line)
    error(what's wrong and why) = Argument 3 passed to pocketmine\inventory\ShapedRecipe::addIngredient() must be an instance of pocketmine\item\Item, none given
    location(PHP is trying to tell you where that error occured) = ...\ArchonEnchants\Loader.php
    line(Which Line of that file) = 42
    meaning you try to pass something that is NOT instance of Item in this case it is nothing into addIngredient() on the 3rd argument
    and the error occurred on Loader.php line 42

    see how much i can tell you just by looking at the error?, without asking you for your code?
    next time try that yourself
     
    XShockinFireX likes this.
  13. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Facepalm, I know what it means, i dont know how to fix it
     
  14. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    to say it in a very simple way
    you forget to give an instance of item to pocketmine\inventory\ShapedRecipe::addIngredient()
     
    XShockinFireX likes this.
  15. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Okay, how do I go about giving an instance of item?
     
  16. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Maybe point out the line that has the error first? You should read your error message before asking so that you know what information to give.
     
    Primus likes this.
  17. Aviv

    Aviv Baby Zombie

    Messages:
    156
    ShapedRecipe::addIngredient($argument1, $argument2, $argument3, etc...);
    this mean argument3 needs to be instanceof pocketmine\item\Item, find what argument 3 in line 85 is, and fix it.
    Reading the problem is that simple
     
    XShockinFireX and SOFe like 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.