#Custom Crafting GUI Api
1 messages · Page 1 of 1 (latest)
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
but it takes
Can you not use Bukkit.addRecipe?
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
how do u use it?
Then remove the coal recipe
docs dont really help
they really do
still dont know how to create a recipe in bukkit...
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
if you click on the Recipe hyperlink, it'll bring you to the Recipe class: https://i.imgur.com/Xcgf8pm.png
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
hmm
Bukkit's recipe system uses a key system, where you have 3 3 letter strings designating the slots of a crafting table
for instance
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?
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?
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
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
if you write Material. does a list of the materials come up?
no
do you have Material imported?
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
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
english pls