en
Switch Language
  1. PowerNukkitX
  2. Get Started
  3. Config

    1. server.properties
    2. nukkit.yml
    3. pnx-cli-config.ini
    4. Anti-xray
    5. Resource Encryption
    6. Compression Acceleration
    7. PNX with WaterDogPE
    8. Flat World
  4. FAQ

    1. To Newcomers
    2. How to use PNX-CLI
    3. Common Questions
    4. Terra Questions
    5. Spawn-point Questions
    6. Convert Worlds
  5. For Devs

    1. Java

      1. Goto JavaDoc
      2. Mod API

        1. Custom Block
        2. Custom Item
        3. Custom Entity
        4. Custom Enchantment
      3. Entity AI

        1. Behavior
        2. Memory
        3. Sensor
        4. Motion Controller
        5. Navigator
        6. Behavior Group
        7. Work Cycle
    2. JavaScript

      1. setup dev env
      2. Base LLSELib dev
      3. Hello World
      4. Basic knowledge
      5. Event Listener
      6. FAQ
    3. Resources

      1. Event List
      2. IDs(block & item)

Chapter 7 Work cycle

author: daoge_cmd

The translation made by AzaleeX contributed to the PowerNukkitX documentation

After understanding all the components, let's finally examine the AI work cycle

1.0 What is the work cycle

Before we start the content, let's clarify the concept of work cycle

The work cycle, similar to the game engraving gametick, in which the AI completes a work cycle includes, but is not limited to, the following:

All work is done in parallel and we need to continue with the source code by describing:

1.1 asyncPrepare() Methods

The asyncPrepare() method runs in parallel between entities. Its completes the entirety of a work cycle

The details are as follows:

public class EntityIntelligent{

    /**
     * Other methods are omitted here
     */
    
    @Override
    public void asyncPrepare(int currentTick) {
        // Calculate if active
        isActive = level.isHighLightChunk(getChunkX(), getChunkZ());
        if (!this.isImmobile()) { // immobile will disable entity AI
            var behaviorGroup = getBehaviorGroup();
            if (behaviorGroup == null) return;
            behaviorGroup.collectSensorData(this);
            behaviorGroup.evaluateCoreBehaviors(this);
            behaviorGroup.evaluateBehaviors(this);
            behaviorGroup.updateRoute(this);
            behaviorGroup.tickRunningCoreBehaviors(this);
            behaviorGroup.tickRunningBehaviors(this);
            behaviorGroup.applyController(this);
            if (EntityAI.checkDebugOption(EntityAI.DebugOption.BEHAVIOR)) behaviorGroup.debugTick(this);
        }
        super.asyncPrepare(currentTick);
    }
}

To organize, we can summarize what is done successively in a work cycle:

1.2 Off-topic: About debug mode

The framework has a "DEBUG mode" in which the creature name will show the current behavior and when you take the stick and right click on the entity a pop-up window will appear showing information about the entity

You can enable debug mode by setting debug.commands in nukkit.yml to true and using the command /debug entity <option> true in-game


© PowerNukkitX Dev team