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,CrafterSmartPort,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
FieldsModifier and TypeFieldDescriptionprotected SlimefunAddonThis is a reference to theSlimefunAddonthat registered thisSlimefunItem, if the item has not been registered yet, it will be null.protected booleanprotected booleanprotected booleanprotected org.bukkit.inventory.ItemStackprotected boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionSlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, org.bukkit.inventory.ItemStack[] recipe) This creates a newSlimefunItemfrom the given arguments.SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, org.bukkit.inventory.ItemStack[] recipe, org.bukkit.inventory.ItemStack recipeOutput) This creates a newSlimefunItemfrom the given arguments.protectedSlimefunItem(ItemGroup itemGroup, org.bukkit.inventory.ItemStack item, String id, RecipeType recipeType, org.bukkit.inventory.ItemStack[] recipe) -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddItemHandler(ItemHandler... handlers) This method will add any givenItemHandlerto thisSlimefunItem.final voidaddItemSetting(ItemSetting<?>... settings) This method will add any givenItemSettingto thisSlimefunItem.final voidaddOfficialWikipage(String page) Deprecated.final voidaddWikiPage(String page) 指定该物品的 Wiki 页面<T extends ItemHandler>
booleancallItemHandler(Class<T> c, Consumer<T> callable) This method calls everyItemHandlerof the givenClassand performs the action as specified via theConsumer.booleancanUse(org.bukkit.entity.Player p, boolean sendMessage) This method checks if the givenPlayeris able to use thisSlimefunItem.voiddisable()This method is called when thisSlimefunItemis disabled after reloaded.voidenable()final booleanvoidThis will throw aThrowableto the console and signal that this was caused by thisSlimefunItem.final SlimefunAddongetAddon()This method returns theSlimefunAddonthat registered thisSlimefunItem.static SlimefunItemRetrieve aSlimefunItemby its id.static SlimefunItemgetByItem(org.bukkit.inventory.ItemStack item) Retrieve aSlimefunItemfrom anItemStack.Collection<org.bukkit.inventory.ItemStack> getDrops()Collection<org.bukkit.inventory.ItemStack> getDrops(org.bukkit.entity.Player p) This method returns a Set of item handlers associated with this Item.final StringgetId()Returns the identifier of thisSlimefunItem.org.bukkit.inventory.ItemStackgetItem()This returns theItemStackof thisSlimefunItem.This returns theItemGroupof ourSlimefunItem, everySlimefunItemis associated with exactly oneItemGroup.final StringThis method will return this Item's Name (The name that is displayed when hovering over thisItemStackin anInventory).<T> Optional<ItemSetting<T>> getItemSetting(String key, Class<T> c) This method returns anOptionalholding anItemSettingwith the given key and data type.Set<ItemSetting<?>> static Optional<SlimefunItem> Retrieve aOptionalSlimefunItemby its id.static Optional<SlimefunItem> getOptionalByItem(org.bukkit.inventory.ItemStack item) org.bukkit.inventory.ItemStack[]Retrieve the recipe for thisSlimefunItem.org.bukkit.inventory.ItemStackThis method returns the result of crafting thisSlimefunItemThis method returns theRecipeType.final ResearchThis method returns theResearchthisSlimefunItemis linked to.getState()This method returns theItemStatethisSlimefunItemis currently in.This method returns the wiki page that has been assigned to this item.final inthashCode()final booleanThis returns whether thisSlimefunItemhas aResearchassigned to it.voidThis will send an info message to the console and signal that this message came from thisSlimefunItem, the message will be sent using theLoggerof theSlimefunAddonwhich registered thisSlimefunItem.booleanThis method returns whether thisSlimefunItemis disabled.booleanisDisabledIn(org.bukkit.World world) This method returns whether thisSlimefunItemis disabled for that specificWorld.booleanThis returns whether or not thisSlimefunItemis allowed to be used in anAutoDisenchanter.booleanThis returns whether or not thisSlimefunItemis allowed to be used in anAutoEnchanter.final booleanisHidden()This method returns whether thisSlimefunItemwas hidden from theSlimefunGuide.booleanisItem(org.bukkit.inventory.ItemStack item) This method checks whether the providedItemStackrepresents thisSlimefunItem.protected booleanThis method returns whether the originalSlimefunItemStackof thisSlimefunItemis immutable.booleanThis returns whether or not we are scheduling a ticking task for this block.booleanThis method returns whether or not thisSlimefunItemis allowed to be used in a Crafting Table.voidload()This method is used for internal purposes only.booleanShould load theSlimefunBlockDataby default.voidThis method is called afterregister(SlimefunAddon).voidThis method is called beforeregister(SlimefunAddon).voidregister(SlimefunAddon addon) This method registers thisSlimefunItem.voidsendDeprecationWarning(org.bukkit.entity.Player player) This method informs the givenPlayerthat thisSlimefunItemwill be removed soon.voidsetHidden(boolean hidden) This method will forcefully hide thisSlimefunItemfrom theSlimefunGuide.voidsetItemGroup(ItemGroup itemGroup) This sets theItemGroupin which thisSlimefunItemwill be displayed.voidsetRecipe(org.bukkit.inventory.ItemStack[] recipe) Sets the recipe for thisSlimefunItem.voidsetRecipeOutput(org.bukkit.inventory.ItemStack output) This method will set the result of crafting thisSlimefunItem.voidsetRecipeType(RecipeType type) Sets theRecipeTypefor thisSlimefunItem.voidsetResearch(Research research) This method will set theResearchof thisSlimefunItem.setUseableInWorkbench(boolean useable) This sets whether or not thisSlimefunItemis allowed to be used in a normal Crafting Table.toString()voidThis will send a warning to the console and signal that this warning came from thisSlimefunItem, the warning will be sent using theLoggerof theSlimefunAddonwhich registered thisSlimefunItem.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.github.thebusybiscuit.slimefun4.core.attributes.Placeable
useVanillaBlockBreaking
-
Field Details
-
addon
This is a reference to theSlimefunAddonthat registered thisSlimefunItem, if the item has not been registered yet, it will be null. -
recipeOutput
protected org.bukkit.inventory.ItemStack 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, org.bukkit.inventory.ItemStack[] recipe) This creates a newSlimefunItemfrom the given arguments.- Parameters:
itemGroup- TheItemGroupthisSlimefunItembelongs toitem- TheSlimefunItemStackthat describes the visual features of ourSlimefunItemrecipeType- theRecipeTypethat determines how thisSlimefunItemis craftedrecipe- An Array representing the recipe of thisSlimefunItem
-
SlimefunItem
@ParametersAreNonnullByDefault public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, org.bukkit.inventory.ItemStack[] recipe, @Nullable org.bukkit.inventory.ItemStack recipeOutput) This creates a newSlimefunItemfrom the given arguments.- Parameters:
itemGroup- TheItemGroupthisSlimefunItembelongs toitem- TheSlimefunItemStackthat describes the visual features of ourSlimefunItemrecipeType- theRecipeTypethat determines how thisSlimefunItemis craftedrecipe- An Array representing the recipe of thisSlimefunItemrecipeOutput- The result of crafting this item
-
SlimefunItem
@ParametersAreNonnullByDefault protected SlimefunItem(ItemGroup itemGroup, org.bukkit.inventory.ItemStack item, String id, RecipeType recipeType, org.bukkit.inventory.ItemStack[] recipe)
-
-
Method Details
-
getId
Returns the identifier of thisSlimefunItem.- Returns:
- the identifier of this
SlimefunItem
-
getState
This method returns theItemStatethisSlimefunItemis currently in. This can be used to determine whether aSlimefunItemis enabled or disabled.VanillaItemrepresents a special case here.- Returns:
- The
ItemStateof thisSlimefunItem
-
getItem
@Nonnull public org.bukkit.inventory.ItemStack getItem()This returns theItemStackof thisSlimefunItem. TheItemStackdescribes the look and feel of thisSlimefunItem.- Returns:
- The
ItemStackthat thisSlimefunItemrepresents
-
getItemGroup
This returns theItemGroupof ourSlimefunItem, everySlimefunItemis associated with exactly oneItemGroup.- Returns:
- The
ItemGroupthat thisSlimefunItembelongs to
-
getRecipe
@Nonnull public org.bukkit.inventory.ItemStack[] getRecipe()Retrieve the recipe for thisSlimefunItem.- Returns:
- An
ItemStackarray of 9 which represents the recipe for thisSlimefunItem
-
getRecipeType
- Returns:
- The
RecipeTypeof thisSlimefunItem
-
getRecipeOutput
@Nonnull public org.bukkit.inventory.ItemStack getRecipeOutput()This method returns the result of crafting thisSlimefunItem- Returns:
- The recipe output of this
SlimefunItem
-
getResearch
This method returns theResearchthisSlimefunItemis linked to. This will be null if the item is not linked to anyResearch- Returns:
- The linked
Researchor null
-
hasResearch
public final boolean hasResearch()This returns whether thisSlimefunItemhas aResearchassigned to it. It is equivalent to a null check performed ongetResearch().- Returns:
- Whether this
SlimefunItemhas aResearch
-
getItemSettings
- Returns:
- A
Setof everyItemSettingfor thisSlimefunItem
-
getItemSetting
@Nonnull public <T> Optional<ItemSetting<T>> getItemSetting(@Nonnull String key, @Nonnull Class<T> c) This method returns anOptionalholding anItemSettingwith the given key and data type. Or an emptyOptionalif thisSlimefunItemhas no suchItemSetting.- Type Parameters:
T- The Type of value stored in thisItemSetting- Parameters:
key- The key of thisItemSettingc- TheClassof the type of value stored by this setting- Returns:
- An
Optionaldescribing the result
-
isEnchantable
public boolean isEnchantable()This returns whether or not thisSlimefunItemis allowed to be used in anAutoEnchanter.- Returns:
- Whether this
SlimefunItemcan be enchanted.
-
isDisenchantable
public boolean isDisenchantable()This returns whether or not thisSlimefunItemis allowed to be used in anAutoDisenchanter.- Returns:
- Whether this
SlimefunItemcan be disenchanted.
-
isHidden
public final boolean isHidden()This method returns whether thisSlimefunItemwas hidden from theSlimefunGuide.- Returns:
- Whether this
SlimefunItemis hidden.
-
setHidden
public void setHidden(boolean hidden) This method will forcefully hide thisSlimefunItemfrom theSlimefunGuide.- Parameters:
hidden- Whether to hide thisSlimefunItemor not
-
isDisabled
public boolean isDisabled()This method returns whether thisSlimefunItemis disabled.- Returns:
- Whether this
SlimefunItemis disabled.
-
isDisabledIn
public boolean isDisabledIn(@Nonnull org.bukkit.World world) This method returns whether thisSlimefunItemis disabled for that specificWorld. Note that if the item is disabled globally, this method will still return false.- Parameters:
world- TheWorldto check- Returns:
- Whether this
SlimefunItemis disabled in that world (or in general).
-
getAddon
This method returns theSlimefunAddonthat registered thisSlimefunItem. If this Item is from Slimefun itself, the current instance ofSlimefunwill be returned. Use an instanceof check to account for that.- Returns:
- The
SlimefunAddonthat registered thisSlimefunItem
-
getBlockTicker
-
register
This method registers thisSlimefunItem. Always call this method after yourSlimefunItemhas been initialized. Never call it more than once!- Parameters:
addon- TheSlimefunAddonthat thisSlimefunItembelongs to.
-
enable
public void enable() -
disable
public void disable()This method is called when thisSlimefunItemis disabled after reloaded. -
isItemStackImmutable
protected boolean isItemStackImmutable()This method returns whether the originalSlimefunItemStackof thisSlimefunItemis immutable. Iftrueis returned, then any changes to the originalSlimefunItemStackwill be rejected with aWrongItemStackException. This ensures integrity so developers don't accidentally damage the wrongItemStack.- Returns:
- Whether the original
SlimefunItemStackis immutable.
-
setResearch
This method will set theResearchof thisSlimefunItem. You don't have to call this method if yourSlimefunItemwas linked to yourResearchusingResearch.addItems(SlimefunItem...)- Parameters:
research- The newResearchfor thisSlimefunItem, or null
-
setRecipe
public void setRecipe(@Nonnull org.bukkit.inventory.ItemStack[] recipe) Sets the recipe for thisSlimefunItem.- Parameters:
recipe- The recipe for thisItemStack
-
setRecipeType
Sets theRecipeTypefor thisSlimefunItem.- Parameters:
type- TheRecipeTypefor thisSlimefunItem
-
setItemGroup
This sets theItemGroupin which thisSlimefunItemwill be displayed.- Parameters:
itemGroup- The newItemGroup
-
setRecipeOutput
public void setRecipeOutput(@Nullable org.bukkit.inventory.ItemStack output) 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- TheItemStackthat will be the result of crafting thisSlimefunItem
-
isUseableInWorkbench
public boolean isUseableInWorkbench()This method returns whether or not thisSlimefunItemis allowed to be used in a Crafting Table. Items of typeVanillaItemmay be used in workbenches for example.- Returns:
- Whether this
SlimefunItemmay be used in a Workbench. - See Also:
-
setUseableInWorkbench
This sets whether or not thisSlimefunItemis allowed to be used in a normal Crafting Table.- Parameters:
useable- Whether thisSlimefunItemshould be useable in a workbench- Returns:
- This instance of
SlimefunItem
-
isItem
public boolean isItem(@Nullable org.bukkit.inventory.ItemStack item) This method checks whether the providedItemStackrepresents thisSlimefunItem.- Parameters:
item- TheItemStackto compare- Returns:
- Whether the given
ItemStackrepresents thisSlimefunItem
-
load
public void load()This method is used for internal purposes only. -
addItemHandler
This method will add any givenItemHandlerto thisSlimefunItem. Note that this will not work after theSlimefunItemwas registered.- Parameters:
handlers- AnyItemHandlerthat should be added to thisSlimefunItem
-
addItemSetting
This method will add any givenItemSettingto thisSlimefunItem. Note that this will not work after theSlimefunItemwas registered.- Parameters:
settings- AnyItemSettingthat should be added to thisSlimefunItem
-
preRegister
public void preRegister()This method is called beforeregister(SlimefunAddon). Override this method to add any additional setup, adding anItemHandlerfor 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
Deprecated.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. 返回非官方中文Wiki地址 下游应使用addWikiPage(String)来添加Wiki页面- Parameters:
page- The associated wiki page
-
addWikiPage
指定该物品的 Wiki 页面- Parameters:
page- 物品的 Wiki 页面
-
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 thisItemStackin anInventory).- Returns:
- This item's name in
ItemStackform
-
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 everyItemHandlerof the givenClassand performs the action as specified via theConsumer.- Type Parameters:
T- The type ofItemHandlerto call.- Parameters:
c- TheClassof theItemHandlerto call.callable- AConsumerthat is called for any foundItemHandler.- Returns:
- Whether or not an
ItemHandlerwas found.
-
isTicking
public boolean isTicking()This returns whether or not we are scheduling a ticking task for this block.- Returns:
- Whether this
SlimefunItemis 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 theLoggerof theSlimefunAddonwhich 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 theLoggerof theSlimefunAddonwhich registered thisSlimefunItem.- Parameters:
message- The message to send
-
error
This will throw aThrowableto the console and signal that this was caused by thisSlimefunItem.- Parameters:
message- The message to display alongside this Stacktracethrowable- TheThrowableto throw as a stacktrace.
-
sendDeprecationWarning
@ParametersAreNonnullByDefault public void sendDeprecationWarning(org.bukkit.entity.Player player) This method informs the givenPlayerthat thisSlimefunItemwill be removed soon.- Parameters:
player- ThePlayerto inform.
-
canUse
public boolean canUse(@Nonnull org.bukkit.entity.Player p, boolean sendMessage) This method checks if the givenPlayeris able to use thisSlimefunItem. APlayercan use it if the following conditions apply:- The
SlimefunItemis not disabled - The
SlimefunItemwas not disabled for thatPlayer'sWorld. - The
Playerhas the requiredPermission(if present) - The
Playerhas unlocked the requiredResearch(if present)
false, then an optional message will be sent to thePlayer.- Parameters:
p- ThePlayerto checksendMessage- Whether to send thatPlayera message response.- Returns:
- Whether this
Playeris able to use thisSlimefunItem.
- The
-
equals
-
hashCode
public final int hashCode() -
getById
Retrieve aSlimefunItemby its id.- Parameters:
id- The id of theSlimefunItem- Returns:
- The
SlimefunItemassociated with that id. Null if non-existent
-
getOptionalById
Retrieve aOptionalSlimefunItemby its id.- Parameters:
id- The id of theSlimefunItem- Returns:
- The
OptionalSlimefunItemassociated with that id. Empty if non-existent
-
getByItem
Retrieve aSlimefunItemfrom anItemStack.- Parameters:
item- TheItemStackto check- Returns:
- The
SlimefunItemassociated with thisItemStackif present, otherwise null
-
getOptionalByItem
@Nonnull public static Optional<SlimefunItem> getOptionalByItem(@Nullable org.bukkit.inventory.ItemStack item) - Parameters:
item- TheItemStackto check- Returns:
- The
OptionalSlimefunItemassociated with thisItemStackif present, otherwise empty
-
loadDataByDefault
public boolean loadDataByDefault()Should load theSlimefunBlockDataby default. If return false, only the item withBlockTickerwill be loaded withChunkLoadEvent.- Returns:
- true if the data should be loaded by default, false otherwise
-