Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 250 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
**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.

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

## Usage Example

Below is an example of how to use **RecipesAPI** in your Spigot plugin.
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.
Below is an example of how to use **RecipesAPI** in your Spigot plugin.
This example demonstrates adding multiple types of recipes including shapeless, shaped, custom ingredients, and furnace recipes.
You can see how easy it is to create and register recipes with the API.
The exemple plugin is available in the `test-plugin` directory.
The example plugin is available in the `test-plugin` directory.

### Programmatic Recipe Creation

```java
public final class TestPlugin extends JavaPlugin {
Expand All @@ -54,19 +56,19 @@ public final class TestPlugin extends JavaPlugin {

@Override
public void onEnable() {
// Initialize RecipesAPI
// Initialize RecipesAPI (plugin, debug mode enabled)
recipesAPI = new RecipesAPI(this, true);

// Create a simple shapeless crafting recipe (DIRT -> 64 DIAMOND)
ItemRecipe recipe = new RecipeBuilder()
// 1. Simple shapeless crafting recipe (DIRT -> 64 DIAMOND)
ItemRecipe recipe1 = new RecipeBuilder()
.setType(RecipeType.CRAFTING_SHAPELESS)
.setName("example-simple")
.setResult(new ItemStack(Material.DIAMOND))
.setAmount(64)
.addIngredient(Material.DIRT)
.build();

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

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

ItemRecipe recipe3 = new RecipeBuilder()
.setType(RecipeType.CRAFTING_SHAPELESS)
.setName("example-complex")
.setName("example-custom-ingredient")
.setResult(new ItemStack(Material.DIAMOND))
.setAmount(64)
.addIngredient(ingredient)
.addIngredient(magicPaper)
.build();

// Create a furnace smelting recipe (PAPER -> 64 DIAMOND)
// 4. Furnace smelting recipe with cooking time and experience
ItemRecipe recipe4 = new RecipeBuilder()
.setType(RecipeType.SMELTING)
.setName("example-furnace")
.setResult(new ItemStack(Material.DIAMOND))
.setAmount(64)
.addIngredient(ingredient)
.setCookingTime(10)
.addIngredient(Material.COAL)
.setCookingTime(200) // in ticks (200 ticks = 10 seconds)
.setExperience(10.0f)
.build();

// Add the recipes to the API
recipesAPI.addRecipe(recipe);
// Add all recipes to the API
recipesAPI.addRecipe(recipe1);
recipesAPI.addRecipe(recipe2);
recipesAPI.addRecipe(recipe3);
recipesAPI.addRecipe(recipe4);
}
}
```

## How to Use
### Loading Recipes from YAML Files

RecipesAPI provides a flexible `RecipeLoader` for loading recipes from YAML files:

```java
public final class TestPlugin extends JavaPlugin {

private RecipesAPI recipesAPI;
private RecipeLoader recipeLoader;

- **Shapeless Recipe**: Add items to crafting in any arrangement.
- **Shaped Recipe**: Define specific patterns for crafting items.
- **Custom Ingredients**: Use items with custom names or metadata in recipes.
- **Furnace Recipes**: Create custom smelting recipes with adjustable cooking time.
@Override
public void onEnable() {
// Initialize RecipesAPI
recipesAPI = new RecipesAPI(this, true);

// Create a RecipeLoader and configure it
recipeLoader = recipesAPI.createLoader()
.addFolder("recipes/") // Load all .yml files from recipes/ folder
.addFolder("recipes/custom/") // Load from additional folders
.addFile("special/unique.yml"); // Load a specific file

// Load all configured recipes
recipeLoader.load();
}

// Reload recipes at runtime
public void reloadRecipes() {
recipeLoader.reload();
}
}
```

**How RecipeLoader works:**
- All paths are relative to the plugin's data folder
- `addFolder()` loads recipes recursively from the specified folder
- If a folder doesn't exist, it automatically extracts default recipes from your plugin JAR
- `addFile()` loads a single recipe file
- `load()` loads all configured recipes
- `reload()` unregisters all recipes and reloads them

