#Recipes

1 messages · Page 1 of 1 (latest)

patent plume
#

List<Recipe> recipes = Bukkit.getRecipesFor(playerMenuUtility.getItemToCraft()); has 6 recipes in it while I registered only one ShapedRecipe for my custom item.

        System.out.println(playerMenuUtility.getItemToCraft().getItemMeta().getDisplayName());
        System.out.println(recipes.size());
[11:42:04] [Server thread/INFO]: test
[11:42:04] [Server thread/INFO]: 6
#

When I iterate through it - ShapedRecipe returns me my registered recipe (9 diamonds), but ShapelessRecipe returns me 9 diamond blocks

idle lichen
#

show yoru recipe code

patent plume
# idle lichen show yoru recipe code
    public static void registerCustomItemsRecipes() {
        Main.getInstance().getConfigManager().getCustomItems().getConfigurationSection("CustomItems").getKeys(false).forEach(item -> {
            List<String> matrix = Main.getInstance().getConfigManager().getCustomItems().getStringList("CustomItems." + item + ".Craft.Matrix");
            ShapedRecipe shapedRecipe = new ShapedRecipe(new NamespacedKey(Main.getInstance(), item.toLowerCase()), ItemUtils.getCustomItemFromConfig(item).getItemStack());
            shapedRecipe.shape(matrix.get(0),
                               matrix.get(1),
                               matrix.get(2));
            Main.getInstance().getConfigManager().getCustomItems().getConfigurationSection("CustomItems." + item + ".Craft.Ingredients").getKeys(false).forEach(ingredient -> {
                String customItemName = Main.getInstance().getConfigManager().getCustomItems().getString("CustomItems." + item + ".Craft.Ingredients." + ingredient + ".CustomItem");
                if(customItemName != null) {
                    TWDItem twdItem = ItemUtils.getCustomItemFromConfig(customItemName);
                    shapedRecipe.setIngredient(ingredient.charAt(0), new RecipeChoice.ExactChoice(twdItem.getItemStack()));
                } else {
                    Material material = Material.valueOf(Main.getInstance().getConfigManager().getCustomItems().getString("CustomItems." + item + ".Craft.Ingredients." + ingredient + ".Material").toUpperCase());
                    shapedRecipe.setIngredient(ingredient.charAt(0), material);
                }
            });
            shapedRecipes.add(shapedRecipe);
            Bukkit.addRecipe(shapedRecipe);
        });
    }
idle lichen
#

and yrou config

#

for the items

patent plume
#
CustomItems:
  TestItem:
    Name: 'test'
    Material: 'diamond'
    Lore: []
    Tier: 0
    Craft:
      Matrix:
        - 'XXX'
        - 'YYY'
        - 'ZZZ'
      Ingredients:
        X:
          Material: 'diamond'
        Y:
          Material: 'diamond'
        Z:
          Material: 'diamond'
idle lichen
#

This path is invalid String customItemName = Main.getInstance().getConfigManager().getCustomItems().getString("CustomItems." + item + ".Craft.Ingredients." + ingredient + ".CustomItem");

patent plume
#
                if(customItemName != null) {
                    TWDItem twdItem = ItemUtils.getCustomItemFromConfig(customItemName);
                    shapedRecipe.setIngredient(ingredient.charAt(0), new RecipeChoice.ExactChoice(twdItem.getItemStack()));
                } else {
                    Material material = Material.valueOf(Main.getInstance().getConfigManager().getCustomItems().getString("CustomItems." + item + ".Craft.Ingredients." + ingredient + ".Material").toUpperCase());
                    shapedRecipe.setIngredient(ingredient.charAt(0), material);
                }
#

the shaped recipe works fine, but idk why there is 6 recipes registered for my item

idle lichen
#

Material.matchMaterial not Material.valueOf

patent plume
#

and diamond blocks in the shapeless recipe

patent plume
idle lichen
#

matchMaterial is the correct one to use when searching by name

#

you also don;t need to uppercase the string when using matchMaterial

patent plume
#

ok, I will test it now

idle lichen
#

what is this TWDItem?

patent plume
#

still 6 recipes

#

and diamond blocks

idle lichen
#

Then check if yoru ItemStacks are the same in ShapedRecipe shapedRecipe = new ShapedRecipe(new NamespacedKey(Main.getInstance(), item.toLowerCase()), ItemUtils.getCustomItemFromConfig(item).getItemStack()); and TWDItem twdItem = ItemUtils.getCustomItemFromConfig(customItemName);

patent plume
idle lichen
#

ah

patent plume
#

Only the result is an custom item

idle lichen
#

ok I was confusing yoru result

patent plume
#

I can debug all the objects of the recipes list

#

if u need it

#

or something else

idle lichen
#

You must have something else that is registering a recipe for a diamond

#

I see nothing in teh code you have shown that would do it

patent plume
#

well, I actually don't

#

see

#

if I remove the check of ShapelessRecipe

#

it shows diamonds

#

not diamond blocks

idle lichen
#

check for shapelsss? I've seen no shapeless

patent plume
#

yeah

#

here is my method

#
[12:29:07] [Server thread/INFO]: test
[12:29:07] [Server thread/INFO]: 6
[12:29:07] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftBlastingRecipe@3eaa826b
[12:29:07] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftBlastingRecipe@6bdae8d0
[12:29:07] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftFurnaceRecipe@59cef8e1
[12:29:07] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftFurnaceRecipe@f1905bd
[12:29:07] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftShapedRecipe@65ca67ef
[12:29:07] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftShapelessRecipe@59ea9fee
idle lichen
#

