接口 LivingEntity

所有超级接口:
Attributable, CommandSender, Damageable, Entity, Metadatable, Nameable, Permissible, PersistentDataHolder, ProjectileSource, ServerOperator
所有已知子接口:
AbstractHorse, AbstractSkeleton, AbstractVillager, Ageable, Allay, Ambient, Animals, ArmorStand, Axolotl, Bat, Bee, Blaze, Breedable, Camel, Cat, CaveSpider, ChestedHorse, Chicken, Cod, ComplexLivingEntity, Cow, Creature, Creeper, Dolphin, Donkey, Drowned, ElderGuardian, EnderDragon, Enderman, Endermite, Enemy, Evoker, Fish, Flying, Fox, Frog, Ghast, Giant, GlowSquid, Goat, Golem, Guardian, Hoglin, Horse, HumanEntity, Husk, Illager, Illusioner, IronGolem, Llama, MagmaCube, Mob, Monster, Mule, MushroomCow, NPC, Ocelot, Panda, Parrot, Phantom, Pig, Piglin, PiglinAbstract, PiglinBrute, PigZombie, Pillager, Player, PolarBear, PufferFish, Rabbit, Raider, Ravager, Salmon, Sheep, Shulker, Silverfish, Skeleton, SkeletonHorse, Slime, Sniffer, Snowman, Spellcaster, Spider, Squid, Steerable, Stray, Strider, Tadpole, Tameable, TraderLlama, TropicalFish, Turtle, Vex, Villager, Vindicator, WanderingTrader, Warden, WaterMob, Witch, Wither, WitherSkeleton, Wolf, Zoglin, Zombie, ZombieHorse, ZombieVillager