## Recipe Types

RecipesAPI supports all vanilla Minecraft recipe types:

- **`CRAFTING_SHAPELESS`** - Shapeless crafting recipes (items in any arrangement)
- **`CRAFTING_SHAPED`** - Shaped crafting recipes (specific pattern required)
- **`SMELTING`** - Furnace smelting recipes
- **`BLASTING`** - Blast furnace recipes
- **`SMOKING`** - Smoker recipes
- **`CAMPFIRE_COOKING`** - Campfire cooking recipes
- **`STONE_CUTTING`** - Stonecutter recipes
- **`SMITHING_TRANSFORM`** - Smithing table transformation recipes

## Custom Ingredients

The API supports several types of ingredients:

- **Material**: Simple material type (e.g., `Material.DIAMOND`)
- **ItemStack**: Items with custom metadata (lore, custom model data, PDC)
- **Strict ItemStack**: Exact item match including all metadata
- **Tag**: Minecraft tags (e.g., planks, logs, wool)
- **Plugin Items**: ItemsAdder and Oraxen custom items

### Important Notes
- **Display Name**: Player can rename items - only lore, custom model data, and PDC are checked
- **Strict Mode**: Use `.addIngredient(item, sign, true)` to require exact match including display name

## API Documentation
The API is simple and intuitive to use. You can easily:
- **Define crafting types**: `RecipeType.CRAFTING_SHAPELESS`, `RecipeType.CRAFTING_SHAPED`,
`RecipeType.SMELTING`, etc.
- **Add ingredients**: Either regular materials or custom items with `ItemMeta`.
- **Set crafting patterns**: For shaped recipes, you can define the crafting grid with `.setPattern()`.
- **Control output**: Set the resulting item and amount.

