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; }
public UpgradeItem(SQTechDrill plugin) { this.main = plugin; upgradeItem = new ItemStack(Material.WRITTEN_BOOK); BookMeta bookMeta = (BookMeta) upgradeItem.getItemMeta(); //bookMeta.setDisplayName(ChatColor.BLUE + "" + ChatColor.ITALIC + "Drill Upgrade"); bookMeta.setAuthor(ChatColor.AQUA + "Drill"); bookMeta.setPages("Test pgae 1\n s","asgsgge 2"); bookMeta.setGeneration(BookMeta.Generation.ORIGINAL); bookMeta.setTitle(ChatColor.BLUE + "" + ChatColor.ITALIC + "Drill Upgrade"); upgradeItem.setItemMeta(bookMeta); ShapelessRecipe recipe = new ShapelessRecipe(upgradeItem); //TODO temp recipe recipe.addIngredient(Material.DIRT); //Adds the specified ingredient. main.getServer().addRecipe(recipe); }
/** * Add our recipes */ @Override protected void enableCallback() { //Make a recipe that will return a golden carrot when the right shape is made ShapedRecipe newGoldenCarrot = new ShapedRecipe(new ItemStack(Material.GOLDEN_CARROT, 1)); //8 gold ingots surrounding an apple newGoldenCarrot.shape("AAA", "ABA", "AAA"); newGoldenCarrot.setIngredient('A', Material.GOLD_INGOT); newGoldenCarrot.setIngredient('B', Material.CARROT_ITEM); Bukkit.addRecipe(newGoldenCarrot); //Make the recipe for glistering melons minus a set shape (glistering melon is speckled melon in code ShapelessRecipe newGlisteringMelon = new ShapelessRecipe(new ItemStack(Material.SPECKLED_MELON, 1)); //1 gold ingot with a melon newGlisteringMelon.addIngredient(Material.GOLD_BLOCK); newGlisteringMelon.addIngredient(Material.MELON); Bukkit.addRecipe(newGlisteringMelon); }
@SuppressWarnings("deprecation") private static void injectRecipes() { ShapedRecipe slimeBlock = new ShapedRecipe(new ItemStack( Material.getMaterial("slime"))).shape( new String[] { "###", "###", "###" }).setIngredient('#', Material.SLIME_BALL); Bukkit.getServer().addRecipe(slimeBlock); ShapelessRecipe deslimeBlock = new ShapelessRecipe(new ItemStack( Material.SLIME_BALL, 9)); deslimeBlock.addIngredient(Material.getMaterial("slime")); Bukkit.getServer().addRecipe(deslimeBlock); ShapedRecipe redSandStone = new ShapedRecipe(new ItemStack(Material.getMaterial("red_sandstone"))) .shape(new String[] { " ", "## ", "## " }).setIngredient('#', Material.SAND, 1); Bukkit.getServer().addRecipe(redSandStone); }
@Override public void onEnable() { ConfigurationSerialization.registerClass(CustomItemStackImpl.class); ConfigurationSerialization.registerClass(CustomMaterialImpl.class); recipeManager = new RecipeManager(this); recipeManager.setupRecipes(); saveResource("music/canon.mid", false); jingleNoteManager = new JingleNoteManager(); registerListeners(new EntityShootBowListener(this), new PlayerQuitListener(this)); Map<Character, ItemStack> harpIngredients = new HashMap<>(); harpIngredients.put('s', new ItemStack(Material.STRING)); harpIngredients.put('S', new ItemStack(Material.STICK)); CustomMaterial harp = new CustomMaterialImpl("Harp", Material.BOW, new String[] {"ssS", "ssS", "ssS"}, harpIngredients); addMaterial(harp); Map<Character, ItemStack> bandageIngredients = new HashMap<>(); bandageIngredients.put('w', new ItemStack(Material.WOOL, 1)); CustomMaterial bandage = new CustomMaterialImpl("Bandage", Material.PAPER, new String[] {"www"}, bandageIngredients); addMaterial(bandage); ShapelessRecipe bandageRecipe = new ShapelessRecipe(new CustomItemStackImpl(bandage, 3).toMinecraftItemStack()); bandageRecipe.addIngredient(Material.LEATHER_CHESTPLATE); getServer().addRecipe(bandageRecipe); }
public void setupRecipes() { ShapelessRecipe beerRecipe = new ShapelessRecipe(getDrink("Beer")).addIngredient(Material.WHEAT).addIngredient(Material.POTION).addIngredient(Material.POTATO_ITEM).addIngredient(Material.SUGAR); plugin.getServer().addRecipe(beerRecipe); ShapelessRecipe wineRecipe = new ShapelessRecipe(getDrink("Wine")).addIngredient(Material.MELON).addIngredient(Material.POTION); plugin.getServer().addRecipe(wineRecipe); ShapelessRecipe sherryRecipe = new ShapelessRecipe(getDrink("Sherry")).addIngredient(5, Material.MELON).addIngredient(Material.POTION); plugin.getServer().addRecipe(sherryRecipe); ShapelessRecipe vodkaRecipe = new ShapelessRecipe(getDrink("Vodka")).addIngredient(Material.POISONOUS_POTATO).addIngredient(Material.POTION); plugin.getServer().addRecipe(vodkaRecipe); ShapelessRecipe whiskyRecipe = new ShapelessRecipe(getDrink("Whisky")).addIngredient(5, Material.WHEAT).addIngredient(Material.POTION); plugin.getServer().addRecipe(whiskyRecipe); ShapelessRecipe rumRecipe = new ShapelessRecipe(getDrink("Rum")).addIngredient(Material.SUGAR_CANE).addIngredient(Material.POTION); plugin.getServer().addRecipe(rumRecipe); ShapelessRecipe ciderRecipe = new ShapelessRecipe(getDrink("Cider")).addIngredient(Material.APPLE).addIngredient(Material.POTION); plugin.getServer().addRecipe(ciderRecipe); }
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; }
@EventHandler public void onSaddleSign(final PrepareItemCraftEvent event) { if (event.getRecipe() instanceof ShapelessRecipe) { final ShapelessRecipe recipe = (ShapelessRecipe)event.getRecipe(); if (recipe.getIngredientList().equals(Sddls.recipe.getIngredientList())) { final Player player = (Player) event.getView().getPlayer(); ItemStack saddle = null; for (final ItemStack item : event.getInventory().getMatrix()) if (item.getType() == Material.SADDLE) saddle = item; saddle = Sddls.signSaddle(saddle, player); event.getInventory().setResult(saddle); } } }
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; }
public static <T> T accept(Recipe recipe, RecipeVisitor<T> visitor) { if (recipe instanceof ShapedRecipe) { ShapedRecipe shapedRecipe = (ShapedRecipe) recipe; return visitor.visit(shapedRecipe); } else if (recipe instanceof ShapelessRecipe) { ShapelessRecipe shapelessRecipe = (ShapelessRecipe) recipe; return visitor.visit(shapelessRecipe); } else if (recipe instanceof FurnaceRecipe) { FurnaceRecipe furnaceRecipe = (FurnaceRecipe) recipe; return visitor.visit(furnaceRecipe); } return visitor.visitOther(recipe); }
protected Recipe getUncraftingRecipe() { ItemStack ingredient = getIngredient(); if(ingredient == null) return null; ingredient = ingredient.clone(); ingredient.setAmount(getMatterRatio()); ShapelessRecipe recipe = new ShapelessRecipe(ingredient); recipe.addIngredient(makeItem(1).getData()); return recipe; }
public boolean commandUse(CommandSender sender, String[] args) { Variables var = Necessities.getVar(); if (sender instanceof Player) { Material mat; Player p = (Player) sender; if (args.length == 0) { p.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You must enter an item to craft."); return true; } mat = Material.fromString(args[0]); if (Bukkit.getRecipesFor(mat.getBukkitMaterial().toItemStack(1)).isEmpty()) { p.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "There are no recipes to craft that item."); return true; } HashMap<ItemStack, Integer> items = new HashMap<>(); Recipe r = Bukkit.getRecipesFor(mat.getBukkitMaterial().toItemStack(1)).get(0); if (r instanceof ShapedRecipe) { ShapedRecipe s = (ShapedRecipe) r; for (Character c : s.getIngredientMap().keySet()) if (s.getIngredientMap().get(c) != null) items.put(s.getIngredientMap().get(c), items.containsKey(s.getIngredientMap().get(c)) ? items.get(s.getIngredientMap().get(c)) + 1 : 1); } else if (r instanceof ShapelessRecipe) for (ItemStack i : ((ShapelessRecipe) r).getIngredientList()) items.put(i, items.containsKey(i) ? items.get(i) + 1 : 1); for (Map.Entry<ItemStack, Integer> itemStackIntegerEntry : items.entrySet()) Bukkit.broadcastMessage(itemStackIntegerEntry.getValue() + " " + itemStackIntegerEntry.getKey().getType().toString()); Bukkit.broadcastMessage("results in " + r.getResult().getAmount() + ' ' + r.getResult().getType().toString()); } else sender.sendMessage(var.getEr() + "Error: " + var.getErMsg() + "You must be a player to craft items."); return true; }
static void addAllRecipes (FileConfiguration config) { if (config.getBoolean("allowFleshSmelt")) { Bukkit.addRecipe(new FurnaceRecipe(new ItemStack(Material.LEATHER),Material.ROTTEN_FLESH)); } if (config.getBoolean("allowJerky")){ ShapelessRecipe jerky = new ShapelessRecipe(new ItemStack(Material.RAW_BEEF)); jerky.addIngredient(2, Material.ROTTEN_FLESH); jerky.addIngredient(Material.SUGAR); Bukkit.addRecipe(jerky); } }
static void removeAllRecipes() { Recipe recipe; // Check iterator for any of our recipes, if so, remove them Iterator<Recipe> iter = Bukkit.recipeIterator(); while (iter.hasNext()) { recipe = iter.next(); // Check if this Recipe is one of the ones we are responsible for // First, Furnace Recipes try { if (recipe instanceof FurnaceRecipe) { if ((Material.LEATHER == recipe.getResult().getType()) && (Material.ROTTEN_FLESH == ((FurnaceRecipe) recipe).getInput().getType())){ iter.remove(); } } // Check for our Shapeless Recipes if (recipe instanceof ShapelessRecipe) { if (Material.RAW_BEEF == recipe.getResult().getType()) { List<ItemStack> ingredients = ((ShapelessRecipe) recipe).getIngredientList(); if (3 == ingredients.size() && ingredients.contains(new ItemStack(Material.ROTTEN_FLESH)) && ingredients.contains(new ItemStack(Material.SUGAR))) { iter.remove(); } } } } catch (NullPointerException e) { System.out.print("[ERROR]: Failed to process Recipe iterator"); e.printStackTrace(); // Don't rethrow, attempt recovery } } }
Transaction collect(ShapelessRecipe recipe) { List<ItemStack> ingredients = recipe.getIngredientList(); List<ItemStack> collected = new ArrayList<ItemStack>(ingredients.size()); INGREDIENTS: for (ItemStack ingredient : ingredients) { for (ItemStack item : collected) { if (ItemUtils.itemEqualsTypeAndData(item, ingredient)) { item.setAmount(item.getAmount() + ingredient.getAmount()); continue INGREDIENTS; } } collected.add(ingredient); } return new Transaction(collected, recipe.getResult()); }
/** * Returns true if the recipe contained in this verifier matches the given * {@link ShapelessRecipe}. * * @param recipe * @return True if the recipe was verified. */ boolean verify(ShapelessRecipe recipe) { List<ItemStack> ingredients = recipe.getIngredientList(); for (int i = 0; i < rows; i++) { RECIPEITEM: for (int j = 0; j < columns; j++) { ItemStack recipeItem = matrix[i][j]; if (recipeItem == null) continue; for (Iterator<ItemStack> it = ingredients.iterator(); it.hasNext();) { ItemStack ingredient = it.next(); if (ItemUtils.recipeIngredientEqualsTypeAndData(ingredient, recipeItem)) { int amount = ingredient.getAmount(); if (amount == 1) it.remove(); else ingredient.setAmount(amount - 1); continue RECIPEITEM; } } // An item in the matrix is not on the ingredient list. return false; } } // If the list of ingredients was exhausted, recipe verified. if (ingredients.size() == 0) return true; // Unsatisfied ingredients remain. return false; }
private void setupRecipes() { List<ShapelessRecipe> shapeless = new ArrayList<>(); ShapelessRecipe pickaxeTwo = new ShapelessRecipe(new IronPickaxeTwo()) .addIngredient(1, Material.IRON_PICKAXE) .addIngredient(3, Material.IRON_INGOT); shapeless.add(pickaxeTwo); for(ShapelessRecipe r : shapeless) { getServer().addRecipe(r); } }
public static ShapelessRecipe getChimaeraWingRecipe() { Material ingredient = Config.getInstance().getChimaeraItem(); int amount = Config.getInstance().getChimaeraRecipeCost(); ShapelessRecipe chimeraWing = new ShapelessRecipe(getChimaeraWing(1)); chimeraWing.addIngredient(amount, ingredient); return chimeraWing; }
/** * Check if the recipe has the given material in it * * @param r the recipe to check * @param mat the material to look for * @return true if found, false if not */ private static boolean hasRecipeGotMaterial(Recipe r, Material mat) { Collection<ItemStack> ingredients = null; //noinspection ChainOfInstanceofChecks if(r instanceof ShapedRecipe) { ingredients = ((ShapedRecipe) r).getIngredientMap().values(); } else if(r instanceof ShapelessRecipe) { ingredients = ((ShapelessRecipe) r).getIngredientList(); } return null != ingredients && isMaterialInList(ingredients, mat); }
@Override public Recipe getRecipe() { ShapelessRecipe recipe = new ShapelessRecipe(toItemStack(2)); UnlinkedSCURelay usr = new UnlinkedSCURelay(); registerCustomIngredients(usr); recipe.addIngredient(usr.getMaterialData()); recipe.addIngredient(usr.getMaterialData()); return recipe; }
@Override public Recipe[] getExtraRecipes() { BagOfHolding bag = new BagOfHolding(); registerCustomIngredients(bag); ShapelessRecipe[] res = new ShapelessRecipe[1]; res[0] = new ShapelessRecipe(toItemStack(1)); res[0].addIngredient(bag.getMaterialData()); return res; }
@Override public Recipe getRecipe() { BlankModule bm = new BlankModule(); registerCustomIngredients(bm); ShapelessRecipe recipe = new ShapelessRecipe(toItemStack()); recipe.addIngredient(bm.getMaterialData()); recipe.addIngredient(Material.PISTON_STICKY_BASE); recipe.addIngredient(Material.ARROW); return recipe; }
@Override public Recipe getRecipe() { ShapelessRecipe recipe = new ShapelessRecipe(toItemStack()); BreakerModule b = new BreakerModule(); registerCustomIngredients(b); recipe.addIngredient(b.getMaterialData()); recipe.addIngredient(Material.ENCHANTED_BOOK); return recipe; }
@Override public Recipe getRecipe() { BlankModule bm = new BlankModule(); registerCustomIngredients(bm); ShapelessRecipe recipe = new ShapelessRecipe(toItemStack()); recipe.addIngredient(bm.getMaterialData()); recipe.addIngredient(Material.PISTON_STICKY_BASE); return recipe; }
@Override public Recipe getRecipe() { registerCustomIngredients(new BlankModule()); ShapelessRecipe recipe = new ShapelessRecipe(toItemStack()); recipe.addIngredient(Material.PAPER); recipe.addIngredient(Material.SPIDER_EYE); recipe.addIngredient(Material.ARROW); return recipe; }
@Override public Recipe getRecipe() { BlankModule bm = new BlankModule(); registerCustomIngredients(bm); ShapelessRecipe recipe = new ShapelessRecipe(toItemStack()); recipe.addIngredient(bm.getMaterialData()); recipe.addIngredient(Material.BLAZE_POWDER); recipe.addIngredient(Material.EMERALD); return recipe; }
@Override public Recipe getRecipe() { registerCustomIngredients(new BlankModule()); ShapelessRecipe recipe = new ShapelessRecipe(toItemStack()); recipe.addIngredient(Material.PAPER); recipe.addIngredient(Material.HOPPER); recipe.addIngredient(Material.EYE_OF_ENDER); return recipe; }