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

How to make a Custom Craft Recipe?

Discussion in 'Development' started by Niclas Queen, Oct 19, 2018.

  1. Niclas Queen

    Niclas Queen Spider

    Messages:
    11
    I tried the following but it did'nt work. :/
    PHP:
    $test Item::get(101);
            
    $test->setCustomName(TextFormat::RESET TextFormat::GREEN "Test-Item");
                   
            
    $recipe = new ShapedRecipe($test33);
            
    $recipe->addIngredient(00Item::get(000));
            
    $recipe->addIngredient(01Item::get(000));
            
    $recipe->addIngredient(02Item::get(000));
            
    $recipe->addIngredient(10Item::get(000));
            
    $recipe->addIngredient(11Item::get(37700));
            
    $recipe->addIngredient(12Item::get(000));
            
    $recipe->addIngredient(20Item::get(26500));
            
    $recipe->addIngredient(21Item::get(37401));
            
    $recipe->addIngredient(22Item::get(26500));
            
    $this->plugin->getServer()->getCraftingManager()->registerRecipe($recipe);
    Error:

    Code:
    [Server thread/CRITICAL]: TypeError: "Argument 1 passed to pocketmine\inventory\ShapedRecipe::__construct() must be of the type array, object given, called in /home/Server/plugins/Plugin/src/Nick/Main.php on line 27" (EXCEPTION) in "src/pocketmine/inventory/ShapedRecipe" at line 57
    
    Please help me :(
     
    Last edited: Oct 19, 2018
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
  3. Niclas Queen

    Niclas Queen Spider

    Messages:
    11
    I did..

    If you can, could you correct my code please?
     
  4. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    I don't know if I am right but
    $test = Item::get(1, 0, 1);
    it mean that you already do your "array". 1, 0, 1.
    few lines after, you write
    $recipe = new ShapedRecipe($test, 3, 3);
    so basically, your line mean
    $recipe = new ShapedRecipe(Item::get(1, 0, 1), 3, 3);

    Try that
    $recipe = new ShapedRecipe(Item::get(1, 0, 1));

    or this
    $test = Item::get(1, 0, 1);
    $recipe = new ShapedRecipe($test);
     
  5. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Yes. Both of the lines do the exact same thing but I already got issues with putting the value as a variable (like $test) in the (). So try both, if the variable way work fine, welp that's good Ig lol.
     
  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.