<本站文本内容除另有声明外,转载时均必须注明出处。(详情…中文Minecraft Wiki是完全公开的。请勇于扩充与修正内容!Minecraft中文Wiki微博正在更新!或许有兴趣去看看想与其他用户进行编辑上的沟通?社区专页正是为此创建的。翻译或创建页面之前,不妨看看译名标准化Wiki条例页面。需要管理员的协助?在管理员告示板留言也许可以帮到您。>

Minecraft Wiki:沙盒/基岩版beta实体事件文档

来自Minecraft Wiki
跳转至: 导航搜索
Information icon.svg
此特性为基岩版独有。
Ic translate.svg
此条目的(部分)内容需要翻译。

你可以帮助我们来翻译此条目,但请勿使用机器翻译

This is the entity events documentation for Bedrock Edition beta 1.16.20.52. New features, components, and capabilities in this release are not final and might change without notice before the final release. Be sure to check the documentation once the release is out of beta if the add-on isn't working properly. Resource and behavior packs created for the beta are not guaranteed to work on the final release.

General Notes[编辑源代码]

This document contains details for driving various events via entity .json data. Entity events can go in both behavior and resource packs. Behavior packs use the same animations and animation controllers setup that are used in resource packs, albeit with a different method in the entity .json itself to activate the animations.

Entity events are a way to drive gameplay and entity state changes in the Bedrock engine. These events can typically include slash commands (behavior packs only), entity events (e.g. become an adult), and MoLang expressions (e.g. set the MoLang variable "variable.foo" to 3 on a particular entity). Animations and Animation controllers provide a method for driving state machines and timelines for an entity. For example, a particular animation controller could be in a particular state, and running a particular animation, and we want events triggered when entering/exiting that state. Alternately, an "animation" could be running, and we wish to fire off events during that animation. The entity event timeline mechanic makes this possible.

Animation Notes[编辑源代码]

Entity events occur in animations, which normally occur on the client (via resource packs), but can also occur on the server (via behavior packs). As the server side of the game has no visual aspects to it, obviously no bone-based animations can occur. However, a traditional animation is basically a timeline of events, with the events being bone positions for an animated visual rig that moves the entity's visual shape around. The mechanisms for the Bedrock Edition animation system are state machines (Animation Controllers), and timelines (Animations). These concepts apply directly to the triggering of events, thus the animation system can execute on the server (minus the visual aspects), with the intent of driving entity events.

To use entity events on the server (in a behavior pack), add animation controllers and animations to a behavior pack just as you would to a resource pack. Add animation and animation controllers to an "animations" section in the description field of an entity. These animations and animation controllers will run on the server just as if they were on the client in a resource pack. Add the "scripts" section with an "animate" subsection to specify which animations/animation-controllers to have run.

Client side (resource pack) events do not require special setup as the client side entities usually already have animations and animation controllers in place. Just add the events where the player need them in animations or animation controllers.

{
  // Example of the schema for a server-side entity, modified to run animations and animation controllers
  "format_version": "1.8.0",
  "minecraft:entity": {
    "description": {
      "identifier": "minecraft:cat",
      ...
      "animations": {
        "anim1": "animation.anim1",
        "anim2": "animation.anim2",
        "anim_controller1": "controller.animation.test1",
        "anim_controller2": "controller.animation.test2"
      },
      "scripts": {
        // note that only these animations and animation controllers will automatically run:
        "animate": [
          "anim1",
          "anim_controller1",
          ...
         ]
      }
      ...
    },
    ...
  },
  ...
}

Events[编辑源代码]

Events consist of three categories, all represented by a string:

  • Entity events
  • Commands
  • MoLang Expressions

In detail:

Entity Events: Server side (behavior packs) only. Currently, we only support entity events to self, and these take the form "@s event". These are events declared in the events section of the entity definition file. For example, in the cat.json, "minecraft:ageable_grow_up" event causes the kitten to grow up. This would take the form of "@s minecraft:ageable_grow_up"

Commands: Server side (behavior packs) only. Any slash command can be invoked, such as /particle minecraft:example_smoke_puff ~ ~ ~. The assumed entity for the slash command is the invoking entity, so this particular slash command will spawn a smoke puff effect at the entity's location.

MoLang Expressions: This executes a MoLang expression. The primary usage is to set MoLang variables that can be used later. For example, a state transition might be looking at a particluar MoLang variable, and this expression could change that variable. A particle effect on the entity might change color due to MoLang variables that the effect uses for color tints. An animation to move an arm might use a MoLang variable that was set by an animation event.

// entity event (behavior packs only), put the particular event name after the @s
"@s minecraft:entity_event"

// command (behavior packs only), can be any server-side slash command
// is invoked from the entity, so a teleport, for example, will teleport the entity by default
"/tell @a this is a message"

// MoLang Expressions, executes a molang expression on the entity
"variable.something_to_set = 3;"

Animation Controller Events[编辑源代码]

Animation controllers can trigger events on entry or exit of a state. Events to trigger on state entry go in the "on_entry" section, those on exit go in the "on_exit" section.

{
  "format_version": "1.8.0",
  "animation_controllers": {
    "controller.animation.test": {
      "states": {
        "default": {
          "on_entry": [
            "event1", // note that these events can be any event, slash command, MoLang, or entity event
            "event2",
            "event3"
          ],
          "on_exit": [
            "event1",
            "event2"
          ]
        },
      }
    }
  }
}

Animation Events[编辑源代码]

Animations can have a timeline dedicated to events. The "timeline" section contains the event timeline list. Below there are various examples where particular times can trigger a single event, or an array of events:

{
  "format_version": "1.8.0",
  "animations": {
    "animation.test_events": {
      "timeline": {
        "2.0": "@s minecraft:entity_born",
        "4.0": [ "@s minecraft:ageable_grow_up" ]
      },
      "animation_length": 5.0
    },
    "animation.test_molang": {
      "timeline": {
        "0.0": "variable.pop_smoke = 1; variable.pop_bubbles = 0;",
        "3.0": [
          "variable.pop_smoke = 0;",
          "variable.pop_bubbles = 1;"
        ]
      }
    },
    "animation.test_commands": {
      "timeline": {
        "1.0": "/tell @a timeline command1",
        "2.0": [
          "/tell @a timeline command 2.1",
          "/tell @a timeline command 2.2"
        ],
        "3.0": [ "/tell @a command 3" ]
      }
    }
  }
}