public interface LivingEntity extends Attributable, Damageable, ProjectileSource
代表一个生物实体,比如一只怪物或一名玩家.
  • 方法详细资料

    • getEyeHeight

      double getEyeHeight()
      获取生物实体眼睛离脚高度.

      原文: Gets the height of the living entity's eyes above its Location.

      返回:
      生物实体眼睛离脚高度
    • getEyeHeight

      double getEyeHeight(boolean ignorePose)
      获取生物实体眼睛离脚高度.

      原文: Gets the height of the living entity's eyes above its Location.

      参数:
      ignorePose - 若为true则会无视姿势改变的效果,例如潜行和滑翔
      返回:
      生物实体眼睛离脚高度
    • getEyeLocation

      @NotNull @NotNull Location getEyeLocation()
      获取生物实体眼睛的详细方位的Location对象.

      原文: Get a Location detailing the current eye position of the living entity.

      返回:
      生物实体眼睛的详细方位的Location对象
    • getLineOfSight

      @NotNull @NotNull List<Block> getLineOfSight(@Nullable @Nullable Set<Material> transparent, int maxDistance)
      获取沿生物实体视线上的所有方块.

      这个列表包含生物实体眼睛到目标位置的所有方块. 本方法认为所有方块体积为1x1x1.

      原文: Gets all blocks along the living entity's line of sight.

      This list contains all blocks from the living entity's eye position to target inclusive. This method considers all blocks as 1x1x1 in size.

      参数:
      transparent - 将包含的所有透明方块的ID的Set(设置为null则只包含空气)
      maxDistance - 扫描的最大距离(可能被服务器限制,但至少为100个方块)
      返回:
      包含沿生物实体视线上的所有方块的列表
    • getTargetBlock

      @NotNull @NotNull Block getTargetBlock(@Nullable @Nullable Set<Material> transparent, int maxDistance)
      获取生物实体的目标方块.

      本方法认为所有方块体积为1x1x1. To take exact block collision shapes into account, see getTargetBlockExact(int, FluidCollisionMode).

      原文: Gets the block that the living entity has targeted.

      This method considers all blocks as 1x1x1 in size. To take exact block collision shapes into account, see getTargetBlockExact(int, FluidCollisionMode).

      参数:
      transparent - 将包含的所有透明方块的ID的Set(设置为null则只包含空气)
      maxDistance - 扫描的最大距离(可能被服务器限制,但至少为100个方块)
      返回:
      block 生物实体的目标方块
    • getLastTwoTargetBlocks

      @NotNull @NotNull List<Block> getLastTwoTargetBlocks(@Nullable @Nullable Set<Material> transparent, int maxDistance)
      获取沿生物实体视线上最后两个方块.

      目标方块将是列表中最后的方块. 本方法认为所有方块体积为1x1x1.

      原文: Gets the last two blocks along the living entity's line of sight.

      The target block will be the last block in the list. This method considers all blocks as 1x1x1 in size.

      参数:
      transparent - 将包含的所有透明方块的ID的Set(设置为null则只包含空气)
      maxDistance - 扫描的最大距离。可能被服务器限制,但不会低于100个方块
      返回:
      包含沿生物实体视线上最后两个方块的列表
    • getTargetBlockExact

      @Nullable @Nullable Block getTargetBlockExact(int maxDistance)
      Gets the block that the living entity has targeted.

      This takes the blocks' precise collision shapes into account. Fluids are ignored.

      This may cause loading of chunks! Some implementations may impose artificial restrictions on the maximum distance.

      参数:
      maxDistance - the maximum distance to scan
      返回:
      block that the living entity has targeted
      另请参阅:
    • getTargetBlockExact

      @Nullable @Nullable Block getTargetBlockExact(int maxDistance, @NotNull @NotNull FluidCollisionMode fluidCollisionMode)
      Gets the block that the living entity has targeted.

      This takes the blocks' precise collision shapes into account.

      This may cause loading of chunks! Some implementations may impose artificial restrictions on the maximum distance.

      参数:
      maxDistance - the maximum distance to scan
      fluidCollisionMode - the fluid collision mode
      返回:
      block that the living entity has targeted
      另请参阅:
    • rayTraceBlocks

      @Nullable @Nullable RayTraceResult rayTraceBlocks(double maxDistance)
      Performs a ray trace that provides information on the targeted block.

      This takes the blocks' precise collision shapes into account. Fluids are ignored.

      This may cause loading of chunks! Some implementations may impose artificial restrictions on the maximum distance.

      参数:
      maxDistance - the maximum distance to scan
      返回:
      information on the targeted block, or null if there is no targeted block in range
      另请参阅:
    • rayTraceBlocks

      @Nullable @Nullable RayTraceResult rayTraceBlocks(double maxDistance, @NotNull @NotNull FluidCollisionMode fluidCollisionMode)
      Performs a ray trace that provides information on the targeted block.

      This takes the blocks' precise collision shapes into account.

      This may cause loading of chunks! Some implementations may impose artificial restrictions on the maximum distance.

      参数:
      maxDistance - the maximum distance to scan
      fluidCollisionMode - the fluid collision mode
      返回:
      information on the targeted block, or null if there is no targeted block in range
      另请参阅:
    • getRemainingAir

      int getRemainingAir()
      返回生物实体剩余的氧气值,单位为tick.

      原文: Returns the amount of air that the living entity has remaining, in ticks.

      返回:
      剩余的氧气值
    • setRemainingAir

      void setRemainingAir(int ticks)
      设置生物实体剩余的氧气值,单位为tick.

      原文: Sets the amount of air that the living entity has remaining, in ticks.

      参数:
      ticks - 剩余的氧气值
    • getMaximumAir

      int getMaximumAir()
      返回生物实体所能拥有的氧气最大值,单位为tick.

      原文: Returns the maximum amount of air the living entity can have, in ticks.

      返回:
      氧气最大值
    • setMaximumAir

      void setMaximumAir(int ticks)
      设置生物实体所能拥有的氧气最大值,单位为tick.

      原文: Sets the maximum amount of air the living entity can have, in ticks.

      参数:
      ticks - 氧气最大值
    • getArrowCooldown

      int getArrowCooldown()
      Gets the time in ticks until the next arrow leaves the entity's body.
      返回:
      ticks until arrow leaves
    • setArrowCooldown

      void setArrowCooldown(int ticks)
      Sets the time in ticks until the next arrow leaves the entity's body.
      参数:
      ticks - time until arrow leaves
    • getArrowsInBody

      int getArrowsInBody()
      Gets the amount of arrows in an entity's body.
      返回:
      amount of arrows in body
    • setArrowsInBody

      void setArrowsInBody(int count)
      Set the amount of arrows in the entity's body.
      参数:
      count - amount of arrows in entity's body
    • getMaximumNoDamageTicks

      int getMaximumNoDamageTicks()
      返回生物实体当前最大无伤害时间,单位为tick.

      即生物实体不会受到伤害的最大持续时间.

      原文: Returns the living entity's current maximum no damage ticks.

      This is the maximum duration in which the living entity will not take damage.

      返回:
      最大无伤害时间,单位为tick
    • setMaximumNoDamageTicks

      void setMaximumNoDamageTicks(int ticks)
      设置生物实体当前当前最大无伤害时间,单位为tick.

      原文: Sets the living entity's current maximum no damage ticks.

      参数:
      ticks - 最大无伤害时间,单位为tick
    • getLastDamage

      double getLastDamage()
      返回生物实体在当前无伤害时间最后受到的伤害.

      只有当伤害高于这个数值时生物实体才会进一步受到伤害.

      原文:Returns the living entity's last damage taken in the current no damage ticks time.

      Only damage higher than this amount will further damage the living entity.

      返回:
      上一个无伤害时间段内受到的伤害
    • setLastDamage

      void setLastDamage(double damage)
      设置当前无伤害时间段内处理的伤害.

      原文: Sets the damage dealt within the current no damage ticks time period.

      参数:
      damage - 伤害总量
    • getNoDamageTicks

      int getNoDamageTicks()
      返回生物实体当前无伤害时间,单位为tick.

      原文: Returns the living entity's current no damage ticks.

      返回:
      无伤害时间,单位为tick
    • setNoDamageTicks

      void setNoDamageTicks(int ticks)
      设置生物实体当前无伤害时间,单位为tick.

      原文: Sets the living entity's current no damage ticks.

      参数:
      ticks - 无伤害时间,单位为tick
    • getKiller

      获取击杀指定生物实体的玩家.

      可能为空.

      原文: Gets the player identified as the killer of the living entity.

      May be null.

      返回:
      击杀指定生物实体的玩家,如果找不到则返回null
    • addPotionEffect

      boolean addPotionEffect(@NotNull @NotNull PotionEffect effect)
      向生物实体添加指定的PotionEffect(药水效果).

      原文: Adds the given PotionEffect to the living entity.

      参数:
      effect - 添加的药水效果
      返回:
      效果是否添加
    • addPotionEffect

      @Deprecated boolean addPotionEffect(@NotNull @NotNull PotionEffect effect, boolean force)
      已过时。
      由于现已支持多个同种类型的药水效果, 没必要强制添加.

      译注:在某次版本更新后, Minecraft 自身支持了多个同种药水效果, 效果弱的会被隐藏; 但为兼容性考虑, 如确有覆盖效果需求的, 还是指定force为true

      向生物实体添加指定的PotionEffect(药水效果).

      一个指定的PotionEffectType(药水效果类型)只能有一种药水效果存在.

      原文: Adds the given PotionEffect to the living entity.

      Only one potion effect can be present for a given PotionEffectType.

      参数:
      effect - 添加的药水效果
      force - 是否移除冲突的效果
      返回:
      效果是否添加
    • addPotionEffects

      boolean addPotionEffects(@NotNull @NotNull Collection<PotionEffect> effects)
      尝试向生物实体添加所有指定的PotionEffect(药水效果).

      原文: Attempts to add all of the given PotionEffect to the living entity.

      参数:
      effects - 添加的效果
      返回:
      所有效果是否添加
    • hasPotionEffect

      boolean hasPotionEffect(@NotNull @NotNull PotionEffectType type)
      返回生物实体是否已经存在一个指定的PotionEffectType效果.

      原文: Returns whether the living entity already has an existing effect of the given PotionEffectType applied to it.

      参数:
      type - 检查的药水类型
      返回:
      是否有指定的药水效果作用于生物实体
    • getPotionEffect

      返回指定类型的有效PotionEffect.

      如果效果不存在则会返回null.

      原文: Returns the active PotionEffect of the specified type.

      If the effect is not present on the entity then null will be returned.

      参数:
      type - 检查的药水类型
      返回:
      作用于实体的效果,如果没有则返回null。
    • removePotionEffect

      void removePotionEffect(@NotNull @NotNull PotionEffectType type)
      移除当前所有指定的PotionEffectType效果.

      原文: Removes any effects present of the given PotionEffectType.

      参数:
      type - 移除的药水类型
    • getActivePotionEffects

      @NotNull @NotNull Collection<PotionEffect> getActivePotionEffects()
      返回当前作用于生物实体的所有PotionEffect.

      译注:不要向获得的列表中添加条目, 没有任何效果.

      原文: Returns all currently active PotionEffects on the living entity.

      返回:
      一个PotionEffect的集合
    • hasLineOfSight

      boolean hasLineOfSight(@NotNull @NotNull Entity other)
      检查生物实体是否阻挡另一个的视线.

      这使用了与敌对怪物寻找最近玩家相同的算法.

      原文: Checks whether the living entity has block line of sight to another.

      This uses the same algorithm that hostile mobs use to find the closest player.

      参数:
      other - 确定视线的实体
      返回:
      如果存在视线则返回true,否则返回false
    • getRemoveWhenFarAway

      boolean getRemoveWhenFarAway()
      返回生物实体是否会在远离玩家时消失.

      默认情况下,动物不会被移除而怪物会.

      原文: Returns if the living entity despawns when away from players or not.

      By default, animals are not removed while other mobs are.

      返回:
      如果生物实体会在远离玩家时消失则返回true
    • setRemoveWhenFarAway

      void setRemoveWhenFarAway(boolean remove)
      设置生物实体是否会在远离玩家时消失.

      原文: Sets whether or not the living entity despawns when away from players or not.

      参数:
      remove - 移除状态
    • getEquipment

      获取生物实体穿戴的装备背包栏.

      原文: Gets the inventory with the equipment worn by the living entity.

      返回:
      生物实体的背包栏
    • setCanPickupItems

      void setCanPickupItems(boolean pickup)
      设置生物实体是否能捡拾物品.

      原文: Sets whether or not the living entity can pick up items.

      参数:
      pickup - 生物实体是否能捡拾物品
    • getCanPickupItems

      boolean getCanPickupItems()
      获取生物实体是否能捡拾物品.

      原文: Gets if the living entity can pick up items.

      返回:
      生物实体是否能捡拾物品
    • isLeashed

      boolean isLeashed()
      返回实体当前是否被拴住.

      原文: Returns whether the entity is currently leashed.

      返回:
      实体是否被拴住
    • getLeashHolder

      获取当前牵引此实体的实体.

      原文: Gets the entity that is currently leading this entity.

      返回:
      握持拴绳的实体
      抛出:
      IllegalStateException - 如果当前实体没被拴住则抛出错误
    • setLeashHolder

      boolean setLeashHolder(@Nullable @Nullable Entity holder)
      设置握持拴绳的实体.

      此方法对末影龙,凋零,玩家或蝙蝠无效。除拴绳外的非生物实体将不会像握持拴绳者一样持续存在.

      原文: Sets the leash on this entity to be held by the supplied entity.

      This method has no effect on EnderDragons, Withers, Players, or Bats. Non-living entities excluding leashes will not persist as leash holders.

      参数:
      holder - 握持拴绳的实体
      返回:
      操作是否成功
    • isGliding

      boolean isGliding()
      检查实体是否正在滑翔,如正在使用鞘翅.

      原文: Checks to see if an entity is gliding, such as using an Elytra.

      返回:
      如果实体正在滑翔则返回true
    • setGliding

      void setGliding(boolean gliding)
      Makes entity start or stop gliding. This will work even if an Elytra is not equipped, but will be reverted by the server immediately after unless an event-cancelling mechanism is put in place.
      参数:
      gliding - True if the entity is gliding.
    • isSwimming

      boolean isSwimming()
      Checks to see if an entity is swimming.
      返回:
      True if this entity is swimming.
    • setSwimming

      void setSwimming(boolean swimming)
      Makes entity start or stop swimming. This may have unexpected results if the entity is not in water.
      参数:
      swimming - True if the entity is swimming.
    • isRiptiding

      boolean isRiptiding()
      Checks to see if an entity is currently using the Riptide enchantment.
      返回:
      True if this entity is currently riptiding.
    • isSleeping

      boolean isSleeping()
      返回实体是否正在睡觉.

      原文:Returns whether this entity is slumbering.

      返回:
      实体睡眠状态
    • isClimbing

      boolean isClimbing()
      获取实体是否正在攀爬.

      原文:Gets if the entity is climbing.

      返回:
      实体攀爬状态
    • setAI

      void setAI(boolean ai)
      设置实体是否具有AI. 实体若无AI将完全无法自主移动.

      原文: Sets whether an entity will have AI. The entity will be completely unable to move if it has no AI.

      参数:
      ai - 怪物是否具有AI
    • hasAI

      boolean hasAI()
      检查实体是否具有AI. 实体若无AI将完全无法自主移动.

      原文: Checks whether an entity has AI. The entity will be completely unable to move if it has no AI.

      返回:
      如果实体具有AI则返回true
    • attack

      void attack(@NotNull @NotNull Entity target)
      Makes this entity attack the given entity with a melee attack. Attack damage is calculated by the server from the attributes and equipment of this mob, and knockback is applied to target as appropriate.
      参数:
      target - entity to attack.
    • swingMainHand

      void swingMainHand()
      Makes this entity swing their main hand. This method does nothing if this entity does not have an animation for swinging their main hand.
    • swingOffHand

      void swingOffHand()
      Makes this entity swing their off hand. This method does nothing if this entity does not have an animation for swinging their off hand.
    • setCollidable

      void setCollidable(boolean collidable)
      Set if this entity will be subject to collisions with other entities.

      Exemptions to this rule can be managed with getCollidableExemptions()

      参数:
      collidable - collision status
    • isCollidable

      boolean isCollidable()
      Gets if this entity is subject to collisions with other entities.

      Some entities might be exempted from the collidable rule of this entity. Use getCollidableExemptions() to get these.

      Please note that this method returns only the custom collidable state, not whether the entity is non-collidable for other reasons such as being dead.

      返回:
      collision status
    • getCollidableExemptions

      @NotNull @NotNull Set<UUID> getCollidableExemptions()
      Gets a mutable set of UUIDs of the entities which are exempt from the entity's collidable rule and which's collision with this entity will behave the opposite of it.

      This set can be modified to add or remove exemptions.

      For example if collidable is true and an entity is in the exemptions set then it will not collide with it. Similarly if collidable is false and an entity is in this set then it will still collide with it.

      Note these exemptions are not (currently) persistent.

      返回:
      the collidable exemption set
    • getMemory

      @Nullable <T> T getMemory(@NotNull @NotNull MemoryKey<T> memoryKey)
      Returns the value of the memory specified.

      Note that the value is null when the specific entity does not have that value by default.

      类型参数:
      T - the type of the return value
      参数:
      memoryKey - memory to access
      返回:
      a instance of the memory section value or null if not present
    • setMemory

      <T> void setMemory(@NotNull @NotNull MemoryKey<T> memoryKey, @Nullable T memoryValue)
      Sets the value of the memory specified.

      Note that the value will not be persisted when the specific entity does not have that value by default.

      类型参数:
      T - the type of the passed value
      参数:
      memoryKey - the memory to access
      memoryValue - a typed memory value
    • getHurtSound

      @Nullable @Nullable Sound getHurtSound()
      Get the Sound this entity will make when damaged.
      返回:
      the hurt sound, or null if the entity does not make any sound
    • getDeathSound

      @Nullable @Nullable Sound getDeathSound()
      Get the Sound this entity will make on death.
      返回:
      the death sound, or null if the entity does not make any sound
    • getFallDamageSound

      @NotNull @NotNull Sound getFallDamageSound(int fallHeight)
      Get the Sound this entity will make when falling from the given height (in blocks). The sound will often differ between either a small or a big fall damage sound if the height exceeds 4 blocks.
      参数:
      fallHeight - the fall height in blocks
      返回:
      the fall damage sound
      另请参阅:
    • getFallDamageSoundSmall

      @NotNull @NotNull Sound getFallDamageSoundSmall()
      Get the Sound this entity will make when falling from a small height.
      返回:
      the fall damage sound
    • getFallDamageSoundBig

      @NotNull @NotNull Sound getFallDamageSoundBig()
      Get the Sound this entity will make when falling from a large height.
      返回:
      the fall damage sound
    • getDrinkingSound

      @NotNull @NotNull Sound getDrinkingSound(@NotNull @NotNull ItemStack itemStack)
      Get the Sound this entity will make when drinking the given ItemStack.
      参数:
      itemStack - the item stack being drank
      返回:
      the drinking sound
    • getEatingSound

      @NotNull @NotNull Sound getEatingSound(@NotNull @NotNull ItemStack itemStack)
      Get the Sound this entity will make when eating the given ItemStack.
      参数:
      itemStack - the item stack being eaten
      返回:
      the eating sound
    • canBreatheUnderwater

      boolean canBreatheUnderwater()
      Returns true if this entity can breathe underwater and will not take suffocation damage when its air supply reaches zero.
      返回:
      true if the entity can breathe underwater
    • getCategory

      Get the category to which this entity belongs. Categories may subject this entity to additional effects, benefits or debuffs.
      返回:
      the entity category
    • setInvisible

      void setInvisible(boolean invisible)
      Sets whether the entity is invisible or not.
      参数:
      invisible - If the entity is invisible
    • isInvisible

      boolean isInvisible()
      Gets whether the entity is invisible or not.
      返回:
      Whether the entity is invisible