Skip to main content

基本

int     getId()
String  getName()
String  getDisplayName()
String  getEntityClass()
boolean is(String className)

位置 & 朝向

Vec3   getPosition()
Vec3   getLastPosition()
Vec3   getBlockPosition()
Vec3   getMotion()
float  getYaw()
float  getPitch()
float  getPrevYaw()
float  getPrevPitch()
String getFacing()                  // "N"/"NE"/"E"/"SE"/...

尺寸

float    getEyeHeight()
float    getHeight()
float    getWidth()
double[] getBoundingBox()           // { minX,minY,minZ, maxX,maxY,maxZ }

状态

boolean isOnGround()
boolean isCollided()
boolean isCollidedHorizontally()
boolean isCollidedVertically()
boolean isDead()
boolean isBurning()
boolean isInLava()
boolean isInLiquid()
boolean isInvisible()
boolean isOnLadder()
boolean isRiding()
boolean isSneaking()
boolean isSprinting()
boolean isSleeping()
boolean isOnEdge()
float   getFallDistance()
int     getFireResistance()
int     getTicksExisted()

骑乘

Entity getRidingEntity()
Entity getRiddenByEntity()

距离

double distanceTo(Entity other)
double distanceToSq(Entity other)
double distanceTo(Vec3 point)
double distanceToGround()
double getBPS()             // blocks/sec(水平)
double getSpeed()
boolean canEntityBeSeen(Entity target)

其他

void remove()               // 仅客户端
net.minecraft.world.entity.Entity raw()

子类型

LivingEntity

所有生物(玩家 / 怪 / 村民 / …)。在 Entity 基础上扩展:
float    getHealth()
float    getMaxHealth()
int      getHurtTime()             // 红色受击闪烁剩余 tick

// 装备 —— slot: 0=head, 1=chest, 2=legs, 3=feet
ItemStack getArmorInSlot(int slot)
ItemStack getHeldItem()            // 主手
ItemStack getOffhandItem()         // 副手

// 药水
List<Effect> getPotionEffects()

// 动作
int     getSwingProgress()         // 挥手动画 tick
void    swing(String arm)          // arm: "MAIN" / "OFF"
boolean isConsuming()              // 是否在吃 / 喝 / 拉弓

Entity  getFisher()                // 钓鱼钩子的 owner(仅 Player 有,其他返回 null)

Player

float getExperience()              // 经验进度 0..1
int   getExperienceLevel()         // 经验等级

int   getHunger()                  // 饥饿值 0..20
float getSaturation()              // 饱和度

Entity getFisher()                 // 重写:返回钓鱼钩子的 owner

LocalPlayer

void jump()                        // 起跳一次(等同空格)
void setSpeed(double blocksPerSecond)   // 直接设当前帧水平速度
void setSprinting(boolean on)
void setSneaking(boolean on)

void sendChatMessage(String msg)   // "/" 开头作为命令

ItemStack getInventorySlot(int slot)    // 0..8 hotbar / 9..35 主背包 / 36..39 甲 / 40 副手
int       getSelectedSlot()        // 当前 hotbar 槽

ItemEntity

掉落物(地上的物品)。在 Entity 基础上:
ItemStack getItem()
ItemStack getItemStack()           // 别名
String    getItemId()              // 例 "minecraft:diamond"
String    getItemName()
int       getItemCount()
int       getAge()                 // 已存在的 tick 数(6000 后消失)

示例

for (e : me.getWorld().getEntities()) {
    if (e instanceof LocalPlayer) {
        e.setSprinting(true);
    } else if (e instanceof Player) {
        me.log(e.getName() + " hp=" + e.getHealth() + " hunger=" + e.getHunger());
    } else if (e instanceof LivingEntity) {
        if (e.getHealth() < e.getMaxHealth() / 2) me.subChat(e.getName() + " 半血了");
    } else if (e instanceof ItemEntity) {
        me.log("掉落物:" + e.getItemName() + " ×" + e.getItemCount());
    }
}