Esempio n. 1
0
  public void loadRecipes() {
    System.out.println(
        String.format(
            "%s %s %s",
            config.recipes.FURNACES.size(),
            config.recipes.SHAPED.size(),
            config.recipes.SHAPELESS.size()));
    for (Furnace furnace : config.recipes.FURNACES) {
      FurnaceRecipe furnaceRecipe = new FurnaceRecipe(furnace.result.toItemStack(), furnace.source);
      getServer().addRecipe(furnaceRecipe);
    }
    for (Shaped shaped : config.recipes.SHAPED) {
      ShapedRecipe shapedRecipe = new ShapedRecipe(shaped.result);
      shapedRecipe.shape(shaped.shape);
      for (Character key : shaped.ingredientMap.keySet()) {
        shapedRecipe.setIngredient(key, shaped.ingredientMap.get(key));
      }
      getServer().addRecipe(shapedRecipe);
    }

    for (Shapeless shapeless : config.recipes.SHAPELESS) {
      ShapelessRecipe shapelessRecipe = new ShapelessRecipe(shapeless.result);
      for (MaterialData m : shapeless.ingredients) {
        shapelessRecipe.addIngredient(m);
      }
      getServer().addRecipe(shapelessRecipe);
    }
  }
  private Collection<ItemStack> getStackOnRecipeMatch(final Recipe recipe, final ItemStack stack) {
    final Collection<ItemStack> inputList;

    if (recipe instanceof ShapedRecipe) {
      ShapedRecipe sRecipe = (ShapedRecipe) recipe;
      inputList = sRecipe.getIngredientMap().values();
    } else if (recipe instanceof ShapelessRecipe) {
      ShapelessRecipe slRecipe = (ShapelessRecipe) recipe;
      inputList = slRecipe.getIngredientList();
    } else {
      return null;
    }

    boolean match = true;
    Iterator<ItemStack> iter = inputList.iterator();
    while (iter.hasNext()) {
      ItemStack inputSlot = iter.next();
      if (inputSlot == null) {
        iter.remove();
        continue;
      }

      if (inputSlot.getDurability() == Short.MAX_VALUE) {
        inputSlot.setDurability((short) 0);
      }
      if (!inputSlot.isSimilar(stack)) {
        match = false;
      }
    }

    if (match) {
      return inputList;
    }
    return null;
  }
Esempio n. 3
0
  @Override
  public boolean addRecipe(Recipe recipe) {
    //	GameRegistry.addRecipe((IRecipe) recipe);
    if (recipe instanceof ShapedRecipe) {
      ShapedRecipe r = (ShapedRecipe) recipe;
      boolean useOreDict = false;
      // Map<Character,net.minecraft.item.ItemStack> nmsRecipe = Maps.newHashMap();
      List<Object> objRecipe = new ArrayList<Object>();
      objRecipe.addAll(Arrays.asList(r.getShape()));
      for (Character j : r.getIngredientMap().keySet()) {
        ItemStack x = r.getIngredientMap().get(j);
        net.minecraft.item.ItemStack nms = CraftItemStack.createNMSItemStack(x);
        if (OreDictionary.getOreID(nms) != -1) {
          useOreDict = true;
        }
        if (LiquidContainerRegistry.isContainer(nms)) {
          useOreDict = true;
        }
        objRecipe.add(j);
        objRecipe.add(nms);
      }

      if (useOreDict) {
        ShapedOreRecipe rec =
            new ShapedOreRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), objRecipe);
        GameRegistry.addRecipe(rec);
      } else {
        GameRegistry.addRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), objRecipe);
      }
    } else if (recipe instanceof ShapelessRecipe) {
      ShapelessRecipe r = (ShapelessRecipe) recipe;
      List<net.minecraft.item.ItemStack> items = new ArrayList<net.minecraft.item.ItemStack>();
      boolean useOreDict = false;
      for (ItemStack i : r.getIngredientList()) {
        net.minecraft.item.ItemStack nms = CraftItemStack.createNMSItemStack(i);
        if (OreDictionary.getOreID(nms) != -1) {
          useOreDict = true;
        }
        if (LiquidContainerRegistry.isContainer(nms)) {
          useOreDict = true;
        }
        items.add(nms);
      }
      if (useOreDict) {
        // TODO: Check if the new Class is even required
        // ShapelessOreRecipe nmsRec =
        new ShapelessOreRecipe(CraftItemStack.createNMSItemStack(recipe.getResult()), items);
      } else {
        ShapelessRecipes nmsRec =
            new ShapelessRecipes(CraftItemStack.createNMSItemStack(recipe.getResult()), items);
        GameRegistry.addRecipe(nmsRec);
      }
    }
    return true;
  }
Esempio n. 4
0
  private static boolean match(Recipe recipe1, Recipe recipe2) {
    if (recipe1 instanceof ShapedRecipe) {
      if (recipe2 instanceof ShapedRecipe == false) {
        return false; // if other recipe is not the same type then they're not equal.
      }

      ShapedRecipe r1 = (ShapedRecipe) recipe1;
      ShapedRecipe r2 = (ShapedRecipe) recipe2;

      // convert both shapes and ingredient maps to common ItemStack array.
      ItemStack[] matrix1 = shapeToMatrix(r1.getShape(), r1.getIngredientMap());
      ItemStack[] matrix2 = shapeToMatrix(r2.getShape(), r2.getIngredientMap());

      if (!Arrays.equals(
          matrix1,
          matrix2)) // compare arrays and if they don't match run another check with one shape
                    // mirrored.
      {
        mirrorMatrix(matrix1);

        return Arrays.equals(matrix1, matrix2);
      }

      return true; // ingredients match.
    } else if (recipe1 instanceof ShapelessRecipe) {
      if (recipe2 instanceof ShapelessRecipe == false) {
        return false; // if other recipe is not the same type then they're not equal.
      }

      ShapelessRecipe r1 = (ShapelessRecipe) recipe1;
      ShapelessRecipe r2 = (ShapelessRecipe) recipe2;

      // get copies of the ingredient lists
      List<ItemStack> find = r1.getIngredientList();
      List<ItemStack> compare = r2.getIngredientList();

      if (find.size() != compare.size()) {
        return false; // if they don't have the same amount of ingredients they're not equal.
      }

      for (ItemStack item : compare) {
        if (!find.remove(item)) {
          return false; // if ingredient wasn't removed (not found) then they're not equal.
        }
      }

      return find.isEmpty(); // if there are any ingredients not removed then they're not equal.
    } else if (recipe1 instanceof FurnaceRecipe) {
      if (recipe2 instanceof FurnaceRecipe == false) {
        return false; // if other recipe is not the same type then they're not equal.
      }

      FurnaceRecipe r1 = (FurnaceRecipe) recipe1;
      FurnaceRecipe r2 = (FurnaceRecipe) recipe2;

      // return (r1.getInput().equals(r2.getInput())); // TODO use this when furnace data PR is
      // pulled
      return r1.getInput().getTypeId() == r2.getInput().getTypeId();
    } else {
      throw new IllegalArgumentException(
          "Unsupported recipe type: '" + recipe1 + "', update this class!");
    }
  }