Class SlimefunItem
java.lang.Object
io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem
- All Implemented Interfaces:
Placeable
- Direct Known Subclasses:
AbstractAutoCrafter
,AbstractEnergyProvider
,AbstractGrowthAccelerator
,AbstractMonsterSpawner
,AbstractTeleporterPlate
,AContainer
,AlloyIngot
,AncientAltar
,AutoBreeder
,BeeWings
,BirthdayCake
,BlockPlacer
,Capacitor
,CargoManager
,ElementalRune
,EnchantedItem
,EnderBoots
,EnergyRegulator
,ExpCollector
,FarmerShoes
,GEOMiner
,GoldIngot
,HiddenItem
,HologramProjector
,IgnitionChamber
,JetBoots
,Jetpack
,LumberAxe
,MultiBlockMachine
,MultiTool
,OrganicFertilizer
,OrganicFood
,OutputChest
,Parachute
,ProgrammableAndroid
,RadioactiveItem
,ReactorAccessPort
,SimpleSlimefunItem
,SlimefunArmorPiece
,SlimefunBow
,SolarGenerator
,SolarHelmet
,SoulboundItem
,SteelThruster
,StomperBoots
,SyntheticEmerald
,Talisman
,TrashCan
,VanillaItem
,WitherProofBlock
A
SlimefunItem
is a custom item registered by a SlimefunAddon
.
This class defines the behaviours of the item, you can assign an ItemHandler
to give the item functionality.
In contrast to that the SlimefunItemStack
defines the look and feel of the item.
Remember to call register(SlimefunAddon)
on your SlimefunItem
for it
to appear in the SlimefunGuide
.- Author:
- TheBusyBiscuit, Poslovitch
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected SlimefunAddon
This is a reference to theSlimefunAddon
that registered thisSlimefunItem
, if the item has not been registered yet, it will be null.protected boolean
protected boolean
protected boolean
protected ItemStack
protected boolean
-
Constructor Summary
ModifierConstructorDescriptionSlimefunItem
(ItemGroup itemGroup, SlimefunItemStack item) This creates a newSlimefunItem
from the given arguments.SlimefunItem
(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) This creates a newSlimefunItem
from the given arguments.SlimefunItem
(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) This creates a newSlimefunItem
from the given arguments.protected
SlimefunItem
(ItemGroup itemGroup, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addItemHandler
(ItemHandler... handlers) This method will add any givenItemHandler
to thisSlimefunItem
.final void
addItemSetting
(ItemSetting<?>... settings) This method will add any givenItemSetting
to thisSlimefunItem
.final void
addOfficialWikipage
(String page) This method will assign the given wiki page to this Item.<T extends ItemHandler>
booleancallItemHandler
(Class<T> c, Consumer<T> callable) This method calls everyItemHandler
of the givenClass
and performs the action as specified via theConsumer
.boolean
This method checks if the givenPlayer
is able to use thisSlimefunItem
.final boolean
void
This will throw aThrowable
to the console and signal that this was caused by thisSlimefunItem
.final SlimefunAddon
getAddon()
This method returns theSlimefunAddon
that registered thisSlimefunItem
.static SlimefunItem
Retrieve aSlimefunItem
by its id.static SlimefunItem
Retrieve aSlimefunItem
from anItemStack
.getDrops()
This method returns a Set of item handlers associated with this Item.final String
getId()
Returns the identifier of thisSlimefunItem
.getItem()
This returns theItemStack
of thisSlimefunItem
.This returns theItemGroup
of ourSlimefunItem
, everySlimefunItem
is associated with exactly oneItemGroup
.final String
<T> Optional<ItemSetting<T>>
getItemSetting
(String key, Class<T> c) This method returns anOptional
holding anItemSetting
with the given key and data type.Set<ItemSetting<?>>
static Optional<SlimefunItem>
Retrieve aOptional
SlimefunItem
by its id.static Optional<SlimefunItem>
getOptionalByItem
(ItemStack item) Retrieve the recipe for thisSlimefunItem
.This method returns the result of crafting thisSlimefunItem
This method returns theRecipeType
.final Research
This method returns theResearch
thisSlimefunItem
is linked to.getState()
This method returns theItemState
thisSlimefunItem
is currently in.This method returns the wiki page that has been assigned to this item.final int
hashCode()
final boolean
This returns whether thisSlimefunItem
has aResearch
assigned to it.void
This will send an info message to the console and signal that this message came from thisSlimefunItem
, the message will be sent using theLogger
of theSlimefunAddon
which registered thisSlimefunItem
.boolean
This method returns whether thisSlimefunItem
is disabled.boolean
isDisabledIn
(World world) This method returns whether thisSlimefunItem
is disabled for that specificWorld
.boolean
This returns whether or not thisSlimefunItem
is allowed to be used in anAutoDisenchanter
.boolean
This returns whether or not thisSlimefunItem
is allowed to be used in anAutoEnchanter
.final boolean
isHidden()
This method returns whether thisSlimefunItem
was hidden from theSlimefunGuide
.boolean
This method checks whether the providedItemStack
represents thisSlimefunItem
.protected boolean
This method returns whether the originalSlimefunItemStack
of thisSlimefunItem
is immutable.boolean
This returns whether or not we are scheduling a ticking task for this block.boolean
This method returns whether or not thisSlimefunItem
is allowed to be used in a Crafting Table.void
load()
This method is used for internal purposes only.void
This method is called afterregister(SlimefunAddon)
.void
This method is called beforeregister(SlimefunAddon)
.void
register
(SlimefunAddon addon) This method registers thisSlimefunItem
.void
sendDeprecationWarning
(Player player) This method informs the givenPlayer
that thisSlimefunItem
will be removed soon.void
setHidden
(boolean hidden) This method will forcefully hide thisSlimefunItem
from theSlimefunGuide
.void
setItemGroup
(ItemGroup itemGroup) This sets theItemGroup
in which thisSlimefunItem
will be displayed.void
Sets the recipe for thisSlimefunItem
.void
setRecipeOutput
(ItemStack output) This method will set the result of crafting thisSlimefunItem
.void
setRecipeType
(RecipeType type) Sets theRecipeType
for thisSlimefunItem
.void
setResearch
(Research research) This method will set theResearch
of thisSlimefunItem
.setUseableInWorkbench
(boolean useable) This sets whether or not thisSlimefunItem
is allowed to be used in a normal Crafting Table.toString()
void
This will send a warning to the console and signal that this warning came from thisSlimefunItem
, the warning will be sent using theLogger
of theSlimefunAddon
which registered thisSlimefunItem
.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.Placeable
useVanillaBlockBreaking
-
Field Details
-
addon
This is a reference to theSlimefunAddon
that registered thisSlimefunItem
, if the item has not been registered yet, it will be null. -
recipeOutput
-
enchantable
protected boolean enchantable -
disenchantable
protected boolean disenchantable -
useableInWorkbench
protected boolean useableInWorkbench
-
-
Constructor Details
-
SlimefunItem
@ParametersAreNonnullByDefault public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) This creates a newSlimefunItem
from the given arguments.- Parameters:
itemGroup
- TheItemGroup
thisSlimefunItem
belongs toitem
- TheSlimefunItemStack
that describes the visual features of ourSlimefunItem
recipeType
- theRecipeType
that determines how thisSlimefunItem
is craftedrecipe
- An Array representing the recipe of thisSlimefunItem
-
SlimefunItem
@ParametersAreNonnullByDefault public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, @Nullable ItemStack recipeOutput) This creates a newSlimefunItem
from the given arguments.- Parameters:
itemGroup
- TheItemGroup
thisSlimefunItem
belongs toitem
- TheSlimefunItemStack
that describes the visual features of ourSlimefunItem
recipeType
- theRecipeType
that determines how thisSlimefunItem
is craftedrecipe
- An Array representing the recipe of thisSlimefunItem
recipeOutput
- The result of crafting this item
-
SlimefunItem
This creates a newSlimefunItem
from the given arguments.- Parameters:
itemGroup
- TheItemGroup
thisSlimefunItem
belongs toitem
- TheSlimefunItemStack
that describes the visual features of ourSlimefunItem
-
SlimefunItem
@ParametersAreNonnullByDefault protected SlimefunItem(ItemGroup itemGroup, ItemStack item, String id, RecipeType recipeType, ItemStack[] recipe)
-
-
Method Details
-
getId
Returns the identifier of thisSlimefunItem
.- Returns:
- the identifier of this
SlimefunItem
-
getState
This method returns theItemState
thisSlimefunItem
is currently in. This can be used to determine whether aSlimefunItem
is enabled or disabled.VanillaItem
represents a special case here.- Returns:
- The
ItemState
of thisSlimefunItem
-
getItem
This returns theItemStack
of thisSlimefunItem
. TheItemStack
describes the look and feel of thisSlimefunItem
.- Returns:
- The
ItemStack
that thisSlimefunItem
represents
-
getItemGroup
This returns theItemGroup
of ourSlimefunItem
, everySlimefunItem
is associated with exactly oneItemGroup
.- Returns:
- The
ItemGroup
that thisSlimefunItem
belongs to
-
getRecipe
Retrieve the recipe for thisSlimefunItem
.- Returns:
- An
ItemStack
array of 9 which represents the recipe for thisSlimefunItem
-
getRecipeType
- Returns:
- The
RecipeType
of thisSlimefunItem
-
getRecipeOutput
This method returns the result of crafting thisSlimefunItem
- Returns:
- The recipe output of this
SlimefunItem
-
getResearch
This method returns theResearch
thisSlimefunItem
is linked to. This will be null if the item is not linked to anyResearch
- Returns:
- The linked
Research
or null
-
hasResearch
public final boolean hasResearch()This returns whether thisSlimefunItem
has aResearch
assigned to it. It is equivalent to a null check performed ongetResearch()
.- Returns:
- Whether this
SlimefunItem
has aResearch
-
getItemSettings
- Returns:
- A
Set
of everyItemSetting
for thisSlimefunItem
-
getItemSetting
@Nonnull public <T> Optional<ItemSetting<T>> getItemSetting(@Nonnull String key, @Nonnull Class<T> c) This method returns anOptional
holding anItemSetting
with the given key and data type. Or an emptyOptional
if thisSlimefunItem
has no suchItemSetting
.- Type Parameters:
T
- The Type of value stored in thisItemSetting
- Parameters:
key
- The key of thisItemSetting
c
- TheClass
of the type of value stored by this setting- Returns:
- An
Optional
describing the result
-
isEnchantable
public boolean isEnchantable()This returns whether or not thisSlimefunItem
is allowed to be used in anAutoEnchanter
.- Returns:
- Whether this
SlimefunItem
can be enchanted.
-
isDisenchantable
public boolean isDisenchantable()This returns whether or not thisSlimefunItem
is allowed to be used in anAutoDisenchanter
.- Returns:
- Whether this
SlimefunItem
can be disenchanted.
-
isHidden
public final boolean isHidden()This method returns whether thisSlimefunItem
was hidden from theSlimefunGuide
.- Returns:
- Whether this
SlimefunItem
is hidden.
-
setHidden
public void setHidden(boolean hidden) This method will forcefully hide thisSlimefunItem
from theSlimefunGuide
.- Parameters:
hidden
- Whether to hide thisSlimefunItem
or not
-
isDisabled
public boolean isDisabled()This method returns whether thisSlimefunItem
is disabled.- Returns:
- Whether this
SlimefunItem
is disabled.
-
isDisabledIn
This method returns whether thisSlimefunItem
is disabled for that specificWorld
. Note that if the item is disabled globally, this method will still return false.- Parameters:
world
- TheWorld
to check- Returns:
- Whether this
SlimefunItem
is disabled in that world (or in general).
-
getAddon
This method returns theSlimefunAddon
that registered thisSlimefunItem
. If this Item is from Slimefun itself, the current instance ofSlimefun
will be returned. Use an instanceof check to account for that.- Returns:
- The
SlimefunAddon
that registered thisSlimefunItem
-
getBlockTicker
-
register
This method registers thisSlimefunItem
. Always call this method after yourSlimefunItem
has been initialized. Never call it more than once!- Parameters:
addon
- TheSlimefunAddon
that thisSlimefunItem
belongs to.
-
isItemStackImmutable
protected boolean isItemStackImmutable()This method returns whether the originalSlimefunItemStack
of thisSlimefunItem
is immutable. Iftrue
is returned, then any changes to the originalSlimefunItemStack
will be rejected with aWrongItemStackException
. This ensures integrity so developers don't accidentally damage the wrongItemStack
.- Returns:
- Whether the original
SlimefunItemStack
is immutable.
-
setResearch
This method will set theResearch
of thisSlimefunItem
. You don't have to call this method if yourSlimefunItem
was linked to yourResearch
usingResearch.addItems(SlimefunItem...)
- Parameters:
research
- The newResearch
for thisSlimefunItem
, or null
-
setRecipe
Sets the recipe for thisSlimefunItem
.- Parameters:
recipe
- The recipe for thisItemStack
-
setRecipeType
Sets theRecipeType
for thisSlimefunItem
.- Parameters:
type
- TheRecipeType
for thisSlimefunItem
-
setItemGroup
This sets theItemGroup
in which thisSlimefunItem
will be displayed.- Parameters:
itemGroup
- The newItemGroup
-
setRecipeOutput
This method will set the result of crafting thisSlimefunItem
. If null is passed, then it will use the default item as the recipe result.- Parameters:
output
- TheItemStack
that will be the result of crafting thisSlimefunItem
-
isUseableInWorkbench
public boolean isUseableInWorkbench()This method returns whether or not thisSlimefunItem
is allowed to be used in a Crafting Table. Items of typeVanillaItem
may be used in workbenches for example.- Returns:
- Whether this
SlimefunItem
may be used in a Workbench. - See Also:
-
setUseableInWorkbench
This sets whether or not thisSlimefunItem
is allowed to be used in a normal Crafting Table.- Parameters:
useable
- Whether thisSlimefunItem
should be useable in a workbench- Returns:
- This instance of
SlimefunItem
-
isItem
This method checks whether the providedItemStack
represents thisSlimefunItem
.- Parameters:
item
- TheItemStack
to compare- Returns:
- Whether the given
ItemStack
represents thisSlimefunItem
-
load
public void load()This method is used for internal purposes only. -
addItemHandler
This method will add any givenItemHandler
to thisSlimefunItem
. Note that this will not work after theSlimefunItem
was registered.- Parameters:
handlers
- AnyItemHandler
that should be added to thisSlimefunItem
-
addItemSetting
This method will add any givenItemSetting
to thisSlimefunItem
. Note that this will not work after theSlimefunItem
was registered.- Parameters:
settings
- AnyItemSetting
that should be added to thisSlimefunItem
-
preRegister
public void preRegister()This method is called beforeregister(SlimefunAddon)
. Override this method to add any additional setup, adding anItemHandler
for example. -
postRegister
public void postRegister()This method is called afterregister(SlimefunAddon)
. Override this method to add any additional setup that needs to happen after the original registration of thisSlimefunItem
. -
addOfficialWikipage
This method will assign the given wiki page to this Item. Note that you only need to provide the page name itself, the URL to our wiki is prepended automatically.- Parameters:
page
- The associated wiki page
-
getWikipage
This method returns the wiki page that has been assigned to this item. It will return null, if no wiki page was found.- Returns:
- This item's wiki page
- See Also:
-
getItemName
This method will return this Item's Name (The name that is displayed when hovering over thisItemStack
in anInventory
).- Returns:
- This item's name in
ItemStack
form
-
getHandlers
This method returns a Set of item handlers associated with this Item.- Returns:
- The Set of item handlers
-
callItemHandler
@ParametersAreNonnullByDefault public <T extends ItemHandler> boolean callItemHandler(Class<T> c, Consumer<T> callable) This method calls everyItemHandler
of the givenClass
and performs the action as specified via theConsumer
.- Type Parameters:
T
- The type ofItemHandler
to call.- Parameters:
c
- TheClass
of theItemHandler
to call.callable
- AConsumer
that is called for any foundItemHandler
.- Returns:
- Whether or not an
ItemHandler
was found.
-
isTicking
public boolean isTicking()This returns whether or not we are scheduling a ticking task for this block.- Returns:
- Whether this
SlimefunItem
is a ticking block
-
toString
-
getDrops
-
getDrops
-
info
This will send an info message to the console and signal that this message came from thisSlimefunItem
, the message will be sent using theLogger
of theSlimefunAddon
which registered thisSlimefunItem
.- Parameters:
message
- The message to send
-
warn
This will send a warning to the console and signal that this warning came from thisSlimefunItem
, the warning will be sent using theLogger
of theSlimefunAddon
which registered thisSlimefunItem
.- Parameters:
message
- The message to send
-
error
This will throw aThrowable
to the console and signal that this was caused by thisSlimefunItem
.- Parameters:
message
- The message to display alongside this Stacktracethrowable
- TheThrowable
to throw as a stacktrace.
-
sendDeprecationWarning
This method informs the givenPlayer
that thisSlimefunItem
will be removed soon.- Parameters:
player
- ThePlayer
to inform.
-
canUse
This method checks if the givenPlayer
is able to use thisSlimefunItem
. APlayer
can use it if the following conditions apply:- The
SlimefunItem
is not disabled - The
SlimefunItem
was not disabled for thatPlayer
'sWorld
. - The
Player
has the requiredPermission
(if present) - The
Player
has unlocked the requiredResearch
(if present)
false
, then an optional message will be sent to thePlayer
.- Parameters:
p
- ThePlayer
to checksendMessage
- Whether to send thatPlayer
a message response.- Returns:
- Whether this
Player
is able to use thisSlimefunItem
.
- The
-
equals
-
hashCode
public final int hashCode() -
getById
Retrieve aSlimefunItem
by its id.- Parameters:
id
- The id of theSlimefunItem
- Returns:
- The
SlimefunItem
associated with that id. Null if non-existent
-
getOptionalById
Retrieve aOptional
SlimefunItem
by its id.- Parameters:
id
- The id of theSlimefunItem
- Returns:
- The
Optional
SlimefunItem
associated with that id. Empty if non-existent
-
getByItem
Retrieve aSlimefunItem
from anItemStack
.- Parameters:
item
- TheItemStack
to check- Returns:
- The
SlimefunItem
associated with thisItemStack
if present, otherwise null
-
getOptionalByItem
- Parameters:
item
- TheItemStack
to check- Returns:
- The
Optional
SlimefunItem
associated with thisItemStack
if present, otherwise empty
-