侧边栏壁纸
  • 累计撰写 793 篇文章
  • 累计创建 1 个标签
  • 累计收到 1 条评论
标签搜索

目 录CONTENT

文章目录
MC

citizen

Dettan
2021-07-10 / 0 评论 / 0 点赞 / 149 阅读 / 454 字
温馨提示:
本文最后更新于 2022-07-23,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。
EntityCitizen 是mc里的entity子类,
在构造函数里初始化了一个statemachine
entityStatemachine.addTransition(new TickingTransition<>(EntityState.INIT, () -> true, this::initialize, 40));

entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_CLIENT, () -> {citizenColonyHandler.updateColonyClient();return false;}, () -> null, 1));
entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_CLIENT, this::shouldBeInactive, () -> EntityState.INACTIVE, TICKS_20));
entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_CLIENT, this::refreshCitizenDataView, () -> null, TICKS_20));

entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_SERVER, this::updateSaturation, () -> null, HEAL_CITIZENS_AFTER));
entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_SERVER, this::updateVisualData, () -> null, 200));
entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_SERVER, this::onServerUpdateHandlers, () -> null, TICKS_20));
entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_SERVER, this::onTickDecrements, () -> null, 1));
entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_SERVER, this::shouldBeInactive, () -> EntityState.INACTIVE, TICKS_20));
entityStatemachine.addTransition(new TickingTransition<>(EntityState.ACTIVE_SERVER, this::determineDesiredActivity, () -> null, 100));

entityStatemachine.addTransition(new TickingTransition<>(EntityState.INACTIVE, this::isAlive, () -> EntityState.INIT, 100));
entityCitizen还有一个livingTick方法 负责
/**
 * Called frequently so the entity can update its state every tick as required. 
	For example, zombies and skeletons. use this to react to sunlight and start to burn.
 */
@Override
public void livingTick()
{
    super.livingTick();
    entityStatemachine.tick();
}
有一个statemachine 承担状态变化的任务,如 active 死亡 回血 初始化,这些
还有一个mc的ai实现方案实现一些ai,如 吃 睡 躲怪 哀悼 生病 注视等
this.goalSelector.addGoal(++priority, new EntityAIEatTask(this));

job ai
分配工作时: this.goalSelector.addGoal(++priority, new EntityAIEatTask(this));
这里是 和 其他 交流的地方, ai只会调用job的方法.

EntityAIWorkDeliveryman
这个是Goal的子类, 可以直接添加到entity的goalSelector里
里面也包含一个状态机,主要负责的是工作相关的AI
public EntityAIWorkDeliveryman(@NotNull final JobDeliveryman deliveryman)
{
    super(deliveryman);
    super.registerTargets(
      /*
       * Check if tasks should be executed.
       */
      new AITarget(IDLE, () -> START_WORKING, 1),
      new AITarget(START_WORKING, this::checkIfExecute, this::decide, DECISION_DELAY),
      new AITarget(PREPARE_DELIVERY, this::prepareDelivery, STANDARD_DELAY),
      new AITarget(DELIVERY, this::deliver, STANDARD_DELAY),
      new AITarget(PICKUP, this::pickup, PICKUP_DELAY),
      new AITarget(DUMPING, this::dump, TICKS_SECOND)

    );
    worker.setCanPickUpLoot(true);
}

job 与 ai
ai里会调用job里的方法,
0

评论区