Class ItemEntity

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

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

    • ItemEntity

      public ItemEntity(@NotNull @NotNull 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
    • spawn

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

      @NotNull public @NotNull 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

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

      public void setItemStack(@NotNull @NotNull 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 and the delay getPickupDelay() to be long gone.

      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, @NotNull @NotNull 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
    • getSpawnTime

      public long getSpawnTime()
      Used to know if the ItemEntity can be pickup.
      Returns:
      the time in milliseconds since this entity has spawn