mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Added documentation
This commit is contained in:
parent
eeb89c3c3b
commit
baa4f92ea1
@ -180,6 +180,15 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
|||||||
*/
|
*/
|
||||||
protected abstract void updateRecipe(@Nonnull Block b, @Nonnull Player p);
|
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) {
|
protected void setSelectedRecipe(@Nonnull Block b, @Nullable AbstractRecipe recipe) {
|
||||||
BlockState state = PaperLib.getBlockState(b, false).getState();
|
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
|
@ParametersAreNonnullByDefault
|
||||||
protected void showRecipe(Player p, Block b, AbstractRecipe recipe) {
|
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());
|
ChestMenu menu = new ChestMenu(getItemName());
|
||||||
menu.setPlayerInventoryClickable(false);
|
menu.setPlayerInventoryClickable(false);
|
||||||
menu.setEmptySlotsClickable(false);
|
menu.setEmptySlotsClickable(false);
|
||||||
@ -259,6 +282,20 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
|
|||||||
return false;
|
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) {
|
public boolean craft(@Nonnull Inventory inv, @Nonnull AbstractRecipe recipe) {
|
||||||
Validate.notNull(inv, "The Inventory must not be null");
|
Validate.notNull(inv, "The Inventory must not be null");
|
||||||
Validate.notNull(recipe, "The Recipe shall not be null");
|
Validate.notNull(recipe, "The Recipe shall not be null");
|
||||||
|
@ -10,40 +10,103 @@ import javax.annotation.ParametersAreNonnullByDefault;
|
|||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.Recipe;
|
import org.bukkit.inventory.Recipe;
|
||||||
|
import org.bukkit.inventory.RecipeChoice.MaterialChoice;
|
||||||
import org.bukkit.inventory.ShapedRecipe;
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
import org.bukkit.inventory.ShapelessRecipe;
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
|
|
||||||
|
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask;
|
import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask;
|
||||||
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
|
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
|
||||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
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 {
|
public abstract class AbstractRecipe {
|
||||||
|
|
||||||
private final Collection<Predicate<ItemStack>> inputs;
|
/**
|
||||||
|
* Our {@link Collection} of ingredients / predicates.
|
||||||
|
*/
|
||||||
|
private final Collection<Predicate<ItemStack>> ingredients;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The recipe result.
|
||||||
|
*/
|
||||||
private final ItemStack 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
|
@ParametersAreNonnullByDefault
|
||||||
protected AbstractRecipe(Collection<Predicate<ItemStack>> inputs, ItemStack result) {
|
protected AbstractRecipe(Collection<Predicate<ItemStack>> ingredients, ItemStack result) {
|
||||||
Validate.notEmpty(inputs, "The input predicates cannot be null or an empty array");
|
Validate.notEmpty(ingredients, "The input predicates cannot be null or an empty array");
|
||||||
Validate.notNull(result, "The recipe result must not be null!");
|
Validate.notNull(result, "The recipe result must not be null!");
|
||||||
|
|
||||||
this.inputs = inputs;
|
this.ingredients = ingredients;
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This returns the {@link Collection} of ingredients as {@link Predicate Predicates}.
|
||||||
|
*
|
||||||
|
* @return The ingredients for this {@link AbstractRecipe}
|
||||||
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Collection<Predicate<ItemStack>> getIngredients() {
|
public Collection<Predicate<ItemStack>> 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
|
@Nonnull
|
||||||
public ItemStack getResult() {
|
public ItemStack getResult() {
|
||||||
return result;
|
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);
|
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}.
|
||||||
|
* <p>
|
||||||
|
* 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
|
@Nullable
|
||||||
public static AbstractRecipe of(@Nullable Recipe recipe) {
|
public static AbstractRecipe of(@Nullable Recipe recipe) {
|
||||||
if (recipe instanceof ShapedRecipe) {
|
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
|
@Nullable
|
||||||
public static AbstractRecipe of(@Nullable SlimefunItem item) {
|
public static AbstractRecipe of(@Nullable SlimefunItem item) {
|
||||||
if (item != null && item.getRecipeType().equals(RecipeType.ENHANCED_CRAFTING_TABLE)) {
|
if (item != null && item.getRecipeType().equals(RecipeType.ENHANCED_CRAFTING_TABLE)) {
|
||||||
|
@ -16,6 +16,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
|
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
|
||||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
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.implementation.tasks.AsyncRecipeChoiceTask;
|
||||||
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
|
||||||
import io.papermc.lib.PaperLib;
|
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.Objects.SlimefunItem.SlimefunItem;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
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 {
|
public class EnhancedAutoCrafter extends AbstractAutoCrafter {
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
|
@ -36,6 +36,18 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
|
|||||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
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 {
|
public class VanillaAutoCrafter extends AbstractAutoCrafter {
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
|
Loading…
Reference in New Issue
Block a user