ah ok

#

those are all different recipes which can produce a diamond

#

you only added the shaped one

#

if you don;t register any recipe you should see one less

#

but you will still have some

#

as diamond blocks can make diamonds

patent plume
#

yeah, but there are 9 diamond blocks

#

or did I understand u wrong

idle lichen
#

comment out the line in yoru code Bukkit.addRecipe(shapedRecipe);

#

then see how many recipes it shows

patent plume
#

k

#

did u mean that if I check it for itemstack then I should override all it's default crafts?

#

and should I use NamespacedKey instead

patent plume
# idle lichen then see how many recipes it shows
[12:34:47] [Server thread/INFO]: test
[12:34:47] [Server thread/INFO]: 5
[12:34:47] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftBlastingRecipe@45b34a67
[12:34:47] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftBlastingRecipe@2063e25c
[12:34:47] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftFurnaceRecipe@3a01d436
[12:34:47] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftFurnaceRecipe@554e49e4
[12:34:47] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftShapelessRecipe@af1c158
idle lichen
#

5 recipes without yours

patent plume
#

yes

idle lichen
#

those are default recipes

patent plume
#

how can I remove them

#

for this item

idle lichen
#

you would be better registering a custom item recipe than using a straight diamond

patent plume
#

wdym

idle lichen
#

ie you would not want to prevent players converting diamond blocks back into diamonds

patent plume
#

no

idle lichen
#

your recipe created a diamond

#

from 9 diamonds

#

just with a custom name?

patent plume
#

with a custom name and custom nbt tags

idle lichen
#

does ItemUtils.getCustomItemFromConfig(item).getItemStack() return the correct item with name and NBT?

#

AND its teh exact same item that thsi returns? playerMenuUtility.getItemToCraft()

#

If those two methods do return teh correct ItemStack it would tend to indicate an issue with getRecipesFor

#

however that would be unlikely

idle lichen
#

in that case I'd suggest changing to use ```
getRecipe
@Nullable
public static Recipe getRecipe(@NotNull
NamespacedKey recipeKey)
Get the Recipe for the given key.

Parameters:
recipeKey - the key of the recipe to return
Returns:
the recipe for the given key or null.```

patent plume
#

will I have the possibility to support the legacy versions using this?

idle lichen
#

I've no idea how far back that is supported

#

set your api version and try it

#

check playerMenuUtility.getItemToCraft() make sure it is returning the correct ItemStack

patent plume
#

ok, I will check it now

idle lichen
#

it seems like getRecipesFor is returning ANY recipe that produces that ItemStack. It seems to be ignoring any meta

patent plume
#

System.out.println(playerMenuUtility.getItemToCraft().equals(ItemUtils.getCustomItemFromConfig(nbtManager.getNBT(playerMenuUtility.getItemToCraft(), "twd_customItem"))));

[12:51:02] [Server thread/INFO]: false

#

oh

#

nvm

#

I should get an ItemStack

#

from TWDItem class

#

also

#

one sec

#

System.out.println(playerMenuUtility.getItemToCraft().equals(ItemUtils.getCustomItemFromConfig(nbtManager.getNBT(playerMenuUtility.getItemToCraft(), "twd_customItem")).getItemStack()));

[12:54:21] [Server thread/INFO]: true

idle lichen
#

one sec I'll pull up the code for getRecipeFor

patent plume
#

ok

idle lichen
#

a quick test you could do, set teh durability on teh ItemStack you call getRecipeFor to -1 before you search

#

the javadoc is a little cryptic on its search

#

They may be using the durability as a flag to tell teh method to match all data or just material

patent plume
#

@NotNull
public static List<Recipe> getRecipesFor(@NotNull
ItemStack result)
Get a list of all recipes for a given item. The stack size is ignored in comparisons. If the durability is -1, it will match any data value.

Parameters:
result - the item to match against recipe results
Returns:
a list of recipes with the given result

#

ok

#

one sec

patent plume
idle lichen
#

use it anyway, its only a test

patent plume
#

k

patent plume
#
[13:07:05] [Server thread/INFO]: test
[13:07:05] [Server thread/INFO]: true
[13:07:05] [Server thread/INFO]: 6
[13:07:05] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftBlastingRecipe@12420bdb
[13:07:05] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftBlastingRecipe@2dac34c
[13:07:05] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftFurnaceRecipe@642440a3
[13:07:05] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftFurnaceRecipe@34862fdf
[13:07:05] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftShapedRecipe@3698f647
[13:07:05] [Server thread/INFO]: org.bukkit.craftbukkit.v1_17_R1.inventory.CraftShapelessRecipe@620c837b
#
        ItemStack testItem = playerMenuUtility.getItemToCraft();
        testItem.setDurability((short) -1);
idle lichen
#

no clue then. It seems to be getting recipes for teh Material and doesn;t care about any meta

patent plume
#

ok, let's try to use the NamespacedKey

#

yeah, it works for NamespacedKey

#

ty, but anyways the question is how to use it without using the NamespacedKey

idle lichen
#

he's doing a shapeless recipe not shaped

#

there are also no other recipes that can make a Spruce sapling

patent plume
#

yeah

#

😦