org.bukkit.inventory.ShapelessRecipe Java Examples

The following examples show how to use org.bukkit.inventory.ShapelessRecipe. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CraftingModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
public Recipe parseShapelessRecipe(MapFactory factory, Element elRecipe)
    throws InvalidXMLException {
  ShapelessRecipe recipe = new ShapelessRecipe(parseRecipeResult(factory, elRecipe));

  for (Element elIngredient : XMLUtils.getChildren(elRecipe, "ingredient", "i")) {
    SingleMaterialMatcher item = XMLUtils.parseMaterialPattern(elIngredient);
    int count = XMLUtils.parseNumber(elIngredient.getAttribute("amount"), Integer.class, 1);
    if (item.dataMatters()) {
      recipe.addIngredient(count, item.getMaterialData());
    } else {
      recipe.addIngredient(count, item.getMaterial());
    }
  }

  if (recipe.getIngredientList().isEmpty()) {
    throw new InvalidXMLException(
        "Crafting recipe must have at least one ingredient", elRecipe);
  }

  return recipe;
}
 
Example #2
Source File: RecipeIterator.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public Recipe next() {
    if (recipes.hasNext()) {
        removeFrom = recipes;
        IRecipe recipe = recipes.next();
        if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) {
            return recipe.toBukkitRecipe();
        } else {
            return new CraftCustomModRecipe(recipe);
        }
    } else {
        net.minecraft.item.ItemStack item;
        if (smeltingCustom.hasNext()) {
            removeFrom = smeltingCustom;
            item = smeltingCustom.next();
        } else {
            removeFrom = smeltingVanilla;
            item = smeltingVanilla.next();
        }

        CraftItemStack stack = CraftItemStack.asCraftMirror(FurnaceRecipes.instance().getSmeltingResult(item));

        return new CraftFurnaceRecipe(stack, CraftItemStack.asCraftMirror(item));
    }
}
 
Example #3
Source File: CraftingModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public Recipe parseShapelessRecipe(MapModuleContext context, Element elRecipe) throws InvalidXMLException {
    ShapelessRecipe recipe = new ShapelessRecipe(parseRecipeResult(context, elRecipe));

    for(Element elIngredient : XMLUtils.getChildren(elRecipe, "ingredient", "i")) {
        MaterialPattern item = XMLUtils.parseMaterialPattern(elIngredient);
        int count = XMLUtils.parseNumber(elIngredient.getAttribute("amount"), Integer.class, 1);
        if(item.dataMatters()) {
            recipe.addIngredient(count, item.getMaterialData());
        } else {
            recipe.addIngredient(count, item.getMaterial());
        }
    }

    if(recipe.getIngredientList().isEmpty()) {
        throw new InvalidXMLException("Crafting recipe must have at least one ingredient", elRecipe);
    }

    return recipe;
}
 
Example #4
Source File: RecipeShapeless.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
public void unregister(){
	Iterator<org.bukkit.inventory.Recipe> it = ProRecipes.getPlugin().getServer().recipeIterator();
	org.bukkit.inventory.Recipe recipe = null;
       while(it.hasNext())
       {
           recipe = it.next();
           
           	 if (recipe != null && recipe instanceof ShapelessRecipe)
                {
                	ShapelessRecipe b = (ShapelessRecipe)recipe;
                	if(ingredientCheck(b.getIngredientList(), registerer.getIngredientList())){
                		//it.remove();
                		break;
                	}
                	
                }
           	 recipe = null;
           	 
       }
       
       if(recipe != null){
       	 ProRecipes.getPlugin().mv.getChecker().removeRecipe(it, ((ShapelessRecipe)recipe));
       }
      
}
 
Example #5
Source File: CraftServer.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean addRecipe(Recipe recipe) {
    CraftRecipe toAdd;
    if (recipe instanceof CraftRecipe) {
        toAdd = (CraftRecipe) recipe;
    } else {
        if (recipe instanceof ShapedRecipe) {
            toAdd = CraftShapedRecipe.fromBukkitRecipe((ShapedRecipe) recipe);
        } else if (recipe instanceof ShapelessRecipe) {
            toAdd = CraftShapelessRecipe.fromBukkitRecipe((ShapelessRecipe) recipe);
        } else if (recipe instanceof FurnaceRecipe) {
            toAdd = CraftFurnaceRecipe.fromBukkitRecipe((FurnaceRecipe) recipe);
        } else {
            return false;
        }
    }
    toAdd.addToCraftingManager();
    //net.minecraft.item.crafting.CraftingManager.getInstance().sort(); // Cauldron - mod recipes not necessarily sortable
    return true;
}
 
Example #6
Source File: RecipeUtil.java    From UHC with MIT License 6 votes vote down vote up
/**
 * Check if the recipe has the given material in it.
 *
 * @param recipe   the recipe to check
 * @param mat the material to look for
 * @return true if found, false if not
 */
