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
Modifier and TypeFieldDescriptionprotected final int[]
protected final NamespacedKey
TheNamespacedKey
used to determine whether the recipe is enabled.protected final 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
ModifierConstructorDescriptionprotected
AbstractAutoCrafter
(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) -
Method Summary
Modifier and TypeMethodDescriptionboolean
craft
(Inventory 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
This method returns the currently selectedAbstractRecipe
for the givenBlock
.protected boolean
isValidInventory
(Block block) protected boolean
protected boolean
void
onRightClick
(Block b, Player p) This method handles our right-clicking behaviour.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
(Block b, AbstractRecipe recipe) This method sets the selectedAbstractRecipe
for the givenBlock
.protected void
showRecipe
(Player p, Block b, AbstractRecipe recipe) This shows the givenAbstractRecipe
to thePlayer
in a preview window.protected void
This method performs one tick for theAbstractAutoCrafter
.protected abstract void
updateRecipe
(Block b, 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, callItemHandler, canUse, 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, postRegister, 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, 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
TheNamespacedKey
used to store recipe data. -
recipeEnabledKey
TheNamespacedKey
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, ItemStack[] recipe)
-
-
Method Details
-
onRightClick
This method handles our right-clicking behaviour.Do not call this method directly, see our
AutoCrafterListener
for the intended use case. -
tick
This method performs one tick for theAbstractAutoCrafter
.- Parameters:
b
- The block for thisAbstractAutoCrafter
data
- The data stored on this block
-
isValidInventory
-
getSelectedRecipe
This method returns the currently selectedAbstractRecipe
for the givenBlock
.- Parameters:
b
- TheBlock
- Returns:
- The currently selected
AbstractRecipe
or null
-
updateRecipe
This method is called when aPlayer
right clicks theAbstractAutoCrafter
while holding the shift button. Use it to choose theAbstractRecipe
. -
setSelectedRecipe
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
This shows the givenAbstractRecipe
to thePlayer
in a preview window.- Parameters:
p
- ThePlayer
b
- TheBlock
of theAbstractAutoCrafter
recipe
- TheAbstractRecipe
to show them
-
matches
-
matchesAny
-
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.
-