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.NamespacedKey
TheNamespacedKey
used to determine whether the recipe is enabled.protected final org.bukkit.NamespacedKey
TheNamespacedKey
used to store recipe data.Fields inherited from class io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
addon, disenchantable, enchantable, hidden, recipeOutput, useableInWorkbench
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractAutoCrafter
(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, org.bukkit.inventory.ItemStack[] recipe) -
Method Summary
Modifier and TypeMethodDescriptionboolean
craft
(CrafterInteractable inv, AbstractRecipe recipe) This method performs a crafting operation.int
This method returns the max amount of electricity this machine can hold.final EnergyNetComponentType
This method returns the Type ofEnergyNetComponentType
thisSlimefunItem
represents.int
This method returns the amount of energy that is consumed per operation.abstract AbstractRecipe
getSelectedRecipe
(org.bukkit.block.Block b) This method returns the currently selectedAbstractRecipe
for the givenBlock
.protected boolean
isValidInventory
(org.bukkit.block.Block block) This method checks if the givenBlock
has a validInventory
where the Auto Crafter could be placed upon.protected boolean
This method checks whether the givenPredicate
matches the providedItemStack
.boolean
matchesAny
(org.bukkit.inventory.Inventory inv, Map<Integer, Integer> itemQuantities, Predicate<org.bukkit.inventory.ItemStack> predicate) void
onRightClick
(org.bukkit.block.Block b, org.bukkit.entity.Player p) This method handles our right-clicking behaviour.void
This method is called afterSlimefunItem.register(SlimefunAddon)
.void
register
(SlimefunAddon addon) This method registers thisSlimefunItem
.final AbstractAutoCrafter
setCapacity
(int capacity) This sets the energy capacity for this machine.final AbstractAutoCrafter
setEnergyConsumption
(int energyConsumption) This method sets the energy consumed by this machine per tick.protected void
setSelectedRecipe
(org.bukkit.block.Block b, AbstractRecipe recipe) This method sets the selectedAbstractRecipe
for the givenBlock
.protected void
showRecipe
(org.bukkit.entity.Player p, org.bukkit.block.Block b, AbstractRecipe recipe) This shows the givenAbstractRecipe
to thePlayer
in a preview window.protected void
tick
(org.bukkit.block.Block b, SlimefunBlockData data) This method performs one tick for theAbstractAutoCrafter
.protected abstract void
updateRecipe
(org.bukkit.block.Block b, org.bukkit.entity.Player p) This method is called when aPlayer
right clicks theAbstractAutoCrafter
while 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, warn
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent
addCharge, getCharge, getCharge, getCharge, isChargeable, removeCharge, setCharge
Methods inherited from interface io.github.thebusybiscuit.slimefun4.core.attributes.ItemAttribute
getId
Methods inherited from interface io.github.thebusybiscuit.slimefun4.core.attributes.Placeable
useVanillaBlockBreaking
-
Field Details
-
recipeStorageKey
protected final org.bukkit.NamespacedKey recipeStorageKeyTheNamespacedKey
used to store recipe data. -
recipeEnabledKey
protected final org.bukkit.NamespacedKey recipeEnabledKeyTheNamespacedKey
used 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:SlimefunItem
This 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:
postRegister
in 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
AutoCrafterListener
for the intended use case.- Parameters:
b
- TheBlock
that was clickedp
- ThePlayer
who clicked
-
tick
This method performs one tick for theAbstractAutoCrafter
.- Parameters:
b
- The block for thisAbstractAutoCrafter
data
- 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 givenPredicate
matches the providedItemStack
. -
matchesAny
-
isValidInventory
protected boolean isValidInventory(@Nonnull org.bukkit.block.Block block) This method checks if the givenBlock
has a validInventory
where 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
- TheBlock
to check- Returns:
- Whether that
Block
has a validInventory
-
getSelectedRecipe
This method returns the currently selectedAbstractRecipe
for the givenBlock
.- Parameters:
b
- TheBlock
- Returns:
- The currently selected
AbstractRecipe
or null
-
updateRecipe
protected abstract void updateRecipe(@Nonnull org.bukkit.block.Block b, @Nonnull org.bukkit.entity.Player p) This method is called when aPlayer
right clicks theAbstractAutoCrafter
while holding the shift button. Use it to choose theAbstractRecipe
.- Parameters:
b
- TheBlock
which was clickedp
- ThePlayer
who clicked
-
setSelectedRecipe
protected void setSelectedRecipe(@Nonnull org.bukkit.block.Block b, @Nullable AbstractRecipe recipe) This method sets the selectedAbstractRecipe
for the givenBlock
. The recipe will be stored using thePersistentDataAPI
.- Parameters:
b
- TheBlock
to store the data onrecipe
- TheAbstractRecipe
to select
-
showRecipe
@ParametersAreNonnullByDefault protected void showRecipe(org.bukkit.entity.Player p, org.bukkit.block.Block b, AbstractRecipe recipe) This shows the givenAbstractRecipe
to thePlayer
in a preview window.- Parameters:
p
- ThePlayer
b
- TheBlock
of theAbstractAutoCrafter
recipe
- TheAbstractRecipe
to show them
-
craft
This method performs a crafting operation. It will attempt to fulfill the providedAbstractRecipe
using the givenInventory
. This will consume items and add the result to theInventory
. This method does not handle energy consumption.- Parameters:
inv
- TheInventory
to take resources fromrecipe
- TheAbstractRecipe
to 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:
getCapacity
in 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:SlimefunItem
This method registers thisSlimefunItem
. Always call this method after yourSlimefunItem
has been initialized. Never call it more than once!- Overrides:
register
in classSlimefunItem
- Parameters:
addon
- TheSlimefunAddon
that thisSlimefunItem
belongs to.
-
getEnergyComponentType
Description copied from interface:EnergyNetComponent
This method returns the Type ofEnergyNetComponentType
thisSlimefunItem
represents. It describes how this Block will interact with anEnergyNet
.- Specified by:
getEnergyComponentType
in interfaceEnergyNetComponent
- Returns:
- The
EnergyNetComponentType
thisSlimefunItem
represents.
-