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

public class SlimefunItem extends Object implements Placeable
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 Details

    • addon

      protected SlimefunAddon addon
      This is a reference to the SlimefunAddon that registered this SlimefunItem, 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
    • hidden

      protected boolean hidden
    • useableInWorkbench

      protected boolean useableInWorkbench
  • Constructor Details

  • Method Details

    • getId

      @Nonnull public final String getId()
      Returns the identifier of this SlimefunItem.
      Returns:
      the identifier of this SlimefunItem
    • getState

      @Nonnull public ItemState getState()
      This method returns the ItemState this SlimefunItem is currently in. This can be used to determine whether a SlimefunItem is enabled or disabled. VanillaItem represents a special case here.
      Returns:
      The ItemState of this SlimefunItem
    • getItem

      @Nonnull public org.bukkit.inventory.ItemStack getItem()
      This returns the ItemStack of this SlimefunItem. The ItemStack describes the look and feel of this SlimefunItem.
      Returns:
      The ItemStack that this SlimefunItem represents
    • getItemGroup

      @Nonnull public ItemGroup getItemGroup()
      This returns the ItemGroup of our SlimefunItem, every SlimefunItem is associated with exactly one ItemGroup.
      Returns:
      The ItemGroup that this SlimefunItem belongs to
    • getRecipe

      @Nonnull public org.bukkit.inventory.ItemStack[] getRecipe()
      Retrieve the recipe for this SlimefunItem.
      Returns:
      An ItemStack array of 9 which represents the recipe for this SlimefunItem
    • getRecipeType

      @Nonnull public RecipeType getRecipeType()
      This method returns the RecipeType. The RecipeType determines how this SlimefunItem is crafted.
      Returns:
      The RecipeType of this SlimefunItem
    • getRecipeOutput

      @Nonnull public org.bukkit.inventory.ItemStack getRecipeOutput()
      This method returns the result of crafting this SlimefunItem
      Returns:
      The recipe output of this SlimefunItem
    • getResearch

      @Nullable public final Research getResearch()
      This method returns the Research this SlimefunItem is linked to. This will be null if the item is not linked to any Research
      Returns:
      The linked Research or null
    • hasResearch

      public final boolean hasResearch()
      This returns whether this SlimefunItem has a Research assigned to it. It is equivalent to a null check performed on getResearch().
      Returns:
      Whether this SlimefunItem has a Research
    • getItemSettings

      @Nonnull public Set<ItemSetting<?>> getItemSettings()
      This returns a Set containing all instances of ItemSetting for this SlimefunItem.
      Returns:
      A Set of every ItemSetting for this SlimefunItem
    • getItemSetting

      @Nonnull public <T> Optional<ItemSetting<T>> getItemSetting(@Nonnull String key, @Nonnull Class<T> c)
      This method returns an Optional holding an ItemSetting with the given key and data type. Or an empty Optional if this SlimefunItem has no such ItemSetting.
      Type Parameters:
      T - The Type of value stored in this ItemSetting
      Parameters:
      key - The key of this ItemSetting
      c - The Class of the type of value stored by this setting
      Returns:
      An Optional describing the result
    • isEnchantable

      public boolean isEnchantable()
      This returns whether or not this SlimefunItem is allowed to be used in an AutoEnchanter.
      Returns:
      Whether this SlimefunItem can be enchanted.
    • isDisenchantable

      public boolean isDisenchantable()
      This returns whether or not this SlimefunItem is allowed to be used in an AutoDisenchanter.
      Returns:
      Whether this SlimefunItem can be disenchanted.
    • isHidden

      public final boolean isHidden()
      This method returns whether this SlimefunItem was hidden from the SlimefunGuide.
      Returns:
      Whether this SlimefunItem is hidden.
    • setHidden

      public void setHidden(boolean hidden)
      This method will forcefully hide this SlimefunItem from the SlimefunGuide.
      Parameters:
      hidden - Whether to hide this SlimefunItem or not
    • isDisabled

      public boolean isDisabled()
      This method returns whether this SlimefunItem is disabled.
      Returns:
      Whether this SlimefunItem is disabled.
    • isDisabledIn

      public boolean isDisabledIn(@Nonnull org.bukkit.World world)
      This method returns whether this SlimefunItem is disabled for that specific World. Note that if the item is disabled globally, this method will still return false.
      Parameters:
      world - The World to check
      Returns:
      Whether this SlimefunItem is disabled in that world (or in general).
    • getAddon

      @Nonnull public final SlimefunAddon getAddon()
      This method returns the SlimefunAddon that registered this SlimefunItem. If this Item is from Slimefun itself, the current instance of Slimefun will be returned. Use an instanceof check to account for that.
      Returns:
      The SlimefunAddon that registered this SlimefunItem
    • getBlockTicker

      public BlockTicker getBlockTicker()
    • register

      public void register(@Nonnull SlimefunAddon addon)
      This method registers this SlimefunItem. Always call this method after your SlimefunItem has been initialized. Never call it more than once!
      Parameters:
      addon - The SlimefunAddon that this SlimefunItem belongs to.
    • enable

      public void enable()
    • disable

      public void disable()
      This method is called when this SlimefunItem is disabled after reloaded.
    • isItemStackImmutable

      protected boolean isItemStackImmutable()
      This method returns whether the original SlimefunItemStack of this SlimefunItem is immutable. If true is returned, then any changes to the original SlimefunItemStack will be rejected with a WrongItemStackException. This ensures integrity so developers don't accidentally damage the wrong ItemStack.
      Returns:
      Whether the original SlimefunItemStack is immutable.
    • setResearch

      public void setResearch(@Nullable Research research)
      This method will set the Research of this SlimefunItem. You don't have to call this method if your SlimefunItem was linked to your Research using Research.addItems(SlimefunItem...)
      Parameters:
      research - The new Research for this SlimefunItem, or null
    • setRecipe

      public void setRecipe(@Nonnull org.bukkit.inventory.ItemStack[] recipe)
      Sets the recipe for this SlimefunItem.
      Parameters:
      recipe - The recipe for this ItemStack
    • setRecipeType

      public void setRecipeType(@Nonnull RecipeType type)
      Sets the RecipeType for this SlimefunItem.
      Parameters:
      type - The RecipeType for this SlimefunItem
    • setItemGroup

      public void setItemGroup(@Nonnull ItemGroup itemGroup)
      This sets the ItemGroup in which this SlimefunItem will be displayed.
      Parameters:
      itemGroup - The new ItemGroup
    • setRecipeOutput

      public void setRecipeOutput(@Nullable org.bukkit.inventory.ItemStack output)
      This method will set the result of crafting this SlimefunItem. If null is passed, then it will use the default item as the recipe result.
      Parameters:
      output - The ItemStack that will be the result of crafting this SlimefunItem
    • isUseableInWorkbench

      public boolean isUseableInWorkbench()
      This method returns whether or not this SlimefunItem is allowed to be used in a Crafting Table. Items of type VanillaItem may be used in workbenches for example.
      Returns:
      Whether this SlimefunItem may be used in a Workbench.
      See Also:
    • setUseableInWorkbench

      @Nonnull public SlimefunItem setUseableInWorkbench(boolean useable)
      This sets whether or not this SlimefunItem is allowed to be used in a normal Crafting Table.
      Parameters:
      useable - Whether this SlimefunItem should 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 provided ItemStack represents this SlimefunItem.
      Parameters:
      item - The ItemStack to compare
      Returns:
      Whether the given ItemStack represents this SlimefunItem
    • load

      public void load()
      This method is used for internal purposes only.
    • addItemHandler

      public final void addItemHandler(ItemHandler... handlers)
      This method will add any given ItemHandler to this SlimefunItem. Note that this will not work after the SlimefunItem was registered.
      Parameters:
      handlers - Any ItemHandler that should be added to this SlimefunItem
    • addItemSetting

      public final void addItemSetting(ItemSetting<?>... settings)
      This method will add any given ItemSetting to this SlimefunItem. Note that this will not work after the SlimefunItem was registered.
      Parameters:
      settings - Any ItemSetting that should be added to this SlimefunItem
    • preRegister

      public void preRegister()
      This method is called before register(SlimefunAddon). Override this method to add any additional setup, adding an ItemHandler for example.
    • postRegister

      public void postRegister()
      This method is called after register(SlimefunAddon). Override this method to add any additional setup that needs to happen after the original registration of this SlimefunItem.
    • addOfficialWikipage

      @Deprecated public final void addOfficialWikipage(@Nonnull String page)
      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

      public final void addWikiPage(@Nonnull String page)
      指定该物品的 Wiki 页面
      Parameters:
      page - 物品的 Wiki 页面
    • getWikipage

      @Nonnull public Optional<String> 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

      @Nonnull public final String getItemName()
      This method will return this Item's Name (The name that is displayed when hovering over this ItemStack in an Inventory).
      Returns:
      This item's name in ItemStack form
    • getHandlers

      @Nonnull public Collection<ItemHandler> 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 every ItemHandler of the given Class and performs the action as specified via the Consumer.
      Type Parameters:
      T - The type of ItemHandler to call.
      Parameters:
      c - The Class of the ItemHandler to call.
      callable - A Consumer that is called for any found ItemHandler.
      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

      public String toString()
      Overrides:
      toString in class Object
    • getDrops

      @Nonnull public Collection<org.bukkit.inventory.ItemStack> getDrops()
      Specified by:
      getDrops in interface Placeable
    • getDrops

      @Nonnull public Collection<org.bukkit.inventory.ItemStack> getDrops(org.bukkit.entity.Player p)
      Specified by:
      getDrops in interface Placeable
    • info

      @ParametersAreNonnullByDefault public void info(String message)
      This will send an info message to the console and signal that this message came from this SlimefunItem, the message will be sent using the Logger of the SlimefunAddon which registered this SlimefunItem.
      Parameters:
      message - The message to send
    • warn

      @ParametersAreNonnullByDefault public void warn(String message)
      This will send a warning to the console and signal that this warning came from this SlimefunItem, the warning will be sent using the Logger of the SlimefunAddon which registered this SlimefunItem.
      Parameters:
      message - The message to send
    • error

      @ParametersAreNonnullByDefault public void error(String message, Throwable throwable)
      This will throw a Throwable to the console and signal that this was caused by this SlimefunItem.
      Parameters:
      message - The message to display alongside this Stacktrace
      throwable - The Throwable to throw as a stacktrace.
    • sendDeprecationWarning

      @ParametersAreNonnullByDefault public void sendDeprecationWarning(org.bukkit.entity.Player player)
      This method informs the given Player that this SlimefunItem will be removed soon.
      Parameters:
      player - The Player to inform.
    • canUse

      public boolean canUse(@Nonnull org.bukkit.entity.Player p, boolean sendMessage)
      This method checks if the given Player is able to use this SlimefunItem. A Player can use it if the following conditions apply:
      • The SlimefunItem is not disabled
      • The SlimefunItem was not disabled for that Player's World.
      • The Player has the required Permission (if present)
      • The Player has unlocked the required Research (if present)
      If any of these conditions evaluate to false, then an optional message will be sent to the Player.
      Parameters:
      p - The Player to check
      sendMessage - Whether to send that Player a message response.
      Returns:
      Whether this Player is able to use this SlimefunItem.
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • getById

      @Nullable public static SlimefunItem getById(@Nonnull String id)
      Retrieve a SlimefunItem by its id.
      Parameters:
      id - The id of the SlimefunItem
      Returns:
      The SlimefunItem associated with that id. Null if non-existent
    • getOptionalById

      @Nonnull public static Optional<SlimefunItem> getOptionalById(@Nonnull String id)
      Retrieve a Optional SlimefunItem by its id.
      Parameters:
      id - The id of the SlimefunItem
      Returns:
      The Optional SlimefunItem associated with that id. Empty if non-existent
    • getByItem

      @Nullable public static SlimefunItem getByItem(@Nullable org.bukkit.inventory.ItemStack item)
      Retrieve a SlimefunItem from an ItemStack.
      Parameters:
      item - The ItemStack to check
      Returns:
      The SlimefunItem associated with this ItemStack if present, otherwise null
    • getOptionalByItem

      @Nonnull public static Optional<SlimefunItem> getOptionalByItem(@Nullable org.bukkit.inventory.ItemStack item)
      Retrieve a Optional SlimefunItem from an ItemStack.
      Parameters:
      item - The ItemStack to check
      Returns:
      The Optional SlimefunItem associated with this ItemStack if present, otherwise empty
    • loadDataByDefault

      public boolean loadDataByDefault()
      Should load the SlimefunBlockData by default. If return false, only the item with BlockTicker will be loaded with ChunkLoadEvent.
      Returns:
      true if the data should be loaded by default, false otherwise