Skip to content

Commit 68445e9

Browse files
authored
version 3.0.0 (#32)
* Feat/improve (#25) * Feat/improve (#27) * fix: ia hook (#23) * feat: improve * feat: remove some useless usage of variable * Hotfix/air recipe (#30) * fix: ia hook (#23) * Feat/improve (#25) * Feat/improve (#27) * fix: ia hook (#23) * feat: improve * feat: remove some useless usage of variable * fix: air in recipe doesn't work * Feat/modernize (#31) * feat: modernize * feat: version * fix: shapeless craft
1 parent d451490 commit 68445e9

File tree

11 files changed

+651
-525
lines changed

11 files changed

+651
-525
lines changed

README.md

Lines changed: 250 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
**RecipesAPI** is a lightweight and easy-to-use API that allows you to create custom recipes for your Spigot server. Whether you want to add custom shaped or shapeless crafting recipes, furnace smelting recipes, or other custom item interactions, this API makes it simple to do so.
66

77
## Features
8-
- **Create Custom Recipes**: Add shaped, shapeless, and furnace, and other type recipes with ease.
9-
- **Advanced Recipe Handling**: Support for custom ingredients with meta data (e.g., items with custom names).
8+
- **Create Custom Recipes**: Add shaped, shapeless, furnace, and other types of recipes with ease.
9+
- **Advanced Recipe Handling**: Support for custom ingredients with metadata (lore, custom model data, persistent data container).
1010
- **Easy Integration**: Simple API to integrate into any Spigot plugin.
11-
- **Hooks**: Support ItemsAdder, Oraxen items. You can create your own hook with your customs items systems.
12-
- **Version Compatibility**: Works with recent Spigot versions and allows you to create recipes dynamically. Folia compatibility if you use FoliaLib.
11+
- **Plugin Hooks**: Built-in support for ItemsAdder and Oraxen items. You can create your own hook with your custom item systems.
12+
- **Version Compatibility**: Works with recent Spigot versions and allows you to create recipes dynamically.
1313
- **Lightweight**: No need to include large libraries or dependencies.
1414
- **Open Source**: Available under the MIT License.
1515
- **Javadoc**: Comprehensive documentation for easy reference.
@@ -42,10 +42,12 @@ shadowJar {
4242

4343
## Usage Example
4444

45-
Below is an example of how to use **RecipesAPI** in your Spigot plugin.
46-
This example demonstrates adding four types of recipes: a simple shapeless crafting recipe, a shaped crafting recipe, a custom ingredient shapeless recipe, and a furnace recipe.
45+
Below is an example of how to use **RecipesAPI** in your Spigot plugin.
46+
This example demonstrates adding multiple types of recipes including shapeless, shaped, custom ingredients, and furnace recipes.
4747
You can see how easy it is to create and register recipes with the API.
48-
The exemple plugin is available in the `test-plugin` directory.
48+
The example plugin is available in the `test-plugin` directory.
49+
50+
### Programmatic Recipe Creation
4951

5052
```java
5153
public final class TestPlugin extends JavaPlugin {
@@ -54,19 +56,19 @@ public final class TestPlugin extends JavaPlugin {
5456

5557
@Override
5658
public void onEnable() {
57-
// Initialize RecipesAPI
59+
// Initialize RecipesAPI (plugin, debug mode enabled)
5860
recipesAPI = new RecipesAPI(this, true);
5961

60-
// Create a simple shapeless crafting recipe (DIRT -> 64 DIAMOND)
61-
ItemRecipe recipe = new RecipeBuilder()
62+
// 1. Simple shapeless crafting recipe (DIRT -> 64 DIAMOND)
63+
ItemRecipe recipe1 = new RecipeBuilder()
6264
.setType(RecipeType.CRAFTING_SHAPELESS)
6365
.setName("example-simple")
6466
.setResult(new ItemStack(Material.DIAMOND))
6567
.setAmount(64)
6668
.addIngredient(Material.DIRT)
6769
.build();
6870

69-
// Create a shaped crafting recipe (DIRT and DIAMOND -> 64 DIAMOND)
71+
// 2. Shaped crafting recipe (8 DIRT around 1 DIAMOND -> 64 DIAMOND)
7072
ItemRecipe recipe2 = new RecipeBuilder()
7173
.setType(RecipeType.CRAFTING_SHAPED)
7274
.setName("example-shaped")
@@ -77,56 +79,268 @@ public final class TestPlugin extends JavaPlugin {
7779
.addIngredient(Material.DIAMOND, 'I')
7880
.build();
7981

80-
// Create a shapeless recipe with a custom ingredient (named PAPER)
81-
ItemStack ingredient = new ItemStack(Material.PAPER);
82-
ItemMeta meta = ingredient.getItemMeta();
83-
meta.setDisplayName("Dirt Magic");
84-
ingredient.setItemMeta(meta);
82+
// 3. Custom ingredient with lore (only lore is checked, displayName can be changed by player)
83+
ItemStack magicPaper = new ItemStack(Material.PAPER);
84+
ItemMeta meta = magicPaper.getItemMeta();
85+
meta.setLore(List.of("§6Magic Paper", "§7Used for special crafting"));
86+
magicPaper.setItemMeta(meta);
8587

8688
ItemRecipe recipe3 = new RecipeBuilder()
8789
.setType(RecipeType.CRAFTING_SHAPELESS)
88-
.setName("example-complex")
90+
.setName("example-custom-ingredient")
8991
.setResult(new ItemStack(Material.DIAMOND))
9092
.setAmount(64)
91-
.addIngredient(ingredient)
93+
.addIngredient(magicPaper)
9294
.build();
9395

94-
// Create a furnace smelting recipe (PAPER -> 64 DIAMOND)
96+
// 4. Furnace smelting recipe with cooking time and experience
9597
ItemRecipe recipe4 = new RecipeBuilder()
9698
.setType(RecipeType.SMELTING)
9799
.setName("example-furnace")
98100
.setResult(new ItemStack(Material.DIAMOND))
99101
.setAmount(64)
100-
.addIngredient(ingredient)
101-
.setCookingTime(10)
102+
.addIngredient(Material.COAL)
103+
.setCookingTime(200) // in ticks (200 ticks = 10 seconds)
104+
.setExperience(10.0f)
102105
.build();
103106

104-
// Add the recipes to the API
105-
recipesAPI.addRecipe(recipe);
107+
// Add all recipes to the API
108+
recipesAPI.addRecipe(recipe1);
106109
recipesAPI.addRecipe(recipe2);
107110
recipesAPI.addRecipe(recipe3);
108111
recipesAPI.addRecipe(recipe4);
109112
}
110113
}
111114
```
112115

113-
## How to Use
116+
### Loading Recipes from YAML Files
117+
118+
RecipesAPI provides a flexible `RecipeLoader` for loading recipes from YAML files:
119+
120+
```java
121+
public final class TestPlugin extends JavaPlugin {
122+
123+
private RecipesAPI recipesAPI;
124+
private RecipeLoader recipeLoader;
114125

115-
- **Shapeless Recipe**: Add items to crafting in any arrangement.
116-
- **Shaped Recipe**: Define specific patterns for crafting items.
117-
- **Custom Ingredients**: Use items with custom names or metadata in recipes.
118-
- **Furnace Recipes**: Create custom smelting recipes with adjustable cooking time.
126+
@Override
127+
public void onEnable() {
128+
// Initialize RecipesAPI
129+
recipesAPI = new RecipesAPI(this, true);
130+
131+
// Create a RecipeLoader and configure it
132+
recipeLoader = recipesAPI.createLoader()
133+
.addFolder("recipes/") // Load all .yml files from recipes/ folder
134+
.addFolder("recipes/custom/") // Load from additional folders
135+
.addFile("special/unique.yml"); // Load a specific file
136+
137+
// Load all configured recipes
138+
recipeLoader.load();
139+
}
140+
141+
// Reload recipes at runtime
142+
public void reloadRecipes() {
143+
recipeLoader.reload();
144+
}
145+
}
146+
```
147+
148+
**How RecipeLoader works:**
149+
- All paths are relative to the plugin's data folder
150+
- `addFolder()` loads recipes recursively from the specified folder
151+
- If a folder doesn't exist, it automatically extracts default recipes from your plugin JAR
152+
- `addFile()` loads a single recipe file
153+
- `load()` loads all configured recipes
154+
- `reload()` unregisters all recipes and reloads them
155+
156+
## Recipe Types
157+
158+
RecipesAPI supports all vanilla Minecraft recipe types:
159+
160+
- **`CRAFTING_SHAPELESS`** - Shapeless crafting recipes (items in any arrangement)
161+
- **`CRAFTING_SHAPED`** - Shaped crafting recipes (specific pattern required)
162+
- **`SMELTING`** - Furnace smelting recipes
163+
- **`BLASTING`** - Blast furnace recipes
164+
- **`SMOKING`** - Smoker recipes
165+
- **`CAMPFIRE_COOKING`** - Campfire cooking recipes
166+
- **`STONE_CUTTING`** - Stonecutter recipes
167+
- **`SMITHING_TRANSFORM`** - Smithing table transformation recipes
168+
169+
## Custom Ingredients
170+
171+
The API supports several types of ingredients:
172+
173+
- **Material**: Simple material type (e.g., `Material.DIAMOND`)
174+
- **ItemStack**: Items with custom metadata (lore, custom model data, PDC)
175+
- **Strict ItemStack**: Exact item match including all metadata
176+
- **Tag**: Minecraft tags (e.g., planks, logs, wool)
177+
- **Plugin Items**: ItemsAdder and Oraxen custom items
178+
179+
### Important Notes
180+
- **Display Name**: Player can rename items - only lore, custom model data, and PDC are checked
181+
- **Strict Mode**: Use `.addIngredient(item, sign, true)` to require exact match including display name
119182

120183
## API Documentation
121184
The API is simple and intuitive to use. You can easily:
122-
- **Define crafting types**: `RecipeType.CRAFTING_SHAPELESS`, `RecipeType.CRAFTING_SHAPED`,
123-
`RecipeType.SMELTING`, etc.
124-
- **Add ingredients**: Either regular materials or custom items with `ItemMeta`.
125-
- **Set crafting patterns**: For shaped recipes, you can define the crafting grid with `.setPattern()`.
126-
- **Control output**: Set the resulting item and amount.
127-
128-
You can check javadoc here : [Javadoc](https://jitpack.io/com/github/Traqueur-dev/RecipesAPI/latest/javadoc/)
129-
You can check the wiki here : [Wiki](https://github.com/Traqueur-dev/RecipesAPI/wiki)
185+
- **Define crafting types**: All vanilla recipe types supported
186+
- **Add ingredients**: Regular materials, custom items with `ItemMeta`, or plugin items
187+
- **Set crafting patterns**: For shaped recipes, define the crafting grid with `.setPattern()`
188+
- **Control output**: Set the resulting item and amount
189+
- **Configure cooking**: Set cooking time and experience for smelting recipes
190+
191+
## Plugin Hooks
192+
193+
RecipesAPI provides built-in support for popular custom item plugins:
194+
195+
### Using ItemsAdder Items
196+
197+
```java
198+
// In your YAML recipe file
199+
ingredients:
200+
- item: itemsadder:custom_item_id
201+
202+
# Or in code
203+
ItemRecipe recipe = new RecipeBuilder()
204+
.setType(RecipeType.CRAFTING_SHAPELESS)
205+
.setName("itemsadder-recipe")
206+
.setResult(itemsAdderItem) // Get from ItemsAdder API
207+
.addIngredient(/* ItemsAdder ingredient */)
208+
.build();
209+
```
210+
211+
### Using Oraxen Items
212+
213+
```java
214+
// In your YAML recipe file
215+
ingredients:
216+
- item: oraxen:custom_item_id
217+
218+
# Or in code
219+
ItemRecipe recipe = new RecipeBuilder()
220+
.setType(RecipeType.CRAFTING_SHAPELESS)
221+
.setName("oraxen-recipe")
222+
.setResult(oraxenItem) // Get from Oraxen API
223+
.addIngredient(/* Oraxen ingredient */)
224+
.build();
225+
```
226+
227+
### Creating Custom Hooks
228+
229+
You can create your own hooks for any custom item plugin:
230+
231+
```java
232+
public class MyCustomItemHook implements Hook {
233+
234+
@Override
235+
public String getPluginName() {
236+
return "MyCustomPlugin";
237+
}
238+
239+
@Override
240+
public Ingredient getIngredient(String data, Character sign) {
241+
// Create your custom ingredient implementation
242+
return new MyCustomIngredient(data, sign);
243+
}
244+
245+
@Override
246+
public ItemStack getItemStack(String data) {
247+
// Return the ItemStack for your custom item
248+
return MyCustomPlugin.getItem(data);
249+
}
250+
}
251+
252+
// Register your hook
253+
Hook.addHook(new MyCustomItemHook());
254+
```
255+
256+
## YAML Configuration
257+
258+
RecipesAPI supports loading recipes from YAML files. Simply place `.yml` files in your plugin's `recipes/` folder (or any folder you configure with `RecipeLoader`).
259+
260+
### Recipe File Format
261+
262+
```yaml
263+
type: CRAFTING_SHAPED
264+
pattern:
265+
- "DDD"
266+
- "DID"
267+
- "DDD"
268+
ingredients:
269+
- item: DIRT
270+
sign: D
271+
- item: DIAMOND
272+
sign: I
273+
result:
274+
item: DIAMOND
275+
amount: 64
276+
group: "custom_recipes"
277+
category: "MISC"
278+
```
279+
280+
### YAML Recipe Fields
281+
282+
#### Required Fields
283+
- `type` - Recipe type (see Recipe Types section)
284+
- `ingredients` - List of ingredients (see Ingredient Types below)
285+
- `result.item` - The resulting item
286+
287+
#### Optional Fields
288+
- `result.amount` - Output amount (default: 1)
289+
- `pattern` - Pattern for shaped recipes (max 3 rows, max 3 chars per row)
290+
- `group` - Recipe group for the recipe book
291+
- `category` - Recipe category (BUILDING, REDSTONE, EQUIPMENT, MISC for crafting; FOOD, BLOCKS, MISC for cooking)
292+
- `cooking-time` - Cooking time in ticks for smelting recipes (default: 0)
293+
- `experience` - Experience reward for smelting recipes (default: 0.0)
294+
295+
### Pattern Validation
296+
297+
For `CRAFTING_SHAPED` recipes, the pattern is validated:
298+
- Maximum 3 rows
299+
- Maximum 3 characters per row
300+
- All pattern characters must have corresponding ingredients with matching signs
301+
- Empty rows are not allowed
302+
303+
### Ingredient Types in YAML
304+
- `item: MATERIAL_NAME` - Simple material
305+
- `item: material:MATERIAL_NAME` - Explicit material
306+
- `item: tag:TAG_NAME` - Minecraft tag
307+
- `item: item:BASE64_STRING` or `item: base64:BASE64_STRING` - Custom item from Base64
308+
- `item: itemsadder:ITEM_ID` - ItemsAdder item
309+
- `item: oraxen:ITEM_ID` - Oraxen item
310+
- `sign: X` - Character used in shaped recipe patterns (required for shaped recipes)
311+
- `strict: true` - Require exact item match including display name (optional, default: false)
312+
313+
### Example: Smelting Recipe
314+
315+
```yaml
316+
type: SMELTING
317+
ingredients:
318+
- item: COAL
319+
result:
320+
item: DIAMOND
321+
amount: 64
322+
cooking-time: 200
323+
experience: 10.0
324+
category: MISC
325+
```
326+
327+
### Example: Shapeless Recipe with Custom Item
328+
329+
```yaml
330+
type: CRAFTING_SHAPELESS
331+
ingredients:
332+
- item: item:BASE64_ENCODED_ITEM_HERE
333+
strict: true
334+
result:
335+
item: DIAMOND
336+
amount: 1
337+
```
338+
339+
## Resources
340+
341+
- **Javadoc**: [API Documentation](https://jitpack.io/com/github/Traqueur-dev/RecipesAPI/latest/javadoc/)
342+
- **Wiki**: [GitHub Wiki](https://github.com/Traqueur-dev/RecipesAPI/wiki)
343+
- **Issues**: [Report bugs or request features](https://github.com/Traqueur-dev/RecipesAPI/issues)
130344

131345
## License
132346
This project is licensed under the MIT License.

build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ repositories {
1616
url = "https://oss.sonatype.org/content/groups/public/"
1717
}
1818
maven {
19-
name = "jitpack"
20-
url = "https://jitpack.io"
19+
url "https://maven.devs.beer/"
2120
}
2221
maven {
2322
url "https://repo.oraxen.com/releases"
@@ -29,12 +28,12 @@ dependencies {
2928

3029
// Hooks
3130
compileOnly 'io.th0rgal:oraxen:1.181.0'
32-
compileOnly 'com.github.LoneDev6:API-ItemsAdder:3.6.1'
31+
compileOnly 'dev.lone:api-itemsadder:4.0.10'
3332
}
3433

3534
tasks.register('generateVersionProperties') {
3635
doLast {
37-
def file = new File("$projectDir/src/main/resources/version.properties")
36+
def file = new File("$projectDir/src/main/resources/recipeapi.properties")
3837
if (!file.parentFile.exists()) {
3938
file.parentFile.mkdirs()
4039
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=2.0.2
1+
version=3.0.0

0 commit comments

Comments
 (0)