SkBee icon indicating copy to clipboard operation
SkBee copied to clipboard

[SUGGESTION] Expression for recipe result from items

Open cheeezburga opened this issue 1 year ago • 1 comments

Suggestion

Ran into this earlier, and thought it could be a useful addition to be able to get a recipe from a set of items. The syntax could potentially follow this pattern:

result (of|from) [items] %itemtypes% [in %world%]

Fully understand if the usefulness of this is up for debate. It's the first time I've seen anyone ever need this, so demand wouldn't be through the roof or anything.

Alternatives

Currently, I just use the following using reflect:

function getResultFromItems(i: items) :: item:
	loop {_i::*}:
		add (loop-value).getRandom() to {_n::*}
	set {_recipe} to Bukkit.getCraftingRecipe([{_n::*} as ItemStack], world "world")
	if {_recipe} is set:
		set {_result} to {_recipe}.getResult()
		return {_result}
	return air

The getRandom() calls are just because reflect not properly converting to item stack. This works properly when called like this getResultFromItems(diamond, diamond, diamond, air, stick, air, air, stick, air) (it returns diamond pickaxe).

Additional Information

Paper has got all the needed methods and stuff for this to work, as I'm currently using it with just reflect. To get the recipe from items, a world needs to be provided, as per the following https://jd.papermc.io/paper/1.20/org/bukkit/Bukkit.html#getCraftingRecipe(org.bukkit.inventory.ItemStack[],org.bukkit.World) To get the result, obviously just use getResult(), which is found https://jd.papermc.io/paper/1.17/org/bukkit/inventory/Recipe.html#getResult()

cheeezburga avatar Sep 21 '23 08:09 cheeezburga

This is something I'd like to add however bukkits implemention sucks but I'll look into again some time soon. I will most likely not make it result of itemstacks but you can still use recipe.

Fusezion avatar Sep 21 '23 19:09 Fusezion