en
menu PN X Chapter 6 Behavior Groups - Collections of Components
more_vert
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 6 Behavior Groups - Collections of Components

author: daoge_cmd

The translation made by AzaleeX contributed to the PowerNukkitX documentation

1.0 Containers for all components

In fact, the behavior group BehaviorGroup is not just a container for behaviors, but actually contains all the logical components of a class of creatures, and the behaviors presented in this chapter are only some of its components. A complete behavior group contains:

1.0.1 A complete AI

The behavior group contains all components, i.e. the behavior group forms a complete AI

The creature is initialized with one call to requireBehaviorGroup() method, which returns an instance of the behavior group that will accompany the creature for its entire lifetime

By overriding the requireBehaviorGroup() method of the EntityIntelligent class and returning its own behavior group instance, the creature can obtain its own AI

1.0.2 Singularity

For each creature, there is only one instance of the behavior group in its life cycle

1.1 Create a new behavior group

Let's turn our attention to BehaviorGroup on the constructor of:

@Builder
public BehaviorGroup(int startRouteUpdateTick, Set<IBehavior> coreBehaviors, Set<IBehavior> behaviors, Set<ISensor> sensors, Set<IController> controllers, SimpleRouteFinder routeFinder) {
    //This parameter is used to stagger the time of each entity path update to avoid submitting too many path update tasks in 1gt
    this.currentRouteUpdateTick = startRouteUpdateTick;
    this.coreBehaviors = coreBehaviors;
    this.behaviors = behaviors;
    this.sensors = sensors;
    this.controllers = controllers;
    this.routeFinder = routeFinder;
    this.initPeriodTimer();
}

Constructors with@Builderannotation, we recommend that you use Builder to initialize the object


© PowerNukkitX Dev team