接口 Entity

所有超级接口:
CommandSender, Metadatable, Nameable, Permissible, PersistentDataHolder, ServerOperator
所有已知子接口:
AbstractArrow, AbstractHorse, AbstractSkeleton, AbstractVillager, AbstractWindCharge, Ageable, Allay, Ambient, Animals, AreaEffectCloud, Armadillo, ArmorStand, Arrow, Axolotl, Bat, Bee, Blaze, BlockDisplay, Boat, Bogged, Boss, Breedable, Breeze, BreezeWindCharge, Camel, Cat, CaveSpider, ChestBoat, ChestedHorse, Chicken, Cod, CommandMinecart, ComplexEntityPart, ComplexLivingEntity, Cow, Creature, Creeper, Damageable, Display, Dolphin, Donkey, DragonFireball, Drowned, Egg, ElderGuardian, EnderCrystal, EnderDragon, EnderDragonPart, Enderman, Endermite, EnderPearl, EnderSignal, Enemy, Evoker, EvokerFangs, ExperienceOrb, Explosive, ExplosiveMinecart, FallingBlock, Fireball, Firework, Fish, FishHook, Flying, Fox, Frog, Ghast, Giant, GlowItemFrame, GlowSquid, Goat, Golem, Guardian, Hanging, Hoglin, HopperMinecart, Horse, HumanEntity, Husk, Illager, Illusioner, Interaction, IronGolem, Item, ItemDisplay, ItemFrame, LargeFireball, LeashHitch, LightningStrike, LingeringPotion, LivingEntity, Llama, LlamaSpit, MagmaCube, Marker, Minecart, Mob, Monster, Mule, MushroomCow, NPC, Ocelot, OminousItemSpawner, Painting, Panda, Parrot, Phantom, Pig, Piglin, PiglinAbstract, PiglinBrute, PigZombie, Pillager, Player, PolarBear, PoweredMinecart, Projectile, PufferFish, Rabbit, Raider, Ravager, RideableMinecart, Salmon, Sheep, Shulker, ShulkerBullet, Silverfish, SizedFireball, Skeleton, SkeletonHorse, Slime, SmallFireball, Sniffer, Snowball, Snowman, SpawnerMinecart, SpectralArrow, Spellcaster, Spider, SplashPotion, Squid, Steerable, StorageMinecart, Stray, Strider, Tadpole, Tameable, TextDisplay, ThrowableProjectile, ThrownExpBottle, ThrownPotion, TippedArrow, TNTPrimed, TraderLlama, Trident, TropicalFish, Turtle, Vehicle, Vex, Villager, Vindicator, WanderingTrader, Warden, WaterMob, WindCharge, Witch, Wither, WitherSkeleton, WitherSkull, Wolf, Zoglin, Zombie, ZombieHorse, ZombieVillager

public interface Entity extends Metadatable, CommandSender, Nameable, PersistentDataHolder
表示世界中的基本实体.

isInWorld() 返回 false 时, 不保证所有方法都可用/或者有副作用.

原文: Represents a base entity in the world