public static boolean hasRecipeGotMaterial(Recipe recipe, Material mat) {
    Collection<ItemStack> ingredients = null;

    if (recipe instanceof ShapedRecipe) {
        ingredients = ((ShapedRecipe) recipe).getIngredientMap().values();
    } else if (recipe instanceof ShapelessRecipe) {
        ingredients = ((ShapelessRecipe) recipe).getIngredientList();
    }

    if (null == ingredients) return false;

    for (final ItemStack stack : ingredients) {
        if (stack.getType() == mat) return true;
    }

    return false;
}
 
Example #7
Source File: TestRecipeService.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testShapelessRecipeShape() {
    MinecraftRecipeService service = new MinecraftRecipeService(plugin);

    Assertions.assertThrows(IllegalArgumentException.class, () -> service.getRecipeShape(null));

    NamespacedKey key = new NamespacedKey(plugin, "shapeless_test");
    ShapelessRecipe recipe = new ShapelessRecipe(key, new ItemStack(Material.TNT_MINECART));
    MaterialChoice choice = new MaterialChoice(Material.TNT);
    recipe.addIngredient(choice);

    server.addRecipe(recipe);
    service.refresh();

    Assertions.assertArrayEquals(new RecipeChoice[] { choice }, service.getRecipeShape(recipe));
}
 
Example #8
Source File: CraftShapelessRecipe.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static CraftShapelessRecipe fromBukkitRecipe(ShapelessRecipe recipe) {
    if (recipe instanceof CraftShapelessRecipe) {
        return (CraftShapelessRecipe) recipe;
    }
    CraftShapelessRecipe ret = new CraftShapelessRecipe(recipe.getKey(), recipe.getResult());
    for (ItemStack ingred : recipe.getIngredientList()) {
        ret.addIngredient(ingred.getType(), ingred.getDurability());
    }
    return ret;
}
 
Example #9
Source File: ItemService.java    From Transport-Pipes with MIT License 5 votes vote down vote up
public ShapelessRecipe createShapelessRecipe(TransportPipes transportPipes, String recipeKey, ItemStack resultItem, Material... ingredients) {
    ShapelessRecipe recipe = new ShapelessRecipe(new NamespacedKey(transportPipes, recipeKey), resultItem);
    for (int i = 0; i < ingredients.length; i += 2) {
        recipe.addIngredient(ingredients[i]);
    }
    return recipe;
}
 
Example #10
Source File: CraftShapelessRecipe.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public static CraftShapelessRecipe fromBukkitRecipe(ShapelessRecipe recipe) {
    if (recipe instanceof CraftShapelessRecipe) {
        return (CraftShapelessRecipe) recipe;
    }
    CraftShapelessRecipe ret = new CraftShapelessRecipe(recipe.getResult());
    for (ItemStack ingred : recipe.getIngredientList()) {
        ret.addIngredient(ingred.getType(), ingred.getDurability());
    }
    return ret;
}
 
Example #11
Source File: GlisteringMelonRecipeModule.java    From UHC with MIT License 5 votes vote down vote up
public GlisteringMelonRecipeModule() {
    setId("GlisteringMelonRecipe");

    this.iconName = ICON_NAME;
    this.icon.setType(Material.SPECKLED_MELON);
    this.icon.setWeight(ModuleRegistry.CATEGORY_RECIPIES);

    final ShapelessRecipe modified = new ShapelessRecipe(new ItemStack(Material.SPECKLED_MELON, 1))
            .addIngredient(1, Material.GOLD_BLOCK)
            .addIngredient(1, Material.MELON);

    Bukkit.addRecipe(modified);
}
 
Example #12
Source File: CustomShapelessRecipe.java    From AdditionsAPI with MIT License 4 votes vote down vote up
@Override
public ShapelessRecipe toBukkitRecipe(ItemStack result) {
	return toBukkitRecipe(null, result);
}
 
Example #13
Source File: Recipes.java    From ProRecipes with GNU General Public License v2.0 4 votes vote down vote up
public void addConflict(RecipeShapeless rec, ShapelessRecipe re){
	conflictsShapeless.put(rec, re);
}
 
Example #14
Source File: Archer.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@Override
protected void setUp()
{
	ShapelessRecipe recipe = new ShapelessRecipe(new ItemStack(Material.ARROW,3)).addIngredient(Material.FLINT).addIngredient(Material.STICK);
	Bukkit.addRecipe(recipe);	
}
 
Example #15
Source File: Snowflakes.java    From CardinalPGM with MIT License 4 votes vote down vote up
private List<DyeColor> getColors(Recipe recipe) {
    return recipe instanceof ShapedRecipe ? getColors(((ShapedRecipe) recipe).getIngredientMap().values())
            : recipe instanceof ShapelessRecipe ? getColors(((ShapelessRecipe) recipe).getIngredientList())
            : Lists.newArrayList();
}