org.bukkit.inventory.ShapedRecipe Java Examples
The following examples show how to use
org.bukkit.inventory.ShapedRecipe.
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: RecipeShaped.java From ProRecipes with GNU General Public License v2.0 | 6 votes |
public boolean register(){ //Remove anything that will make a mess of things Iterator<org.bukkit.inventory.Recipe> it = ProRecipes.getPlugin().defaultRecipes.iterator(); org.bukkit.inventory.Recipe recipe; while(it.hasNext()) { recipe = it.next(); if (recipe != null && recipe instanceof ShapedRecipe) { ShapedRecipe b = (ShapedRecipe)recipe; if(matchMaps(b.getIngredientMap(), registerer.getIngredientMap())){ if(Arrays.deepEquals(b.getShape(), registerer.getShape())){ ProRecipes.getPlugin().getRecipes().addConflict(this, b); } } } } //You need your plugin here ProRecipes.getPlugin().getServer().addRecipe(registerer); return ProRecipes.getPlugin().getRecipes().addShaped(this); }
Example #2
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 #3
Source File: CraftsManager.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") public static void registerGoldenHeadCraft(){ ItemStack goldenHead = UhcItems.createGoldenHead(); ShapedRecipe headRecipe = VersionUtils.getVersionUtils().createShapedRecipe(goldenHead, "golden_head"); headRecipe.shape("GGG", "GHG", "GGG"); Material material = UniversalMaterial.PLAYER_HEAD.getType(); MaterialData data = UniversalMaterial.PLAYER_HEAD.getStack().getData(); headRecipe.setIngredient('G', Material.GOLD_INGOT); if (data != null && data.getItemType() == material) { headRecipe.setIngredient('H', data); }else { headRecipe.setIngredient('H', material); } Bukkit.getServer().addRecipe(headRecipe); }
Example #4
Source File: Craft.java From UhcCore with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") private void register(){ ShapedRecipe craftRecipe = VersionUtils.getVersionUtils().createShapedRecipe(craft, UUID.randomUUID().toString()); craftRecipe.shape("abc","def","ghi"); List<Character> symbols = Arrays.asList('a','b','c','d','e','f','g','h','i'); for(int i=0 ; i<9 ; i++){ if(!recipe.get(i).getType().equals(Material.AIR)){ Material material = recipe.get(i).getType(); MaterialData data = recipe.get(i).getData(); if (data != null && data.getItemType() == material) { craftRecipe.setIngredient(symbols.get(i), data); }else { craftRecipe.setIngredient(symbols.get(i), material); } } } Bukkit.getLogger().info("[UhcCore] "+name+" custom craft registered"); Bukkit.getServer().addRecipe(craftRecipe); }
Example #5
Source File: GoldenHeadsModule.java From UHC with MIT License | 6 votes |
public GoldenHeadsModule() { setId("GoldenHeads"); this.iconName = ICON_NAME; this.icon.setType(Material.SKULL_ITEM); this.icon.setDurability(PlayerHeadProvider.PLAYER_HEAD_DATA); this.icon.setWeight(ModuleRegistry.CATEGORY_APPLES); // register the new recipe final ShapedRecipe modified = new ShapedRecipe(new ItemStack(Material.GOLDEN_APPLE, 1)) .shape("AAA", "ABA", "AAA") .setIngredient('A', Material.GOLD_INGOT) .setIngredient('B', Material.SKULL_ITEM, PlayerHeadProvider.PLAYER_HEAD_DATA); Bukkit.addRecipe(modified); }
Example #6
Source File: Injector.java From Carbon-2 with GNU Lesser General Public License v3.0 | 6 votes |
public void registerRecipes() { Bukkit.resetRecipes(); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.BEETROOT_SOUP)).shape(new String[] {"rrr", "rrr", " b "}).setIngredient('r', MaterialList.BEETROOT).setIngredient('b', org.bukkit.Material.BOWL)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.END_BRICKS)).shape(new String[] {"ee", "ee"}).setIngredient('e', org.bukkit.Material.ENDER_STONE)); //Purpur block recipes addRecipe(new FurnaceRecipe(new ItemStack(MaterialList.CHORUS_FRUIT_POPPED), MaterialList.CHORUS_FRUIT)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_BLOCK, 4)).shape(new String[] {"pp", "pp"}).setIngredient('p', MaterialList.CHORUS_FRUIT_POPPED)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_STAIRS, 4)).shape(new String[] {"p ", "pp ", "ppp"}).setIngredient('p', MaterialList.PURPUR_BLOCK)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_STAIRS, 4)).shape(new String[] {" p", " pp", "ppp"}).setIngredient('p', MaterialList.PURPUR_BLOCK)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_SLAB, 6)).shape(new String[] {"ppp"}).setIngredient('p', MaterialList.PURPUR_BLOCK)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_PILLAR)).shape(new String[] {"s", "s"}).setIngredient('s', MaterialList.PURPUR_SLAB)); //Arrows addRecipe(new ShapedRecipe(new ItemStack(MaterialList.SPECTRAL_ARROW, 2)).shape(new String[] {" d ", "dad", " d "}).setIngredient('d', org.bukkit.Material.GLOWSTONE_DUST).setIngredient('a', org.bukkit.Material.ARROW)); }
Example #7
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 #8
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 #9
Source File: Recipes.java From ProRecipes with GNU General Public License v2.0 | 6 votes |
public boolean matchConflict(RecipeShaped rec, ShapedRecipe r){ if(conflictsShaped.containsKey(rec)){ //System.out.println("Contains"); for(ShapedRecipe rr : conflictsShaped.get(rec)){ if(rec.matchMaps(rr.getIngredientMap(), r.getIngredientMap())){ // System.out.println("Maps match"); if(Arrays.deepEquals(rr.getShape(),r.getShape())){ // System.out.println("Shape is the same"); return true; }else{ // System.out.println("Shape is not the same"); } }else{ // System.out.println("Maps don't match"); } } } //////System.out.println("Doesn't contain"); return false; }
Example #10
Source File: Injector.java From Carbon-2 with GNU Lesser General Public License v3.0 | 6 votes |
public void registerRecipes() { Bukkit.resetRecipes(); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.BEETROOT_SOUP)).shape(new String[] {"rrr", "rrr", " b "}).setIngredient('r', MaterialList.BEETROOT).setIngredient('b', org.bukkit.Material.BOWL)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.END_BRICKS)).shape(new String[] {"ee", "ee"}).setIngredient('e', org.bukkit.Material.ENDER_STONE)); //Purpur block recipes addRecipe(new FurnaceRecipe(new ItemStack(MaterialList.CHORUS_FRUIT_POPPED), MaterialList.CHORUS_FRUIT)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_BLOCK, 4)).shape(new String[] {"pp", "pp"}).setIngredient('p', MaterialList.CHORUS_FRUIT_POPPED)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_STAIRS, 4)).shape(new String[] {"p ", "pp ", "ppp"}).setIngredient('p', MaterialList.PURPUR_BLOCK)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_STAIRS, 4)).shape(new String[] {" p", " pp", "ppp"}).setIngredient('p', MaterialList.PURPUR_BLOCK)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_SLAB, 6)).shape(new String[] {"ppp"}).setIngredient('p', MaterialList.PURPUR_BLOCK)); addRecipe(new ShapedRecipe(new ItemStack(MaterialList.PURPUR_PILLAR)).shape(new String[] {"s", "s"}).setIngredient('s', MaterialList.PURPUR_SLAB)); //Arrows addRecipe(new ShapedRecipe(new ItemStack(MaterialList.SPECTRAL_ARROW, 2)).shape(new String[] {" d ", "dad", " d "}).setIngredient('d', org.bukkit.Material.GLOWSTONE_DUST).setIngredient('a', org.bukkit.Material.ARROW)); }
Example #11
Source File: CraftShapedRecipe.java From Thermos with GNU General Public License v3.0 | 6 votes |
public static CraftShapedRecipe fromBukkitRecipe(ShapedRecipe recipe) { if (recipe instanceof CraftShapedRecipe) { return (CraftShapedRecipe) recipe; } CraftShapedRecipe ret = new CraftShapedRecipe(recipe.getResult()); String[] shape = recipe.getShape(); ret.shape(shape); Map<Character, ItemStack> ingredientMap = recipe.getIngredientMap(); for (char c : ingredientMap.keySet()) { ItemStack stack = ingredientMap.get(c); if (stack != null) { ret.setIngredient(c, stack.getType(), stack.getDurability()); } } return ret; }
Example #12
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 #13
Source File: CraftShapedRecipe.java From Kettle with GNU General Public License v3.0 | 6 votes |
public static CraftShapedRecipe fromBukkitRecipe(ShapedRecipe recipe) { if (recipe instanceof CraftShapedRecipe) { return (CraftShapedRecipe) recipe; } CraftShapedRecipe ret = new CraftShapedRecipe(recipe.getKey(), recipe.getResult()); String[] shape = recipe.getShape(); ret.shape(shape); Map<Character, ItemStack> ingredientMap = recipe.getIngredientMap(); for (char c : ingredientMap.keySet()) { ItemStack stack = ingredientMap.get(c); if (stack != null) { ret.setIngredient(c, stack.getType(), stack.getDurability()); } } return ret; }
Example #14
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 #15
Source File: RecipeShaped.java From ProRecipes with GNU General Public License v2.0 | 5 votes |
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) { if (recipe != null && recipe instanceof ShapedRecipe) { ShapedRecipe b = (ShapedRecipe)recipe; if(matchMaps(b.getIngredientMap(), registerer.getIngredientMap())){ if(Arrays.deepEquals(b.getShape(), registerer.getShape())){ //it.remove(); break; } } } recipe = null; } } if(recipe != null){ ProRecipes.getPlugin().mv.getChecker().removeRecipe(it, ((ShapedRecipe)recipe)); } }
Example #16
Source File: GoldenCarrotRecipeModule.java From UHC with MIT License | 5 votes |
public GoldenCarrotRecipeModule() { setId("GoldenCarrotRecipe"); this.iconName = ICON_NAME; this.icon.setType(Material.GOLDEN_CARROT); this.icon.setWeight(ModuleRegistry.CATEGORY_RECIPIES); // register the new recipe final ShapedRecipe modified = new ShapedRecipe(new ItemStack(Material.GOLDEN_CARROT, 1)) .shape("AAA", "ABA", "AAA") .setIngredient('A', Material.GOLD_INGOT) .setIngredient('B', Material.CARROT_ITEM); Bukkit.addRecipe(modified); }
Example #17
Source File: Recipes.java From ProRecipes with GNU General Public License v2.0 | 5 votes |
public boolean isDouble(ShapedRecipe rec){ //long mil = System.currentTimeMillis(); for(ShapedRecipe shaped : doubles){ if(shaped.getIngredientMap().equals(rec.getIngredientMap())){ //System.out.println("Milliseconds spent (isDouble): " + (mil - System.currentTimeMillis())); return true; } } //System.out.println("Milliseconds spent (isDouble): " + (mil - System.currentTimeMillis())); return false; }
Example #18
Source File: RecipeShaped.java From ProRecipes with GNU General Public License v2.0 | 5 votes |
public RecipeShaped(ItemStack it){ result = it; ItemStack i = new ItemStack(Material.TRIPWIRE_HOOK); ItemMeta m = i.getItemMeta(); m.setDisplayName("recipedshapeditem"); i.setItemMeta(m); registerer = new ShapedRecipe(i); }
Example #19
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 #20
Source File: RandomizedCraftsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private ShapedRecipe cloneRecipeWithResult(ShapedRecipe recipe, ItemStack result){ ShapedRecipe clone = VersionUtils.getVersionUtils().createShapedRecipe(result, UUID.randomUUID().toString()); clone.shape(recipe.getShape()); Map<Character, RecipeChoice> recipeChoiceMap = recipe.getChoiceMap(); for (char c : recipeChoiceMap.keySet()){ clone.setIngredient(c, recipeChoiceMap.get(c)); } return clone; }
Example #21
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 #22
Source File: UpsideDownCraftsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private ShapedRecipe getUpsideDownRecipeFor(ShapedRecipe recipe){ ShapedRecipe upsideDown = VersionUtils.getVersionUtils().createShapedRecipe(recipe.getResult(), UUID.randomUUID().toString()); upsideDown.shape(getUpsideDownShape(recipe.getShape())); Map<Character, RecipeChoice> recipeChoiceMap = recipe.getChoiceMap(); for (char c : recipeChoiceMap.keySet()){ upsideDown.setIngredient(c, recipeChoiceMap.get(c)); } return upsideDown; }
Example #23
Source File: ItemService.java From Transport-Pipes with MIT License | 5 votes |
public ShapedRecipe createShapedRecipe(TransportPipes transportPipes, String recipeKey, ItemStack resultItem, String[] shape, Object... ingredientMap) { ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(transportPipes, recipeKey), resultItem); recipe.shape(shape); for (int i = 0; i < ingredientMap.length; i += 2) { char c = (char) ingredientMap[i]; if (ingredientMap[i + 1] instanceof Material) { recipe.setIngredient(c, (Material) ingredientMap[i + 1]); } else { recipe.setIngredient(c, new RecipeChoice.MaterialChoice(((Collection<Material>) ingredientMap[i + 1]).stream().collect(Collectors.toList()))); } } return recipe; }
Example #24
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 #25
Source File: RecipesBanners.java From Carbon with GNU Lesser General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") public void register() { //basic recipes for (int c = 0; c < 16; c++) { @SuppressWarnings("deprecation") ShapedRecipe defaultBanners = new ShapedRecipe(new ItemStack(Carbon.injector().bannerItemMat, 1, (short) (15 - c))).shape(new String[] { "www", "www", " s " }).setIngredient('w', Material.WOOL, c).setIngredient('s', Material.STICK); Bukkit.addRecipe(defaultBanners); } //patterns recipe CraftingManager.getInstance().getRecipes().add(new RecipesBannerPatterns()); //copy recipe CraftingManager.getInstance().getRecipes().add(new RecipesBannerCopy()); }
Example #26
Source File: Snowflakes.java From CardinalPGM with MIT License | 4 votes |
private List<DyeColor> getColors(Recipe recipe) { return recipe instanceof ShapedRecipe ? getColors(((ShapedRecipe) recipe).getIngredientMap().values()) : recipe instanceof ShapelessRecipe ? getColors(((ShapelessRecipe) recipe).getIngredientList()) : Lists.newArrayList(); }
Example #27
Source File: CustomShapedRecipe.java From AdditionsAPI with MIT License | 4 votes |
@Override public ShapedRecipe toBukkitRecipe(ItemStack result) { return toBukkitRecipe(null, result); }
Example #28
Source File: CraftingModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
public Recipe parseShapedRecipe(MapFactory factory, Element elRecipe) throws InvalidXMLException { ShapedRecipe recipe = new ShapedRecipe(parseRecipeResult(factory, elRecipe)); Element elShape = XMLUtils.getRequiredUniqueChild(elRecipe, "shape"); List<String> rows = new ArrayList<>(3); for (Element elRow : elShape.getChildren("row")) { String row = elRow.getTextNormalize(); if (rows.size() >= 3) { throw new InvalidXMLException( "Shape must have no more than 3 rows (" + row + ")", elShape); } if (rows.isEmpty()) { if (row.length() > 3) { throw new InvalidXMLException( "Shape must have no more than 3 columns (" + row + ")", elShape); } } else if (row.length() != rows.get(0).length()) { throw new InvalidXMLException("All rows must be the same width", elShape); } rows.add(row); } if (rows.isEmpty()) { throw new InvalidXMLException("Shape must have at least one row", elShape); } recipe.shape(rows.toArray(new String[rows.size()])); Set<Character> keys = recipe .getIngredientMap() .keySet(); // All shape symbols are present and mapped to null at this point for (Element elIngredient : elRecipe.getChildren("ingredient")) { SingleMaterialMatcher item = XMLUtils.parseMaterialPattern(elIngredient); Attribute attrSymbol = XMLUtils.getRequiredAttribute(elIngredient, "symbol"); String symbol = attrSymbol.getValue(); if (symbol.length() != 1) { throw new InvalidXMLException( "Ingredient key must be a single character from the recipe shape", attrSymbol); } char key = symbol.charAt(0); if (!keys.contains(key)) { throw new InvalidXMLException( "Ingredient key '" + key + "' does not appear in the recipe shape", attrSymbol); } if (item.dataMatters()) { recipe.setIngredient(key, item.getMaterialData()); } else { recipe.setIngredient(key, item.getMaterial()); } } if (recipe.getIngredientMap().isEmpty()) { throw new InvalidXMLException( "Crafting recipe must have at least one ingredient", elRecipe); } return recipe; }
Example #29
Source File: VersionUtils_1_12.java From UhcCore with GNU General Public License v3.0 | 4 votes |
@Override public ShapedRecipe createShapedRecipe(ItemStack craft, String craftKey) { NamespacedKey namespacedKey = new NamespacedKey(UhcCore.getPlugin(), craftKey); return new ShapedRecipe(namespacedKey, craft); }
Example #30
Source File: VersionUtils_1_8.java From UhcCore with GNU General Public License v3.0 | 4 votes |
@Override public ShapedRecipe createShapedRecipe(ItemStack craft, String craftKey) { return new ShapedRecipe(craft); }