Помогите Пустота в крафтах

IcedwinterZ

Активный участник
Пользователь
Баллы
76
Имя в Minecraft
IcedwinterZ
Есть крафт в конфиге

line1: '0 5 0'
line2: '0 5 0'
line1: '5 5 5'

Но ноль - воздух, а в верстаке то воздух просто так не лежит, т.е крафт не получается, что использовать вместо 0?
 
Почему не лежит? =\
 
Попробуй только доставай из конфига dirt.shape
Код:
ShapedRecipe dirt = new ShapedRecipe(result);
        dirt.shape(
                "BAB",
                "BAB",
                "AAA");
        dirt.setIngredient('A',Material.APPLE);
        dirt.setIngredient('B',Material.AIR);
 
Попробуй только доставай из конфига dirt.shape
Код:
ShapedRecipe dirt = new ShapedRecipe(result);
        dirt.shape(
                "BAB",
                "BAB",
                "AAA");
        dirt.setIngredient('A',Material.APPLE);
        dirt.setIngredient('B',Material.AIR);
В том то и дело что из воздуха не крафтится... Воздух просто не лежит там
Код:
public static void onCraft(int id, String dname, FileConfiguration c, String one, String two, String three){
        List<String> lore = new ArrayList<String>();
        ItemStack item = new ItemStack(Material.getMaterial(id));
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(dname);
        meta.setLore(lore);
        meta.addEnchant(Enchantment.DURABILITY, 1, true);
        item.setItemMeta(meta);
      
        String[] splitOne = one.split(" ");
        id1 = Integer.parseInt(splitOne[0]);
        id2 = Integer.parseInt(splitOne[1]);
        id3 = Integer.parseInt(splitOne[2]);
        String[] splitTwo = two.split(" ");
        id4 = Integer.parseInt(splitTwo[0]);
        id5 = Integer.parseInt(splitTwo[1]);
        id6 = Integer.parseInt(splitTwo[2]);
        String[] splitThree = three.split(" ");
        id7 = Integer.parseInt(splitThree[0]);
        id8 = Integer.parseInt(splitThree[1]);
        id9 = Integer.parseInt(splitThree[2]);
      
        ShapedRecipe r = new ShapedRecipe(item);
        r.shape(new String[] {"ABC","DEF","JHK"});
        r.setIngredient('A', Material.getMaterial(id1));
        r.setIngredient('B', Material.getMaterial(id2));
        r.setIngredient('C', Material.getMaterial(id3));
        r.setIngredient('D', Material.getMaterial(id4));
        r.setIngredient('E', Material.getMaterial(id5));
        r.setIngredient('F', Material.getMaterial(id6));
        r.setIngredient('J', Material.getMaterial(id7));
        r.setIngredient('H', Material.getMaterial(id8));
        r.setIngredient('K', Material.getMaterial(id9));
        Bukkit.addRecipe(r);
    }

Вот так это работает, выглядит как гавно - правда? Кто поправит?)
 
В том то и дело что из воздуха не крафтится... Воздух просто не лежит там
Код:
public static void onCraft(int id, String dname, FileConfiguration c, String one, String two, String three){
        List<String> lore = new ArrayList<String>();
        ItemStack item = new ItemStack(Material.getMaterial(id));
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(dname);
        meta.setLore(lore);
        meta.addEnchant(Enchantment.DURABILITY, 1, true);
        item.setItemMeta(meta);
     
        String[] splitOne = one.split(" ");
        id1 = Integer.parseInt(splitOne[0]);
        id2 = Integer.parseInt(splitOne[1]);
        id3 = Integer.parseInt(splitOne[2]);
        String[] splitTwo = two.split(" ");
        id4 = Integer.parseInt(splitTwo[0]);
        id5 = Integer.parseInt(splitTwo[1]);
        id6 = Integer.parseInt(splitTwo[2]);
        String[] splitThree = three.split(" ");
        id7 = Integer.parseInt(splitThree[0]);
        id8 = Integer.parseInt(splitThree[1]);
        id9 = Integer.parseInt(splitThree[2]);
     
        ShapedRecipe r = new ShapedRecipe(item);
        r.shape(new String[] {"ABC","DEF","JHK"});
        r.setIngredient('A', Material.getMaterial(id1));
        r.setIngredient('B', Material.getMaterial(id2));
        r.setIngredient('C', Material.getMaterial(id3));
        r.setIngredient('D', Material.getMaterial(id4));
        r.setIngredient('E', Material.getMaterial(id5));
        r.setIngredient('F', Material.getMaterial(id6));
        r.setIngredient('J', Material.getMaterial(id7));
        r.setIngredient('H', Material.getMaterial(id8));
        r.setIngredient('K', Material.getMaterial(id9));
        Bukkit.addRecipe(r);
    }

Вот так это работает, выглядит как гавно - правда? Кто поправит?)
Разве там нет символа пропуска или пробел, где ничего не нужно?
 
Храни рецепты в таком виде
YAML:
cobble_pickaxe:
    recipe: "ccc; s ; s "
    ingedients:
        c: COBBLESTONE
        s: STICK
    result:
        material: APPLE
        amount: 1
        damage: 0
        name: ""
        lore: []
        enchantaments: []

В итоге код становится намного короче и проще:
Java:
public final void registerCrafts(MemorySection config) {
    MemorySection section;
    for (String key : config.getKeys(false)) {
        section = (MemorySection) config.get(key);
        Material material;
        try {
            material = Material.valueOf(section.getString("result.material"));
        } catch (Exception ex) {
            //Your material is sux
            continue;
        }
        ItemStack result = new ItemStack(
                material, section.getInt("result.amount"), 
                (short) section.getInt("result.damage")
        );
        //TODO: ItemMeta

        String[] shape = section.getString("recipe").split(";");
        MemorySection ingredients = (MemorySection) section.get("ingredients");

        ShapedRecipe recipe = new ShapedRecipe(result);
        recipe.shape(shape);
        for (String character : ingredients.getKeys(false)) {
            try {
                material = Material.valueOf(ingredients.getString(character));
            } catch (Exception ex) {
                //Your material is sux
                continue;
            }
            recipe.setIngredient(character.toCharArray()[0], material);
        }

        try {
            Bukkit.addRecipe(recipe);
        } catch (Exception ex) {
            //Ur recipe is sux.
        }
    }
 
Последнее редактирование:
Ребят, пытаюсь парсить, не понимаю как, натолкните на пример, или дайте код =)
А, все, понял уже...
 
Назад
Верх