Custom recipes

Nouma zer

Member
Hello ! I searched a bit about adding custom recipes for a while and I don't understand why I can't add mine, take a look :
Java:
package me.nouma.ncraft;

import cn.nukkit.inventory.ShapedRecipe;
import cn.nukkit.item.Item;
import cn.nukkit.plugin.PluginBase;

import java.util.ArrayList;
import java.util.HashMap;

public class Main extends PluginBase {

    @Override
    public void onEnable() {
        Item gapple = new Item(Item.GOLDEN_APPLE_ENCHANTED);
        String[] shape = {"GGG", "GAG", "GGG"};
        HashMap<Character, Item> identifiers = new HashMap<>();
        identifiers.put('G', new Item(Item.GOLD_BLOCK));
        identifiers.put('A', new Item(Item.APPLE));
        ArrayList<Item> items = new ArrayList<>();
        items.add(gapple);
        ShapedRecipe recipe = new ShapedRecipe(gapple, shape, identifiers, items);
        getServer().addRecipe(recipe);
    }
}
0 errors in the console and it still doesn't work.

I hope that you'll help me, thanks !
 

CreeperFace

🇨🇿🇺🇦 Слава Україні!
Staff member
Hello ! I searched a bit about adding custom recipes for a while and I don't understand why I can't add mine, take a look :
Code:
package me.nouma.ncraft;

import cn.nukkit.inventory.ShapedRecipe;
import cn.nukkit.item.Item;
import cn.nukkit.plugin.PluginBase;

import java.util.ArrayList;
import java.util.HashMap;

public class Main extends PluginBase {

    @Override
    public void onEnable() {
        Item gapple = new Item(Item.GOLDEN_APPLE_ENCHANTED);
        String[] shape = {"GGG", "GAG", "GGG"};
        HashMap<Character, Item> identifiers = new HashMap<>();
        identifiers.put('G', new Item(Item.GOLD_BLOCK));
        identifiers.put('A', new Item(Item.APPLE));
        ArrayList<Item> items = new ArrayList<>();
        items.add(gapple);
        ShapedRecipe recipe = new ShapedRecipe(gapple, shape, identifiers, items);
        getServer().addRecipe(recipe);
    }
}
0 errors in the console and it still doesn't work.

I hope that you'll help me, thanks !
maybe try calling this method https://github.com/NukkitX/Nukkit/blob/master/src/main/java/cn/nukkit/inventory/CraftingManager.java#L186
 

Nouma zer

Member
I don't know if I doing this wrong but this isn't working neither :(
Java:
package me.nouma.ncraft;

import cn.nukkit.inventory.ShapedRecipe;
import cn.nukkit.item.Item;
import cn.nukkit.plugin.PluginBase;

import java.util.ArrayList;
import java.util.HashMap;

public class Main extends PluginBase {

    @Override
    public void onEnable() {
        Item gapple = new Item(Item.GOLDEN_APPLE_ENCHANTED);

        String[] shape = {"GGG", "GAG", "GGG"};

        HashMap<Character, Item> identifiers = new HashMap<>();
        identifiers.put('G', new Item(Item.GRASS));
        identifiers.put('A', Item.get(Item.STONE));

        ArrayList<Item> items = new ArrayList<>();
        items.add(gapple);

        ShapedRecipe recipe = new ShapedRecipe(gapple, shape, identifiers, items);
        getServer().addRecipe(recipe);
        //getServer().getCraftingManager().registerShapedRecipe(recipe);

        getServer().getCraftingManager().rebuildPacket();
    }
}
 

CreeperFace

🇨🇿🇺🇦 Слава Україні!
Staff member
I don't know if I doing this wrong but this isn't working neither :(
Code:
package me.nouma.ncraft;

import cn.nukkit.inventory.ShapedRecipe;
import cn.nukkit.item.Item;
import cn.nukkit.plugin.PluginBase;

import java.util.ArrayList;
import java.util.HashMap;

public class Main extends PluginBase {

    @Override
    public void onEnable() {
        Item gapple = new Item(Item.GOLDEN_APPLE_ENCHANTED);

        String[] shape = {"GGG", "GAG", "GGG"};

        HashMap<Character, Item> identifiers = new HashMap<>();
        identifiers.put('G', new Item(Item.GRASS));
        identifiers.put('A', Item.get(Item.STONE));

        ArrayList<Item> items = new ArrayList<>();
        items.add(gapple);

        ShapedRecipe recipe = new ShapedRecipe(gapple, shape, identifiers, items);
        getServer().addRecipe(recipe);
        //getServer().getCraftingManager().registerShapedRecipe(recipe);

        getServer().getCraftingManager().rebuildPacket();
    }
}
hm probably it would be better to modify recipes.json for now
 

VixiK

New Member
I had some problem, this thread it partly fixed. Recipe is registerred successfully (I can see right result when I place items into crafting table), but then I cannot take the result. Maybe it's caused because of I'm replacing old recipe ?
 
Top