#Custom Crafting GUI Api

1 messages · Page 1 of 1 (latest)

warped gull
#

Hi im looking for a plugin api, not a plugin itself, to use with my plugin that basically opens a custom crafting gui and i can add my own custom recipes.

#

Why cant you use a workbench?

#

As far as I know workbenches dont take custom items, and I also want to add custom recipes, not a thing with spigot

topaz oxide
#

Can you not use Bukkit.addRecipe?

warped gull
# warped gull but it takes

i meant if i were to create a custom item called "Charcoal Block" with the material of COAL_BLOCK then I wouldn't want it to be crafted to coal

warped gull
topaz oxide
#

I believe spigot has an official guide on it as well

topaz oxide
#

they really do

warped gull
#

still dont know how to create a recipe in bukkit...

topaz oxide
#

https://i.imgur.com/xYvfJ6G.png You can see here that the method is static (you call it by the class, so Bukkit.addRecipe(...); and that the method takes a Recipe object as an input

#

Because Recipe is marked as an interface, you can't directly create an instance of it, so you have to rather use something that implements it

#

you can see that in the "All Known Implementing Classes" section

#

You're probably looking for either ShapedRecipe or ShapelessRecipe, depending on whether you want the recipe to have a fixed shape or not

warped gull
#

hmm

topaz oxide
#

Bukkit's recipe system uses a key system, where you have 3 3 letter strings designating the slots of a crafting table

#

for instance

warped gull
#

yes?

#

uhh youve been typing for a while now lol

topaz oxide
#

If I wanted to make a stone pickaxe, I could designate cobblestone as "c" and stick as "s" and then create a pattern for it.

You'll first need the actual ItemStack of whatever the recipe should output. I'm going to assume I already have one labelled item.

Then create a NamespacedKey, which is just a unique ID for the item the player would be crafting:

NamespacedKey key = new NamespacedKey(<your plugin instance>, "Epic Stone Pickaxe");

Creating the Recipe object itself (because a stone pickaxe has to be in the layout of a pickaxe formation, it has to be ShapedRecipe)

ShapedRecipe recipe = new ShapedRecipe(key, item);

Here I would set the ingredient keys I listed above (C for cobblestone, S for stick) in this format:

recipe.setIngredient('C', Material.<whatever the name for cobblestone is>); 
// Do the same for sticks

and then set the actual shape:

recipe.shape("CCC", " S ", " S ");

This would convert to a recipe that would look like a pickaxe:

CCC
 S
 S

Finally register the item using the addRecipe method:

Bukkit.addRecipe(recipe);
#

@warped gull Does that answer your question?

warped gull
#

mostly, just one bit, do I really have to do this in my onEnable method? I really dont want to clutter it up with all that code, is it possible to do the recipes in one class then somehow register it in onEnable?

topaz oxide
#

Yeah, you can move all of it into a class

#

You'll still need to in some way call Bukkit.addRecipe in your OnEnable though

warped gull
#

yea figured

#

when i put a recipe directly in a class it gives a bunch of errors, so i put it in a method but dont know how to reference the recipe from my Recipes class to my main class

topaz oxide
#

What does the error say?

#

if you hover over setIngredient

warped gull
#

cannot resolve symbol

topaz oxide
#

if you write Material. does a list of the materials come up?

warped gull
#

no

topaz oxide
#

do you have Material imported?

warped gull
#

yes but you didnt read that when i put it in a method its fine, but now i dont know how to reference the recipe from my method

topaz oxide
#

ah

#

you would have recipe as a member variable in your class with a public method getRecipe()

#

then you would create a new instance of that class in your onEnable and use it with that method

warped gull
#

english pls