Class AbstractAutoCrafter
java.lang.Object
io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.AbstractAutoCrafter
- All Implemented Interfaces:
EnergyNetComponent,ItemAttribute,Placeable
- Direct Known Subclasses:
SlimefunAutoCrafter,VanillaAutoCrafter
This is the abstract super class for our auto crafters.
- Author:
- TheBusyBiscuit
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final int[]protected final org.bukkit.NamespacedKeyTheNamespacedKeyused to determine whether the recipe is enabled.protected final org.bukkit.NamespacedKeyTheNamespacedKeyused to store recipe data.Fields inherited from class io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
addon, disenchantable, enchantable, hidden, recipeOutput, useableInWorkbench -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractAutoCrafter(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, org.bukkit.inventory.ItemStack[] recipe) -
Method Summary
Modifier and TypeMethodDescriptionbooleancraft(CrafterInteractable inv, AbstractRecipe recipe) This method performs a crafting operation.intThis method returns the max amount of electricity this machine can hold.final EnergyNetComponentTypeThis method returns the Type ofEnergyNetComponentTypethisSlimefunItemrepresents.intThis method returns the amount of energy that is consumed per operation.abstract AbstractRecipegetSelectedRecipe(org.bukkit.block.Block b) This method returns the currently selectedAbstractRecipefor the givenBlock.protected booleanisValidInventory(org.bukkit.block.Block block) This method checks if the givenBlockhas a validInventorywhere the Auto Crafter could be placed upon.protected booleanThis method checks whether the givenPredicatematches the providedItemStack.booleanmatchesAny(org.bukkit.inventory.Inventory inv, Map<Integer, Integer> itemQuantities, Predicate<org.bukkit.inventory.ItemStack> predicate) voidonRightClick(org.bukkit.block.Block b, org.bukkit.entity.Player p) This method handles our right-clicking behaviour.voidThis method is called afterSlimefunItem.register(SlimefunAddon).voidregister(SlimefunAddon addon) This method registers thisSlimefunItem.final AbstractAutoCraftersetCapacity(int capacity) This sets the energy capacity for this machine.final AbstractAutoCraftersetEnergyConsumption(int energyConsumption) This method sets the energy consumed by this machine per tick.protected voidsetSelectedRecipe(org.bukkit.block.Block b, AbstractRecipe recipe) This method sets the selectedAbstractRecipefor the givenBlock.protected voidshowRecipe(org.bukkit.entity.Player p, org.bukkit.block.Block b, AbstractRecipe recipe) This shows the givenAbstractRecipeto thePlayerin a preview window.protected voidtick(org.bukkit.block.Block b, SlimefunBlockData data) This method performs one tick for theAbstractAutoCrafter.protected abstract voidupdateRecipe(org.bukkit.block.Block b, org.bukkit.entity.Player p) This method is called when aPlayerright clicks theAbstractAutoCrafterwhile holding the shift button.Methods inherited from class io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
addItemHandler, addItemSetting, addOfficialWikipage, addWikiPage, callItemHandler, canUse, disable, enable, equals, error, getAddon, getBlockTicker, getById, getByItem, getDrops, getDrops, getHandlers, getId, getItem, getItemGroup, getItemName, getItemSetting, getItemSettings, getOptionalById, getOptionalByItem, getRecipe, getRecipeOutput, getRecipeType, getResearch, getState, getWikipage, hashCode, hasResearch, info, isDisabled, isDisabledIn, isDisenchantable, isEnchantable, isHidden, isItem, isItemStackImmutable, isTicking, isUseableInWorkbench, load, loadDataByDefault, preRegister, sendDeprecationWarning, setHidden, setItemGroup, setRecipe, setRecipeOutput, setRecipeType, setResearch, setUseableInWorkbench, toString, warnMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent
addCharge, addCharge, getCapacityLong, getCharge, getCharge, getCharge, getCharge, getChargeLong, getChargeLong, getChargeLong, isChargeable, removeCharge, removeCharge, setCharge, setChargeMethods inherited from interface io.github.thebusybiscuit.slimefun4.core.attributes.ItemAttribute
getIdMethods inherited from interface io.github.thebusybiscuit.slimefun4.core.attributes.Placeable
useVanillaBlockBreaking
-
Field Details
-
recipeStorageKey
protected final org.bukkit.NamespacedKey recipeStorageKeyTheNamespacedKeyused to store recipe data. -
recipeEnabledKey
protected final org.bukkit.NamespacedKey recipeEnabledKeyTheNamespacedKeyused to determine whether the recipe is enabled. -
background
protected final int[] background
-
-
Constructor Details
-
AbstractAutoCrafter
@ParametersAreNonnullByDefault protected AbstractAutoCrafter(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, org.bukkit.inventory.ItemStack[] recipe)
-
-
Method Details
-
postRegister
public void postRegister()Description copied from class:SlimefunItemThis method is called afterSlimefunItem.register(SlimefunAddon). Override this method to add any additional setup that needs to happen after the original registration of thisSlimefunItem.- Overrides:
postRegisterin classSlimefunItem
-
onRightClick
@ParametersAreNonnullByDefault public void onRightClick(org.bukkit.block.Block b, org.bukkit.entity.Player p) This method handles our right-clicking behaviour.Do not call this method directly, see our
AutoCrafterListenerfor the intended use case.- Parameters:
b- TheBlockthat was clickedp- ThePlayerwho clicked
-
tick
This method performs one tick for theAbstractAutoCrafter.- Parameters:
b- The block for thisAbstractAutoCrafterdata- The data stored on this block
-
matches
@ParametersAreNonnullByDefault protected boolean matches(org.bukkit.inventory.ItemStack item, Predicate<org.bukkit.inventory.ItemStack> predicate) This method checks whether the givenPredicatematches the providedItemStack. -
matchesAny
-
isValidInventory
protected boolean isValidInventory(@Nonnull org.bukkit.block.Block block) This method checks if the givenBlockhas a validInventorywhere the Auto Crafter could be placed upon. Right now this only supports chests and a few select tile entities but it can change or be overridden in the future.- Parameters:
block- TheBlockto check- Returns:
- Whether that
Blockhas a validInventory
-
getSelectedRecipe
This method returns the currently selectedAbstractRecipefor the givenBlock.- Parameters:
b- TheBlock- Returns:
- The currently selected
AbstractRecipeor null
-
updateRecipe
protected abstract void updateRecipe(@Nonnull org.bukkit.block.Block b, @Nonnull org.bukkit.entity.Player p) This method is called when aPlayerright clicks theAbstractAutoCrafterwhile holding the shift button. Use it to choose theAbstractRecipe.- Parameters:
b- TheBlockwhich was clickedp- ThePlayerwho clicked
-
setSelectedRecipe
protected void setSelectedRecipe(@Nonnull org.bukkit.block.Block b, @Nullable AbstractRecipe recipe) This method sets the selectedAbstractRecipefor the givenBlock. The recipe will be stored using thePersistentDataAPI.- Parameters:
b- TheBlockto store the data onrecipe- TheAbstractRecipeto select
-
showRecipe
@ParametersAreNonnullByDefault protected void showRecipe(org.bukkit.entity.Player p, org.bukkit.block.Block b, AbstractRecipe recipe) This shows the givenAbstractRecipeto thePlayerin a preview window.- Parameters:
p- ThePlayerb- TheBlockof theAbstractAutoCrafterrecipe- TheAbstractRecipeto show them
-
craft
This method performs a crafting operation. It will attempt to fulfill the providedAbstractRecipeusing the givenInventory. This will consume items and add the result to theInventory. This method does not handle energy consumption.- Parameters:
inv- TheInventoryto take resources fromrecipe- TheAbstractRecipeto craft- Returns:
- Whether this crafting operation was successful or not
-
getCapacity
public int getCapacity()This method returns the max amount of electricity this machine can hold.- Specified by:
getCapacityin interfaceEnergyNetComponent- Returns:
- The max amount of electricity this Block can store.
-
getEnergyConsumption
public int getEnergyConsumption()This method returns the amount of energy that is consumed per operation.- Returns:
- The rate of energy consumption
-
setCapacity
This sets the energy capacity for this machine. This method must be called before registering the item and only before registering.- Parameters:
capacity- The amount of energy this machine can store- Returns:
- This method will return the current instance of
AContainer, so that it can be chained.
-
setEnergyConsumption
This method sets the energy consumed by this machine per tick.- Parameters:
energyConsumption- The energy consumed per tick- Returns:
- This method will return the current instance of
AContainer, so that it can be chained.
-
register
Description copied from class:SlimefunItemThis method registers thisSlimefunItem. Always call this method after yourSlimefunItemhas been initialized. Never call it more than once!- Overrides:
registerin classSlimefunItem- Parameters:
addon- TheSlimefunAddonthat thisSlimefunItembelongs to.
-
getEnergyComponentType
Description copied from interface:EnergyNetComponentThis method returns the Type ofEnergyNetComponentTypethisSlimefunItemrepresents. It describes how this Block will interact with anEnergyNet.- Specified by:
getEnergyComponentTypein interfaceEnergyNetComponent- Returns:
- The
EnergyNetComponentTypethisSlimefunItemrepresents.
-