diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractAutoCrafter.java index 42648ba3b..475257ea3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractAutoCrafter.java @@ -180,6 +180,15 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy */ protected abstract void updateRecipe(@Nonnull Block b, @Nonnull Player p); + /** + * This method sets the selected {@link AbstractRecipe} for the given {@link Block}. + * The recipe will be stored using the {@link PersistentDataAPI}. + * + * @param b + * The {@link Block} to store the data on + * @param recipe + * The {@link AbstractRecipe} to select + */ protected void setSelectedRecipe(@Nonnull Block b, @Nullable AbstractRecipe recipe) { BlockState state = PaperLib.getBlockState(b, false).getState(); @@ -194,8 +203,22 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy } } + /** + * This shows the given {@link AbstractRecipe} to the {@link Player} in a preview window. + * + * @param p + * The {@link Player} + * @param b + * The {@link Block} of the {@link AbstractAutoCrafter} + * @param recipe + * The {@link AbstractRecipe} to show them + */ @ParametersAreNonnullByDefault protected void showRecipe(Player p, Block b, AbstractRecipe recipe) { + Validate.notNull(p, "The Player should not be null"); + Validate.notNull(b, "The Block should not be null"); + Validate.notNull(recipe, "The Recipe should not be null"); + ChestMenu menu = new ChestMenu(getItemName()); menu.setPlayerInventoryClickable(false); menu.setEmptySlotsClickable(false); @@ -259,6 +282,20 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy return false; } + /** + * This method performs a crafting operation. + * It will attempt to fulfill the provided {@link AbstractRecipe} using + * the given {@link Inventory}. + * This will consume items and add the result to the {@link Inventory}. + * This method does not handle energy consumption. + * + * @param inv + * The {@link Inventory} to take resources from + * @param recipe + * The {@link AbstractRecipe} to craft + * + * @return Whether this crafting operation was successful or not + */ public boolean craft(@Nonnull Inventory inv, @Nonnull AbstractRecipe recipe) { Validate.notNull(inv, "The Inventory must not be null"); Validate.notNull(recipe, "The Recipe shall not be null"); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractRecipe.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractRecipe.java index d74c9d665..10a53d26c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractRecipe.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/AbstractRecipe.java @@ -10,40 +10,103 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.apache.commons.lang.Validate; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.Recipe; +import org.bukkit.inventory.RecipeChoice.MaterialChoice; import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.ShapelessRecipe; +import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable; import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; +/** + * This class abstracts away from concrete recipes. + * It supports {@link ShapedRecipe}, {@link ShapelessRecipe} and + * recipes made using the {@link EnhancedCraftingTable}. + * + * @author TheBusyBiscuit + * + * @see AbstractAutoCrafter + * @see VanillaRecipe + * @see EnhancedRecipe + * + */ public abstract class AbstractRecipe { - private final Collection> inputs; + /** + * Our {@link Collection} of ingredients / predicates. + */ + private final Collection> ingredients; + + /** + * The recipe result. + */ private final ItemStack result; + /** + * Protected constructor. For implementation classes only. + * + * @param ingredients + * The ingredients for this recipe as predicates + * @param result + * The resulting {@link ItemStack} + */ @ParametersAreNonnullByDefault - protected AbstractRecipe(Collection> inputs, ItemStack result) { - Validate.notEmpty(inputs, "The input predicates cannot be null or an empty array"); + protected AbstractRecipe(Collection> ingredients, ItemStack result) { + Validate.notEmpty(ingredients, "The input predicates cannot be null or an empty array"); Validate.notNull(result, "The recipe result must not be null!"); - this.inputs = inputs; + this.ingredients = ingredients; this.result = result; } + /** + * This returns the {@link Collection} of ingredients as {@link Predicate Predicates}. + * + * @return The ingredients for this {@link AbstractRecipe} + */ @Nonnull public Collection> getIngredients() { - return inputs; + return ingredients; } + /** + * This returns the result of this {@link AbstractRecipe}. + * This will return the original {@link ItemStack}, so make sure to {@link ItemStack#clone()} + * it. + * + * @return The resulting {@link ItemStack} + */ @Nonnull public ItemStack getResult() { return result; } + /** + * This will visually represent this {@link AbstractRecipe} in the given {@link ChestMenu}. + * Any {@link MaterialChoice} will be cycled through using the {@link AsyncRecipeChoiceTask}. + * + * @param menu + * The {@link ChestMenu} to display the recipe in + * @param task + * The {@link AsyncRecipeChoiceTask} instance + */ public abstract void show(@Nonnull ChestMenu menu, @Nonnull AsyncRecipeChoiceTask task); + /** + * This is our static accessor for the {@link AbstractRecipe} class. + * It will create a new {@link VanillaRecipe} for the given {@link Recipe} + * if it is a valid {@link Recipe}. + *

+ * Currently supported recipe types are {@link ShapedRecipe} and {@link ShapelessRecipe}. + * If the {@link Recipe} is null or none of the aforementioned types, null will be returned. + * + * @param recipe + * The {@link Recipe} to wrap + * + * @return The wrapped {@link AbstractRecipe} or null + */ @Nullable public static AbstractRecipe of(@Nullable Recipe recipe) { if (recipe instanceof ShapedRecipe) { @@ -55,6 +118,16 @@ public abstract class AbstractRecipe { } } + /** + * This static accessor is for {@link SlimefunItem} recipes. + * Note that the {@link SlimefunItem} must be crafted using an {@link EnhancedCraftingTable}, + * otherwise null will be returned. + * + * @param item + * The {@link SlimefunItem} the recipe belongs to + * + * @return The wrapped {@link AbstractRecipe} or null + */ @Nullable public static AbstractRecipe of(@Nullable SlimefunItem item) { if (item != null && item.getRecipeType().equals(RecipeType.ENHANCED_CRAFTING_TABLE)) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/EnhancedAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/EnhancedAutoCrafter.java index 55bb09b1c..701c5f4f1 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/EnhancedAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/EnhancedAutoCrafter.java @@ -16,6 +16,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable; import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.papermc.lib.PaperLib; @@ -25,6 +26,17 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * The {@link EnhancedAutoCrafter} is an implementation of the {@link AbstractAutoCrafter}. + * It can craft items that are crafted using the {@link EnhancedCraftingTable}. + * + * @author TheBusyBiscuit + * + * @see AbstractAutoCrafter + * @see VanillaAutoCrafter + * @see EnhancedRecipe + * + */ public class EnhancedAutoCrafter extends AbstractAutoCrafter { @ParametersAreNonnullByDefault diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaAutoCrafter.java index 18cef5781..d5656db4e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/VanillaAutoCrafter.java @@ -36,6 +36,18 @@ import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +/** + * The {@link VanillaAutoCrafter} is an implementation of the {@link AbstractAutoCrafter}. + * It can craft items that are crafted using a normal crafting table. + * Only {@link ShapedRecipe} and {@link ShapelessRecipe} are therefore supported. + * + * @author TheBusyBiscuit + * + * @see AbstractAutoCrafter + * @see EnhancedAutoCrafter + * @see VanillaRecipe + * + */ public class VanillaAutoCrafter extends AbstractAutoCrafter { @ParametersAreNonnullByDefault