Package net.minestom.server.entity
Class ItemEntity
java.lang.Object
net.minestom.server.entity.Entity
net.minestom.server.entity.ObjectEntity
net.minestom.server.entity.ItemEntity
- All Implemented Interfaces:
DataContainer
,EventHandler
,PermissionHandler
,Viewable
public class ItemEntity extends ObjectEntity
Represents an item on the ground.
-
Field Summary
Fields inherited from class net.minestom.server.entity.Entity
air, cachePitch, cacheX, cacheY, cacheYaw, cacheZ, crouched, customName, customNameVisible, eyeHeight, glowing, gravityDragPerTick, instance, invisible, lastPitch, lastVelocityUpdateTime, lastX, lastY, lastYaw, lastZ, METADATA_BOOLEAN, METADATA_BYTE, METADATA_CHAT, METADATA_FLOAT, METADATA_OPTCHAT, METADATA_PARTICLE, METADATA_POSE, METADATA_POSITION, METADATA_ROTATION, METADATA_SLOT, METADATA_STRING, METADATA_VARINT, nextTick, noGravity, onFire, onGround, pose, position, silent, sprinting, swimming, UNUSED_METADATA, usingElytra, uuid, vehicle, velocity, viewers
-
Constructor Summary
Constructors Constructor Description ItemEntity(ItemStack itemStack, Position spawnPosition)
ItemEntity(ItemStack itemStack, Position spawnPosition, Instance instance)
-
Method Summary
Modifier and Type Method Description protected void
fillMetadataIndex(BinaryWriter packet, int index)
Used to fill/write a specific metadata index.ItemStack
getItemStack()
Gets the item stack on ground.float
getMergeRange()
Gets the merge range.static UpdateOption
getMergeUpdateOption()
Gets the update option for the merging feature.java.util.function.Consumer<BinaryWriter>
getMetadataConsumer()
Should be override when wanting to add a new metadata indexint
getObjectData()
Gets the data of this object entity.long
getPickupDelay()
Gets the pickup delay in milliseconds, defined bysetPickupDelay(long, TimeUnit)
.long
getSpawnTime()
Used to know if the ItemEntity can be pickup.boolean
isMergeable()
Gets if the item is mergeable.boolean
isPickable()
Gets if the item is currently pickable.void
setItemStack(ItemStack itemStack)
Changes the item stack on ground.void
setMergeable(boolean mergeable)
When set to true, closeItemEntity
will try to merge together as a single entity when theirgetItemStack()
is similar and allowed to stack together.void
setMergeRange(float mergeRange)
Changes the merge range.static void
setMergeUpdateOption(UpdateOption mergeUpdateOption)
Changes the merge update option.void
setPickable(boolean pickable)
Makes the item pickable.void
setPickupDelay(long delay, TimeUnit timeUnit)
Sets the pickup delay of the ItemEntity.void
spawn()
Called when a new instance is set.void
update(long time)
Called each tick.Methods inherited from class net.minestom.server.entity.Entity
addPassenger, askSynchronization, callEvent, getAliveTicks, getAllPermissions, getBoundingBox, getChunk, getCustomName, getData, getDistance, getEntity, getEntityId, getEntityType, getEventCallbacksMap, getEyeHeight, getInstance, getMetadataPacket, getPassengers, getPassengersPacket, getPosition, getUuid, getVehicle, getVelocity, getVelocityPacket, getVelocityUpdatePeriod, getViewers, handleVoid, hasNoGravity, hasPassenger, hasVelocity, isActive, isAutoViewable, isCustomNameVisible, isGlowing, isInvisible, isOnFire, isOnGround, isRemoved, isRemoveScheduled, isSilent, refreshPosition, refreshPosition, refreshView, remove, removePassenger, removeViewer, sameChunk, sameChunk, scheduleNextTick, scheduleRemove, sendMetadataIndex, sendSynchronization, sendVelocityPacket, setAutoViewable, setBoundingBox, setCustomName, setCustomNameVisible, setData, setEyeHeight, setGlowing, setGravity, setInstance, setInvisible, setNoGravity, setOnFire, setSilent, setSneaking, setSprinting, setUuid, setVelocity, setVelocityUpdatePeriod, setView, setView, shouldRemove, shouldSendVelocityUpdate, teleport, teleport, tick, triggerStatus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minestom.server.event.handler.EventHandler
addEventCallback, callCancellableEvent, getEventCallbacks, getEventCallbacks, removeEventCallback
Methods inherited from interface net.minestom.server.permission.PermissionHandler
addPermission, hasPermission, hasPermission, hasPermission, hasPermission, removePermission
Methods inherited from interface net.minestom.server.Viewable
isViewer, sendPacketsToViewers, sendPacketToViewers, sendPacketToViewersAndSelf
-
Constructor Details
-
Method Details
-
getMergeUpdateOption
Gets the update option for the merging feature.- Returns:
- the merge update option
-
setMergeUpdateOption
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 classObjectEntity
- 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 classObjectEntity
-
getMetadataConsumer
Description copied from class:Entity
Should be override when wanting to add a new metadata index- Overrides:
getMetadataConsumer
in classEntity
- Returns:
- The consumer used to write
EntityMetaDataPacket
inEntity.getMetadataPacket()
-
fillMetadataIndex
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 overrideEntity.getMetadataConsumer()
and fill your newly added index.- Overrides:
fillMetadataIndex
in classEntity
- Parameters:
packet
- the packet writerindex
- 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 classObjectEntity
- Returns:
- an object data
- See Also:
- here
-
getItemStack
Gets the item stack on ground.- Returns:
- the item stack
-
setItemStack
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 delaygetPickupDelay()
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, closeItemEntity
will try to merge together as a single entity when theirgetItemStack()
is similar and allowed to stack together.- Parameters:
mergeable
- should the entity merge with otherItemEntity
-
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 bysetPickupDelay(long, TimeUnit)
.- Returns:
- the pickup delay
-
setPickupDelay
Sets the pickup delay of the ItemEntity.- Parameters:
delay
- the pickup delaytimeUnit
- 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
-