Not all methods are guaranteed to work/may have side effects when isInWorld() is false.

  • 方法详细资料

    • getLocation

      @NotNull @NotNull Location getLocation()
      获取实体当前位置

      原文: Gets the entity's current position

      返回:
      一个新的 Location, 包含此实体的位置
    • getLocation

      @Contract("null -> null; !null -> !null") @Nullable @Nullable Location getLocation(@Nullable @Nullable Location loc)
      将实体的当前位置存储到提供的Location中.
      如果提供的Location为null,则此方法不会执行任何操作并返回null.

      原文: Stores the entity's current position in the provided Location object.

      If the provided Location is null this method does nothing and returns null.

      参数:
      loc - 要复制到的Location实例
      返回:
      提供的Location或null
    • setVelocity

      void setVelocity(@NotNull @NotNull Vector velocity)
      设置此实体的速度 (单位: 米每tick).

      原文: Sets this entity's velocity

      参数:
      velocity - 新的行进速度(向量)
    • getVelocity

      @NotNull @NotNull Vector getVelocity()
      获取此实体的速度.

      原文: Gets this entity's current velocity

      返回:
      实体当前行进速度(向量)
    • getHeight

      double getHeight()
      获取实体高度

      原文: Gets the entity's height

      返回:
      实体高度
    • getWidth

      double getWidth()
      获取实体宽度

      原文: Gets the entity's width

      返回:
      实体宽度
    • getBoundingBox

      @NotNull @NotNull BoundingBox getBoundingBox()
      Gets the entity's current bounding box.

      The returned bounding box reflects the entity's current location and size.

      返回:
      the entity's current bounding box
    • isOnGround

      boolean isOnGround()
      返回实体是否站在地面上.
      此值状态由服务器更新, 除非实体移动,否则不会重新计算.

      原文: Returns true if the entity is supported by a block. This value is a state updated by the server and is not recalculated unless the entity moves.

      返回:
      实体是否站在地上
      另请参阅:
    • isInWater

      boolean isInWater()
      返回实体是否在水中.

      原文: Returns true if the entity is in water.

      返回:
      实体是否在水中
    • getWorld

      @NotNull @NotNull World getWorld()
      获取实体当前所在的世界

      原文: Gets the current world this entity resides in

      返回:
      世界
    • setRotation

      void setRotation(float yaw, float pitch)
      Sets the entity's rotation.

      Note that if the entity is affected by AI, it may override this rotation.

      参数:
      yaw - the yaw
      pitch - the pitch
      抛出:
      UnsupportedOperationException - if used for players
    • teleport

      boolean teleport(@NotNull @NotNull Location location)
      将此实体传送到给定位置.
      如果该实体乘坐载具, 则在传送之前卸下载具.

      原文: Teleports this entity to the given location. If this entity is riding a vehicle, it will be dismounted prior to teleportation.

      参数:
      location - 此实体要传送到的新位置
      返回:
      是否传送成功
    • teleport

      将此实体传送到给定位置.
      如果该实体乘坐载具, 则在传送之前卸下载具.

      原文: Teleports this entity to the given location. If this entity is riding a vehicle, it will be dismounted prior to teleportation.

      参数:
      location - 此实体要传送到的新位置
      cause - 传送原因
      返回:
      是否传送成功
    • teleport

      boolean teleport(@NotNull @NotNull Entity destination)
      将此实体传送到目标实体.
      如果该实体乘坐载具, 则在传送之前离开载具.

      原文: Teleports this entity to the target Entity. If this entity is riding a vehicle, it will be dismounted prior to teleportation.

      参数:
      destination - 目标实体
      返回:
      是否传送成功
    • teleport

      将此实体传送到目标实体.
      如果该实体乘坐载具, 则在传送之前离开载具.

      原文: Teleports this entity to the given location. If this entity is riding a vehicle, it will be dismounted prior to teleportation.

      参数:
      destination - 目标实体
      cause - 传送原因
      返回:
      是否传送成功
    • getNearbyEntities

      @NotNull @NotNull List<Entity> getNearbyEntities(double x, double y, double z)
      返回以此实体为中心的边界框内的所有实体.

      原文: Returns a list of entities within a bounding box centered around this entity

      参数:
      x - 边界框X轴半径
      y - 边界框Y轴半径
      z - 边界框Z轴半径
      返回:
      List<Entity> 附近的实体列表
    • getEntityId

      int getEntityId()
      返回此实体的唯一ID

      原文: Returns a unique id for this entity

      返回:
      实体ID
    • getFireTicks

      int getFireTicks()
      返回实体当前着火的tick (还有多久停止着火)

      原文: Returns the entity's current fire ticks (ticks before the entity stops being on fire).

      返回:
      着火刻的数值
    • getMaxFireTicks

      int getMaxFireTicks()
      返回实体的最大着火刻

      原文: Returns the entity's maximum fire ticks.

      返回:
      最大着火刻的数值
    • setFireTicks

      void setFireTicks(int ticks)
      设置实体当前着火的tick (还有多久停止着火)

      原文: Sets the entity's current fire ticks (ticks before the entity stops being on fire).

      参数:
      ticks - 剩余的刻数
    • setVisualFire

      void setVisualFire(boolean fire)
      Sets if the entity has visual fire (it will always appear to be on fire).
      参数:
      fire - whether visual fire is enabled
    • isVisualFire

      boolean isVisualFire()
      Gets if the entity has visual fire (it will always appear to be on fire).
      返回:
      whether visual fire is enabled
    • getFreezeTicks

      int getFreezeTicks()
      Returns the entity's current freeze ticks (amount of ticks the entity has been in powdered snow).
      返回:
      int freeze ticks
    • getMaxFreezeTicks

      int getMaxFreezeTicks()
      Returns the entity's maximum freeze ticks (amount of ticks before it will be fully frozen)
      返回:
      int max freeze ticks
    • setFreezeTicks

      void setFreezeTicks(int ticks)
      Sets the entity's current freeze ticks (amount of ticks the entity has been in powdered snow).
      参数:
      ticks - Current ticks
    • isFrozen

      boolean isFrozen()
      Gets if the entity is fully frozen (it has been in powdered snow for max freeze ticks).
      返回:
      freeze status
    • remove

      void remove()
      将实体标记为删除.

      原文: Mark the entity's removal.

      抛出:
      UnsupportedOperationException - 如果你试图移除一名 玩家. 对于此场景请使用 Player.kickPlayer(String)
    • isDead

      boolean isDead()
      返回此实体是否已被标记为删除.

      原文: Returns true if this entity has been marked for removal.

      返回:
      实体是否死亡
    • isValid

      boolean isValid()
      如果此实体已经死亡、因为其他原因被抹去或尚未添加到世界, 则返回false.

      原文: Returns false if the entity has died, been despawned for some other reason, or has not been added to the world.

      返回:
      实体是否有效.
    • getServer

      @NotNull @NotNull Server getServer()
      返回包含此实体的服务器

      原文: Gets the Server that contains this Entity

      指定者:
      getServer 在接口中 CommandSender
      返回:
      运行此实体的服务器
    • isPersistent

      boolean isPersistent()
      Returns true if the entity gets persisted.

      By default all entities are persistent. An entity will also not get persisted, if it is riding an entity that is not persistent.

      The persistent flag on players controls whether or not to save their playerdata file when they quit. If a player is directly or indirectly riding a non-persistent entity, the vehicle at the root and all its passengers won't get persisted.

      This should not be confused with LivingEntity.setRemoveWhenFarAway(boolean) which controls despawning of living entities.

      返回:
      true if this entity is persistent
    • setPersistent

      void setPersistent(boolean persistent)
      Sets whether or not the entity gets persisted.
      参数:
      persistent - the persistence status
      另请参阅:
    • getPassenger

      已过时。
      实体可能有多名乘客. 请使用 getPassengers()
      获取乘坐载具的主要乘客.
      可能会有多个乘客, 这个方法只返回主要乘客.

      原文:Gets the primary passenger of a vehicle. For vehicles that could have multiple passengers, this will only return the primary passenger.

      返回:
      一个实体
    • setPassenger

      @Deprecated boolean setPassenger(@NotNull @NotNull Entity passenger)
      已过时。
      实体可能有多名乘客. 请使用 addPassenger(org.bukkit.entity.Entity)
      设置乘坐载具的主要乘客.

      原文: Set the passenger of a vehicle.

      参数:
      passenger - 新乘客
      返回:
      如果因为某种原因不能设置, 则返回false
    • getPassengers

      @NotNull @NotNull List<Entity> getPassengers()
      获取载具的乘客列表.
      对返回列表的操作不会反映到实体的当前乘客列表上, 也不保证返回列表的可变性.

      原文: Gets a list of passengers of this vehicle.

      The returned list will not be directly linked to the entity's current passengers, and no guarantees are made as to its mutability.

      返回:
      与当前乘客相对应的实体列表.
    • addPassenger

      boolean addPassenger(@NotNull @NotNull Entity passenger)
      添加一名乘客.

      原文: Add a passenger to the vehicle.

      参数:
      passenger - 要添加的乘客
      返回:
      如果因为某种原因不能添加, 则返回false
    • removePassenger

      boolean removePassenger(@NotNull @NotNull Entity passenger)
      移除一名乘客.

      原文: Remove a passenger from the vehicle.

      参数:
      passenger - 要移除的乘客
      返回:
      如果因为某种原因不能删除, 则返回false
    • isEmpty

      boolean isEmpty()
      检查是否有乘客.

      原文: Check if a vehicle has passengers.

      返回:
      载具是否为空.
    • eject

      boolean eject()
      弹出所有乘客.

      原文: Eject any passenger.

      返回:
      是否有乘客被弹出.
    • getFallDistance

      float getFallDistance()
      返回此实体已下落的距离.

      原文: Returns the distance this entity has fallen

      返回:
      距离.
    • setFallDistance

      void setFallDistance(float distance)
      设置此实体已下落的距离.

      原文: Sets the fall distance for this entity

      参数:
      distance - 新距离.
    • setLastDamageCause

      @Deprecated(forRemoval=true) void setLastDamageCause(@Nullable @Nullable EntityDamageEvent event)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      此方法仅供内部使用, 将被移除
      记录此实体上的最后一个EntityDamageEvent.

      原文: Record the last EntityDamageEvent inflicted on this entity

      参数:
      event - 一个 EntityDamageEvent
    • getLastDamageCause

      @Nullable @Nullable EntityDamageEvent getLastDamageCause()
      获取此实体上的最后一个EntityDamageEvent.

      原文: Retrieve the last EntityDamageEvent inflicted on this entity. This event may have been cancelled.

      返回:
      最后一个已知的EntityDamageEvent, 如果迄今为止没有受到伤害, 则为null
    • getUniqueId

      @NotNull @NotNull UUID getUniqueId()
      返回实体的UUID (唯一且持久的id)

      原文: Returns a unique and persistent id for this entity

      返回:
      UUID
    • getTicksLived

      int getTicksLived()
      获取此实体生存时间刻.
      这相当于实体的"年龄".

      原文: Gets the amount of ticks this entity has lived for.

      This is the equivalent to "age" in entities.

      返回:
      实体年龄
    • setTicksLived

      void setTicksLived(int value)
      设置此实体生存时间刻.
      这相当于实体中的"年龄". 不得少于一个tick.

      原文: Sets the amount of ticks this entity has lived for.

      This is the equivalent to "age" in entities. May not be less than one tick.

      参数:
      value - 实体年龄
    • playEffect

      void playEffect(@NotNull @NotNull EntityEffect type)
      为此实体执行指定的EntityEffect.
      这将对实体附近的所有玩家都是可见的.
      如果效果不适用于此类实体,则不会播放.

      原文: Performs the specified EntityEffect for this entity.

      This will be viewable to all players near the entity.

      If the effect is not applicable to this class of entity, it will not play.

      参数:
      type - 播放效果.
    • getType

      获取实体类型

      原文: Get the type of the entity.

      返回:
      实体类型.
    • getSwimSound

      @NotNull @NotNull Sound getSwimSound()
      Get the Sound this entity makes while swimming.
      返回:
      the swimming sound
    • getSwimSplashSound

      @NotNull @NotNull Sound getSwimSplashSound()
      Get the Sound this entity makes when splashing in water. For most entities, this is just Sound.ENTITY_GENERIC_SPLASH.
      返回:
      the splash sound
    • getSwimHighSpeedSplashSound

      @NotNull @NotNull Sound getSwimHighSpeedSplashSound()
      Get the Sound this entity makes when splashing in water at high speeds. For most entities, this is just Sound.ENTITY_GENERIC_SPLASH.
      返回:
      the splash sound
    • isInsideVehicle

      boolean isInsideVehicle()
      返回此实体是否在载具内.

      原文: Returns whether this entity is inside a vehicle.

      返回:
      此实体是否在载具内.
    • leaveVehicle

      boolean leaveVehicle()
      离开当前的载具. 如果实体当前在载具中(并从中移除), 则返回true, 否则将返回false.

      原文: Leave the current vehicle. If the entity is currently in a vehicle (and is removed from it), true will be returned, otherwise false will be returned.

      返回:
      是否成功离开.
    • getVehicle

      @Nullable @Nullable Entity getVehicle()
      获取实体所在的载具, 若没有则返回null.

      原文: Get the vehicle that this entity is inside. If there is no vehicle, null will be returned.

      返回:
      当前载具
    • setCustomNameVisible

      void setCustomNameVisible(boolean flag)
      设置是否在客户端上显示实体的自定义名称. 名称将会像玩家一样显示在实体上方.
      这个值对玩家无效, 玩家会一直显示.

      原文: Sets whether or not to display the mob's custom name client side. The name will be displayed above the mob similarly to a player.

      This value has no effect on players, they will always display their name.

      参数:
      flag - 是否显示自定义名称
    • isCustomNameVisible

      boolean isCustomNameVisible()
      获取是否在客户端上显示实体的自定义名称. 名称将会像玩家一样显示在实体上方.
      这个值对玩家无效, 玩家会一直显示.

      原文: Gets whether or not the mob's custom name is displayed client side.

      This value has no effect on players, they will always display their name.

      返回:
      是否显示自定义名称
    • setVisibleByDefault

      void setVisibleByDefault(boolean visible)
      Sets whether or not this entity is visible by default. If this entity is not visible by default, then Player.showEntity(org.bukkit.plugin.Plugin, org.bukkit.entity.Entity) will need to be called before the entity is visible to a given player.
      参数:
      visible - default visibility status
    • isVisibleByDefault

      boolean isVisibleByDefault()
      Gets whether or not this entity is visible by default. If this entity is not visible by default, then Player.showEntity(org.bukkit.plugin.Plugin, org.bukkit.entity.Entity) will need to be called before the entity is visible to a given player.
      返回:
      default visibility status
    • getTrackedBy

      @NotNull @NotNull Set<Player> getTrackedBy()
      Get all players that are currently tracking this entity.

      'Tracking' means that this entity has been sent to the player and that they are receiving updates on its state. Note that the client's 'Entity Distance' setting does not affect the range at which entities are tracked.

      返回:
      the players tracking this entity, or an empty set if none
    • setGlowing

      void setGlowing(boolean flag)
      设置实体是否有团队颜色(默认白色)的发光. 注意:本方法用到了实体的'Glowing'属性, 不是给实体应用发光药水效果.

      原文: Sets whether the entity has a team colored (default: white) glow. nb: this refers to the 'Glowing' entity property, not whether a glowing potion effect is applied

      参数:
      flag - 是否发光
    • isGlowing

      boolean isGlowing()
      获取实体是否发光. 注意:本方法用到了实体的'Glowing'属性, 不是给实体应用发光药水效果.

      原文: nb: this refers to the 'Glowing' entity property, not whether a glowing potion effect is applied

      返回:
      是否发光
    • setInvulnerable

      void setInvulnerable(boolean flag)
      设置实体是否无敌.
      当一个实体无敌时, 它只能被创造性模式中的玩家攻击.

      原文: Sets whether the entity is invulnerable or not.

      When an entity is invulnerable it can only be damaged by players in creative mode.

      参数:
      flag - 是否无敌
    • isInvulnerable

      boolean isInvulnerable()
      获取实体是否无敌.

      原文: Gets whether the entity is invulnerable or not.

      返回:
      是否无敌
    • isSilent

      boolean isSilent()
      获取实体是否保持安静.

      原文: Gets whether the entity is silent or not.

      返回:
      实体是否保持安静
    • setSilent

      void setSilent(boolean flag)
      获取实体是否保持安静.
      当实体静默时, 它不会发出任何声音.

      原文: Sets whether the entity is silent or not.

      When an entity is silent it will not produce any sound.

      参数:
      flag - 实体是否保持安静
    • hasGravity

      boolean hasGravity()
      返回重力是否适用于此实体.

      原文: Returns whether gravity applies to this entity.

      返回:
      重力是否适用于此实体
    • setGravity

      void setGravity(boolean gravity)
      设置重力是否适用于此实体.

      原文: Sets whether gravity applies to this entity.

      参数:
      gravity - 重力是否适用于此实体
    • getPortalCooldown

      int getPortalCooldown()
      获取此实体能再次使用传送门前需要等待的时间 (以刻为单位).

      原文: Gets the period of time (in ticks) before this entity can use a portal.

      返回:
      portal cooldown ticks
    • setPortalCooldown

      void setPortalCooldown(int cooldown)
      Sets the period of time (in ticks) before this entity can use a portal.
      参数:
      cooldown - portal cooldown ticks
    • getScoreboardTags

      @NotNull @NotNull Set<String> getScoreboardTags()
      返回实体标签集合.
      实体的标签数不得超过1024个.

      原文: Returns a set of tags for this entity.
      Entities can have no more than 1024 tags.

      返回:
      此实体的标签集合
    • addScoreboardTag

      boolean addScoreboardTag(@NotNull @NotNull String tag)
      为此实体添加一个标签.
      实体的标签数不得超过1024个.

      原文: Add a tag to this entity.
      Entities can have no more than 1024 tags.

      参数:
      tag - 要添加的标签
      返回:
      是否成功添加
    • removeScoreboardTag

      boolean removeScoreboardTag(@NotNull @NotNull String tag)
      删除此实体的一个标签.
      实体的标签数不得超过1024个.

      原文: Removes a given tag from this entity.

      参数:
      tag - 要删除的标签
      返回:
      是否成功删除
    • getPistonMoveReaction

      @NotNull @NotNull PistonMoveReaction getPistonMoveReaction()
      返回实体被活塞移动时的反应.

      原文: Returns the reaction of the entity when moved by a piston.

      返回:
      反应
    • getFacing

      Get the closest cardinal BlockFace direction an entity is currently facing.
      This will not return any non-cardinal directions such as BlockFace.UP or BlockFace.DOWN.
      Hanging entities will override this call and thus their behavior may be different.
      返回:
      the entity's current cardinal facing.
      另请参阅:
    • getPose

      Gets the entity's current pose. Note that the pose is only updated at the end of a tick, so may be inconsistent with other methods. eg Player.isSneaking() being true does not imply the current pose will be Pose.SNEAKING
      返回:
      current pose
    • getSpawnCategory

      @NotNull @NotNull SpawnCategory getSpawnCategory()
      Get the category of spawn to which this entity belongs.
      返回:
      the entity´s category spawn
    • isInWorld

      boolean isInWorld()
      Checks if this entity has been spawned in a world.
      Entities not spawned in a world will not tick, be sent to players, or be saved to the server files.
      返回:
      whether the entity has been spawned in a world
    • getAsString

      Get this entity as an NBT string.

      This string should not be relied upon as a serializable value.

      返回:
      the NBT string or null if one cannot be made
    • createSnapshot

      Crates an EntitySnapshot representing the current state of this entity.
      返回:
      a snapshot representing this entity or null if one cannot be made
    • copy

      Creates a copy of this entity and all its data. Does not spawn the copy in the world.
      Note: Players cannot be copied.
      返回:
      a copy of this entity.
    • copy

      Creates a copy of this entity and all its data. Spawns the copy at the given location.
      Note: Players cannot be copied.
      参数:
      to - the location to copy to
      返回:
      a copy of this entity.
    • spigot

      指定者:
      spigot 在接口中 CommandSender