Class SlimefunUtils

java.lang.Object
io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils

public final class SlimefunUtils extends Object
This utility class holds method that are directly linked to Slimefun. It provides a very crucial method for ItemStack comparison, as well as a simple method to check if an ItemStack is Soulbound or not.
Author:
TheBusyBiscuit, Walshy, Sfiguz7
  • Method Details

    • hasNoPickupFlag

      public static boolean hasNoPickupFlag(@Nonnull Item item)
      This method quickly returns whether an Item was marked as "no_pickup" by a Slimefun device.
      Parameters:
      item - The Item to query
      Returns:
      Whether the Item is excluded from being picked up
    • markAsNoPickup

      public static void markAsNoPickup(@Nonnull Item item, @Nonnull String context)
      This will prevent the given Item from being picked up. This is useful for display items which the AncientPedestal uses.
      Parameters:
      item - The Item to prevent from being picked up
      context - The context in which this Item was flagged
    • isSoulbound

      public static boolean isSoulbound(@Nullable ItemStack item)
      This method checks whether the given ItemStack is considered Soulbound.
      Parameters:
      item - The ItemStack to check for
      Returns:
      Whether the given item is soulbound
    • isSoulbound

      public static boolean isSoulbound(@Nullable ItemStack item, @Nullable World world)
      This method checks whether the given ItemStack is considered Soulbound. If the provided item is a SlimefunItem then this method will also check that the item is enabled in the provided World. If the provided item is Soulbound through the SlimefunItems.SOULBOUND_RUNE, then this method will also check that the SlimefunItems.SOULBOUND_RUNE is enabled in the provided World
      Parameters:
      item - The ItemStack to check for
      world - The World to check if the SlimefunItem is enabled in if applicable. If null then this will not do a world check.
      Returns:
      Whether the given item is soulbound
    • setSoulbound

      public static void setSoulbound(@Nullable ItemStack item, boolean makeSoulbound)
      Toggles an ItemStack to be Soulbound.
      If true is passed, this will add the SOULBOUND_LORE and add a NamespacedKey to the item so it can be quickly identified by isSoulbound(ItemStack).
      If false is passed, this property will be removed.
      Parameters:
      item - The ItemStack you want to add/remove Soulbound from.
      makeSoulbound - If the item should be soulbound.
      See Also:
    • isRadioactive

      public static boolean isRadioactive(@Nullable ItemStack item)
      This method checks whether the given ItemStack is radioactive.
      Parameters:
      item - The ItemStack to check
      Returns:
      Whether this ItemStack is radioactive or not
    • getCustomHead

      @Nonnull public static ItemStack getCustomHead(@Nonnull String texture)
      This method returns an ItemStack for the given texture. The result will be a Player Head with this texture.
      Parameters:
      texture - The texture for this head (base64 or hash)
      Returns:
      An ItemStack with this Head texture
    • containsSimilarItem

      public static boolean containsSimilarItem(Inventory inventory, ItemStack item, boolean checkLore)
    • isItemSimilar

      public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore)
      Compares two ItemStacks and returns if they are similar or not. Takes into account some shortcut checks specific to SlimefunItems for performance. Will check for distintion of items by default and will also confirm the amount is the same.
      Parameters:
      item - The ItemStack being tested.
      sfitem - The ItemStack that is being compared against.
      checkLore - Whether to include the current lore of either item in the comparison
      Returns:
      True if the given ItemStacks are similar under the given constraints
      See Also:
    • isItemSimilar

      public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount)
      Compares two ItemStacks and returns if they are similar or not. Takes into account some shortcut checks specific to SlimefunItems for performance. Will check for distintion of items by default
      Parameters:
      item - The ItemStack being tested.
      sfitem - The ItemStack that is being compared against.
      checkLore - Whether to include the current lore of either item in the comparison
      checkAmount - Whether to include the item's amount(s) in the comparison
      Returns:
      True if the given ItemStacks are similar under the given constraints
      See Also:
    • isItemSimilar

      public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount, boolean checkDistinction)
      Compares two ItemStacks and returns if they are similar or not. Takes into account some shortcut checks specific to SlimefunItems for performance.
      Parameters:
      item - The ItemStack being tested.
      sfitem - The ItemStack that is being compared against.
      checkLore - Whether to include the current lore of either item in the comparison
      checkAmount - Whether to include the item's amount(s) in the comparison
      checkDistinction - Whether to check for special distinctive properties of the items.
      Returns:
      True if the given ItemStacks are similar under the given constraints
      See Also:
    • equalsLore

      public static boolean equalsLore(@Nonnull List<String> lore1, @Nonnull List<String> lore2)
      This checks if the two provided lores are equal. This method will ignore any lines such as the soulbound one.
      Parameters:
      lore1 - The first lore
      lore2 - The second lore
      Returns:
      Whether the two lores are equal
    • updateCapacitorTexture

      public static void updateCapacitorTexture(@Nonnull Location l, int charge, int capacity)
    • canPlayerUseItem

      public static boolean canPlayerUseItem(@Nonnull Player p, @Nullable ItemStack item, boolean sendMessage)
      This checks whether the Player is able to use the given ItemStack. It will always return true for non-Slimefun items.

      If you already have an instance of SlimefunItem, please use SlimefunItem.canUse(Player, boolean).

      Parameters:
      p - The Player
      item - The ItemStack to check
      sendMessage - Whether to send a message response to the Player
      Returns:
      Whether the Player is able to use that item.
    • spawnItem

      @ParametersAreNonnullByDefault @Nullable public static Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset, @Nullable Player player)
      Helper method to spawn an ItemStack. This method automatically calls a SlimefunItemSpawnEvent to allow other plugins to catch the item being dropped.
      Parameters:
      loc - The Location where to drop the item
      item - The ItemStack to drop
      reason - The ItemSpawnReason why the item is being dropped
      addRandomOffset - Whether a random offset should be added (see World.dropItemNaturally(Location, ItemStack))
      player - The player that caused this SlimefunItemSpawnEvent
      Returns:
      The dropped Item (or null if the SlimefunItemSpawnEvent was cancelled)
    • spawnItem

      @ParametersAreNonnullByDefault @Nullable public static Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason, boolean addRandomOffset)
      Helper method to spawn an ItemStack. This method automatically calls a SlimefunItemSpawnEvent to allow other plugins to catch the item being dropped.
      Parameters:
      loc - The Location where to drop the item
      item - The ItemStack to drop
      reason - The ItemSpawnReason why the item is being dropped
      addRandomOffset - Whether a random offset should be added (see World.dropItemNaturally(Location, ItemStack))
      Returns:
      The dropped Item (or null if the SlimefunItemSpawnEvent was cancelled)
    • spawnItem

      @ParametersAreNonnullByDefault @Nullable public static Item spawnItem(Location loc, ItemStack item, ItemSpawnReason reason)
      Helper method to spawn an ItemStack. This method automatically calls a SlimefunItemSpawnEvent to allow other plugins to catch the item being dropped.
      Parameters:
      loc - The Location where to drop the item
      item - The ItemStack to drop
      reason - The ItemSpawnReason why the item is being dropped
      Returns:
      The dropped Item (or null if the SlimefunItemSpawnEvent was cancelled)
    • isInventoryEmpty

      public static boolean isInventoryEmpty(@Nonnull Inventory inventory)
      Helper method to check if an Inventory is empty (has no items in "storage"). If the MC version is 1.16 or above this will call Inventory.isEmpty() (Which calls MC code resulting in a faster method).
      Parameters:
      inventory - The Inventory to check.
      Returns:
      True if the inventory is empty and false otherwise