Class ItemEntity

java.lang.Object
net.minestom.server.entity.Entity
net.minestom.server.entity.ItemEntity
All Implemented Interfaces:
Identified, Pointered, Sound.Emitter, HoverEventSource<HoverEvent.ShowEntity>, Shape, DataComponent.Holder, EventHandler<EntityEvent>, Snapshotable, Taggable, TagReadable, TagWritable, AcquirableSource<Entity>, Tickable, Schedulable, Viewable

public class ItemEntity extends Entity
Represents an item on the ground.
  • Constructor Details

    • ItemEntity

      public ItemEntity(ItemStack itemStack)
  • Method Details

    • getMergeDelay

      @Nullable public static @Nullable Duration getMergeDelay()
      Gets the update option for the merging feature.
      Returns:
      the merge update option
    • setMergeDelay

      public static void setMergeDelay(@Nullable @Nullable Duration delay)
      Changes the merge delay. Can be set to null to entirely remove the delay.
      Parameters:
      delay - the new merge delay
    • update

      public void update(long time)
      Description copied from class: Entity
      Called each tick.
      Overrides:
      update in class Entity
      Parameters:
      time - time of the update in milliseconds. This may only be used as a delta and has no meaning in the real world
    • movementTick

      public void movementTick()
      Overrides:
      movementTick in class Entity
    • spawn

      public void spawn()
      Description copied from class: Entity
      Called when a new instance is set.
      Overrides:
      spawn in class Entity
    • getEntityMeta

      public ItemEntityMeta getEntityMeta()
      Description copied from class: Entity
      Gets metadata of this entity. You may want to cast it to specific implementation.
      Overrides:
      getEntityMeta in class Entity
      Returns:
      metadata of this entity.
    • getItemStack

      public ItemStack getItemStack()
      Gets the item stack on ground.
      Returns:
      the item stack
    • setItemStack

      public void setItemStack(ItemStack itemStack)
      Changes the item stack on ground.
      Parameters:
      itemStack - the item stack
    • isPickable

      public boolean isPickable()
      Gets if the item is currently pickable.

      setPickable(boolean) needs to be true, the delay getPickupDelay() to be long gone, and the item must not have been removed.

      Returns:
      true if the item is pickable, false otherwise
    • setPickable

      public void setPickable(boolean pickable)
      Makes the item pickable.
      Parameters:
      pickable - true to make the item pickable, false otherwise
    • isMergeable

      public boolean isMergeable()
      Gets if the item is mergeable.
      Returns:
      true if the entity is mergeable, false otherwise
    • setMergeable

      public void setMergeable(boolean mergeable)
      When set to true, close ItemEntity will try to merge together as a single entity when their getItemStack() is similar and allowed to stack together.
      Parameters:
      mergeable - should the entity merge with other ItemEntity
    • getMergeRange

      public float getMergeRange()
      Gets the merge range.
      Returns:
      the merge range
    • setMergeRange

      public void setMergeRange(float mergeRange)
      Changes the merge range.
      Parameters:
      mergeRange - the merge range
    • getPickupDelay

      public long getPickupDelay()
      Gets the pickup delay in milliseconds, defined by setPickupDelay(Duration).
      Returns:
      the pickup delay
    • setPickupDelay

      public void setPickupDelay(long delay, TemporalUnit temporalUnit)
      Sets the pickup delay of the ItemEntity.
      Parameters:
      delay - the pickup delay
      temporalUnit - the unit of the delay
    • setPickupDelay

      public void setPickupDelay(Duration delay)
      Sets the pickup delay of the ItemEntity.
      Parameters:
      delay - the pickup delay
    • getTimeSinceSpawn

      public long getTimeSinceSpawn()
      Used to know if the ItemEntity can be picked up.
      Returns:
      the elapsed time in milliseconds since this entity has spawned
    • acquirable

      @Experimental public Acquirable<? extends ItemEntity> acquirable()
      Description copied from interface: AcquirableSource
      Obtains an Acquirable. To safely perform operations on this object, the user must call Acquirable.sync(Consumer), Acquirable.applySync(Function), or Acquirable.lock() (followed by a subsequent unlock) on the Acquirable instance.
      Specified by:
      acquirable in interface AcquirableSource<Entity>
      Overrides:
      acquirable in class Entity
      Returns:
      an Acquirable which can be used to synchronize access to this object