Class ItemEntity

java.lang.Object
All Implemented Interfaces:
DataContainer, EventHandler, PermissionHandler, Viewable

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

  • Method Details

    • getMergeUpdateOption

      @Nullable public static UpdateOption getMergeUpdateOption()
      Gets the update option for the merging feature.
      Returns:
      the merge update option
    • setMergeUpdateOption

      public static void setMergeUpdateOption​(@Nullable UpdateOption mergeUpdateOption)
      Changes the merge update option. Can be set to null to entirely remove the delay.
      Parameters:
      mergeUpdateOption - the new merge update option
    • update

      public void update​(long time)
      Description copied from class: Entity
      Called each tick.
      Overrides:
      update in class ObjectEntity
      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 ObjectEntity
    • getMetadataConsumer

      @NotNull public java.util.function.Consumer<BinaryWriter> getMetadataConsumer()
      Description copied from class: Entity
      Should be override when wanting to add a new metadata index
      Overrides:
      getMetadataConsumer in class Entity
      Returns:
      The consumer used to write EntityMetaDataPacket in Entity.getMetadataPacket()
    • fillMetadataIndex

      protected void fillMetadataIndex​(@NotNull BinaryWriter packet, int index)
      Description copied from class: Entity
      Used to fill/write a specific metadata index. The proper use to add a new metadata index is to override this and add your case. Then you can also override Entity.getMetadataConsumer() and fill your newly added index.
      Overrides:
      fillMetadataIndex in class Entity
      Parameters:
      packet - the packet writer
      index - the index to fill/write
    • getObjectData

      public int getObjectData()
      Description copied from class: ObjectEntity
      Gets the data of this object entity.
      Specified by:
      getObjectData in class ObjectEntity
      Returns:
      an object data
      See Also:
      here
    • 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 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(long, TimeUnit).
      Returns:
      the pickup delay
    • setPickupDelay

      public void setPickupDelay​(long delay, @NotNull TimeUnit timeUnit)
      Sets the pickup delay of the ItemEntity.
      Parameters:
      delay - the pickup delay
      timeUnit - the unit of the delay
    • getSpawnTime

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