Skip to content

【1.12.2】有考虑修复NPC的逻辑更新吗? #2

Description

@GaoXanSheng
/**
 * 实现了NPC的逻辑更新。
 * 注意:该方法可能会耗费一定的时间,可以考虑改为异步操作以提高性能。
 * 该方法会在每个游戏刻(tick)被调用,具体包含以下逻辑:
 * 1. 调用父类方法实现通用逻辑更新。
 * 2. 每隔10个游戏刻,计算起始Y坐标并触发事件。
 * 3. 更新计时器。
 * 4. 如果游戏在客户端运行且被击杀状态改变,则更新击杀状态和碰撞箱。
 * 5. 如果当前动画为14,则设置死亡动画为19。
 */
public void func_70071_h_() {
    super.func_70071_h_(); // 调用父类方法实现通用逻辑更新
    if (this.field_70173_aa % 10 == 0) { // 每隔10个游戏刻
        this.startYPos = calculateStartYPos(this.ais.startPos()) + 1.0d; // 计算起始Y坐标
        if (this.startYPos < 0.0d && !isRemote()) { // 如果起始Y坐标小于0且不是远程玩家
            func_70106_y(); // 销毁实体对象
        }
        EventHooks.onNPCTick(this); // 触发NPC逻辑更新事件
    }
    this.timers.update(); // 更新计时器
    if (this.field_70170_p.field_72995_K && this.wasKilled != isKilled()) { // 如果游戏在客户端运行且被击杀状态改变
        this.field_70725_aQ = 0; // 重置击杀时间
        updateHitbox(); // 更新碰撞箱
    }
    this.wasKilled = isKilled(); // 更新被击杀状态
    if (this.currentAnimation == 14) { // 如果当前动画为14
        this.field_70725_aQ = 19; // 设置死亡动画为19
    }
}`
1.12.2的自定义NPC在运行更新时会导致机器tick负载800ms
测试在 windows 10 5950X 32G
同时活动NPC 4746
NPC的配置文件设置为
ChuckLoaders=100
测试在CustomNPCs_1.12.2-(01Oct19)会导致严重的性能下降,本来想修,但是我不会在1.12中怎么去搞,就只能翻译翻译逻辑交给开发者了。 

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions