org.bukkit.scoreboard.DisplaySlot#org.bukkit.inventory.ShapedRecipe源码实例Demo

下面列出了org.bukkit.scoreboard.DisplaySlot#org.bukkit.inventory.ShapedRecipe 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Kettle   文件: CraftShapedRecipe.java
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;
}
 
源代码2 项目: Kettle   文件: RecipeIterator.java
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));
    }
}
 
源代码3 项目: UhcCore   文件: Craft.java
@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);
}
 
源代码4 项目: UhcCore   文件: CraftsManager.java
@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);
}
 
源代码5 项目: ProRecipes   文件: RecipeShaped.java
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);
}
 
源代码6 项目: ProRecipes   文件: Recipes.java
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;
}
 
源代码7 项目: Carbon-2   文件: Injector.java
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));
}
 
源代码8 项目: Thermos   文件: CraftShapedRecipe.java
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;
}
 
源代码9 项目: Thermos   文件: CraftServer.java
@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;
}
 
源代码10 项目: UHC   文件: RecipeUtil.java
/**
 * 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;
}
 
源代码11 项目: UHC   文件: GoldenHeadsModule.java
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);
}
 
源代码12 项目: Carbon-2   文件: Injector.java
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));
}
 
源代码13 项目: civcraft   文件: ConfigRemovedRecipes.java
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;
				}
			}
		}
	}
}
 
源代码14 项目: Slimefun4   文件: MinecraftRecipeService.java
/**
 * 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);
    }
}
 
源代码15 项目: Transport-Pipes   文件: ItemService.java
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;
}
 
源代码16 项目: UhcCore   文件: UpsideDownCraftsListener.java
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;
}
 
源代码17 项目: UhcCore   文件: RandomizedCraftsListener.java
@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));
}
 
源代码18 项目: UhcCore   文件: RandomizedCraftsListener.java
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;
}
 
源代码19 项目: StackMob-3   文件: DropTools.java
/**
 * 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;
}
 
源代码20 项目: ProRecipes   文件: RecipeShaped.java
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);
}
 
源代码21 项目: ProRecipes   文件: RecipeShaped.java
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));
      }
}
 
源代码22 项目: ProRecipes   文件: Recipes.java
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;
	
}
 
源代码23 项目: UHC   文件: GoldenCarrotRecipeModule.java
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);
}
 
源代码24 项目: Slimefun4   文件: TestVanillaMachinesListener.java
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;
}
 
源代码25 项目: Carbon   文件: RecipesBanners.java
@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());
}
 
源代码26 项目: PGM   文件: CraftingModule.java
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;
}
 
源代码27 项目: MineTinker   文件: Modifier.java
protected void registerCraftingRecipe() {
	if (!hasRecipe()) {
		return;
	}

	FileConfiguration config = getConfig();
	try {
		NamespacedKey nkey = new NamespacedKey(MineTinker.getPlugin(), "Modifier_" + getKey());
		ShapedRecipe newRecipe = new ShapedRecipe(nkey, this.getModItem()); //reload recipe
		String top = config.getString("Recipe.Top");
		String middle = config.getString("Recipe.Middle");
		String bottom = config.getString("Recipe.Bottom");
		ConfigurationSection materials = config.getConfigurationSection("Recipe.Materials");

		newRecipe.shape(top, middle, bottom); //makes recipe

		if (materials != null) {
			for (String key : materials.getKeys(false)) {
				String materialName = materials.getString(key);

				if (materialName == null) {
					ChatWriter.logInfo(LanguageManager.getString("Modifier.MaterialEntryNotFound"));
					return;
				}

				Material material = Material.getMaterial(materialName);

				if (material == null) {
					ChatWriter.log(false, "Material [" + materialName + "] is null for mod [" + this.name + "]");
					return;
				} else {
					newRecipe.setIngredient(key.charAt(0), material);
				}
			}
		} else {
			ChatWriter.logError("Could not register recipe for the " + this.name + "-Modifier!"); //executes if the recipe could not initialize
			ChatWriter.logError("Cause: Malformed recipe config.");

			return;
		}

		MineTinker.getPlugin().getServer().addRecipe(newRecipe); //adds recipe
		ChatWriter.log(false, "Registered recipe for the " + this.name + "-Modifier!");
		ModManager.instance().recipe_Namespaces.add(nkey);
	} catch (Exception e) {
		ChatWriter.logError("Could not register recipe for the " + this.name + "-Modifier!"); //executes if the recipe could not initialize
	}
}
 
源代码28 项目: ProjectAres   文件: CraftingModule.java
public Recipe parseShapedRecipe(MapModuleContext context, Element elRecipe) throws InvalidXMLException {
    ShapedRecipe recipe = new ShapedRecipe(parseRecipeResult(context, 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")) {
        MaterialPattern 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;
}
 
源代码29 项目: Transport-Pipes   文件: PipeManager.java
public ShapedRecipe getWrenchRecipe() {
    return wrenchRecipe;
}
 
源代码30 项目: UhcCore   文件: VersionUtils_1_13.java
@Override
public ShapedRecipe createShapedRecipe(ItemStack craft, String craftKey) {
    NamespacedKey namespacedKey = new NamespacedKey(UhcCore.getPlugin(), craftKey);
    return new ShapedRecipe(namespacedKey, craft);
}