Class ItemUtils

java.lang.Object
com.hypixel.hytale.server.core.entity.ItemUtils

public class ItemUtils extends Object
A utility class that contains a variety of useful item-related functionalities and utilities.
  • Field Details

  • Constructor Details

    • ItemUtils

      public ItemUtils()
  • Method Details

    • interactivelyPickupItem

      public static void interactivelyPickupItem(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, @Nullable org.joml.Vector3d origin, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to attempt to pick up the given item stack
      Parameters:
      ref - The entity reference of the instigating entity.
      itemStack - The ItemStack instance to attempt to pick up.
      origin - The origin position from which the item is being picked up, can be null.
      componentAccessor - The ComponentAccessor for component access.
    • throwItem

      @Nullable public static Ref<EntityStore> throwItem(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, float throwSpeed, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to create a new item drop instance, based on the provided ItemStack, which spawns into the world, with the applied velocity towards the given direction

      This specific method uses the current rotation of the living entity as the direction

      Parameters:
      ref - The entity reference of the instigating entity.
      itemStack - The itemStack that we want to throw
      throwSpeed - The speed at which to throw the item
      componentAccessor - The ComponentAccessor for component access.
      Returns:
      the newly created thrown item entity instance, if successful
    • throwItem

      @Nullable public static Ref<EntityStore> throwItem(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> store, @Nonnull ItemStack itemStack, @Nonnull org.joml.Vector3d throwDirection, float throwSpeed)
      Called to create a new item drop instance, based on the provided ItemStack, which spawns into the world, with the applied velocity towards the given direction
      Parameters:
      ref - The entity reference of the instigating entity.
      store - The component accessor for components
      itemStack - The itemStack that we want to throw
      throwDirection - The direction we want the velocity to be in
      throwSpeed - The speed at which to throw the item
      Returns:
      the newly created thrown item entity instance, if successful
    • dropItem

      @Nullable public static Ref<EntityStore> dropItem(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to attempt to drop the given item stack to the ground, with a subtle amount of force applied
      Parameters:
      ref - The entity reference of the entity dropping the item.
      itemStack - The ItemStack instance to drop.
      componentAccessor - The ComponentAccessor for component access.
      Returns:
      the newly created dropped item entity instance, if successful.
    • canDecreaseItemStackDurability

      public static boolean canDecreaseItemStackDurability(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> accessor)
      Returns whether durability can be decreased for items held by the given entity.

      Players in Creative mode cannot decrease durability; non-player entities cannot decrease durability at all.

      Parameters:
      ref - The entity reference.
      accessor - The ComponentAccessor for component access.
      Returns:
      true if durability can be decreased, false otherwise.
    • canApplyItemStackPenalties

      public static boolean canApplyItemStackPenalties(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> accessor)
      Returns whether broken-item penalties should be applied for the given entity.

      Players in Creative mode do not receive penalties; all other entities do.

      Parameters:
      ref - The entity reference.
      accessor - The ComponentAccessor for component access.
      Returns:
      true if penalties should be applied, false otherwise.
    • updateItemStackDurability

      @Nonnull public static ItemStackSlotTransaction updateItemStackDurability(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, ItemContainer container, int slotId, double durabilityChange, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Updates the durability of an item stack in a container slot.
      Parameters:
      ref - The entity reference.
      itemStack - The item stack to update.
      container - The container holding the item.
      slotId - The slot ID within the container.
      durabilityChange - The amount to change durability by (negative to decrease).
      componentAccessor - The ComponentAccessor for component access.
      Returns:
      the resulting ItemStackSlotTransaction. The transaction fails, and the slot is left untouched, when the slot does not hold itemStack.
    • decreaseItemStackDurability

      @Nullable public static ItemStackSlotTransaction decreaseItemStackDurability(@Nonnull Ref<EntityStore> ref, @Nullable ItemStack itemStack, int inventoryId, int slotId, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Decreases the durability of an item stack if possible, applying penalties if the item breaks.
      Parameters:
      ref - The entity reference.
      itemStack - The item stack to decrease durability of.
      inventoryId - The ID of the inventory containing the item stack.
      slotId - The slot ID of the item stack within the inventory.
      componentAccessor - The ComponentAccessor for component access.
      Returns:
      the resulting ItemStackSlotTransaction if durability was decreased, or null if durability could not be decreased.