You can check javadoc here : [Javadoc](https://jitpack.io/com/github/Traqueur-dev/RecipesAPI/latest/javadoc/)
You can check the wiki here : [Wiki](https://github.com/Traqueur-dev/RecipesAPI/wiki)
- **Define crafting types**: All vanilla recipe types supported
- **Add ingredients**: Regular materials, custom items with `ItemMeta`, or plugin items
- **Set crafting patterns**: For shaped recipes, define the crafting grid with `.setPattern()`
- **Control output**: Set the resulting item and amount
- **Configure cooking**: Set cooking time and experience for smelting recipes

## Plugin Hooks

RecipesAPI provides built-in support for popular custom item plugins:

### Using ItemsAdder Items

```java
// In your YAML recipe file
ingredients:
- item: itemsadder:custom_item_id

# Or in code
ItemRecipe recipe = new RecipeBuilder()
.setType(RecipeType.CRAFTING_SHAPELESS)
.setName("itemsadder-recipe")
.setResult(itemsAdderItem) // Get from ItemsAdder API
.addIngredient(/* ItemsAdder ingredient */)
.build();
```

### Using Oraxen Items

```java
// In your YAML recipe file
ingredients:
- item: oraxen:custom_item_id

# Or in code
ItemRecipe recipe = new RecipeBuilder()
.setType(RecipeType.CRAFTING_SHAPELESS)
.setName("oraxen-recipe")
.setResult(oraxenItem) // Get from Oraxen API
.addIngredient(/* Oraxen ingredient */)
.build();
```

### Creating Custom Hooks

You can create your own hooks for any custom item plugin:

```java
public class MyCustomItemHook implements Hook {

@Override
public String getPluginName() {
return "MyCustomPlugin";
}

@Override
public Ingredient getIngredient(String data, Character sign) {
// Create your custom ingredient implementation
return new MyCustomIngredient(data, sign);
}

@Override
public ItemStack getItemStack(String data) {
// Return the ItemStack for your custom item
return MyCustomPlugin.getItem(data);
}
}

// Register your hook
Hook.addHook(new MyCustomItemHook());
```

## YAML Configuration

RecipesAPI supports loading recipes from YAML files. Simply place `.yml` files in your plugin's `recipes/` folder (or any folder you configure with `RecipeLoader`).

### Recipe File Format

```yaml
type: CRAFTING_SHAPED
pattern:
- "DDD"
- "DID"
- "DDD"
ingredients:
- item: DIRT
sign: D
- item: DIAMOND
sign: I
result:
item: DIAMOND
amount: 64
group: "custom_recipes"
category: "MISC"
```

### YAML Recipe Fields

#### Required Fields
- `type` - Recipe type (see Recipe Types section)
- `ingredients` - List of ingredients (see Ingredient Types below)
- `result.item` - The resulting item

#### Optional Fields
- `result.amount` - Output amount (default: 1)
- `pattern` - Pattern for shaped recipes (max 3 rows, max 3 chars per row)
- `group` - Recipe group for the recipe book
- `category` - Recipe category (BUILDING, REDSTONE, EQUIPMENT, MISC for crafting; FOOD, BLOCKS, MISC for cooking)
- `cooking-time` - Cooking time in ticks for smelting recipes (default: 0)
- `experience` - Experience reward for smelting recipes (default: 0.0)

### Pattern Validation

For `CRAFTING_SHAPED` recipes, the pattern is validated:
- Maximum 3 rows
- Maximum 3 characters per row
- All pattern characters must have corresponding ingredients with matching signs
- Empty rows are not allowed

### Ingredient Types in YAML
- `item: MATERIAL_NAME` - Simple material
- `item: material:MATERIAL_NAME` - Explicit material
- `item: tag:TAG_NAME` - Minecraft tag
- `item: item:BASE64_STRING` or `item: base64:BASE64_STRING` - Custom item from Base64
- `item: itemsadder:ITEM_ID` - ItemsAdder item
- `item: oraxen:ITEM_ID` - Oraxen item
- `sign: X` - Character used in shaped recipe patterns (required for shaped recipes)
- `strict: true` - Require exact item match including display name (optional, default: false)

### Example: Smelting Recipe

```yaml
type: SMELTING
ingredients:
- item: COAL
result:
item: DIAMOND
amount: 64
cooking-time: 200
experience: 10.0
category: MISC
```

### Example: Shapeless Recipe with Custom Item

```yaml
type: CRAFTING_SHAPELESS
ingredients:
- item: item:BASE64_ENCODED_ITEM_HERE
strict: true
result:
item: DIAMOND
amount: 1
```

## Resources

- **Javadoc**: [API Documentation](https://jitpack.io/com/github/Traqueur-dev/RecipesAPI/latest/javadoc/)
- **Wiki**: [GitHub Wiki](https://github.com/Traqueur-dev/RecipesAPI/wiki)
- **Issues**: [Report bugs or request features](https://github.com/Traqueur-dev/RecipesAPI/issues)

## License
This project is licensed under the MIT License.
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ repositories {
url = "https://oss.sonatype.org/content/groups/public/"
}
maven {
name = "jitpack"
url = "https://jitpack.io"
url "https://maven.devs.beer/"
}
maven {
url "https://repo.oraxen.com/releases"
Expand All @@ -29,12 +28,12 @@ dependencies {

// Hooks
compileOnly 'io.th0rgal:oraxen:1.181.0'
compileOnly 'com.github.LoneDev6:API-ItemsAdder:3.6.1'
compileOnly 'dev.lone:api-itemsadder:4.0.10'
}

tasks.register('generateVersionProperties') {
doLast {
def file = new File("$projectDir/src/main/resources/version.properties")
def file = new File("$projectDir/src/main/resources/recipeapi.properties")
if (!file.parentFile.exists()) {
file.parentFile.mkdirs()
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.0.2
version=3.0.0
Loading
Loading