Esempio n. 1
0
  @Override
  public ShapedRecipe matchShapedRecipe(List<List<Material>> materials) {
    Set<Material> set = new HashSet<Material>();
    List<List<Material>> list = new ArrayList<List<Material>>();
    List<List<Material>> parentList = new ArrayList<List<Material>>();
    for (List<Material> materialsRow : materials) {
      List<Material> parentRow = new ArrayList<Material>();
      List<Material> row = new ArrayList<Material>();
      for (Material m : materialsRow) {
        row.add(m);
        Material parent = m;
        if (m != null) {
          set.add(m);
          if (m.isSubMaterial()) {
            parent = m.getParentMaterial();
          }
        }
        parentRow.add(parent);
      }
      parentList.add(parentRow);
      list.add(row);
    }

    if (!allShapedRecipes.containsKey(set.size())) {
      return null;
    }
    ShapedRecipe recipe = allShapedRecipes.get(set.size()).matchShapedRecipe(list, true);
    if (recipe == null) {
      recipe = allShapedRecipes.get(set.size()).matchShapedRecipe(parentList, false);
    }
    return recipe;
  }
Esempio n. 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;
      }
    }
  }
Esempio n. 3
0
 @Override
 public int compare(Material o1, Material o2) {
   if (o1 == null) {
     if (o2 == null) {
       return 0;
     }
     return -1;
   }
   if (o2 == null) {
     return 1;
   }
   if (o1.equals(o2)) {
     return 0;
   }
   return o1.getName().compareTo(o2.getName());
 }
Esempio n. 4
0
  @Override
  public ShapelessRecipe matchShapelessRecipe(Plugin plugin, List<Material> materials) {
    Set<Material> unique = new HashSet<Material>();
    List<Material> parentList = new ArrayList<Material>();
    for (Material m : materials) {
      if (m.isSubMaterial()) {
        m = m.getParentMaterial();
      }
      parentList.add(m);
    }
    unique.addAll(parentList);
    unique.removeAll(Collections.singletonList(null));

    ShapelessRecipe recipe = null;
    if (registeredShapelessRecipes.containsKey(plugin)
        && registeredShapelessRecipes.get(plugin).containsKey(unique.size())) {
      for (ShapelessRecipe r : registeredShapelessRecipes.get(plugin).get(unique.size())) {
        if (r.getIncludeData()) {
          List<Material> materialsCopy = new ArrayList<Material>(materials);
          List<Material> ingredientsCopy = new ArrayList<Material>(r.getIngredients());
          Collections.sort(materialsCopy, new MaterialComparable());
          Collections.sort(ingredientsCopy, new MaterialComparable());
          if (materialsCopy.equals(ingredientsCopy)) {
            recipe = r;
            break;
          }
        } else {
          List<Material> parentsCopy = new ArrayList<Material>(parentList);
          List<Material> ingredientsCopy = new ArrayList<Material>(r.getIngredients());
          Collections.sort(parentsCopy, new MaterialComparable());
          Collections.sort(ingredientsCopy, new MaterialComparable());
          if (parentsCopy.equals(ingredientsCopy)) {
            recipe = r;
            break;
          }
        }
      }
    }
    if (recipe == null) {
      recipe = matchShapelessRecipe(materials);
    }

    return recipe;
  }
 @Override
 public int getAndSetBlock(int x, int y, int z, MaterialSource material) {
   Material m = material.getMaterial();
   return getAndSetBlock(x, y, z, m.getId(), m.getData());
 }
  @Command(
      aliases = {"give"},
      usage = "[player] <block> [amount] ",
      desc = "Lets a player spawn items",
      min = 1,
      max = 3)
  @CommandPermissions("vanilla.command.give")
  public void give(CommandContext args, CommandSource source) throws CommandException {
    int index = 0;
    Player player = null;

    if (args.length() != 1) {
      if (Spout.getEngine() instanceof Client) {
        throw new CommandException("You cannot search for players unless you are in server mode.");
      }
      player = Spout.getEngine().getPlayer(args.getString(index++), true);
    }

    if (player == null) {
      switch (args.length()) {
        case 3:
          throw new CommandException(args.getString(0) + " is not online.");
        case 2:
          index--;
        case 1:
          if (!(source instanceof Player)) {
            throw new CommandException("You must be a player to give yourself materials!");
          }

          player = (Player) source;
          break;
      }
    }

    Material material;
    if (args.isInteger(index)) {
      material = VanillaMaterials.getMaterial((short) args.getInteger(index));
    } else {
      String name = args.getString(index);

      if (name.contains(":")) {
        String[] parts = args.getString(index).split(":");
        material =
            VanillaMaterials.getMaterial(Short.parseShort(parts[0]), Short.parseShort(parts[1]));
      } else {
        material = Material.get(args.getString(index));
      }
    }

    if (material == null) {
      throw new CommandException(args.getString(index) + " is not a block!");
    }

    int count = args.getInteger(++index, 1);
    player.get(PlayerInventory.class).add(new ItemStack(material, count));
    source.sendMessage(
        plugin.getPrefix(),
        ChatStyle.BRIGHT_GREEN,
        "Gave ",
        ChatStyle.WHITE,
        player.getName() + " ",
        count,
        ChatStyle.BRIGHT_GREEN,
        " of ",
        ChatStyle.WHITE,
        material.getDisplayName());
  }