en
menu PN X Chapter 3 Sensors - The Senses of the Entity
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 3 Sensors - The Senses of the Entity

author: daoge_cmd

The translation made by AzaleeX contributed to the PowerNukkitX documentation

1.0 Obtaining information from the outside world

"When you approach a sheep, it looks at you."

Thinking about the above behavior flow, the sheep must first discover the presence of players nearby, and then activate the "look at the nearest player" behavior. In other words, the entity must have the ability to obtain information from the outside world

1.0.1 Use of sensors

Before touching the sensor, you might write the logic for detecting nearby players in the evaluator of the behavior to implement the above functionality. However, in fact we don't do that, we separate this logic to a component called Sensor

The sensor interface is described as follows.

sense method contains the main logic of the sensor, e.g. the above logic for getting the nearest player should be written inside this method. The information obtained should be written to the entity's memory (although there are no code level restrictions)

getPeriod method determines how many gt the sensor is called once and defaults to 1 (called every gt). Considering performance, it may be appropriate to stretch the call period of some sensors


© PowerNukkitX Dev team