org.bukkit.inventory.Recipe Java Examples
The following examples show how to use
org.bukkit.inventory.Recipe.
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: NBTChecker_v1_13_R1.java From ProRecipes with GNU General Public License v2.0 | 6 votes |
@Override public void removeRecipe(Iterator<Recipe> it, Recipe recipe) { System.out.println("REMOVING: " + recipe.getResult().getType().toString()); Iterator<Recipe> recipes = ProRecipes.getPlugin().getServer().recipeIterator(); HashSet<Recipe> storedRecipes = new HashSet<Recipe>(); while(recipes.hasNext()){ storedRecipes.add(recipes.next()); } storedRecipes.remove(recipe); ProRecipes.getPlugin().getServer().clearRecipes(); for(Recipe rec : storedRecipes){ ProRecipes.getPlugin().getServer().addRecipe(rec); } System.out.println("REMOVED: " + recipe.getResult().getType().toString()); }
Example #2
Source File: ModManager.java From MineTinker with GNU General Public License v3.0 | 6 votes |
public void removeRecipes() { Iterator<Recipe> it = Bukkit.getServer().recipeIterator(); //TODO: Find a different way to remove recipes! Bukkit is bugged atm while (it.hasNext()) { ItemStack result = it.next().getResult(); //Modifieritems if (ModManager.instance().isModifierItem(result)) { it.remove(); continue; } //Builderswands if (ModManager.instance().isWandViable(result)) { it.remove(); } } ModManager.instance().recipe_Namespaces.clear(); }
Example #3
Source File: CraftingModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
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 #4
Source File: TestRecipeService.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Test public void testRecipe() { MinecraftRecipeService service = new MinecraftRecipeService(plugin); NamespacedKey key = new NamespacedKey(plugin, "furnace_recipe_test"); ItemStack result = new ItemStack(Material.EMERALD_BLOCK); FurnaceRecipe recipe = new FurnaceRecipe(key, result, new MaterialChoice(Material.DIAMOND), 1, 2); server.addRecipe(recipe); // The Snapshot has not been taken, so it should fallback to an empty array Assertions.assertEquals(0, service.getRecipesFor(result).length); service.refresh(); Recipe[] recipes = service.getRecipesFor(result); Assertions.assertEquals(1, recipes.length); Assertions.assertEquals(recipe, recipes[0]); }
Example #5
Source File: CraftingModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
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 #6
Source File: MinecraftRecipeService.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
/** * This returns the shape of a given {@link Recipe}. * For any shapeless {@link Recipe} the result will be equivalent to * {@link RecipeSnapshot#getRecipeInput(Recipe)}. * For a {@link ShapedRecipe} this method will fix the order so it matches a * 3x3 crafting grid. * * @param recipe * The {@link Recipe} to get the shape from * @return An Array of {@link RecipeChoice} representing the shape of this {@link Recipe} */ public RecipeChoice[] getRecipeShape(Recipe recipe) { Validate.notNull(recipe, "Recipe must not be null!"); if (recipe instanceof ShapedRecipe) { List<RecipeChoice> choices = new LinkedList<>(); for (String row : ((ShapedRecipe) recipe).getShape()) { int columns = row.toCharArray().length; for (char key : row.toCharArray()) { choices.add(((ShapedRecipe) recipe).getChoiceMap().get(key)); } while (columns < 3) { choices.add(null); columns++; } } return choices.toArray(new RecipeChoice[0]); } else { return snapshot.getRecipeInput(recipe); } }
Example #7
Source File: RecipeIterator.java From Kettle with GNU General Public License v3.0 | 6 votes |
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 #8
Source File: ConfigRemovedRecipes.java From civcraft with GNU General Public License v2.0 | 6 votes |
public static void removeRecipes(FileConfiguration cfg, HashMap<Integer, ConfigRemovedRecipes> removedRecipies){ List<Map<?, ?>> configMaterials = cfg.getMapList("removed_recipes"); for (Map<?, ?> b : configMaterials) { ConfigRemovedRecipes item = new ConfigRemovedRecipes(); item.type_id = (Integer)b.get("type_id"); item.data = (Integer)b.get("data"); removedRecipies.put(item.type_id, item); Iterator<Recipe> it = Bukkit.getServer().recipeIterator(); while (it.hasNext()) { Recipe recipe = it.next(); if (recipe instanceof ShapedRecipe) { ShapedRecipe shapedRecipe = (ShapedRecipe)recipe; if (ItemManager.getId(shapedRecipe.getResult()) == item.type_id && shapedRecipe.getResult().getDurability() == (short)item.data) { it.remove(); break; } } } } }
Example #9
Source File: RecipeUtil.java From UHC with MIT License | 6 votes |
/** * 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 #10
Source File: CraftServer.java From Thermos with GNU General Public License v3.0 | 6 votes |
@Override public List<Recipe> getRecipesFor(ItemStack result) { Validate.notNull(result, "Result cannot be null"); List<Recipe> results = new ArrayList<Recipe>(); Iterator<Recipe> iter = recipeIterator(); while (iter.hasNext()) { Recipe recipe = iter.next(); ItemStack stack = recipe.getResult(); if (stack.getType() != result.getType()) { continue; } if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) { results.add(recipe); } } return results; }
Example #11
Source File: CraftServer.java From Thermos with GNU General Public License v3.0 | 6 votes |
@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 #12
Source File: VersionUtils_1_13.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@Override public void removeRecipeFor(ItemStack item){ Iterator<Recipe> iterator = Bukkit.recipeIterator(); try { while (iterator.hasNext()){ if (iterator.next().getResult().isSimilar(item)){ iterator.remove(); Bukkit.getLogger().info("[UhcCore] Banned item "+JsonItemUtils.getItemJson(item)+" registered"); } } }catch (Exception ex){ Bukkit.getLogger().warning("[UhcCore] Failed to register "+JsonItemUtils.getItemJson(item)+" banned craft"); ex.printStackTrace(); } }
Example #13
Source File: VersionUtils_1_8.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@Override public void removeRecipeFor(ItemStack item){ Iterator<Recipe> iterator = Bukkit.recipeIterator(); try { while (iterator.hasNext()){ if (iterator.next().getResult().isSimilar(item)){ iterator.remove(); Bukkit.getLogger().info("[UhcCore] Banned item "+JsonItemUtils.getItemJson(item)+" registered"); } } }catch (Exception ex){ Bukkit.getLogger().warning("[UhcCore] Failed to register "+JsonItemUtils.getItemJson(item)+" banned craft"); ex.printStackTrace(); } }
Example #14
Source File: NBTChecker_v1_12_R1.java From ProRecipes with GNU General Public License v2.0 | 6 votes |
@Override public void removeRecipe(Iterator<Recipe> it, Recipe recipe) { System.out.println("REMOVING: " + recipe.getResult().getType().toString()); Iterator<Recipe> recipes = ProRecipes.getPlugin().getServer().recipeIterator(); HashSet<Recipe> storedRecipes = new HashSet<Recipe>(); while(recipes.hasNext()){ storedRecipes.add(recipes.next()); } storedRecipes.remove(recipe); ProRecipes.getPlugin().getServer().clearRecipes(); for(Recipe rec : storedRecipes){ ProRecipes.getPlugin().getServer().addRecipe(rec); } System.out.println("REMOVED: " + recipe.getResult().getType().toString()); }
Example #15
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private CraftItemEvent mockCraftingEvent(ItemStack item) { Recipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "test_recipe"), new ItemStack(Material.EMERALD)); Player player = server.addPlayer(); CraftingInventory inv = Mockito.mock(CraftingInventory.class); Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { item, null, null, null, null, null, null, null, null }); InventoryView view = player.openInventory(inv); CraftItemEvent event = new CraftItemEvent(recipe, view, SlotType.RESULT, 9, ClickType.LEFT, InventoryAction.PICKUP_ALL); listener.onCraft(event); return event; }
Example #16
Source File: ChestSlimefunGuide.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Override public void displayItem(PlayerProfile profile, ItemStack item, int index, boolean addToHistory) { Player p = profile.getPlayer(); if (p == null || item == null || item.getType() == Material.AIR) { return; } SlimefunItem sfItem = SlimefunItem.getByItem(item); if (sfItem != null) { displayItem(profile, sfItem, addToHistory); return; } if (!showVanillaRecipes) { return; } Recipe[] recipes = SlimefunPlugin.getMinecraftRecipeService().getRecipesFor(item); if (recipes.length == 0) { return; } showMinecraftRecipe(recipes, index, item, profile, p, addToHistory); }
Example #17
Source File: GlisteringMelonRecipeModule.java From UHC with MIT License | 5 votes |
@EventHandler public void on(PrepareItemCraftEvent event) { final Recipe recipe = event.getRecipe(); if (recipe.getResult().getType() != Material.SPECKLED_MELON) return; if (RecipeUtil.hasRecipeGotMaterial(recipe, isEnabled() ? Material.GOLD_NUGGET : Material.GOLD_BLOCK)) { event.getInventory().setResult(new ItemStack(Material.AIR)); } }
Example #18
Source File: GoldenCarrotRecipeModule.java From UHC with MIT License | 5 votes |
@EventHandler public void on(PrepareItemCraftEvent event) { final Recipe recipe = event.getRecipe(); if (recipe.getResult().getType() != Material.GOLDEN_CARROT) return; if (RecipeUtil.hasRecipeGotMaterial(recipe, isEnabled() ? Material.GOLD_NUGGET : Material.GOLD_INGOT)) { event.getInventory().setResult(new ItemStack(Material.AIR)); } }
Example #19
Source File: CraftInventoryCrafting.java From Thermos with GNU General Public License v3.0 | 5 votes |
public Recipe getRecipe() { net.minecraft.item.crafting.IRecipe recipe = ((net.minecraft.inventory.InventoryCrafting)getInventory()).currentRecipe; // Cauldron start - handle custom recipe classes without Bukkit API equivalents try { return recipe == null ? null : recipe.toBukkitRecipe(); } catch (AbstractMethodError ex) { // No Bukkit wrapper provided return new CustomModRecipe(recipe); } // Cauldron end }
Example #20
Source File: NMSUtils.java From Transport-Pipes with MIT License | 5 votes |
public static boolean isFurnaceBurnableItem(ItemStack item) { Iterator<Recipe> recipeIt = Bukkit.recipeIterator(); while (recipeIt.hasNext()) { Recipe recipe = recipeIt.next(); if (!(recipe instanceof FurnaceRecipe)) continue; if(!((FurnaceRecipe) recipe).getInputChoice().test(item)) continue; return true; } return false; }
Example #21
Source File: MinecraftRecipeService.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
/** * This returns an array containing all {@link Recipe Recipes} for crafting the given * {@link ItemStack}. * * @param item * The {@link ItemStack} for which to get the recipes * @return An array of {@link Recipe Recipes} to craft the given {@link ItemStack} */ public Recipe[] getRecipesFor(ItemStack item) { if (snapshot == null || item == null) { return new Recipe[0]; } else { return snapshot.getRecipesFor(item).toArray(new Recipe[0]); } }
Example #22
Source File: RecipeCalculator.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
public static ItemStack getSmeltedOutput(Material type) { ItemStack result = null; Iterator<Recipe> iter = Bukkit.recipeIterator(); while (iter.hasNext()) { Recipe recipe = iter.next(); if (!(recipe instanceof FurnaceRecipe)) continue; if (((FurnaceRecipe) recipe).getInput().getType() != type) continue; result = recipe.getResult(); break; } return result; }
Example #23
Source File: RecipeManager.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
public static void removeRecipe(Material type, short durability) { Iterator<Recipe> recipes = Bukkit.recipeIterator(); Recipe recipe; while (recipes.hasNext()) { recipe = recipes.next(); if (recipe != null && recipe.getResult().getType() == type && recipe.getResult().getDurability() == durability) { recipes.remove(); } } }
Example #24
Source File: RecipeManager.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
public static void removeVanillaRecipe(Material type) { Iterator<Recipe> recipes = Bukkit.recipeIterator(); Recipe recipe; while (recipes.hasNext()) { recipe = recipes.next(); if (recipe != null && recipe.getResult().isSimilar(new ItemStack(type))) { recipes.remove(); } } }
Example #25
Source File: RecipeManager.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
public static void removeRecipe(Material type) { Iterator<Recipe> recipes = Bukkit.recipeIterator(); Recipe recipe; while (recipes.hasNext()) { recipe = recipes.next(); if (recipe != null && recipe.getResult().getType() == type) { recipes.remove(); } } }
Example #26
Source File: RandomizedCraftsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@Override public void onEnable(){ Iterator<Recipe> iterator = Bukkit.recipeIterator(); List<ItemStack> results = new ArrayList<>(); Set<ShapedRecipe> removeRecipes = new HashSet<>(); Recipe recipe; while (iterator.hasNext()){ recipe = iterator.next(); if (!(recipe instanceof ShapedRecipe)){ continue; } results.add(recipe.getResult()); removeRecipes.add((ShapedRecipe) recipe); } Collections.shuffle(results); Iterator<ItemStack> resultIterator = results.iterator(); Set<ShapedRecipe> randomizedRecipes = new HashSet<>(); for (ShapedRecipe oldRecipe : removeRecipes){ ShapedRecipe newRecipe = cloneRecipeWithResult(oldRecipe, resultIterator.next()); randomizedRecipes.add(newRecipe); VersionUtils.getVersionUtils().removeRecipeFor(newRecipe.getResult()); } randomizedRecipes.forEach(r -> Bukkit.getServer().addRecipe(r)); }
Example #27
Source File: CraftingModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public Recipe parseSmeltingRecipe(MapFactory factory, Element elRecipe) throws InvalidXMLException { SingleMaterialMatcher ingredient = XMLUtils.parseMaterialPattern( XMLUtils.getRequiredUniqueChild(elRecipe, "ingredient", "i")); ItemStack result = parseRecipeResult(factory, elRecipe); if (ingredient.dataMatters()) { return new FurnaceRecipe(result, ingredient.getMaterialData()); } else { return new FurnaceRecipe(result, ingredient.getMaterial()); } }
Example #28
Source File: DropTools.java From StackMob-3 with GNU General Public License v3.0 | 5 votes |
/** * TODO: Fix this */ private Map<ItemStack, Integer> compressDrops(Map<ItemStack, Integer> items){ Map<ItemStack, Integer> list = new HashMap<>(); for(Map.Entry<ItemStack, Integer> entry : items.entrySet()){ ItemStack item = entry.getKey(); int amount = entry.getValue(); Iterator<Recipe> recipes = sm.getServer().recipeIterator(); while (recipes.hasNext()){ Recipe recipe = recipes.next(); if(recipe instanceof ShapedRecipe){ ShapedRecipe slRecipe = (ShapedRecipe) recipe; if(slRecipe.getIngredientMap().values().size() < 9){ continue; } if(slRecipe.getIngredientMap().values().stream() .anyMatch(itemStack -> notValid(item, itemStack))){ continue; } double totalAmount = (double) amount / 9D; int blockAmount = (int) Math.floor(totalAmount); int leftOver = (int) Math.round((totalAmount - blockAmount) * 9); list.put(recipe.getResult(), blockAmount); list.put(item, leftOver); } } if(!list.containsKey(item)){ list.put(item, amount); } } return list; }
Example #29
Source File: RecipeUtils.java From AdditionsAPI with MIT License | 5 votes |
public static JsonObject getRecipeJson(Recipe recipe) { JsonObject json = new JsonObject(); JsonObject object=new JsonObject(); object.addProperty("number", 1); object.addProperty("latitude", 2); object.addProperty("longitude", 3); object.addProperty("text", 4); return json; }
Example #30
Source File: CraftingPipeSettingsInventory.java From Transport-Pipes with MIT License | 5 votes |
private Recipe calculateRecipe() { ItemStack[] items = new ItemStack[9]; for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { if (inv.getItem(9 + 1 + row * 9 + col) != null) { items[row * 3 + col] = inv.getItem(9 + 1 + row * 9 + col); } else { items[row * 3 + col] = null; } } } return getCraftingRecipe(items); }