1.15.2 help with custom recipes

Discussion in 'Spigot Plugin Development' started by lelesape, Feb 6, 2020.

  1. Hello spigot members, I need a bit of help with a plugin, I am currently on the making of an autobreaker plugin and I cannot seem to get custom recipes quite right, as I am trying to set quantities to ingredients, instead of making the recipe 1 of each ingredient.
    The way I was trying to do this is registering a shaped recipe and then check PrepareItemCraftEvent for quantities, but once the item is crafted, it only takes one of each ingredient, is there any way around this? Or is there any other way to check quantities?
    This is my code:
    Code (Java):
    if(event.getInventory().getResult() != null) {
                if(event.getInventory().getResult().hasItemMeta()) {
                    if(event.getInventory().getResult().equals(farmer())) {

                        String[] ingA = config.getString("config.recipes.auto farmer.A").split(",");
                        String[] ingB = config.getString("config.recipes.auto farmer.B").split(",");
                        String[] ingC = config.getString("config.recipes.auto farmer.C").split(",");
                        String[] ingD = config.getString("config.recipes.auto farmer.D").split(",");
                        String[] ingE = config.getString("config.recipes.auto farmer.E").split(",");
                        String[] ingF = config.getString("config.recipes.auto farmer.F").split(",");
                        String[] ingG = config.getString("config.recipes.auto farmer.G").split(",");
                        String[] ingH = config.getString("config.recipes.auto farmer.H").split(",");
                        String[] ingI = config.getString("config.recipes.auto farmer.I").split(",");
                        if(event.getInventory().getItem(1).getAmount() >= Integer.parseInt(ingA[1]) &&
                                event.getInventory().getItem(2).getAmount() >= Integer.parseInt(ingB[1]) &&
                                event.getInventory().getItem(3).getAmount() >= Integer.parseInt(ingC[1]) &&
                                event.getInventory().getItem(4).getAmount() >= Integer.parseInt(ingD[1]) &&
                                event.getInventory().getItem(5).getAmount() >= Integer.parseInt(ingE[1]) &&
                                event.getInventory().getItem(6).getAmount() >= Integer.parseInt(ingF[1]) &&
                                event.getInventory().getItem(7).getAmount() >= Integer.parseInt(ingG[1]) &&
                                event.getInventory().getItem(8).getAmount() >= Integer.parseInt(ingH[1]) &&
                                event.getInventory().getItem(9).getAmount() >= Integer.parseInt(ingI[1])) {
                        }else {
                            event.getInventory().setResult(new ItemStack(Material.AIR));
                    }else {

    Code (Java):
    public void registerFarmer() {
                    ItemStack breaker = new ItemStack(Material.DISPENSER);
                    ItemMeta meta = breaker.getItemMeta();
                    String path = "config.item.auto farmer";
                    meta.setDisplayName(this.getConfig().getString(path+".lvl1.name").replace("&", "ยง"));
                    List <String> lore = new ArrayList<>();
                    for (String linea : this.getConfig().getStringList(path+".lvl1.lore")) {
                        lore.add(ChatColor.translateAlternateColorCodes('&', linea));
                    breaker.addUnsafeEnchantment(Enchantment.DURABILITY, 10);

                    String[] ingA = this.getConfig().getString("config.recipes.auto farmer.A").split(",");
                    String[] ingB = this.getConfig().getString("config.recipes.auto farmer.B").split(",");
                    String[] ingC = this.getConfig().getString("config.recipes.auto farmer.C").split(",");
                    String[] ingD = this.getConfig().getString("config.recipes.auto farmer.D").split(",");
                    String[] ingE = this.getConfig().getString("config.recipes.auto farmer.E").split(",");
                    String[] ingF = this.getConfig().getString("config.recipes.auto farmer.F").split(",");
                    String[] ingG = this.getConfig().getString("config.recipes.auto farmer.G").split(",");
                    String[] ingH = this.getConfig().getString("config.recipes.auto farmer.H").split(",");
                    String[] ingI = this.getConfig().getString("config.recipes.auto farmer.I").split(",");
                    NamespacedKey key = new NamespacedKey(this, this.getConfig().getString(path+".lvl1.key"));
                    ShapedRecipe autof1 = new ShapedRecipe(key,breaker);
                    autof1.setIngredient('A', Material.valueOf(ingA[0]));
                    autof1.setIngredient('B', Material.valueOf(ingB[0]));
                    autof1.setIngredient('C', Material.valueOf(ingC[0]));
                    autof1.setIngredient('D', Material.valueOf(ingD[0]));
                    autof1.setIngredient('E', Material.valueOf(ingE[0]));
                    autof1.setIngredient('F', Material.valueOf(ingF[0]));
                    autof1.setIngredient('G', Material.valueOf(ingG[0]));
                    autof1.setIngredient('H', Material.valueOf(ingH[0]));
                    autof1.setIngredient('I', Material.valueOf(ingI[0]));
    btw i know there are lots of things that i could do better but I was just testing things, this is not in any way the final form of the code
  2. Well i usually tend to separate these kind of things by using a middle man(e.q.Need some kind of machine with should require more than 1 ingredient,create that "casing" needed to make it),if you know where im going with this,i want to keep it as simple as possible as i tend to take rly long breaks from time to time
  3. Thank you for you reply, do you mean like a new inventory where i could check for itemstacks and quantities?
  4. No,so i had a "Crusher" does stuff.. to craft it i need 4 iron 1 redstone 3 wood and 1 "Machine Casing"(this thing as middleman),so instead of lets say i need double the amount of iron and redstone,i make a casing to basically hold the item value

    So instead of purely using 8 iron 2 redstone and such... i half them but i add a custom item to be used instead

    In the end you still need the same amount of stuff but in different forms
    • Like Like x 1
  5. Ooooh i get it now, it seems like a good workaround, do you give that casing a custom meta then check it in PrepareItemCraftEvent?
    The thing is, I was planning on using 64 hay blocks for one crafting so this idea doesn't seem applicable in this case
  6. Why use prepareitemcraftevent?
    Shaped/lessRecipes now allow itemstacks as ingredients so you can use custom..
  7. Oh do they? i tried that the other day but had an error, im going to test it out now

    Edit: I see fml, it asked me to cast it as a recipechoice though

    Edit 2: Nope, console error, how do you make an itemstack an ingredient?
    #7 lelesape, Feb 7, 2020
    Last edited: Feb 7, 2020