getIngredientList() public method

public getIngredientList ( ) : Item[]
return pocketmine\item\Item[]
コード例 #1
0
 private static function writeShapelessRecipe(ShapelessRecipe $recipe, BinaryStream $stream)
 {
     $stream->putInt($recipe->getIngredientCount());
     foreach ($recipe->getIngredientList() as $item) {
         $stream->putSlot($item);
     }
     $stream->putInt(1);
     $stream->putSlot($recipe->getResult());
     $stream->putUUID($recipe->getId());
     return CraftingDataPacket::ENTRY_SHAPELESS;
 }
コード例 #2
0
 /**
  * @param ShapelessRecipe $recipe
  * @return bool
  */
 public function matchRecipe(ShapelessRecipe $recipe)
 {
     if (!isset($this->recipeLookup[$idx = $recipe->getResult()->getId() . ":" . $recipe->getResult()->getDamage()])) {
         return false;
     }
     $hash = "";
     $ingredients = $recipe->getIngredientList();
     usort($ingredients, [$this, "sort"]);
     foreach ($ingredients as $item) {
         $hash .= $item->getId() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
     }
     if (isset($this->recipeLookup[$idx][$hash])) {
         return true;
     }
     $hasRecipe = null;
     foreach ($this->recipeLookup[$idx] as $recipe) {
         if ($recipe instanceof ShapelessRecipe) {
             if ($recipe->getIngredientCount() !== count($ingredients)) {
                 continue;
             }
             $checkInput = $recipe->getIngredientList();
             foreach ($ingredients as $item) {
                 $amount = $item->getCount();
                 foreach ($checkInput as $k => $checkItem) {
                     if ($checkItem->equals($item, $checkItem->getDamage() === null ? false : true, $checkItem->getCompoundTag() === null ? false : true)) {
                         $remove = min($checkItem->getCount(), $amount);
                         $checkItem->setCount($checkItem->getCount() - $remove);
                         if ($checkItem->getCount() === 0) {
                             unset($checkInput[$k]);
                         }
                         $amount -= $remove;
                         if ($amount === 0) {
                             break;
                         }
                     }
                 }
             }
             if (count($checkInput) === 0) {
                 $hasRecipe = $recipe;
                 break;
             }
         }
         if ($hasRecipe instanceof Recipe) {
             break;
         }
     }
     return $hasRecipe !== null;
 }
コード例 #3
0
 /**
  * @param ShapelessRecipe $recipe
  * @return bool
  */
 public function matchRecipe(ShapelessRecipe $recipe)
 {
     if (!isset($this->recipeLookup[$idx = $recipe->getResult()->getId() . ":" . $recipe->getResult()->getDamage()])) {
         return false;
     }
     $hash = "";
     $ingredients = $recipe->getIngredientList();
     usort($ingredients, [$this, "sort"]);
     foreach ($ingredients as $item) {
         $hash .= $item->getId() . ":" . ($item->getDamage() === null ? "?" : $item->getDamage()) . "x" . $item->getCount() . ",";
     }
     return isset($this->recipeLookup[$idx][$hash]);
 }
コード例 #4
0
 public function getRecipeMap(ShapelessRecipe $recipe)
 {
     //todo 効率的な処理
     $data = array("map" => array(), "items" => array());
     $map = array();
     $mapc = 0;
     $items = $recipe->getIngredientList();
     for ($i = 0; $i < count($items); $i++) {
         $item = $items[$i];
         $map[] = $mapc;
         if (isset($items[$i + 1])) {
             if ($items[$i + 1]->equals($item)) {
                 continue;
             }
         }
         $r = true;
         foreach ($data["items"] as $item2) {
             if ($item2->equals($item)) {
                 $r = false;
                 break;
             }
         }
         if ($r === true) {
             $data["items"][$mapc] = $item;
             $mapc++;
         }
     }
     $data["map"] = $map + array(0 => " ", 1 => " ", 2 => " ", 3 => " ", 4 => " ", 5 => " ", 6 => " ", 7 => " ", 8 => " ");
     return $data;
 }