Interface ItemEntity

All Superinterfaces:
Entity, HoverEventSource<HoverEvent.ShowEntity>, SchedulerSource, Sound.Emitter, Sound.Source.Provider

public interface ItemEntity extends Entity
A stack of items lying on the ground (minecraft:item), dropped by a player, thrown out of a window or spilled by a block.

It falls, slides, merges with similar stacks nearby and despawns after 6000 ticks. Once its pickup delay is over, the first player who walks over it takes as much of it as fits in their inventory.

Like every entity, change it from the region thread owning its chunk.

Since:
0.1.0
See Also:
  • Field Details

    • DEFAULT_LIFETIME

      static final int DEFAULT_LIFETIME
      How many ticks an item stays on the ground before it despawns: five minutes.
      Since:
      0.1.0
      See Also:
    • INFINITE_PICKUP_DELAY

      static final int INFINITE_PICKUP_DELAY
      A pickup delay that never runs out: nobody can pick the item up, and it never merges with another one.
      Since:
      0.1.0
      See Also:
    • THROWN_PICKUP_DELAY

      static final int THROWN_PICKUP_DELAY
      The pickup delay of an item a player throws away, so that it does not land straight back in their inventory: two seconds.
      Since:
      0.1.0
      See Also:
    • DEFAULT_PICKUP_DELAY

      static final int DEFAULT_PICKUP_DELAY
      The pickup delay of an item spilled by a block or a window: half a second.
      Since:
      0.1.0
      See Also:
  • Method Details

    • item

      ItemStack item()
      Returns the stack this entity carries, never empty while the entity is alive.
      Returns:
      the stack this entity carries, never empty while the entity is alive
      Since:
      0.1.0
    • setItem

      void setItem(ItemStack item)
      Replaces the stack this entity carries. An empty stack removes the entity.
      Parameters:
      item - the new stack
      Since:
      0.1.0
    • pickupDelay

      int pickupDelay()
      Returns how many ticks are left before the item may be picked up, 0 when it may be picked up now.
      Returns:
      how many ticks are left before the item may be picked up, 0 when it may be picked up now
      Since:
      0.1.0
    • setPickupDelay

      void setPickupDelay(int ticks)
      Sets how many ticks are left before the item may be picked up.
      Parameters:
      ticks - the delay, 0 for right away, INFINITE_PICKUP_DELAY for never
      Since:
      0.1.0
    • age

      int age()
      Returns how many ticks this item has been on the ground.
      Returns:
      how many ticks this item has been on the ground
      Since:
      0.1.0
    • setAge

      void setAge(int ticks)
      Sets how many ticks this item has been on the ground: it despawns once this reaches 6000, unless its lifetime is unlimited.
      Parameters:
      ticks - the age
      Since:
      0.1.0
    • hasUnlimitedLifetime

      boolean hasUnlimitedLifetime()
      Returns whether this item stays on the ground forever.
      Returns:
      whether this item stays on the ground forever
      Since:
      0.1.0
    • setUnlimitedLifetime

      void setUnlimitedLifetime(boolean unlimited)
      Sets whether this item stays on the ground forever instead of despawning after 6000 ticks.
      Parameters:
      unlimited - true to keep the item forever
      Since:
      0.1.0
    • owner

      @Nullable UUID owner()
      Returns the only player allowed to pick this item up, null when anybody may.
      Returns:
      the only player allowed to pick this item up, null when anybody may
      Since:
      0.1.0
    • setOwner

      void setOwner(@Nullable UUID owner)
      Restricts who may pick this item up.
      Parameters:
      owner - the only player allowed to, null to let anybody
      Since:
      0.1.0
    • thrower

      @Nullable UUID thrower()
      Returns the entity that dropped or threw this item, null when unknown.
      Returns:
      the entity that dropped or threw this item, null when unknown
      Since:
      0.1.0
    • setThrower

      void setThrower(@Nullable UUID thrower)
      Sets the entity that dropped or threw this item.
      Parameters:
      thrower - its UUID, null when unknown
      Since:
      0.1.0
    • velocityX

      double velocityX()
      Returns the velocity along x, in blocks per tick.
      Returns:
      the velocity along x, in blocks per tick
      Since:
      0.1.0
    • velocityY

      double velocityY()
      Returns the velocity along y, in blocks per tick, positive upwards.
      Returns:
      the velocity along y, in blocks per tick, positive upwards
      Since:
      0.1.0
    • velocityZ

      double velocityZ()
      Returns the velocity along z, in blocks per tick.
      Returns:
      the velocity along z, in blocks per tick
      Since:
      0.1.0
    • setVelocity

      void setVelocity(double x, double y, double z)
      Overwrites the velocity, in blocks per tick.
      Parameters:
      x - the velocity along x
      y - the velocity along y, positive upwards
      z - the velocity along z
      Since:
      0.1.0
    • onGround

      boolean onGround()
      Returns whether the item rests on a block.
      Returns:
      whether the item rests on a block
      Since:
      0.1.0