Class ItemComponent

java.lang.Object
com.hypixel.hytale.server.core.modules.entity.item.ItemComponent
All Implemented Interfaces:
Component<EntityStore>, Cloneable

public class ItemComponent extends Object implements Component<EntityStore>
A component that represents an entity that has an affiliated item stack.
  • Field Details

    • CODEC

      @Nonnull public static final BuilderCodec<ItemComponent> CODEC
      The codec used to parse ItemComponent instances.
    • DEFAULT_PICKUP_DELAY

      public static final float DEFAULT_PICKUP_DELAY
      The default pickup delay, in seconds, for picking up items.
      See Also:
    • PICKUP_DELAY_DROPPED

      public static final float PICKUP_DELAY_DROPPED
      The pickup delay, in seconds, for items that are dropped.
      See Also:
    • PICKUP_THROTTLE

      public static final float PICKUP_THROTTLE
      The default delay, in seconds for pickup throttle.
      See Also:
    • DEFAULT_MERGE_DELAY

      public static final float DEFAULT_MERGE_DELAY
      The default delay, in seconds, between attempting to merge with nearby stacks.
      See Also:
  • Constructor Details

    • ItemComponent

      public ItemComponent()
      Default Constructor for a ItemComponent instance.
    • ItemComponent

      public ItemComponent(@Nullable ItemStack itemStack)
      Constructor for a ItemComponent instance with a default item stack value.
      Parameters:
      itemStack - The ItemStack instance for this item component.
    • ItemComponent

      public ItemComponent(@Nullable ItemStack itemStack, float mergeDelay, float pickupDelay, float pickupThrottle, boolean removedByPlayerPickup)
      Constructor for a ItemComponent instance with default parameters.
      Parameters:
      itemStack - The ItemStack instance for this item component.
      mergeDelay - The configured merge delay, in seconds.
      pickupDelay - The pickup delay, in seconds.
      pickupThrottle - The pickup throttle, in seconds.
      removedByPlayerPickup - Whether this item has been removed via player pickup.
  • Method Details

    • getComponentType

      @Nonnull public static ComponentType<EntityStore, ItemComponent> getComponentType()
      Returns:
      the ItemComponent component type.
    • getItemStack

      @Nullable public ItemStack getItemStack()
      Returns:
      the associated ItemStack instance, or null if none are set.
    • setItemStack

      public void setItemStack(@Nullable ItemStack itemStack)
      Called to manually set the ItemStack associated with this item component.
      Parameters:
      itemStack - The ItemStack instance to set, or null for no item stack.
    • setPickupDelay

      public void setPickupDelay(float pickupDelay)
      Called to manually set the pickup delay for this specific item component.
      Parameters:
      pickupDelay - The delay, in seconds, to set.
    • getPickupRadius

      public float getPickupRadius(@Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Fetches the pickup radius for this item component.
      Parameters:
      componentAccessor - The component store for component access.
      Returns:
      the pickup radius of this item component.
    • getMergeRadius

      public float getMergeRadius(@Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Fetches the merge radius for this item component.
      Parameters:
      componentAccessor - The component store for component access.
      Returns:
      the merge radius of this item component.
    • setMergeRadius

      public void setMergeRadius(float mergeRadius)
      Overrides the merge radius for this item component.

      Pass a negative value to clear the override. The next call to getMergeRadius(ComponentAccessor) then refetches the value from the item and world config.

      Parameters:
      mergeRadius - The merge radius to set.
    • computeLifetimeSeconds

      public float computeLifetimeSeconds(@Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Computes the lifetime of this item stack based on the config.
      Parameters:
      componentAccessor - The component store for component access.
      Returns:
      The time in seconds this item should live for or null to never despawn.
    • computeDynamicLight

      @Nullable public ColorLight computeDynamicLight()
      Called to compute the dynamic light value of this item component.
      Returns:
      the computed ColorLight value, if available.
    • pollPickupDelay

      public boolean pollPickupDelay(float dt)
      Called to poll the current pickup delay of this item component.
      Parameters:
      dt - The delta time of the current tick.
      Returns:
      true if the pickup throttle has concluded, false otherwise.
    • pollPickupThrottle

      public boolean pollPickupThrottle(float dt)
      Called to poll the current pickup throttle of this item component.
      Parameters:
      dt - The delta time of the current tick.
      Returns:
      true if the pickup throttle has concluded, false otherwise.
    • pollMergeDelay

      public boolean pollMergeDelay(float dt)
      Called to poll the current merge delay of this item component.
      Parameters:
      dt - The delta time of the current tick.
      Returns:
      true if the delay has concluded, false otherwise.
    • canPickUp

      public boolean canPickUp()
      Determines whether this item can be picked up.
      Returns:
      true if it can be picked up, false otherwise.
    • isRemovedByPlayerPickup

      public boolean isRemovedByPlayerPickup()
      Returns:
      true if the item was removed by player pickup, false otherwise.
    • setRemovedByPlayerPickup

      public void setRemovedByPlayerPickup(boolean removedByPlayerPickup)
      Called to set whether this item entity was removed due to player pickup.
      Parameters:
      removedByPlayerPickup - Whether this item entity was removed due to player pickup.
    • consumeNetworkOutdated

      public boolean consumeNetworkOutdated()
      Called to consume and return whether this item component is network outdated.
      Returns:
      true if outdated, false otherwise.
    • clone

      @Nonnull public ItemComponent clone()
      Specified by:
      clone in interface Component<EntityStore>
      Returns:
      a clone instance of the original component instance.

    • generateItemDrops

      @Nonnull public static Holder<EntityStore>[] generateItemDrops(@Nonnull ComponentAccessor<EntityStore> accessor, @Nonnull List<ItemStack> itemStacks, @Nonnull org.joml.Vector3d position, @Nonnull Rotation3fc rotation)
      Called to generate an array of entity item entity holders based on the provided item stacks.
      Parameters:
      accessor - The ComponentAccessor for entity store access.
      itemStacks - The collection of ItemStack instances to be dropped.
      position - The position to drop the item stacks around.
      rotation - The rotation of the dropped items.
      Returns:
      the array of entity holders for the newly created entity items.
    • generateItemDrop

      @Nullable public static Holder<EntityStore> generateItemDrop(@Nonnull ComponentAccessor<EntityStore> accessor, @Nullable ItemStack itemStack, @Nonnull org.joml.Vector3d position, @Nonnull Rotation3fc rotation, float velocityX, float velocityY, float velocityZ)
      Generates a single entity holder for an entity item based on the given item stack to be dropped.
      Parameters:
      accessor - The ComponentAccessor for entity store access.
      itemStack - The ItemStack instance that is to be dropped.
      position - The position to drop the item stack at.
      rotation - The rotation to be applied during the dropping.
      velocityX - The X velocity of the drop.
      velocityY - The Y velocity of the drop.
      velocityZ - The Z velocity of the drop.
      Returns:
      the newly created entity holder for the item entity.
    • generatePickedUpItem

      @Nullable public static Holder<EntityStore> generatePickedUpItem(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull Ref<EntityStore> targetRef, @Nonnull org.joml.Vector3d targetPosition)
      Creates a new pick-up item entity based on the holder of the given item entity.
      Parameters:
      ref - The entity reference of the original item entity.
      componentAccessor - The command buffer for component access.
      targetRef - The entity reference of the target entity.
      targetPosition - The position of the target entity.
      Returns:
      the entity store Holder of the pickup item entity.
    • generatePickedUpItem

      @Nonnull public static Holder<EntityStore> generatePickedUpItem(@Nonnull ItemStack itemStack, @Nonnull org.joml.Vector3d position, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull Ref<EntityStore> targetRef)
      Creates a new pick-up item entity based on the holder of the given item stack.
      Parameters:
      itemStack - The ItemStack instance to be picked up.
      position - The position to spawn the pick-up item entity at.
      componentAccessor - The command buffer for component access.
      targetRef - The entity reference of the target entity.
      Returns:
      the entity store Holder of the pickup item entity.
    • addToItemContainer

      @Nullable public static ItemStack addToItemContainer(@Nonnull Store<EntityStore> store, @Nonnull Ref<EntityStore> itemRef, @Nonnull ItemContainer itemContainer)
      Called to add the contents of the ItemStack of this component to the given containers.
      Parameters:
      store - The entity store for component access.
      itemRef - The ref of the item entity.
      itemContainer - The item containers to add to.
      Returns:
      the remaining ItemStack instance, or null if the full stack was consumed.