Esempio n. 1
0
  private void updateOutput() {
    Set<Recipe> recipes = Spout.getEngine().getRecipeManager().getAllRecipes();
    for (Recipe recipe : recipes) {
      boolean craft = false;
      Inventory grid = craftingGrid.getGridInventory();
      int[] gridArray = craftingGrid.getGridArray();
      if (recipe instanceof ShapelessRecipe) {
        List<Material> materials = new ArrayList<Material>(gridArray.length);
        for (int slot : gridArray) {
          ItemStack item = grid.getItem(slot);
          if (item != null) {
            materials.add(item.getMaterial());
          }
        }
        if (materials.containsAll(recipe.getIngredients())) {
          craft = true;
        }
      } else if (recipe instanceof ShapedRecipe) {
        ShapedRecipe shapedRecipe = (ShapedRecipe) recipe;
        List<List<Character>> rows = shapedRecipe.getRows();
        if (rows.size() > craftingGrid.getColumnSize()) {
          break;
        }

        int index = -1;
        for (List<Character> row : rows) {
          if (row.size() > craftingGrid.getRowSize()) {
            break;
          }

          HashMap<Character, Material> ingredientsMap = shapedRecipe.getIngredientsMap();
          for (Character character : row) {
            index++;
            Material req = ingredientsMap.get(character),
                actual = grid.getItem(gridArray[index]).getMaterial();
            if (!req.equals(actual)) {
              craft = false;
              break;
            }
            craft = true;
          }
        }
      }

      int outputSlot = craftingGrid.getOutputSlot();
      if (grid.getItem(outputSlot) == null && craft) {
        grid.setItem(outputSlot, recipe.getResult());
        break;
      }
    }
  }
Esempio n. 2
0
 private boolean updateOutput() {
   RecipeManager recipeManager = Spout.getEngine().getRecipeManager();
   Inventory grid = craftingGrid.getGridInventory();
   int[] gridArray = craftingGrid.getGridArray();
   int rowSize = craftingGrid.getRowSize();
   List<List<Material>> materials = new ArrayList<List<Material>>();
   List<Material> current = new ArrayList<Material>();
   List<Material> shapeless = new ArrayList<Material>();
   int cntr = 0;
   for (int slot : gridArray) {
     cntr++;
     ItemStack item = grid.getItem(slot);
     Material mat = null;
     if (item != null) {
       mat = item.getMaterial();
     }
     current.add(mat);
     if (mat != null) {
       shapeless.add(mat);
     }
     if (cntr >= rowSize) {
       materials.add(current);
       current = new ArrayList<Material>();
       cntr = 0;
     }
   }
   Recipe recipe = null;
   recipe = recipeManager.matchShapedRecipe(materials);
   if (recipe == null) {
     recipe = recipeManager.matchShapelessRecipe(shapeless);
   }
   if (recipe != null) {
     int outputSlot = craftingGrid.getOutputSlot();
     if (grid.getItem(outputSlot) == null) {
       grid.setItem(outputSlot, recipe.getResult());
     }
     return true;
   }
   return false;
 }