DREAMFIRE Docs ← Back to site
Loading...
Searching...
No Matches
IDreamRecipe.java
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Dreamfire Studio
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24package com.dreamfirestudios.dreamcore.DreamRecipe;
25
26import com.dreamfirestudios.dreamcore.DreamCore;
27import org.bukkit.Material;
28import org.bukkit.NamespacedKey;
29import org.bukkit.event.inventory.PrepareItemCraftEvent;
30import org.bukkit.inventory.*;
31import org.bukkit.plugin.java.JavaPlugin;
32
33import java.util.ArrayList;
34import java.util.HashMap;
35import java.util.List;
36
59public interface IDreamRecipe {
60 // Default values used in all recipes
61
64
66 ItemStack recipeResult();
67
72 default String recipeName(){ return getClass().getSimpleName(); }
73
78 default String nameSpace(){ return String.format("%s_%s", com.dreamfirestudios.dreamcore.DreamCore.class.getSimpleName(), recipeName()).toLowerCase(); }
79
80 // Values used in one or more recipe types
81
86 default HashMap<Character, RecipeChoice> recipeMaterials(){ return new HashMap<>(); }
87
92 default List<RecipeChoice> recipeListMaterials(){ return new ArrayList<>(); }
93
98 default List<String> recipeShape(){ return new ArrayList<>(); }
99
101 default RecipeChoice recipeSource(){ return new RecipeChoice.ExactChoice(new ItemStack(Material.AIR)); }
102
104 default RecipeChoice recipeAddition(){ return new RecipeChoice.ExactChoice(new ItemStack(Material.AIR)); }
105
107 default float recipeExperience(){ return 10f; }
108
110 default int recipeCookingTime(){ return 20; }
111
113 default int recipeUses(){ return 1; }
114
116 default int recipeMaxUsers(){ return 2; }
117
119 default boolean recipeExperienceReward(){ return false; }
120
122 default float recipePriceMultiplier(){ return 1f; }
123
125 default int recipeDemand(){ return 1; }
126
128 default int recipeSpecialPrice(){ return 1; }
129
145 @SuppressWarnings("deprecation")
146 default Recipe ReturnRecipe(JavaPlugin javaPlugin){
147
149 return new BlastingRecipe(new NamespacedKey(javaPlugin, nameSpace()), recipeResult(), recipeSource(), recipeExperience(), recipeCookingTime());
150 }else if(recipeType() == RecipeType.CampfireRecipe){
151 return new CampfireRecipe(new NamespacedKey(javaPlugin, nameSpace()), recipeResult(), recipeSource(), recipeExperience(), recipeCookingTime());
152 }else if(recipeType() == RecipeType.FurnaceRecipe){
153 return new FurnaceRecipe(new NamespacedKey(javaPlugin, nameSpace()), recipeResult(), recipeSource(), recipeExperience(), recipeCookingTime());
154 }else if(recipeType() == RecipeType.MerchantRecipe){
156 }else if(recipeType() == RecipeType.ShapedRecipe){
157 var shapedRecipe = new ShapedRecipe(new NamespacedKey(javaPlugin, nameSpace()), recipeResult());
158 shapedRecipe.shape(recipeShape().get(0), recipeShape().get(1), recipeShape().get(2));
159 for(var c : recipeMaterials().keySet()) shapedRecipe.setIngredient(c, recipeMaterials().get(c));
160 return shapedRecipe;
162 var shapelessRecipe = new ShapelessRecipe(new NamespacedKey(javaPlugin, nameSpace()), recipeResult());
163 for(var recipeChoice : recipeListMaterials()) shapelessRecipe.addIngredient(recipeChoice);
164 return shapelessRecipe;
165 }else if(recipeType() == RecipeType.SmithingRecipe){
166 return new SmithingRecipe(new NamespacedKey(javaPlugin, nameSpace()), recipeResult(), recipeSource(), recipeAddition());
167 }else if(recipeType() == RecipeType.SmokingRecipe){
168 return new SmokingRecipe(new NamespacedKey(javaPlugin, nameSpace()), recipeResult(), recipeSource(), recipeExperience(), recipeCookingTime());
170 return new StonecuttingRecipe(new NamespacedKey(javaPlugin, nameSpace()), recipeResult(), recipeSource());
171 }
172 return null;
173 }
174}
Supported recipe families for IDreamRecipe.
Contract for defining DreamCore recipes with sensible defaults and a factory to build Bukkit recipe i...
default String recipeName()
Optional display/registry name; defaults to the class simple name.
default int recipeCookingTime()
Cooking time (ticks) for furnace-like recipes.
ItemStack recipeResult()
Resulting item produced by the recipe.
default RecipeChoice recipeSource()
Primary source/base item (furnace/smithing/cutting/etc.).
default int recipeSpecialPrice()
Special price value for merchant trades.
default List< RecipeChoice > recipeListMaterials()
Ingredient list used by shapeless recipes.
default float recipePriceMultiplier()
Price multiplier for merchant trades.
default int recipeDemand()
Demand parameter for merchant trade economics.
default Recipe ReturnRecipe(JavaPlugin javaPlugin)
Builds the appropriate Bukkit Recipe instance from the configured properties.
default HashMap< Character, RecipeChoice > recipeMaterials()
Character-to-ingredient mapping used by shaped recipes.
default List< String > recipeShape()
Three-row shape used by shaped recipes, e.g., ["ABC","DEF","GHI"].
default int recipeUses()
Allowed uses for merchant recipes.
default RecipeChoice recipeAddition()
Additional item for smithing recipes.
default boolean recipeExperienceReward()
Whether a merchant trade rewards experience.
default float recipeExperience()
Experience yielded by furnace-like recipes.
default String nameSpace()
Namespaced key local part (lowercase) used for registration.
RecipeType recipeType()
Type/family of this recipe.
default int recipeMaxUsers()
Maximum users for merchant recipes (villager demand system).