Example #1
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;
  }
Example #2
0
 private void unloadExplosives() {
   Iterator<Recipe> iterator = getServer().recipeIterator();
   while (iterator.hasNext()) {
     Recipe recipe = iterator.next();
     EItem explosive = explosivesConfig.searchExplosiveByItemStack(recipe.getResult());
     if (explosive != null) {
       iterator.remove();
       consoleLogger.info("Removed " + explosive);
     }
   }
 }
Example #3
0
  public void removeDiamondRecipe() {

    Iterator<Recipe> iterator = getServer().recipeIterator();

    while (iterator.hasNext()) {
      Recipe recipe = iterator.next();
      if (recipe.getResult().equals(new ItemStack(Material.DIAMOND))) {

        iterator.remove();
        break;
      }
    }
  }
Example #4
0
  /**
   * Checks if both recipes are equal.<br>
   * Compares both ingredients and results.<br>
   * <br>
   * NOTE: If both arguments are null it returns true.
   *
   * @param recipe1
   * @param recipe2
   * @return true if ingredients and results match, false otherwise.
   * @throws IllegalArgumentException if recipe is other than ShapedRecipe, ShapelessRecipe or
   *     FurnaceRecipe.
   */
  public static boolean areEqual(Recipe recipe1, Recipe recipe2) {
    if (recipe1 == recipe2) {
      return true; // if they're the same instance (or both null) then they're equal.
    }

    if (recipe1 == null || recipe2 == null) {
      return false; // if only one of them is null then they're surely not equal.
    }

    if (!recipe1.getResult().equals(recipe2.getResult())) {
      return false; // if results don't match then they're not equal.
    }

    return match(recipe1, recipe2); // now check if ingredients match
  }
Example #5
0
 public void resetRecipe(boolean removeOld) {
   if (removeOld) {
     Iterator<Recipe> it = Bukkit.recipeIterator();
     while (it.hasNext()) {
       Recipe recipe = it.next();
       RPGItem rpgitem = ItemManager.toRPGItem(recipe.getResult());
       if (rpgitem == null) continue;
       if (rpgitem.getID() == getID()) {
         it.remove();
       }
     }
   }
   if (hasRecipe) {
     Set<ItemStack> iSet = new HashSet<ItemStack>();
     for (ItemStack m : recipe) {
       iSet.add(m);
     }
     ItemStack[] iList = iSet.toArray(new ItemStack[iSet.size()]);
     item.setItemMeta(getLocaleMeta("en_GB"));
     ShapedRecipe shapedRecipe = new ShapedRecipe(item);
     int i = 0;
     Map<ItemStack, Character> iMap = new HashMap<ItemStack, Character>();
     for (ItemStack m : iList) {
       iMap.put(m, (char) (65 + i));
       i++;
     }
     iMap.put(null, ' ');
     StringBuilder out = new StringBuilder();
     for (ItemStack m : recipe) {
       out.append(iMap.get(m));
     }
     String shape = out.toString();
     shapedRecipe.shape(shape.substring(0, 3), shape.substring(3, 6), shape.substring(6, 9));
     for (Entry<ItemStack, Character> e : iMap.entrySet()) {
       if (e.getKey() != null) {
         shapedRecipe.setIngredient(
             e.getValue(), e.getKey().getType(), e.getKey().getDurability());
       }
     }
     Bukkit.addRecipe(shapedRecipe);
   }
 }
  private SimpleRecipe getCondenseType(final ItemStack stack) {
    if (condenseList.containsKey(stack)) {
      return condenseList.get(stack);
    }

    final Iterator<Recipe> intr = ess.getServer().recipeIterator();
    while (intr.hasNext()) {
      final Recipe recipe = intr.next();
      final Collection<ItemStack> recipeItems = getStackOnRecipeMatch(recipe, stack);

      if (recipeItems != null
          && (recipeItems.size() == 4 || recipeItems.size() == 9)
          && (recipeItems.size() > recipe.getResult().getAmount())) {
        final ItemStack input = stack.clone();
        input.setAmount(recipeItems.size());
        final SimpleRecipe newRecipe = new SimpleRecipe(recipe.getResult(), input);
        condenseList.put(stack, newRecipe);
        return newRecipe;
      }
    }

    condenseList.put(stack, null);
    return null;
  }