Beispiel #1
0
 @Override
 public boolean onClick(int clickedSlot, boolean rightClick, boolean shift) {
   int size = 0;
   for (InventoryBase i : getInventory().getInventories()) {
     if (i != craftingGrid.getGridInventory()) {
       size += i.getSize();
     }
   }
   if (itemOnCursor != null && clickedSlot == craftingGrid.getOutputSlot() + size && !shift) {
     return false;
   }
   return super.onClick(clickedSlot, rightClick, shift);
 }
Beispiel #2
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;
      }
    }
  }
Beispiel #3
0
 @Override
 public void onSlotSet(InventoryBase inventory, int slot, ItemStack item) {
   super.onSlotSet(inventory, slot, item);
   int size = 0;
   for (InventoryBase i : getInventory().getInventories()) {
     if (i != craftingGrid.getGridInventory() && slot > i.getSize() + size) {
       size += i.getSize();
     }
   }
   for (int i : craftingGrid.getGridArray()) {
     if (i + size == slot) {
       updateOutput();
       break;
     }
   }
 }
Beispiel #4
0
 @Override
 public boolean onClick(int clickedSlot, boolean rightClick, boolean shift) {
   if (itemOnCursor != null && clickedSlot == craftingGrid.getOutputSlot() && !shift) {
     return false;
   }
   return super.onClick(clickedSlot, rightClick, shift);
 }
Beispiel #5
0
 @Override
 public void onSlotSet(InventoryBase inventory, int slot, ItemStack item) {
   super.onSlotSet(inventory, slot, item);
   for (int i : craftingGrid.getGridArray()) {
     if (i == slot) {
       System.out.println("Updating output");
       updateOutput();
       break;
     }
   }
 }
Beispiel #6
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;
 }