@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length == 0) return false; String recipeType = args[0]; List<? extends Recipe> recipes = recipesByTypeMapper.apply(recipeType); if (recipes == null) { sender.sendMessage(ChatColor.RED + "Unknown recipe type: " + recipeType); return true; } else if (recipes.isEmpty()) { sender.sendMessage(ChatColor.RED + "No recipes found for type: " + recipeType); return true; } return sender instanceof Player ? listPlayer((Player) sender, recipeType, recipes) : listSender(sender, recipeType, recipes); }
@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; }
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; }
@Test public void oakPlanksHaveAtLeastOneRecipe() { Iterator<Recipe> iterator = Bukkit.getServer().recipeIterator(); while (iterator.hasNext()) { Recipe recipe = iterator.next(); SortedSet<ItemStack> ingredients = ingredientsGetter.getIngredients(recipe); boolean shownOutput = false; for (ItemStack ingredient : ingredients) { if (ingredient.getType().equals(Material.WOOD)) { if (!shownOutput) { shownOutput = true; } MaterialData data = ingredient.getData(); } } } }
@Test public void realTest() { MaterialRecipes materialRecipes = recipeSnapshot.getMaterialRecipes(new MaterialData(Material.WORKBENCH)); Collection<Recipe> recipes = materialRecipes.getRecipes(); assertEqual(recipes.size(), 1); Recipe first = recipes.iterator().next(); SortedSet<ItemStack> ingredients = ingredientsGetter.getIngredients(first); for (ItemStack ingredient : ingredients) { if (ingredient != null) { assertEqual(ingredient.getData().getData(), (byte)-1); } } MaterialRecipes recipes1 = recipeSnapshot.getMaterialRecipes(new MaterialData(Material.WOOD_STAIRS)); assertEqual(recipes1.getRecipes().size(), 1); Recipe theRecipe = recipes1.getRecipes().iterator().next(); SortedSet<ItemStack> stairsIngredients = ingredientsGetter.getIngredients(theRecipe); for (ItemStack stairsIngredient : stairsIngredients) { if (stairsIngredient != null) { assertEqual(stairsIngredient.getData().getData(), (byte)0); } } Bukkit.getServer().broadcastMessage("realtest passed"); }
@Test public void jungleWoodPlanksCanCreateCraftingTableAndJungleWoodStairs() { Tree planks = new Tree(Material.WOOD); planks.setSpecies(TreeSpecies.JUNGLE); MaterialRecipes materialRecipes = recipeSnapshot.getMaterialRecipes(planks); boolean foundWorkBench = false; boolean foundJungleWoodPlanks = false; for (Recipe recipe : materialRecipes.getUsages()) { ItemStack result = recipe.getResult(); if (Material.WORKBENCH.equals(result.getType())) { foundWorkBench = true; } else if (Material.JUNGLE_WOOD_STAIRS.equals(result.getType())) { foundJungleWoodPlanks = true; } } assertEqual(true, foundWorkBench); assertEqual(true, foundJungleWoodPlanks); }
@Override public void registerItem(Item item) { this.itemMap.put(item.getItemName(), item); if (item instanceof ActionItem) { this.actionMap.put(item.getItemName(), (ActionItem)item); } if (item instanceof Listener) { Bukkit.getPluginManager().registerEvents((Listener)item, ZephyrPlugin.getInstance()); } if (item.getRecipe() != null) { @SuppressWarnings("deprecation") ItemStack stack = new ItemStack(item.getItemId(), 1); ItemMeta meta = stack.getItemMeta(); meta.setDisplayName(item.getItemNameColor() + item.getItemName()); meta.setLore(item.getItemLore()); stack.setItemMeta(meta); stack.setDurability((short)item.getItemData()); Recipe recipe = createRecipe(item.getRecipe(), stack); Bukkit.addRecipe(recipe); } }
public Recipe next() { if (recipes.hasNext()) { removeFrom = recipes; return recipes.next().toBukkitRecipe(); } else { net.minecraft.server.ItemStack item; if (smeltingCustom.hasNext()) { removeFrom = smeltingCustom; item = smeltingCustom.next(); } else { removeFrom = smeltingVanilla; item = smeltingVanilla.next(); } CraftItemStack stack = CraftItemStack.asCraftMirror(RecipesFurnace.getInstance().getResult(item)); return new CraftFurnaceRecipe(stack, CraftItemStack.asCraftMirror(item)); } }
@Override public Iterable<Recipe> getCraftingRecipes() { ShapedRecipe portalRecipe = new ShapedRecipe(makeItem(getAmountPerCraft())); portalRecipe.shape("BOB", "PCP", "OPO"); Dye purpleDye = new Dye(Material.INK_SACK); purpleDye.setColor(DyeColor.PURPLE); portalRecipe.setIngredient('B', Material.BLAZE_POWDER); portalRecipe.setIngredient('O', Material.OBSIDIAN); portalRecipe.setIngredient('P', Material.ENDER_PEARL); portalRecipe.setIngredient('C', purpleDye.toItemStack(1).getData()); return Collections.singletonList((Recipe) portalRecipe); }
@Override public Iterable<Recipe> getCraftingRecipes() { ArrayList<Recipe> recipes = new ArrayList<>(); ShapedRecipe baseRecipe = CraftingRecipes.shaped(makeItem(1), Material.STICK, Material.IRON_INGOT); recipes.add(CraftingRecipes.shaped(baseRecipe, "BBA", " ", " ")); recipes.add(CraftingRecipes.shaped(baseRecipe, " ", "BBA", " ")); recipes.add(CraftingRecipes.shaped(baseRecipe, " ", " ", "BBA")); recipes.add(CraftingRecipes.shaped(baseRecipe, "ABB", " ", " ")); recipes.add(CraftingRecipes.shaped(baseRecipe, " ", "ABB", " ")); recipes.add(CraftingRecipes.shaped(baseRecipe, " ", " ", "ABB")); return recipes; }
@Override public Recipe getRecipe() { ShapedRecipe recipe = new ShapedRecipe(toItemStack()); ToughMachineFrame mf = new ToughMachineFrame(); IntegratedCircuit ic = new IntegratedCircuit(); registerCustomIngredients(mf, ic); recipe.shape("OCO", "DFP", "RGR"); recipe.setIngredient('O', Material.OBSIDIAN); recipe.setIngredient('C', ic.getMaterialData()); recipe.setIngredient('D', Material.DISPENSER); recipe.setIngredient('F', mf.getMaterialData()); recipe.setIngredient('P', Material.DIAMOND_PICKAXE); recipe.setIngredient('R', Material.REDSTONE); recipe.setIngredient('G', Material.GOLD_INGOT); return recipe; }
@Override public void addCustomRecipes(CustomRecipeManager crm) { // add a corresponding smelter recipe for every known vanilla furnace recipe Iterator<Recipe> iter = Bukkit.recipeIterator(); while (iter.hasNext()) { Recipe r = iter.next(); if (r instanceof FurnaceRecipe) { FurnaceRecipe fr = (FurnaceRecipe) r; if (RecipeUtil.isVanillaSmelt(fr.getInput().getType())) { crm.addCustomRecipe(new SimpleCustomRecipe(this, fr.getInput(), fr.getResult(), getProcessingTime(fr.getInput()))); } } } // add a processing recipe for any STB item which reports itself as smeltable for (String key : SensibleToolbox.getItemRegistry().getItemIds()) { BaseSTBItem item = SensibleToolbox.getItemRegistry().getItemById(key); if (item.getSmeltingResult() != null) { ItemStack stack = item.toItemStack(); crm.addCustomRecipe(new SimpleCustomRecipe(this, stack, item.getSmeltingResult(), getProcessingTime(stack))); } } }
public ListRecipesCommandExecutor(Function<String, ? extends List<? extends Recipe>> recipesByTypeMapper, Map<String, Function<? super Recipe, ? extends ItemStack>> recipeToItemMap, Map<String, BiConsumer<? super Recipe, ? super CommandSender>> recipeToCommandSenderDiplayMap) { this.recipesByTypeMapper = recipesByTypeMapper; this.recipeToItemMap = recipeToItemMap; this.recipeToCommandSenderDiplayMap = recipeToCommandSenderDiplayMap; }
private boolean listPlayer(Player player, String recipeType, List<? extends Recipe> recipes) { Function<? super Recipe, ? extends ItemStack> representationFunction = recipeToItemMap.get(recipeType); if (representationFunction == null) { player.sendMessage(ChatColor.RED + "No representation function found for this type of recipe. Trying chat messages.."); return listSender(player, recipeType, recipes); } List<? extends ItemStack> representations = recipes.stream().map(representationFunction).collect(Collectors.toList()); player.openInventory(new ListRecipesInventoryHolder(recipeType, representations).getInventory()); return true; }
private boolean listSender(CommandSender sender, String recipeType, List<? extends Recipe> recipes) { BiConsumer<? super Recipe, ? super CommandSender> recipeDisplayFunction = recipeToCommandSenderDiplayMap.get(recipeType); if (recipeDisplayFunction == null) { sender.sendMessage(ChatColor.RED + "No display function found for this type of recpie."); return true; } recipes.forEach(recipe -> recipeDisplayFunction.accept(recipe, sender)); return true; }
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 }
public Recipe parseSmeltingRecipe(MapModuleContext context, Element elRecipe) throws InvalidXMLException { MaterialPattern ingredient = XMLUtils.parseMaterialPattern(XMLUtils.getRequiredUniqueChild(elRecipe, "ingredient", "i")); ItemStack result = parseRecipeResult(context, elRecipe); if(ingredient.dataMatters()) { return new FurnaceRecipe(result, ingredient.getMaterialData()); } else { return new FurnaceRecipe(result, ingredient.getMaterial()); } }
@Override public Recipe getRecipe() { ShapedRecipe r = new ShapedRecipe(baseItem); r.shape(" x", " y ", "x "); r.setIngredient('x', Material.REDSTONE); r.setIngredient('y', Material.STICK); return r; }
@EventHandler public void onPrepareCraft(PrepareItemCraftEvent e) { Recipe r = e.getInventory().getRecipe(); if (r == null || e.getViewers().size() != 1) { return; } Player viewer = (Player) e.getViewers().get(0); if (r.getResult() != null) { DuctDetails ductDetails = DuctItemUtils.getDuctDetailsOfItem(r.getResult()); if (ductDetails != null) { if (!viewer.hasPermission(ductDetails.getCraftPermission())) { e.getInventory().setResult(null); return; } } else if (DuctItemUtils.getWrenchItem().isSimilar(r.getResult())) { if (!viewer.hasPermission("transportpipes.craft.wrench")) { e.getInventory().setResult(null); return; } } if (ductDetails != null && ductDetails.getDuctType() == DuctType.PIPE) { boolean prevent = false; for (int i = 1; i < 10; i++) { ItemStack is = e.getInventory().getItem(i); if (is != null && is.getType() == Material.SKULL_ITEM && is.getDurability() == SkullType.PLAYER.ordinal()) { DuctDetails isDuctDetails = DuctItemUtils.getDuctDetailsOfItem(is); prevent |= isDuctDetails == null; } } if (prevent) { e.getInventory().setResult(null); } } } }
private static void onCraftItem(Recipe recipe, CraftingInventory inventory) { if (recipe.getResult().getType() == Material.WOOD_SWORD || recipe.getResult().getType() == Material.STONE_SWORD || recipe.getResult().getType() == Material.IRON_SWORD || recipe.getResult().getType() == Material.GOLD_SWORD || recipe.getResult().getType() == Material.DIAMOND_SWORD) inventory.setResult(new ItemStack(Material.AIR)); }
private void onCraftItem(Recipe recipe, CraftingInventory inventory) { if (recipe.getResult().getType() == Material.WOOD_SWORD) inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_SWORD))); else if (recipe.getResult().getType() == Material.WOOD_PICKAXE) inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_PICKAXE))); else if (recipe.getResult().getType() == Material.WOOD_AXE) inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_AXE))); else if (recipe.getResult().getType() == Material.WOOD_SPADE) inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_SPADE))); }
/** * Removes the ender-chest crafting recipe from the server meaning it can only be obtained from creative mode. */ private void removeRecipe() { for (Iterator<Recipe> iterator = Bukkit.recipeIterator(); iterator.hasNext();) { if (iterator.next().getResult().getType() == Material.ENDER_CHEST) { iterator.remove(); } } }
@Override protected void setRawSlot( short slot, ItemStack itemStack ) { this.setItem( slot, itemStack ); if( slot > 0 ) { me.lukas81298.flexmc.inventory.crafting.Recipe recipe = Flex.getServer().getRecipeManager().getRecipe( this ); if( recipe != null ) { setItem( 0, recipe.getResult() ); } } }
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(); } } }