添加了部分来自于BedrockWiki的文章!

This commit is contained in:
boybook
2025-03-19 22:17:04 +08:00
parent 41635cf9bb
commit c25ebf2767
558 changed files with 96136 additions and 24 deletions

View File

@@ -0,0 +1,165 @@
---
title: Creating Boats
category: Tutorials
tags:
- recipe
- intermediate
mentions:
- SirLich
- Joelant05
- MedicalJewel105
- StealthyExpertX
- TheItsNameless
---
:::warning Requires Format Version 1.16.100 or Lower
The behavior format version now requires 1.16.100 or lower for the `minecraft:behavior.rise_to_liquid_level` and `minecraft:buoyant` methods to work.
If you find a new method that works in the newer format versions, you should consider helping to contribute by updating the wiki.
:::
## Using Runtime Identifiers
You can read more about runtime identifiers [here](/entities/runtime-identifier). Using runtime identifiers, you can implement most of the boat's hard-coded behaviors. However, your boat won't rotate with you, and it will always face North.
## Using Components
Currently, the best way to create a boat entity is by using components. 1.16 introduced new components that we can use to our advantage: `minecraft:behavior.rise_to_liquid_level` and `minecraft:buoyant`. Striders use the first one in vanilla to make them float on lava, but we can repurpose it for water as well.
## 1st method: minecraft:behavior.rise_to_liquid_level
<CodeHeader>BP/entities/bar</CodeHeader>
```json
{
"minecraft:entity": {
"format_version": "1.14.0",
"description": {
"identifier": "foo:bar",
"is_summonable": true,
"is_spawnable": true,
"is_experimental": false
},
"components": {
//This is the component that does the magic
"minecraft:behavior.rise_to_liquid_level": {
"priority": 0,
//This property can adjust how high your boat is above the water
"liquid_y_offset": 0.5,
//Positive vertical displacement, in other words, how much the boat will move up
"rise_delta": 0.05,
//Negative vertical displacement, in other words, how much the boat will move down
"sink_delta": 0.05
//Use rise_delta and sink_delta to simulate waves/bouncing effect
},
//Sets the boat speed in water
"minecraft:underwater_movement": {
"value": 5
},
//This component is important, without it the boat will sink
"minecraft:navigation.walk": {
"can_sink": false
},
"minecraft:rideable": {
"seat_count": 1,
"family_types": ["player"],
"interact_text": "action.interact.enter_boat",
"seats": {
"position": [0, 0, 0]
}
},
//Add this component if you want your boat to be controlled with WASD
"minecraft:input_ground_controlled": {},
"minecraft:health": {
"value": 10,
"max": 10
},
//Sets the boat speed on the ground (set this to zero if you don't want your boats to move on the ground)
"minecraft:movement": {
"value": 3
},
//This is to prevent the boat from not stopping whenever a player exits, said the boat
"minecraft:movement.basic": {},
"minecraft:collision_box": {
"width": 1,
"height": 1
},
"minecraft:physics": {}
}
}
}
```
## 2nd method: minecraft:buoyant
<CodeHeader></CodeHeader>
```json
{
"minecraft:entity": {
"format_version": "1.14.0",
"description": {
"identifier": "foo:bar",
"is_summonable": true,
"is_spawnable": true,
"is_experimental": false
},
"components": {
"minecraft:buoyant": {
//Determines whether gravity should be taken into account (useful with waterfalls)
"apply_gravity": true,
//Range: 0-1. This controls how high the boat is above the water
"base_buoyancy": 1.0,
//A "wave" makes the entity bounce up and down. A big wave simply amplifies this effect. Note: setting simulate_waves to false won't make the effect go away completely.
"simulate_waves": true,
//How likely a "big" wave will hit this boat
"big_wave_probability": 0.03,
//How strong the "big" wave will be
"big_wave_speed": 10.0,
//How strong will the boat be dragged down in case this component is removed
"drag_down_on_buoyancy_removed": 0,
//Blocks this entity can be buoyant in. Only actual liquids are allowed: lava and water
"liquid_blocks": ["water"]
},
//Sets the boat speed in water
"minecraft:underwater_movement": {
"value": 5
},
//This component is important, without it the boat will sink
"minecraft:navigation.walk": {
"can_sink": false
},
"minecraft:rideable": {
"seat_count": 1,
"family_types": ["player"],
"interact_text": "action.interact.enter_boat",
"seats": {
"position": [0, 0, 0]
}
},
//Add this component if you want your boat to be controlled with WASD
"minecraft:input_ground_controlled": {},
"minecraft:health": {
"value": 10,
"max": 10
},
//Sets the boat speed on the ground (set this to zero if you don't want your boats to move on the ground)
"minecraft:movement": {
"value": 3
},
//This is to prevent the boat from not stopping whenever a player exits the boat
"minecraft:movement.basic": {},
"minecraft:collision_box": {
"width": 1,
"height": 1
},
"minecraft:physics": {}
}
}
}
```
## What method to use?
Both methods are suitable but have their pros and cons. If you want to disable the bouncing effect, use the first method. If you want more control over it, use the second method. I use the second method for static objects, such as buoys, and the first method for movable entities, such as boats, emulating the vanilla behavior.

View File

@@ -0,0 +1,221 @@
---
title: Detecting Other Entities
category: Tutorials
tags:
- intermediate
mentions:
- ANightDazingZoroark
- SmokeyStack
- MedicalJewel105
- SirLich
- Luthorius
- TheItsNameless
---
You might have thought about making your entities fire an event when other entities are nearby. This article details the various known ways to do so.
## minecraft:entity_sensor
This is probably the most basic way to detect other entities. The main issues is it only accepts one entry and testing if the entity is out of range can be very tricky. Because it's an entity component, you can just place into your entity behavior file and edit the Minecraft filters. Here's a demonstration:
<CodeHeader>BP/entities/my_entity.json#components</CodeHeader>
```json
"minecraft:entity_sensor": {
"sensor_range": 2.5, //this is for the radius in blocks it will detect other entities in
"relative_range": false, //if true, the sensor range is additive on top of the entity's hitbox size
"require_all": true, //if true, all nearby entities must pass the filter conditions for the event to send
"minimum_count": 1, //minimum amount of entities required for the event to fire. by default, it's 1
"maximum_count": 4, //maximum amount of entities required for the event to fire. by default it's -1, which means infinity
"event_filters": { //you can put any filter you want here, the one that's being used in this example just detects players
"test": "is_family",
"subject": "other",
"value": "player"
},
"event": "event:on_player_detected" //the event that fires when all the conditions in event_filters are met
}
```
## `/execute`
Using the new `/execute` command that has been introduced since 1.19.50, you can execute commands as long as another entity is nearby.
This example you'll be following will make pigs say "oink oink" upon detecting players, though you can replace those with whatever you want. First of all, copy-paste these BP animations.
<CodeHeader>BP/animations/detection_animation.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"animations": {
"animation.pig.find_player": {
"animation_length": 0.05,
"loop": true,
"timeline": {
"0": [
"/execute as @s if entity @e[type=player, r=4] run event entity @s wiki:player_detected"
]
}
},
"animation.pig.find_no_player": {
"animation_length": 0.05,
"loop": true,
"timeline": {
"0": [
"/execute as @s unless entity @e[type=player, r=4] run event entity @s wiki:no_player_detected"
]
}
}
}
}
```
The first one is for detecting if the entity is present, and the other for detecting if the entity is not present. The events used in the `/event` part of the `/execute` commands can be used for adding a [dummy component](/entities/dummy-components) or updating an [actor property](https://learn.microsoft.com/en-us/minecraft/creator/documents/introductiontoentityproperties).
Next of all, copy paste this BP animation controller. This assumes that you set up the `/event` parts of the `/execute` commands to add or remove `minecraft:is_sheared`.
<CodeHeader>BP/animation_controllers/pig_animation_controllers.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.pig_find_player": {
"initial_state": "default",
"states": {
"default": {
"animations": ["find_player"],
"transitions": [
{
"detected": "q.is_sheared"
}
]
},
"detected": {
"animations": ["find_no_player"],
"transitions": [
{
"default": "!q.is_sheared"
}
],
"on_entry": ["/say oink oink"]
}
}
}
}
}
```
Finally, copy-paste this snippet into the behavior file for the pig-like so. Make sure to insert this in `description`.
<CodeHeader>BP/entities/my_entity.json#description</CodeHeader>
```json
"animations": {
"manage_find_player": "controller.animation.pig_find_player",
"find_player": "animation.pig.find_player",
"find_no_player": "animation.pig.find_no_player"
},
"scripts": {
"animate": [
"manage_find_player"
]
}
```
## Molang, BP Animations & Animation Controllers
The `for_each` function and `q.get_nearby_entities` or `q.get_nearby_entities_except_self` can also be used for detecting other entities. They are more effective than using `minecraft:entity_sensor` because they are better at detecting if the entity you want to detect goes away than with `minecraft:entity_sensor`. The only downside is that they're experimental.
Just like in the previous method we will make pigs say "oink oink" upon detecting players, though you can replace those with whatever you want. First of all, copy-paste this BP animation:
<CodeHeader>BP/animations/detection_animation.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"animations": {
"animation.pig.find_player": {
"animation_length": 0.05,
"loop": true,
"timeline": {
"0": [
"v.x = 0.0; for_each(t.player, q.get_nearby_entities_except_self(16, 'minecraft:player'), { v.x = v.x + 1; }); return v.x > 0.0;"
]
}
}
}
}
```
The first parameter that `q.get_nearby_entities_except_self` needs to work is the radius in blocks it will detect other entities in. The other is the identifier of the mob you want to make it detect.
Now that's good and all, but on the off chance, you want to make the pig detect players with some attribute that can be detected with Molang, use this.
<CodeHeader>BP/animations/detection_animation.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"animations": {
"animation.pig.find_player": {
"animation_length": 0.05,
"loop": true,
"timeline": {
"0": [
"v.x = 0.0; for_each(t.player, q.get_nearby_entities_except_self(2, 'minecraft:player'), { v.x = v.x + (t.player -> q.is_sheared); }); return v.x > 0.0;"
]
}
}
}
}
```
Next of all, copy paste this BP animation controller:
<CodeHeader>BP/animation_controllers/pig_animation_controllers.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.pig_find_player": {
"initial_state": "default",
"states": {
"default": {
"animations": ["find_player"],
"transitions": [
{
"detected": "v.x > 0"
}
]
},
"detected": {
"animations": ["find_player"],
"transitions": [
{
"default": "v.x <= 0"
}
],
"on_entry": ["/say oink oink"]
}
}
}
}
}
```
Finally, copy-paste this snippet into the behavior file for the pig-like so. Make sure to insert this in `description`.
<CodeHeader>BP/entities/my_entity.json#description</CodeHeader>
```json
"animations": {
"manage_find_player": "controller.animation.pig_find_player",
"find_player": "animation.pig.find_player"
},
"scripts": {
"animate": [
"manage_find_player"
]
}
```

View File

@@ -0,0 +1,184 @@
---
title: Disabling Team-damage
category: Tutorials
tags:
- intermediate
mentions:
- SirLich
- solvedDev
- Joelant05
- MedicalJewel105
- Luthorius
- TCLynx
---
If you wish to disable team damage (so one cannot hurt their teammates), assign a tag with the team name to every teammate (I'm going to use `team1`, `team2`, `team3` and `team4` for this example).
WARNING: This will NOT work on realms, the reason for this is that on realms there is a bug where modified player.json files in the behavior packs do not work, and the gmae just ignores them (This may be fixed in the future but as of 1.20.15 it is not fixed. (This also applies to older version of minecraft as well.))
Now add this damage sensor component into your `player.json`s `"components": {}`. See comments for explanation.
<CodeHeader>BP/entities/player.json#components</CodeHeader>
```json
"minecraft:damage_sensor":{
"triggers":[
{ //if you already have a damage sensor, simply copy this object into the "triggers" array
"on_damage":{
"filters":{
"any_of":[
{
"all_of":[
{ "test":"has_tag", "value":"team1" }, //Does the player have this tag?
{ "test":"has_tag", "subject":"other", "value":"team1" } //If so, does the entity they're trying to hurt have this tag?
]
},
{
"all_of":[
{ "test":"has_tag", "value":"team2" }, //repeats for every team
{ "test":"has_tag", "subject":"other", "value":"team2" }
]
},
{
"all_of":[
{ "test":"has_tag", "value":"team3" },
{ "test":"has_tag", "subject":"other", "value":"team3" }
]
},
{
"all_of":[
{ "test":"has_tag", "value":"team4" },
{ "test":"has_tag", "subject":"other", "value":"team4" }
]
},
{
"all_of":[
{ "test":"has_tag", "value":"team5" },
{ "test":"has_tag", "subject":"other", "value":"team5" }
]
}
]
}
},
"deals_damage":false //if any of these filters evaluate to true in the current attack interaction, the target will not be hurt.
}
]
}
```
### Projectiles
Due to the primitive filters used by projectile entities, you have to use a completely different method to achieve this.
The process uses:
- Tags
- Ticking
- Hurt on Condition
- Functions
<CodeHeader>BP/entities/player.json#components</CodeHeader>
```json
//"components"
"minecraft:timer": { //This is for applying teams to a projectile to nearby
"time": [ //untagged projectiles, through an event.
0.0,
0.1
],
"looping": true,
"time_down_event": {
"event": "wiki:projectile_team",
"target": "self"
}
},
"minecraft:hurt_on_condition": { //The projectile will be unable to directly deal
"damage_conditions": [ //damage, so instead we'll apply tags to the
{ //player, which will trigger this . . .
"filters": {
"test": "has_tag",
"value": "damage"
},
"cause": "projectile",
"damage_per_tick": 4
}
]
},
"minecraft:damage_sensor": { //. . . which in turn, will trigger an event
"triggers": { //to remove this tag, so the damage only
"cause": "projectile", //happens once.
"deals_damage": true,
"on_damage": {
"filters": {
"test": "has_tag",
"value": "damage"
},
"event": "wiki:stop_damage"
}
}
}
//"events"
"wiki:projectile_team": { //The function here will apply tags depending on
"run_command": { //which team tags the player has.
"command": [
"function wiki-apply_team"
]
}
},
"wiki:stop_damage": { //The event that simply removes the damage tag.
"run_command": {
"command": [
"tag @s remove damage"
]
}
}
```
<CodeHeader>BP/functions/wiki-apply_team.mcfunction</CodeHeader>
```
execute @s[tag=team1] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team1
execute @s[tag=team2] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team2
execute @s[tag=team3] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team3
execute @s[tag=team4] ~ ~ ~ tag @e[rm=0,r=1,c=1,type=arrow,tag=] add team4
```
<CodeHeader>BP/entities/arrow.json</CodeHeader>
```json
//"components"
"on_hit": { //On_hit, trigger an event . . .
"definition_event": {
"affect_projectile": true,
"event_trigger": {
"event": "wiki:hit",
"target": "self"
}
},
"remove_on_hit": {}
}
//"events"
"wiki:hit": { //. . . which executes a function, applying
"run_command": { //the damage tag to any players of a different team!
"command": [
"function wiki-apply_damage"
]
}
}
```
<CodeHeader>BP/functions/wiki-apply_damage.mcfunction</CodeHeader>
```
execute @s[tag=team1] ~ ~ ~ tag @p[rm=0,r=1,tag=!team1] add damage
execute @s[tag=team2] ~ ~ ~ tag @p[rm=0,r=1,tag=!team2] add damage
execute @s[tag=team3] ~ ~ ~ tag @p[rm=0,r=1,tag=!team3] add damage
execute @s[tag=team4] ~ ~ ~ tag @p[rm=0,r=1,tag=!team4] add damage
```
If you modify `arrow.json`, take into consideration the component groups.

View File

@@ -0,0 +1,146 @@
---
title: Dummy Entities
category: Tutorials
tags:
- beginner
mentions:
- SirLich
- Joelant05
- MedicalJewel105
- aexer0e
---
Dummy entities are invisible entities which are used behind the scenes for game-play purposes. Dummy entities are a very useful tool, and this document will cover some of the ways they are utilized, as well as showing how to set up the resource side of things.
## Using Dummies
This is a non-exhaustive list of how dummies can be used:
- **For data storage**: by adding tags to the entity, we can use it as a "game manager", much like Armor Stands used to be used.
- **As a named entity:** by name-tagging a dummy, and then using `execute` to select for it, you can make command-blocks `/say` with a pretty display name.
- **As a location marker:** you can run `execute` commands located at a dummy to get relative coordinates at a location.
- **As a waypoint:** by making entities which are aggressive to your dummy, you can pathfind entities to any location by placing a dummy there.
## Creating Dummies
### Behavior Entity
You can use whatever behaviors you like, but here is a good template. The important aspects are: no damage, and can't be pushed.
<CodeHeader>BP/entities/dummy.json</CodeHeader>
```json
{
"format_version": "1.16.0",
"minecraft:entity": {
"description": {
"identifier": "wiki:dummy",
"is_summonable": true,
"is_spawnable": false,
"is_experimental": false
},
"components": {
"minecraft:breathable": { //Optional, allows the entity to breath underwater
"breathes_water": true
},
"minecraft:physics": {
"has_gravity": false, //Optional, allows the entity to not be affected by gravity or water
"has_collision": false
},
"minecraft:custom_hit_test": {
"hitboxes": [
{
"pivot": [0, 100, 0],
"width": 0,
"height": 0
}
]
},
"minecraft:damage_sensor": {
"triggers": {
"deals_damage": false
}
},
"minecraft:pushable": {
"is_pushable": false,
"is_pushable_by_piston": false
},
"minecraft:collision_box": {
"width": 0.0001,
"height": 0.0001
}
}
}
}
```
If you want to disable collision at all (so you can place a block at it's position), you can use arrow runtime identifier, however, there can be some side effects.
### Resource Entity
<CodeHeader>RP/entity/dummy.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"minecraft:client_entity": {
"description": {
"identifier": "wiki:dummy",
"materials": {
"default": "entity_alphatest"
},
"geometry": {
"default": "geometry.dummy"
},
"render_controllers": ["controller.render.dummy"],
"textures": {
"default": "textures/entity/dummy"
}
}
}
}
```
### Geometry
<CodeHeader>RP/models/entity/dummy.json</CodeHeader>
```json
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.dummy",
"texture_width": 16,
"texture_height": 16
}
}
]
}
```
### Render Controller (Optional)
<CodeHeader>RP/render_controllers/dummy.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"render_controllers": {
"controller.render.dummy": {
"geometry": "Geometry.default",
"textures": ["Texture.default"],
"materials": [
{
"*": "Material.default"
}
]
}
}
}
```
### Texture (Optional)
You can either leave the texture location blank, or open the model in blockbench and create a blank texture.

View File

@@ -0,0 +1,570 @@
---
title: Entity Attacks
category: Tutorials
mentions:
- Luthorius
- TheDoctor15
- SirLich
- MedicalJewel105
- epxzzy
- ThomasOrs
tags:
- intermediate
---
Entity attacks are a complex subject that require many different things to work correctly:
- Navigation and movement abilities to move towards its target
- Targeting abilities to pick which entity to attack
- Attack type, such as melee or ranged
- Attack damage and effects
## Selecting Targets
### Movement
Before a mob can attack, it will need various [movement components](/entities/entity-movement).
Before starting to create your entity attacks, you should ensure that your entity can walk around, and navigate its surroundings.
:::warning
Even if you are making an unmoving entity (like turret), you still need to add navigation component, so your entity can find the entity to shoot.
:::
### Triggering Hostility
There are many ways to trigger hostility. The most common type `nearest_attackable_target`, is shown here. It generally allows you to define which entities this entity is interested in attacking:
<CodeHeader></CodeHeader>
```json
"minecraft:behavior.nearest_attackable_target": {
"must_see": true, //If true, potential target must be in mob's line of sight
"reselect_targets": true, //Allows mob to select new target, if one is closer than current
"within_radius": 25.0, //Radius that potential target must be withing
"must_see_forget_duration": 17.0, //If "must_see" = true, time before forgetting target
"entity_types": [
{
"filters": { //Entities to attack
"test": "is_family",
"subject": "other",
"value": "player"
},
"max_dist": 48.0
}
]
}
```
For more fine control, you may also consider using one of the following components:
| Component | Note |
| -------------------------------------------------------- | ------------------------------------------------------------ |
| minecraft:behavior.nearest_attackable_target | Targets entity meeting the given requirements |
| minecraft:behavior.nearest_prioritized_attackable_target | Allows for "priority": [integer] to be set after each filter |
| minecraft:behavior.defend_trusted_target | Targets entity that hurts any entities specified in filters |
But there is also one more - `minecraft:lookat`
This last component is slightly different to the other three, as it is for detecting and targeting entities that attempt eye contact. It is structured like so:
<CodeHeader>BP/entities/enderman.json</CodeHeader>
```json
"minecraft:lookat": {
"search_radius": 64.0,
"set_target": true, //Becomes a valid target if true
"look_cooldown": 5.0,
"filters": {
"all_of": [
{
"subject": "other",
"test": "is_family",
"value": "player"
},
{
"test": "has_equipment",
"domain": "head",
"subject": "other",
"operator": "not",
"value": "carved_pumpkin" //All players not with carved_pumpkin equipped on head
}
]
}
}
```
### Target selecting
:::tip
This section shows you how to configure the "Targeting" components, explained above.
:::
Mobs find targets by using [filters](https://bedrock.dev/docs/stable/Entities#Filters) can be used to determine which entities are a valid target, through `test`, `subject`, `operator`, and `value`.
<CodeHeader></CodeHeader>
```json
"entity_types":[
{
"filters":{
"any_of":[
{
"test":"is_family",
"subject":"other",
"operator":"==",
"value":"snow_golem"
},
{
"test":"is_family",
"subject":"other",
"operator":"==",
"value":"iron_golem"
}
//anything that is equal to either" snow_golem" or "iron_golem"
]
},
"max_dist":24
},
{
"filters":{
"all_of":[
{
"test":"is_family",
"subject":"other",
"operator":"==",
"value":"player"
},
{
"test":"has_equipment",
"subject":"other",
"domain":"head",
"operator":"=!",
"value":"turtle_helmet"
}
//anything equal to player AND not wearing "turtle_helmet" on head
]
},
"max_dist":24
}
]
```
This would only target `snow_golem`s, `iron_golem`s, and `player`s that are **not** wearing `turtle_helmet`s.
## Types of Attack
Here are the available attacks:
| Component | Note |
| ---------------------------------------------------- | -------------------------------------------------------- |
| [minecraft:behavior.melee_attack](#melee) | Deals damage to a single target |
| [minecraft:behavior.ranged_attack](#ranged) | Fires a projectile towards a target |
| [minecraft:area_attack](#area) | Effectively melee attacks on anything withing range |
| [minecraft:behavior.knockback_roar](#knockback-roar) | Similar to minecraft:area_attack, but much more flexible |
### Melee
Melee attacks are the most common type of attack, they cause knockback, and have a 100% success rate at accuracy.
<CodeHeader></CodeHeader>
```json
"wiki:melee_attack": {
"minecraft:attack": {
"damage": 3,
"effect_name": "slowness",
"effect_duration": 20
},
"minecraft:behavior.melee_attack": {
"priority": 3,
"melee_fov": 90.0, //The allowable FOV the actor will use to determine if it can make a valid melee attack
"speed_multiplier": 1,
"track_target": false,
"require_complete_path": true
}
}
```
Set the damage, choose a mob effect, and change some additional properties.
The value defined in components stating integers of damage can simply be a constant, or a string containing 2 numbers, for a range of possible values.
`"damage": 3` would result in 3 each time
`"damage": [ 2, 6 ]` would result in any integer between 2 and 6
Both the mob effect and duration timer are optional, but when they are used, the available effects are as following:
| Effect Name |
| --------------- |
| speed |
| slowness |
| haste |
| mining_fatigue |
| strength |
| instant_health |
| instant_damage |
| jump_boost |
| nausea |
| regeneration |
| resistance |
| fire_resistance |
| water_breathing |
| invisibility |
| blindness |
| night_vision |
| hunger |
| weakness |
| poison |
| wither |
| health_boost |
| absorption |
| saturation |
| levitation |
| fatal_poison |
| slow_falling |
| conduit_power |
| bad_omen |
| village_hero |
| darkness |
### Ranged
Fires specified [projectiles](/documentation/projectiles) towards target at set intervals.
<CodeHeader></CodeHeader>
```json
"wiki:ranged_attack": {
"minecraft:behavior.ranged_attack": {
"priority": 2,
"ranged_fov": 90.0, //The allowable FOV the actor will use to determine if it can make a valid ranged attack
"attack_interval_min": 1.0,
"attack_interval_max": 3.0,
"attack_radius": 15.0
},
"minecraft:shooter": {
"def": "wiki:projectile"
}
}
```
List of vanilla projectiles:
| Vanilla Projectiles |
| -------------------------------- |
| minecraft:arrow |
| minecraft:dragon_fireball |
| minecraft:egg |
| minecraft:ender_pearl |
| minecraft:fireball |
| minecraft:fishing_hook |
| minecraft:lingering_potion |
| minecraft:llama_spit |
| minecraft:skulker_bullet |
| minecraft:small_fireball |
| minecraft:snowball |
| minecraft:splash_potion |
| minecraft:thrown_trident |
| minecraft:wither_skull |
| minecraft:wither_skull_dangerous |
| minecraft:xp_bottle |
Only one item has an effect on an entity's ranged attacks. Crossbows. If one is equipped, it is first required for it to be "charged" before the entity can fire anything. Regardless of the projectile stated in `minecraft:shooter`, the item to charge the crossbow with should always be `minecraft:arrow`.
<CodeHeader></CodeHeader>
```json
"minecraft:behavior.charge_held_item": {
"priority": 2,
"items": [
"minecraft:arrow"
]
}
```
Once `minecraft:behavior.charge_held_item` has been achieved, the entity will be able to execute the process of `minecraft:behavior.ranged_attack`, and will then need to charge again.
### Area
These attacks damage all entities within a set radius. It is different to both ranged and melee in that this component doesnt actually require a target. Regardless of the entities behaviour, _all_ entities will be affected by this. It appears to be similar to melee attacks, as it deals knockback in a similar manner, though dealing damage at a constant rate.
<CodeHeader></CodeHeader>
```json
"minecraft:area_attack" : {
"damage_range": 1, //distance in blocks
"damage_per_tick": 2,
"cause": "contact",
"entity_filter": {
"any_of": [
{
"test": "is_family",
"subject": "other",
"value": "player"
},
{
"test": "is_family",
"subject": "other",
"value": "monster"
}
]
}
}
```
[Entity damage sources](https://bedrock.dev/docs/stable/Addons#Entity%20Damage%20Source). It is important to take these into consideration, as certain items in vanilla can protect from some, like armour enchantments, and you can also make mobs immune to specific sources using `minecraft:damage_sensor`.
### Knockback Roar
Many similarities between this and `minecraft:area_attack`, this component though having much more flexibility.
<CodeHeader></CodeHeader>
```json
"wiki:roar_attack": {
"minecraft:behavior.knockback_roar":{
"priority":2,
"duration":0.7,
"attack_time":0.2,
"knockback_damage":1,
"knockback_horizontal_strength":1,
"knockback_vertical_strength":1,
"knockback_range":5,
"knockback_filters":{
"test":"is_family",
"subject":"other",
"operator":"==",
"value":"player"
},
"damage_filters":{
"test":"is_family",
"subject":"other",
"operator":"==",
"value":"player"
},
"on_roar_end":{
"event":"wiki:other_event"
},
"cooldown_time":10
}
}
```
This is more like a shockwave of damage. Extremely versatile in uses. Produces a particle effect, which can be disabled by adding a modified version of `knockback_roar.json` to a resource pack's particles folder.
## More on Attacks
Entity Attacks don't have to be as simple as Mob being hostile towards X target, doing X attack, dealing X damage.
### Difficulty Dependant Attacks
Express components and values to use for each difficulty.
<CodeHeader>BP/entities/bee.json</CodeHeader>
```json
"easy_attack": {
"minecraft:attack": {
"damage": 2
}
},
"normal_attack": {
"minecraft:attack": {
"damage": 2,
"effect_name": "poison",
"effect_duration": 10
}
},
"hard_attack": {
"minecraft:attack": {
"damage": 2,
"effect_name": "poison",
"effect_duration": 18
}
}
```
### Switching Modes
You can use events to make your mob only attack under specific circumstances, or swap between the different types of attack. This can be achieved through simple usage of [events](/entities/entity-events) and component groups. Two prime examples being `minecraft:environment_sensor` and `minecraft:target_nearby_sensor`. The two are pretty similar in regards of structure, difference being that one is for sensing environments and the other for testing for target distance.
#### Attacks
Component groups are required to define the different modes of attack, such as:
<CodeHeader></CodeHeader>
```json
"wiki:ranged_components": {
"minecraft:shooter": {
"def": "wiki:projectile"
},
"minecraft:behavior.ranged_attack": {
"priority": 3,
"ranged_fov": 90.0,
"attack_interval_min": 1.0,
"attack_interval_max": 3.0,
"attack_radius": 15.0
}
}
```
<CodeHeader></CodeHeader>
```json
"wiki:melee_components": {
"minecraft:attack": {
"damage": 6
},
"minecraft:behavior.melee_attack": {
"priority": 3
}
}
```
Those are examples of your attack modes, but they are not the only ones you can use. `wiki:ranged_components` and `wiki:melee_components` are generic names for the components within them, they can have any name, but it's what's nested inside them that counts.
#### Events
These component groups won't actually do anything by themselves. Another component group is required, and some events to add/remove the attack modes.
<CodeHeader></CodeHeader>
```json
"wiki:melee_swap": { //When triggered, adds component group for ranged and removes melee component group
"remove": {
"component_groups": [
"wiki:ranged_components"
]
},
"add": {
"component_groups": [
"wiki:melee_components"
]
}
}
```
<CodeHeader></CodeHeader>
```json
"wiki:ranged_swap": { //When triggered, adds component group for melee and removes ranged component group
"remove": {
"component_groups": [
"wiki:melee_components"
]
},
"add": {
"component_groups": [
"wiki:ranged_components"
]
}
}
```
The events are effectively for just turning attack modes on and off, by adding and removing different component groups.
#### Sensors
To trigger the events, another component group is used. Sensors are components that can trigger events when certain conditions are fulfilled. Here are 2 examples of different sensors:
- For sensing the distance between the mob and target
<CodeHeader></CodeHeader>
```json
"wiki:switcher_range": {
"minecraft:target_nearby_sensor": {
"inside_range": 4.0,
"outside_range": 5.0,
"must_see": true,
"on_inside_range": { //When target is within 4 blocks range, trigger "wiki:melee_swap" event
"event": "wiki:melee_swap",
"target": "self"
},
"on_outside_range": { //When target is beyond 5 blocks range, trigger "wiki:ranged_swap" event
"event": "wiki:ranged_swap",
"target": "self"
}
}
}
```
- For sensing certain features of the environment of which the mob is exposed to
<CodeHeader></CodeHeader>
```json
"wiki:switcher_environment": {
"minecraft:environment_sensor": {
"triggers": [
{
"filters": { //When underwater, trigger "wiki:melee_swap" event
"test": "is_underwater",
"subject": "self",
"operator": "==",
"value": true
},
"event": "wiki:melee_swap"
},
{
"filters": { //When not underwater, trigger "wiki:ranged_swap" event
"test": "is_underwater",
"subject": "self",
"operator": "==",
"value": false
},
"event": "wiki:ranged_swap"
}
]
}
}
```
This uses `Filters`, similar to how the [target is initially selected](#target-selecting).
:::tip
You aren't limited to just 2 attack types, you can have as many as you want! Just make sure to have the event's and sensors to compensate for them.
:::
## Visual Animations
Attacks and animations go hand in hand. Within resource packs, the following 3 directories are required:
- animations (entityname.animation.json)
- animation_controllers (entityname.animation_controller.json)
- entity (entityname.json)
Or as long as you know the names of vanilla animations and animation controllers, you can define them in the latter directory and folder.
### Animations
Animations are self explanatory. The files themselves contain all specific animations for the given entity. The recommended way to make animations is by using [blockbench](/guide/blockbench).
Though it is possible to create them in a simple text editor.
| Vanilla Attack Animations |
| -------------------------------------------- |
| "animation.zombie.attack_bare_hand" |
| "animation.skeleton.attack.v1.0" |
| "animation.humanoid.bow_and_arrow.v1.0" |
| "animation.humanoid.damage_nearby_mobs.v1.0" |
A few examples of Animations. Locate /vanilla_resource_pack/animations for all of them.
### Animation Controllers
List of states that trigger animations.
| Vanilla Attack Animation Controllers |
| ---------------------------------------------- |
| "controller.animation.zombie.attack_bare_hand" |
| "controller.animation.skeleton.attack" |
| "controller.animation.humanoid.bow_and_arrow" |
| "controller.animation.humanoid.attack" |
A few examples of Animation Controllers. Locate /vanilla_resource_pack/animation_controllers for all of them
More information on animations can be found [here](https://bedrock.dev/docs/stable/Animations).

View File

@@ -0,0 +1,76 @@
---
title: Entity Holds Item
category: Tutorials
tags:
- intermediate
mentions:
- pieterdefour
- SirLich
- solvedDev
- stirante
- Joelant05
- destruc7ion
- Dreamedc2015
- sermah
- 7dev7urandom
---
::: tip
This tutorial assumes you have a basic understanding of entities, loot tables, and Blockbench.
:::
In this tutorial, you will learn to have an entity spawn with an item in its hand. I'll be using a custom `mandalorian_armorer` entity and a custom `hammer` item for the examples.
## Model
First of all, you'll need to have a model in Blockbench that has a map called `rightArm`. Within this map, there needs to be a submap called 'rightItem'.
Now set the position of the pivot point of this submap, so it sits in the place you want the entity to hold the item at.
![](/assets/images/tutorials/entity-holds-item/blockbench.png)
## Behavior Pack-side
Now you'll need to add a `minecraft:equipment` component in the component list for your entity and add a loot table with the desired item.
In our example it will look like this:
<CodeHeader>BP/entity/mandolorian.json#components</CodeHeader>
```json
"minecraft:equipment": {
"table": "loot_tables/entities/gear/mandolorian.json"
}
```
## Loot Table
Finally, add the loot table for your entity. It needs to be in `loot_tables/entities/<your_loot_table_name>.json` in the behavior pack. In our case, it's called `mandolorian.json`.
:::warning
This isn't the same loot table as what it drops on death. So make sure it has a different name.
:::
To have the entity always spawn with the same item, add the following loot table:
<CodeHeader>BP/loot_tables/entities/gear/mandolorian.json</CodeHeader>
```json
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "dd:hammer",
"weight": 1
}
]
}
]
}
```
If everything went well, you'd have something looking like this:
![](/assets/images/tutorials/entity-holds-item/finished_result.png)

View File

@@ -0,0 +1,202 @@
---
title: Entity Movement
category: Tutorials
mentions:
- SirLich
- sermah
- MedicalJewel105
- TheDoctor15
---
In Minecraft, entities have the ability to move through the world, either by walking, swimming or flying. To get these behaviors, your entity will generally need quite a few behaviors, broken out into various types.
As you read this tutorial, keep in mind that your entity will need at least:
- [A component that sets the entities movement speed.](#movement-speed)
- [A component to set how the entity will move (walking, flying, etc)](#movement-type)
- [A component to set the entities navigation abilities, so it can generate paths.](#navigation-abilities)
- [A component that sets where/when the entity should move (AI Goals).](#ai)
:::tip
The best way to create a moving entity is by picking a similar entity from the vanilla behavior pack, and copying the components into your entity.
For example entities like Phantom, or Ghast, or Parrot are all flying entities, but have very different in-game behavior! Use the closest-matching entity as a template.
:::
## Movement Speed
The first thing your entity needs is a speed component. This sets how quickly your entity will move through the world.
| Component | Note |
| ---------------------------------------------------------------------------------------------------------------- | -------------------------------- |
| [minecraft:movement](/entities/vanilla-usage-components#movement) | Set movement speed (required) |
| [minecraft:underwater_movement](/entities/vanilla-usage-components#underwater-movement) | Set movement speed in the water. |
| [minecraft:flying_speed](/entities/vanilla-usage-components#flying-speed) | Set the speed in the air. |
You should always include `minecraft:movement`. Add the other two as needed.
All vanilla "swimming" entities like Dolphin include `underwater_movement`. Only some flying entities have `flying_speed`. It is not known why this is the case.
## Movement Type
Your entity will also need a movement type. Movement types set hard-coded behavior for _how_ your entity will move through the world.
You may only include one movement type in your entity. Select the component that most closely matches your needs. Generally `basic`, `amphibious` and `fly` are good ones to use.
| Component | Note |
| --------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| [minecraft:movement.amphibious](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.amphibious) | This move control allows the mob to swim in the water and walk on land. |
| [minecraft:movement.basic](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.basic) | This component accents the movement of an entity. |
| [minecraft:movement.fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.fly) | This move control causes the mob to fly. |
| [minecraft:movement.generic](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.generic) | This move control allows a mob to fly, swim, climb, etc. |
| [minecraft:movement.hover](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.hover) | This move control causes the mob to hover. |
| [minecraft:movement.jump](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.jump) | Move control causes the mob to jump as it moves with a specified delay between jumps. |
| [minecraft:movement.skip](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.skip) | This move control causes the mob to hop as it moves. |
| [minecraft:movement.sway](https://bedrock.dev/docs/stable/Entities#minecraft%3Amovement.sway) | This move control causes the mob to sway side to side, giving the impression it is swimming. |
## Movement Modifiers
Movement modifiers provide additional information about how your entity will move through the world. These components are not required for normal entities, but you should be aware of them.
| Component | Note |
| ----------------------------------------------------------------------------------------------------- | -------------------------------------------------- |
| [minecraft:water_movement](https://bedrock.dev/docs/stable/Entities#minecraft%3Awater_movement) | Sets the friction the entity experiences in water. |
| [minecraft:rail_movement](https://bedrock.dev/docs/stable/Entities#minecraft%3Arail_movement) | Sets that the entity can move on rails (only). |
| [minecraft:friction_modifier](https://bedrock.dev/docs/stable/Entities#minecraft%3Afriction_modifier) | Sets the friction the entity experiences on land. |
## Navigation
The next thing your entity needs is a navigation component. Navigation components have quite a few fields, like whether the entity can open doors or avoid sunlight. How you set these fields is generally more important than the navigation component you pick!
The reason there are so many navigation components is that each one gives a slightly different hard-coded behavior. Pick the navigation component whose name/description best matches the kind of navigation your entity will be doing.
You can only have one navigation component at any given time.
:::tip
This component is very important. You should check vanilla examples for inspiration on what fields and values to use.
:::
| Component | Note |
| ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| [minecraft:navigation.climb](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.climb) | Allows this entity to generate paths that include vertical walls like the vanilla Spiders do. |
| [minecraft:navigation.float](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.float) | Allows this entity to generate paths by flying around the air like the regular Ghast. |
| [minecraft:navigation.generic](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.generic) | Allows this entity to generate paths by walking, swimming, flying and climbing around, and jumping up and down a block. |
| [minecraft:navigation.fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.fly) | Allows this entity to generate paths in the air as the vanilla Parrots do. |
| [minecraft:navigation.swim](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.swim) | Allows this entity to generate paths that include water. |
| [minecraft:navigation.walk](https://bedrock.dev/docs/stable/Entities#minecraft%3Anavigation.walk) | Allows this entity to generate paths by walking around and jumping up and down a block like regular mobs. |
## Navigation Abilities
On top of the movement and the navigation component, there exist many additional components to augment the abilities of your entity as they move through the world.
| Component | Note |
| ------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| [minecraft:annotation.break_door](https://bedrock.dev/docs/stable/Entities#minecraft%3Aannotation.break_door) | Allows entity to break doors. It must also be turned on in the navigation component. |
| [minecraft:annotation.open_door](https://bedrock.dev/docs/stable/Entities#minecraft%3Aannotation.open_door) | Allows entity to open doors. It must also be turned on in the navigation component. |
| [minecraft:buoyant](https://bedrock.dev/docs/stable/Entities#minecraft%3Abuoyant) | Specifies which liquids the entity can float in. |
| [minecraft:can_climb](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_climb) | Allows this entity to climb up ladders. |
| [minecraft:can_fly](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_fly) | Marks the entity as being able to fly. The pathfinder won't be restricted to paths where a solid block is required underneath it. |
| [minecraft:can_power_jump](https://bedrock.dev/docs/stable/Entities#minecraft%3Acan_power_jump) | Allows the entity to power jump like the horse does in vanilla. |
| [minecraft:floats_in_liquid](https://bedrock.dev/docs/stable/Entities#minecraft%3Afloats_in_liquid) | Sets that this entity can float in liquid blocks. |
| [minecraft:jump.dynamic](https://bedrock.dev/docs/stable/Entities#minecraft%3Ajump.dynamic) | Defines a dynamic type jump control that will change jump properties based on the speed modifier of the mob. |
| [minecraft:jump.static](https://bedrock.dev/docs/stable/Entities#minecraft%3Ajump.static) | Gives the entity the ability to jump. |
There are also components like `minecraft:preferred_path`, which will modify navigation based on block-based path-cost.
## AI Goals
The navigation component tells the entity _how_ to generate paths, but it doesn't say _when_ or _where_ to generate paths. This is what the AI components are for.
AI Goals are prefixed with `behavior` and follow a priority system to pick which behavior to run. The lower priorities will be picked first.
In general, you should usually add quite a few AI components, with different priorities. Layered together, these will create realistic movement and behavior for your entity. As always, vanilla entities provide a good template for which components to add, and with what properties/priorities.
There are too many AI components that generate paths to list in this document. A few will be provided as examples:
| Component |
| --------------------------------------------------------------------------------------------------------------------------------- |
| [minecraft:behavior.random_stroll](https://bedrock.dev/docs/stable/Entities#minecraft%3Abehavior.random_stroll) |
| [minecraft:behavior.follow_owner](https://bedrock.dev/docs/stable/Entities#minecraft%3Abehavior.follow_owner) |
| [minecraft:behavior.move_to_water](https://bedrock.dev/docs/stable/Entities#minecraft%3Abehavior.move_to_water) |
| [minecraft:behavior.stroll_towards_village](https://bedrock.dev/docs/stable/Entities#minecraft%3Abehavior.stroll_towards_village) |
For a full list, visit [bedrock.dev](https://bedrock.dev/docs/stable/Entities#AI%20Goals).
### Pathfinding
Making entities go to specific places is one of the most common requests for Marketplace content.
The best way to do pathfinding uses a second entity, which the first entity will be attracted to. I am going to call this secondary entity the **marker**. If you are confused on how to create a marker, visit the [Dummy Entities](/entities/dummy-entities) page.
#### Idea
The way we are going to do pathfinding is actually fairly simple: Make our entity aggressive towards our marker, and then simply place our marker where we want our entity to path to. The hard part is knowing what components to add so we get really long-range pathing.
#### Components
These components can be edited as needed to create good pathing. Make sure to update the `nearest_attackable_target` to point to your marker entity. This takes a `family_type`, so you should set one of those on your marker.
Don't forget to add some basic movement and navigation components so your entity is able to move.
<CodeHeader></CodeHeader>
```json
"minecraft:behavior.nearest_attackable_target": {
"priority": 0,
"reselect_targets": true,
"target_search_height": 1000,
"within_radius": 1000,
"must_see": false,
"entity_types": [
{
"filters": [
{
"test": "is_family",
"subject": "other",
"value": "waypoint_1"
}
],
"max_dist": 1000
}
]
},
"minecraft:attack": {
"damage": 0
},
"minecraft:behavior.melee_attack": {
"priority": 0,
"require_complete_path": true,
"track_target": true
},
"minecraft:follow_range": {
"value": 1000,
"max": 1000
}
```
#### Detecting a reached waypoint
You can use `minecraft:target_nearby_sensor` to detect when you have reached the marker entity:
<CodeHeader></CodeHeader>
```json
"minecraft:target_nearby_sensor": {
"inside_range": 2.0,
"outside_range": 4.0,
"must_see": true,
"on_inside_range": {
"event": "reached_waypoint"
},
"on_outside_range": {
"event": "not_reached_waypoint"
}
}
```
## Other
:::tip
You can trigger entity walking animation via command.
`/execute as @e[type=...] at @s run tp @s ^^^0.1`
This way you can control where entity goes and make it look natural.
:::

View File

@@ -0,0 +1,359 @@
---
title: Flying Entities
category: Tutorials
tags:
- recipe
- intermediate
mentions:
- SirLich
- Joelant05
- Dreamedc2015
- MedicalJewel105
- aexer0e
- imsolucid
- nebulacrab
- Luthorius
- TheItsNameless
---
Whether making a plane or a dragon, adding controllability to flying entities will probably challenge most devs who haven't dabbled around this concept. Since there is no "right" way of adding a piloting mechanic to flying entities, I'll showcase 3 main workaround ways you can use to achieve this.
## Great Jump, Slow Fall
While not exactly "flying", setting the entity's jumping power high and giving it slow falling & speed effects as it falls is probably the most straightforward method.
To achieve this, we will need to add the `"minecraft:horse.jump_strength"` component to our entity. Adding this will allow you to control its jumping power and disable dismounting when the player presses the jump button.
<CodeHeader></CodeHeader>
```json
"minecraft:horse.jump_strength": {
"value": 7
}
```
We can also use `"value"` as an object to utilize the **range bar** players will see when holding down the jump button.
<CodeHeader></CodeHeader>
```json
"minecraft:horse.jump_strength": {
"value": { "range_min": 0.6, "range_max": 1.2 }
}
```
Now we will give it slow falling and speed as it's falling so that it doesn't instantly fall. To do this, we will make an animation controller and give it those effects when it's not on the ground as so:
(You can read a tutorial on how to use animation controllers to execute commands [here](/animation-controllers/entity-commands).)
<CodeHeader></CodeHeader>
```json
"controller.animation.dragon.flying":{
"states":{
"default":{
"transitions":[
{
"jumping":"!q.is_on_ground"
}
]
},
"jumping":{
"transitions":[
{
"default":"q.is_on_ground"
}
],
"on_entry":[
"/effect @s slow_falling 20000 0 true",
"/effect @s speed 20000 10 true"
],
"on_exit":[
"/effect @s clear"
]
}
}
}
```
We'll also need to hook it up to our entity as so:
<CodeHeader></CodeHeader>
```json
"description":{
"identifier":"wiki:dragon",
"is_spawnable":true,
"is_summonable":true,
"is_experimental":false,
"scripts":{
"animate":[
"flying"
]
},
"animations":{
"flying":"controller.animation.dragon.flying"
}
}
```
Now, we should have a mechanic at least resemblant of flying. You can change the values like jump_strength and speed, but the entity will always fall using this method.
## Controlling Through Looking
This is probably the most popular method of piloting flying entities, and unlike the first method, this one gives players control over the vertical movement of the entity so that you don't always have to fall every time you jump, with the downside being you can't look around freely without changing the entity's vertical trajectory.
This method detects the riding player's vertical rotation and applies levitation/slow_falling effects to the entity accordingly.
There are multiple ways of achieving that, but in this tutorial, we'll be using the target selectors `rym` (minimum y-rotation) and `ry` (maximum y-rotation) in a chain of repeating command-blocks to detect the player's pitch, and depending on the range, giving our entity levitation or slowly falling.
<CodeHeader></CodeHeader>
```
execute @a[rxm=-90,rx=-25] ~~~ effect @e[type=wiki:dragon,r=1] levitation 1 6 true
execute @a[rxm=-25,rx=-15] ~~~ effect @e[type=wiki:dragon,r=1] levitation 1 3 true
execute @a[rxm=-15,rx=-5] ~~~ effect @e[type=wiki:dragon,r=1] levitation 1 2 true
execute @a[rxm=-5,rx=20] ~~~ effect @e[type=wiki:dragon,r=1] levitation 1 1 true
execute @a[rxm=20,rx=35] ~~~ effect @e[type=wiki:dragon,r=1] slow_falling 1 1 true
execute @a[rxm=35,rx=90] ~~~ effect @e[type=wiki:dragon,r=1] clear
```
**Depending on how big your entity is and how far away the player's seat is from its pivot, you might need to change the radius `r` to a more significant value.**
After you run those commands in a repeating command block, you should control its vertical movement by looking up and down.
or you may use a simple animation controller and link it to the entity, so it always plays the function.
It's recommended that you link this animation controller to the player.
<CodeHeader></CodeHeader>
```json
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.base": {
"initial_state": "default",
"states": {
"default": {
"transitions": [
{
"base": "(1.0)"
}
],
"on_entry": [
"/function dragon_control"
]
},
"base": {
"transitions": [
{
"default": "(1.0)"
}
],
"on_entry": [
"/function dragon_control"
]
}
}
}
}
}
```
The entity will probably still be too slow when flying, so we'll borrow our animation controller from the first method with some changes to give the entity speed when it's flying.
<CodeHeader></CodeHeader>
```json
"controller.animation.dragon.flying":{
"states":{
"default":{
"transitions":[
{
"jumping_1":"!q.is_on_ground"
}
]
},
"jumping_1":{
"transitions":[
{
"transition_to_default":"q.is_on_ground"
},
{
"jumping_2":"true"
}
],
"on_entry":[
"/effect @s speed 15 10 true"
]
},
"jumping_2":{
"transitions":[
{
"transition_to_default":"q.is_on_ground"
},
{
"jumping_1":"true"
}
],
"on_entry":[
"/effect @s speed 15 10 true"
]
},
"transition_to_default":{
"transitions":[
{
"transition_to_default":"true"
}
],
"on_entry":[
"/effect @s clear"
]
}
}
}
```
_Since the entity's effects might be cleared when it's being flown, we changed the animation controller to give the entity speed every tick it's not on the ground._
You might also notice that the entity levitates when you go near it. We can fix this by giving the entity a tag when it's being ridden (removing it when it isn't being ridden) and only applying those effects when the entity has the tag by making and animating another animation controller and updating our commands.
<CodeHeader></CodeHeader>
```json
"controller.animation.dragon.test_rider":{
"states":{
"default":{
"transitions":[
{
"has_rider":"q.has_rider"
}
]
},
"has_rider":{
"transitions":[
{
"default":"!q.has_rider"
}
],
"on_entry":[
"/tag @s add has_rider"
],
"on_exit":[
"/tag @s remove has_rider"
]
}
}
}
```
<CodeHeader></CodeHeader>
```
execute @a[rxm=-90,rx=-25] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levitation 1 6 true
execute @a[rxm=-25,rx=-15] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levitation 1 3 true
execute @a[rxm=-15,rx=-5] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levitation 1 2 true
execute @a[rxm=-5,rx=20] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] levitation 1 1 true
execute @a[rxm=20,rx=35] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] slow_falling 1 1 true
execute @a[rxm=35,rx=90] ~~~ effect @e[type=wiki:dragon,r=1,tag=has_rider] clear
```
## Controlling Through Jumping
A third method of controlling flying entities uses the player's jump button. The entity rises when the player is holding the jump button and falls when they release their jump button.
To do this, we need an animation controller attached to the player rather than the entity itself to detect when the player uses their jump button. We also need to disable dismounting when the player presses the jump button.
First, on the entity, disable dismounting and jumping:
<CodeHeader></CodeHeader>
```json
"minecraft:horse.jump_strength": {
"value": 0
},
"minecraft:can_power_jump": {}
```
Next, we need an animation controller that causes the entity to levitate when the player uses their jump button and resets the levitation when they release their jump button.
<CodeHeader></CodeHeader>
```json
"controller.animation.fly_dragon":{
"initial_state":"falling",
"states":{
"falling":{
"on_entry":[
"/effect @e[type=wiki:dragon,r=1,c=1] levitation 0"
],
"transitions":[
{
"rising":"q.is_jumping"
}
]
},
"rising":{
"on_entry":[
"/effect @e[type=wiki:dragon,r=1,c=1] levitation 100000 6 true"
],
"transitions":[
{
"falling":"!q.is_jumping"
}
]
}
}
}
```
Now, we need a copy of the player's behavior file, which we will modify slightly. You can find the player's behavior file in the vanilla behavior pack provided by Mojang (found [here](https://aka.ms/behaviorpacktemplate)). Once you have copied the player's behavior file to your own behavior pack, find their `"description"` object and add the animation controller. We also want to ensure that the entity will only respond to the player's jump input when the player is riding it, so we can use a Molang query in the player's behavior to only activate the animation controller when the player is riding.
<CodeHeader></CodeHeader>
```json
"description":{
"identifier":"minecraft:player",
"is_spawnable":false,
"is_summonable":false,
"animations":{
"fly_dragon":"controller.animation.fly_dragon"
},
"scripts":{
"animate":[
{
"fly_dragon":"q.is_riding"
}
]
}
}
```
The entity can now be controlled with the jump key, but there's a bug. If the player dismounts the entity while holding the jump key, it will continue rising. We can fix this with an animation controller on the entity itself that resets the levitation whenever a player dismounts it.
<CodeHeader></CodeHeader>
```json
"controller.animation.reset_levitation":{
"initial_state":"no_rider",
"states":{
"no_rider":{
"transitions":[
{
"has_rider":"q.has_rider"
}
]
},
"has_rider":{
"on_exit":[
"/effect @s levitation 0"
],
"transitions":[
{
"no_rider":"!q.has_rider"
}
]
}
}
}
```

View File

@@ -0,0 +1,78 @@
---
title: Introduction to AOE Clouds
category: Tutorials
tags:
- intermediate
mentions:
- Sprunkles137
- MedicalJewel105
---
**Area-of-effect clouds**, also known as AOE clouds and `minecraft:area_effect_cloud` internally, are special entities that have many unique properties. Normally these entities are created through throwing lingering potions, but with structures and some NBT editing magic we can manipulate them in very powerful ways for map-making.
## Overview
Area-of-effect clouds have several special features we can take advantage of:
- As [dummy entities](/entities/dummy-entities), they are highly performant and barely affect framerate, and they are also completely static and have no collision with the world. This makes them perfect for situations around players or where precise positioning is important.
- It does not send the client updates. Once it spawns in, it will visually appear to be frozen in place until it despawns. However, it can still be moved around through commands just fine.
- It can apply any potion effect in highly configurable ways. The duration can be set down to the tick, as well as whether or not the effect is ambient, or displays on the screen, if it emits particles, etc.
- Entities with a runtime identifier of `minecraft:area_effect_cloud` inherit these same properties.
## Method 1: Projectile Component
The projectile component supports spawning in area-of-effect clouds on hit. Minecraft uses this to spawn in AOE clouds from lingering potions.
[Projectiles Documentation](/documentation/projectiles#spawn-aoe-cloud)
## Method 2: NBT Editing
Another way to spawn in these area-of-effect clouds is through structure files. This grants us finer control over the potion effects the cloud can have. So, our first order of business is getting a means to edit these structures.
### NBT Editors
One of the following NBT editors are recommended:
- [NBT Studio](https://github.com/tryashtar/nbt-studio) (a standalone program by tryashtar)
- [NBT Viewer](https://marketplace.visualstudio.com/items?itemName=Misodee.vscode-nbt) (a Visual Studio Code extension by Misode)
### Structure file
For convenience, this article contains a premade structure file you can download and use. Inside is an AOE cloud that exists for the maximum possible time.
<BButton
link="/assets/packs/entities/aec/aec.mcstructure" download
color=blue
>Download MCSTRUCTURE</BButton>
Refer to this article for editing structure files: [.mcstructure](/nbt/mcstructure)
### NBT Format
| Tag | Type | Description |
| --------------------- | ------- | ----------------- |
| Duration | Integer | How long the cloud exists for before expiring, in ticks. |
| DurationOnUse | Integer | How much the duration should change when effects are applied. |
| InitialRadius | Float | The size of this cloud's radius when created. |
| ParticleColor | Integer | The color of the particle effect, in decimal. |
| ParticleId | Integer | The particle effect this cloud emits. 0 emits no particles. |
| PotionId | Short | This cloud's potion effect ID when created. Has no effect. |
| RadiusChangeOnPickup | Float | Unknown. |
| RadiusOnUse | Float | How much the radius should change when effects are applied. |
| RadiusPerTick | Float | How much the radius changes every tick. |
| ReapplicationDelay | Integer | The interval at which effects can be applied, in ticks. |
| mobEffects | List | Describes what potion effects should be applied. |
Below are the parameters for the `mobEffects` tag.
| Tag | Type | Description |
| ------------------------------- | ------- | --------------- |
| Ambient | Byte | Defines whether this effect's particles should be translucent or not. |
| Amplifier | Byte | The strength of this potion effect. |
| DisplayOnScreenTextureAnimation | Byte | Unknown. |
| Duration | Integer | The amount of time this effect is applied for, in ticks. |
| DurationEasy | Integer | Unknown, seemingly unused. |
| DurationNormal | Integer | Unknown, seemingly unused. |
| DurationHard | Integer | Unknown, seemingly unused. |
| Id | Byte | The potion effect ID for this effect. |
| ShowParticles | Byte | Defines whether this effect's particles should appear or not. |

View File

@@ -0,0 +1,67 @@
---
title: Invulnerable Entities
category: Tutorials
tags:
- beginner
mentions:
- SirLich
- Joelant05
- solvedDev
- MedicalJewel105
---
## Using Damage Sensor
The best and most flexible way of disabling damage for entities is using the `minecraft:damage_sensor` component. The component allows us to use `filters` to determine which damage sources can damage our entity.
The best way to learn about this component is by using the vanilla examples for damage sensor or reading [documentation](https://bedrock.dev/docs/stable/Entities#minecraft:damage_sensor)
### Completely Invulnerable Entity
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
```json
"minecraft:damage_sensor": {
"triggers": {
"cause": "all",
"deals_damage": false
}
}
```
### Disable Damage from Player
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
```json
"minecraft:damage_sensor": {
"triggers": {
"on_damage": {
"filters": {
"test": "is_family",
"subject": "other",
"value": "player"
}
},
"deals_damage": false
}
}
```
## Min Health
The `min` property in the `minecraft:health` component allows us to make invincible entities that cannot die. This includes when using `/kill @e`. This is not considered a good solution because entities like this are hard to get rid of.
If you choose to use this component, please make sure you have another method for killing the entity. Triggering `minecraft:instant_despawn` from something like an environment sensor, a timer, or an interact is a good solution. You also can call it using `/event`.
<CodeHeader>BP/entities/entity.json#minecraft:entity/components</CodeHeader>
```json
"minecraft:health": {
"value": 1,
"max": 1,
"min": 1
}
```
Note that setting it to 0 breaks some death and spawn animations/effects.

View File

@@ -0,0 +1,44 @@
---
title: Look at Entity
category: Tutorials
tags:
- intermediate
mentions:
- shanewolf38
- MedicalJewel105
- TheItsNameless
- SmokeyStack
---
The following tutorial provides a resource pack method to detect when the player is looking at an entity. The code below must be placed inside the entity that will be looked at by the player, and will provide a variable `v.look_at_entity` which returns true when the entity is being looked at.
## variable
<CodeHeader>RP/entity/mob.entity.json</CodeHeader>
```json
"pre_animation": [
"v.look_at_entity = Math.abs(Math.abs(q.rotation_to_camera(1) - q.camera_rotation(1)) - 180) < (20 / q.distance_from_camera) && Math.abs(q.rotation_to_camera(0) + q.camera_rotation(0)) < (10 / q.distance_from_camera);"
],
```
:::tip
Because the query `q.rotation_to_camera` is based at the origin of the entity (their feet), the vertical detection range will be based around the bottom of the entity. The code below creates a modified variable for the vertical angle which takes a positional offset into account to allow the vertical detection range to be based around the center of the entity.
:::
<CodeHeader>RP/entity/mob.entity.json</CodeHeader>
```json
"pre_animation": [
"v.rotation_to_camera_0 = -Math.atan2(-q.distance_from_camera * Math.sin(q.rotation_to_camera(0)) - 1, q.distance_from_camera * Math.cos(q.rotation_to_camera(0)));",
"v.look_at_entity = Math.abs(Math.abs(q.rotation_to_camera(1) - q.camera_rotation(1)) - 180) < (20 / q.distance_from_camera) && Math.abs(v.rotation_to_camera_0 + q.camera_rotation(0)) < (60 / q.distance_from_camera);"
],
```
## Modifying
The provided code is very accurate for the standard Minecraft mob size of 1 block wide and 2 blocks tall, but for entities of different sizes the parameters should be changed. The `- 1` controls the positional offset of the center of the mob (- is upward, + is downward), the `20` controls the horizontal angle sensitivity, and the `60` controls the vertical angle sensitivity.
## Explanation
The variable detects when the player is looking at the entity by checking if the rotation angle required for the entity to look at the player is opposite the rotation angle required for the player to look at the entity. The horizontal and vertical angle sensitivity are modified by the distance of the entity from the camera to maintain accuracy.

View File

@@ -0,0 +1,396 @@
---
title: Sleeping Entities
category: Tutorials
tags:
- intermediate
mentions:
- MedicalJewel105
- SirLich
---
This tutorial will explain how to make entity sleep.
## Sleeping in beds
This behavior is inspired from villagers.
### Features
- Entity sleeps during the night and wakes up at day time.
- Interaction with entity will wake it up and after a while it goes sleeping again.
- If entity is hurt, it wakes up.
### Behavior Pack
In this section behavior pack components will be discussed.
#### Components
Let's start with some basic components that you need to add to your entity.
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
```json
"minecraft:dweller": {
"dwelling_type": "village",
"dweller_role": "inhabitant",
"can_find_poi": true
}
```
Undocumented, needed for entity to be able to sleep.
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
```json
"minecraft:environment_sensor": {
"triggers": [
{
"filters": {
"test": "is_daytime",
"value": false
},
"event": "sleep"
}
]
}
```
This component is required for entity understand when to sleep.
It runs event if it isn't day time.
:::warning
You need some basic navigation components for your entity be able to move to bed.
:::
#### Component Groups
Now you need some component groups for your entity with some components.
<CodeHeader>BP/entities/sleeping_entity.json#component_groups</CodeHeader>
```json
"sleeping": {
"minecraft:behavior.sleep": {
"priority": 0,
"goal_radius": 1.5,
"speed_multiplier": 1.25,
"sleep_collider_height": 0.3,
"sleep_collider_width": 1,
"sleep_y_offset": 0.6,
"timeout_cooldown": 10
},
"minecraft:damage_sensor": {
"triggers": {
"on_damage": {
"event": "wake_up"
}
}
},
"minecraft:environment_sensor": {
"triggers": [
{
"filters": {
"test": "is_daytime",
"value": true
},
"event": "wake_up"
}
]
},
"minecraft:interact": {
"interactions": [
{
"on_interact": {
"filters": {
"all_of": [
{
"test": "is_family",
"subject": "other",
"value": "player"
}
]
},
"event": "woken_up"
}
}
]
}
}
```
- `minecraft:behavior.sleep`
Determines sleep details, priority needs to be at `0` (the biggest weight).
- `minecraft:damage_sensor``
Add it if you want your entity wake up if it is being attacked.
- `minecraft:environment_sensor`
Runs `wake_up` event when it is day time.
- `minecraft:interact`
This makes player to be able wake up entity without hurting it.
<CodeHeader>BP/entities/sleeping_entity.json#component_groups</CodeHeader>
```json
"sleep_timer": {
"minecraft:timer": {
"time": 15,
"time_down_event": {
"event": "sleep_again"
}
}
}
```
This component group is required for entity to fall asleep again (with some delay) after it was woken up.
#### Events
Here you will find all events that you need.
I don't really think it needs explanation.
<CodeHeader>BP/entities/sleeping_entity.json#events</CodeHeader>
```json
"sleep": {
"add": {
"component_groups": [
"sleeping"
]
}
},
"wake_up": {
"remove": {
"component_groups": [
"sleeping"
]
}
},
"woken_up": {
"remove": {
"component_groups": [
"sleeping"
]
},
"add": {
"component_groups": [
"sleep_timer"
]
}
},
"sleep_again": {
"add": {
"component_groups": [
"sleeping"
]
},
"remove": {
"component_groups": [
"sleep_timer"
]
}
}
```
### Resource Pack
Don't forget that you need to add sleeping animation and controller for it to your entity!
#### Animation
Just copy/paste it.
<CodeHeader>RP/animations/sleeping_entity.animation.json</CodeHeader>
```json
{
"format_version": "1.8.0",
"animations": {
"animation.sleeping_entity.sleep": {
"loop": "hold_on_last_frame",
"animation_length": 0.5,
"bones": {
"body": {
"rotation": {
"0.0": [0, 0, 0],
"0.5": [-90, 0, 0]
},
"position": [0, 2, -15]
}
}
}
}
}
```
#### Animation Controller
Again just copy/paste it if you need.
<CodeHeader>RP/animations_controllers/ac.sleeping_entity.sleep.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.sleeping_entity.sleep": {
"initial_state": "default",
"states": {
"default": {
"transitions": [
{
"sleep": "q.is_sleeping"
}
]
},
"sleep": {
"animations": ["sleeping"],
"transitions": [
{
"default": "!q.is_sleeping"
}
]
}
}
}
}
}
```
Note that you will need to define animation in client entity like this:
`"sleeping": "animation.sleeping_entity.sleep"`
### Result
![](/assets/images/tutorials/sleeping-entities/result.png)
## Taking naps
This behavior is inspired from foxes.
### Features
- Entity sleeps when feels safe, far from mobs or when the weather is not a thunderstorm.
- Approaching the entity will make it wake up unless it's a trusted or sneaking player, or it's another entity with the family group `sleeping_entity`.
- If entity is hurt, it wakes up.
### Behavior Pack
In this section behavior pack components will be discussed.
#### Components
For this behavior you will need only one component:
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
```json
"minecraft:behavior.nap": {
"priority": 8,
"cooldown_min": 2.0,
"cooldown_max": 7.0,
"mob_detect_dist": 12.0,
"mob_detect_height": 6.0,
"can_nap_filters": {
"all_of": [
{
"test": "in_water",
"subject": "self",
"operator": "==",
"value": false
},
{
"test": "on_ground",
"subject": "self",
"operator": "==",
"value": true
},
{
"test": "is_underground",
"subject": "self",
"operator": "==",
"value": true
},
{
"test": "weather_at_position",
"subject": "self",
"operator": "!=",
"value": "thunderstorm"
}
]
},
"wake_mob_exceptions": {
"any_of": [
{
"test": "trusts",
"subject": "other",
"operator": "==",
"value": true
},
{
"test": "is_family",
"subject": "other",
"operator": "==",
"value": "sleeping_entity"
},
{
"test": "is_sneaking",
"subject": "other",
"operator": "==",
"value": true
}
]
}
}
```
If you want to also use the trusting mechanic, add:
<CodeHeader>BP/entities/sleeping_entity.json#components</CodeHeader>
```json
"minecraft:trust": {}
```
### Resource Pack
In our resource pack you can run an animation when entity starts to sleep.
<CodeHeader>RP/animations_controllers/ac.sleeping_entity.sleep.json</CodeHeader>
```json
{
"format_version": "1.10.0",
"animation_controllers": {
"controller.animation.sleeping_entity.sleep": {
"initial_state": "default",
"states": {
"default": {
"transitions": [
{
"sleep": "q.is_sleeping"
}
]
},
"sleep": {
"animations": ["sleeping"],
"transitions": [
{
"default": "!q.is_sleeping"
}
]
}
}
}
}
}
```
The last thing, you will have to create and register a sleeping animation for you entity. If you don't know how to do it check out the [BlockBench page](/guide/blockbench.html#animating).

View File

@@ -0,0 +1,90 @@
---
title: Solid Entities
category: Tutorials
tags:
- recipe
- intermediate
mentions:
- SirLich
- Joelant05
- Chikorita-Lover
- Luthorius
- MedicalJewel105
- ThomasOrs
---
Solid entities are entities that the player can bump into, step on, or otherwise physically interact with without passing through. Entities like this have many uses, such as emulating blocks.
This page will discuss some of the ways that solid entities can be created.
Not all techniques are ideal for all scenarios. Experiment, and figure out what works best for you.
## Runtime Identifiers
[Runtime identifiers](/entities/runtime-identifier) can be used to achieve solid entities, but currently only 2, each with a specific shape, and their own side effects. Neither collision shapes are possible to change or scale.
### Boat
<CodeHeader>BP/entities/entity_name.json</CodeHeader>
```json
{
"format_version": "1.16.0",
"minecraft:entity": {
"description": {
"identifier": "wiki:solid_entity",
"runtime_identifier": "minecraft:boat"
. . .
}
}
}
```
- Boat-shaped solid collision
- Certain other boat-like effects
### Shulker
<CodeHeader>BP/entities/entity_name.json</CodeHeader>
```json
{
"format_version": "1.16.0",
"minecraft:entity": {
"description": {
"identifier": "wiki:solid_entity",
"runtime_identifier": "minecraft:shulker"
. . .
}
}
}
```
- 1x1 block sized solid collision.
- Sticks to block grid.
- Teleports randomly when supporting block removed.
## minecraft:is_stackable
Add `minecraft:is_stackable` to your entity you want to be treated as being solid.
**Note:** This requires editing `player.json` if you wish the entity to be solid for the player.
`"minecraft:is_stackable": {}`
You will also need to add `minecraft:push_through` and set its `value` parameter to 1.
`"minecraft:push_through": 1`
(they should both go in `components`)
## Faking it with blocks
In some scenarios, it's probably better to `/setblock` or `/fill` to place barrier blocks, either statically or dynamically. There needs to be both a way of placing the barriers, and removing them.
`/fill ~ ~ ~ ~ ~1 ~ barrier 0 replace air`
Places barriers in a 1x1x2 area.
`/fill ~1 ~1 ~1 ~-1 ~-1 ~-1 air 0 replace barrier`
Removes barriers within a 3x3x3 area.
These [commands](/animation-controllers/entity-commands) will have to be triggering at a constant rate, for consistency. They can either be triggered through entity components, or animation controllers.

View File

@@ -0,0 +1,320 @@
---
title: Entity Timers
category: Tutorials
tags:
- intermediate
mentions:
- SirLich
- Joelant05
- MedicalJewel105
- aexer0e
- Justash01
- TheItsNameless
- zheaEvyline
---
Time-based interactions are extremely useful tools for map making. This article hopes to provide an extensive list which details the many ways which timers can be made. For convenience, this page will be split up into two main sections: component-based timers and animation-based timers. Each has their own advantages and disadvantages, which will be outlined in their respective sections.
You might also find useful [Scoreboard Timers](/commands/scoreboard-timers).
## Component-based timers
Component-based timers are done inside the entity.json file of the behavior pack. They have the distinct advantage of persisting upon the entity being reloaded, but are limited by the number of timing components (duplicate components replace each other, which means defining multiple timers using the `minecraft:timer` component isn't possible).
### minecraft:timer
This is the simplest but most effective component for triggering events after an elapsed amount of time. The component [minecraft:timer](https://bedrock.dev/docs/1.14.0.0/1.14.30.2/Entities#minecraft:timer) provides three main ways in which the amount of time before the event can be defined:
- Exact timing: an exact amount of time after which the event will fire is defined (e.g. 3.4 seconds)
- Random interval: an interval is defined in which the event will fire at a random time inside that interval (e.g. between 3 to 5 seconds)
- Weighted random choice: a number of times are defined and assigned weights, one of which will be chosen for the event to fire (e.g. a 20% chance for the event to fire at 5 seconds, and an 80% chance to fire at 20 seconds)
In the vanilla Behavior Pack, this component is used in all kinds of circumstances. For example:
- The dolphin can only spend 20 seconds on land before it dries out
- Bees will perish between 10 and 60 seconds after stinging
- The wandering trader will only stay for either 2400 or 3600 seconds
A simple example which triggers an event after 5.6 seconds:
<CodeHeader></CodeHeader>
```json
"minecraft:timer": {
"time": 5.6,
"time_down_event": {
"event": "wiki:my_event"
}
}
```
A more complex example which triggers an event after a randomized amount of delay using weighted values:
<CodeHeader></CodeHeader>
```json
"minecraft:timer": {
"looping": false, //true will fires event after every execution, false will fire event only once.
"random_time_choices": [
{
"weight": 25,
"value": 0.5 //Half a second of delay
},
{
"weight": 25,
"value": 10 //Ten seconds of delay
},
{
"weight": 25,
"value": 30 //Thirty seconds of delay
},
{
"weight": 25,
"value": 120 //2 minutes of delay
}
],
"time_down_event": {
"event": "wiki:event",
"target": "self"
}
}
```
A particularly useful way to handle time events is using a single, looping `minecraft:timer` component and processing the events on each tick (or however often you decide to fire the timer). This is done by using the `randomize` parameter in events, where a weight may be used determine how often other events will be run. This can get you a lot of extra mileage out of a single timer component.
<CodeHeader></CodeHeader>
```json
"wiki:do_event": {
"randomize": [
{
"weight": 1,
"add": {
"component_groups": [
"wiki:my_event"
]
}
},
{
"weight": 5,
"add": {
"component_groups": [
"wiki:my_more_frequent_event"
]
}
},
{
"weight": 50 //Fires nothing
}
]
}
```
### minecraft:environment_sensor
Another component ([minecraft:environment_sensor](https://bedrock.dev/docs/stable/Entities#minecraft:environment_sensor)) which can be very useful for time-based events is `minecraft:environment_sensor`. Pairing this sensor with the `hourly_clock_time` or `clock_time` filters can be used to trigger events based off in-game time.
Here is an example which is used to fire an event 800 ticks after the start of the day (valid range is 0 to 24000):
<CodeHeader></CodeHeader>
```json
"minecraft:environment_sensor": {
"triggers": [
{
"filters": {
"test": "hourly_clock_time",
"operator": "=",
"value": 800
},
"event": "wiki:my_daily_event"
}
]
}
```
### minecraft:ageable
If this component ([minecraft:ageable](https://bedrock.dev/docs/stable/Entities#minecraft:ageable)) is not being used in the entity's behavior for a different purpose, it can be useful as an additional timer. It's important to note that it requires the `minecraft:is_baby` component to be defined in order to function.
Here is an example which fires an event after four seconds:
<CodeHeader></CodeHeader>
```json
"minecraft:is_baby": {},
"minecraft:ageable": {
"duration": 4,
"grow_up": {
"event": "wiki:my_other_event",
"target": "self"
}
}
```
### Other dummy-timers:
Taking a peak at the docs suggest there are other components which can also can be used for timing. Essentially, you are looking for any component with a "time down event" or a "duration".
Non-exhaustive list of promising examples:
- `minecraft:angry` (requires the entity to have a target, time must be an integer)
- `minecraft.behavior.hide`
- `minecraft:behavior.celebrate`
## Animation-based timers
Behavior pack animations are an extremely powerful tool for triggering time-based events. They have the distinct advantage of providing an "infinite" amount of timers, but are restarted upon an entity being reloaded (leaving and rejoining the world or the chunk containing the entity unloading will cause the timer to restart when the entity reloads).
Animations function differently in behavior packs than in resource packs. If you are unfamiliar with how they operate, it is recommended to learn more about them by checking out the official documentation or the other pages on this wiki.
### Simple timers
By triggering animations from an animation controller or directly from the scripts section, you can execute specific events, commands, or molang expressions in a timed-sequence, called a timeline.
You can set up timelines like this:
<CodeHeader></CodeHeader>
```json
{
"format_version": "1.8.0",
"animations": {
"animation.command.example_timeline": {
"timeline": {
"0.0": "/say this will trigger instantly",
"3.0": "/say this will trigger after 3 seconds"
},
"animation_length": 3.1
},
"animation.command.example_timeline_2": {
"timeline": {
"100": "/say this will trigger after 100 seconds",
"0.0": [
"/say you can trigger multiple events at once",
"/say by using timelines."
],
"55.55": "/say this will trigger after 55.55 seconds."
},
"animation_length": 100.1
}
}
}
```
### Random interval
A very useful feature of the timer component is its ability to define a random interval in which the event will be triggered. This functionality can be replicated using animations and a controller. Below is an example of an animation triggered by adding the `minecraft:is_sheared` component to an entity which randomly fires an event between 2 to 7 seconds after activation. Animation and controller version 1.10.0.
<CodeHeader></CodeHeader>
```json
"controller.animation.shanewolf.random_interval": {
"initial_state": "inactive",
"states": {
"inactive": {
"transitions": [
{
"active": "q.is_sheared"
}
]
},
"active": {
"on_entry": [
"v.random_interval = math.random(2, 7);",
"/say random interval started"
],
"animations": [
"wiki:animate_interval"
],
"transitions": [
{
"inactive": "q.anim_time >= v.random_interval"
}
],
"on_exit": [
"@s wiki:stop_random_interval",
"/say random interval finished"
]
}
}
}
```
<CodeHeader></CodeHeader>
```json
"animation.shanewolf.random_interval": {
"animation_length": 100
}
```
Explanation: Upon entry into the state beginning the animation, a variable is given a random value between 2 and 7. The animation finishes when the current animation time is greater than or equal to the value of this v.
**Notes**:
- The animation length can be set to any value greater than the maximum end of the time range (100 is used as a general template)
- math.random(a, b) is used to trigger an event in the range [a, b]
- math.floor(math.random(a, b.99)) may be used to end the timer at integer values (0.99 must be added to b)
- Any events or commands to run when the animation is finished are put inside on_exit
### Weighted random choice
Another useful feature of the timer component is its ability to trigger events at a time determined by a weighted list of values. This functionality can also be replicated using animations and a controller. Below is an example of an animation triggered by adding the `minecraft:is_charged` component to an entity which randomly fires an event at either 2, 5, or 9 seconds with weights of 30, 60, and 10, respectively. Animation and controller version 1.10.0.
<CodeHeader></CodeHeader>
```json
"controller.animation.shanewolf.random_choices": {
"initial_state": "inactive",
"states": {
"inactive": {
"transitions": [
{
"active": "q.is_powered"
}
]
},
"active": {
"on_entry": [
"v.random_choices = math.random(0, 100);",
"/say random interval started"
],
"animations": [
"wiki:animate_choices"
],
"transitions": [
{
"inactive": "q.anim_time >= 2.0 && v.random_choices < 30"
},
{
"inactive": "q.anim_time >= 5.0 && v.random_choices < 90"
},
{
"inactive": "q.anim_time >= 9.0 && v.random_choices <= 100"
}
],
"on_exit": [
"@s wiki:stop_random_choices",
"/say random choices finished"
]
}
}
}
```
<CodeHeader></CodeHeader>
```json
"animation.shanewolf.random_choices": {
"animation_length": 100
}
```
Explanation: Upon entry into the state beginning the animation, a variable is given a random value between 0 and 100 (sum of the weights). The transitions are laid out with the list of values ordered from the smallest time to the largest time. This is done so multiple && operators are not required in the latter transitions to define the variable's range (the query for the smallest times return true first and have their weights checked before the others--flipping 2 and 5 would result in 2 mistakenly having a weight of 90 instead of 30). The animation finishes when the current animation time is greater than or equal to a time in the list and the value of the random variable falls within that time's defined weight range.
**Notes**:
- The animation length can be set to any value greater than the maximum end of the time range (100 is used as a general template)
- For this particular format to work, order the list of valid times from smallest to largest
- To assign a weight to a time in the list, add the weight to the value the randomized variable must be less than in the list's previous entry (e.g. 5 seconds has a weight of 90 - 30 = 60)
- Any events or commands to run when the animation is finished are put inside on_exit
Hopefully this spread some light on the subject of handling time in Minecraft Bedrock! As shown above, there are many possible ways it can be done, each with their own pros and cons. If you have any other useful methods for creating time-based events, please [contribute to the wiki](/contribute)!

View File

@@ -0,0 +1,357 @@
---
title: Village Mechanic
category: Tutorials
mentions:
- AeroForta
- MedicalJewel105
- stirante
- SmokeyStack
- SirLich
- Ciosciaa
- ThomasOrs
---
This article is for anyone who wants to try imitate the village mechanic for their entities
## Navigation Behavior
First let's start with some basic navigation behavior.
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:preferred_path":{
"max_fall_blocks":1,
"jump_cost":5,
"default_block_cost":1.5,
"preferred_path_blocks":[
{
"cost":0,
"blocks":[
"grass_path"
]
},
{
"cost":1,
"blocks":[
"cobblestone",
"stone"
]
},
{
"cost":50,
"blocks":[
"bed",
"lectern"
]
}
]
}
```
Allows entity to do random walk.
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:behavior.random_stroll":{
"priority":9,
"speed_multiplier":0.55,
"xz_dist":10,
"y_dist":5
}
```
Make entity return to inside dwelling bound, in this case inside a village border. Requiring minecraft:dweller component that will be explained below.
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:behavior.move_towards_dwelling_restriction": {
"priority": 4,
"speed_multiplier": 1.0
}
```
Makes entity navigate around a village by creating a path to patrol. Used by Iron Golem.
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:behavior.move_through_village": {
"priority": 3,
"speed_multiplier": 0.6,
"only_at_night": true
}
```
Allows entity to enter a building and also take shelter when raining. Needs open door capabilities.
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:behavior.move_indoors":{
"priority":5
}
```
Makes entity stay indoors while sun is down.
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:behavior.restrict_open_door":{
"priority": 5
}
```
Use in pair with:
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:annotation.open_door":{
"priority": 5
}
```
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:navigation.walk":{
"can_pass_doors":true,
"can_open_doors":true
}
```
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:behavior.open_door":{
"priority":6,
"close_door_after":true
}
```
## Main Behavior
<CodeHeader>BP/entities/custom_villager.json#components</CodeHeader>
```json
"minecraft:dweller": {
"dwelling_type": "village",
"dweller_role": "inhabitant",
"preferred_profession": "farmer",
"update_interval_base": 60,
"update_interval_variant": 40,
"can_find_poi": true,
"can_migrate": true,
"first_founding_reward": 5
}
```
- `dweller_role: inhabitant`
Allows entity claim a bed and bell.
`minecraft:behavior.sleep` needed.
- `preferred_profession: farmer`
Optional for `minecraft:behavior.work`
- `can_find_poi`
Add it so entity is able to find point of interest.
Known POI types:
```
bed
jobsite
meeting_area
```
- `can_migrate`
Defines if entity can migrate from one village to another or not.
### Sleep
You can find out how to make your entity sleep [here](/entities/sleeping-entities).
### Work
Requires "dweller_role" set to be "inhabitant" also if "preferred_profession" doesn't exist the entity will try to move to the closest any job site.
<CodeHeader></CodeHeader>
```json
"minecraft:behavior.work": {
"priority": 4,
"active_time": 250,
"speed_multiplier": 0.5,
"goal_cooldown": 200,
"sound_delay_min": 100,
"sound_delay_max": 200,
"can_work_in_rain": false,
"work_in_rain_tolerance": 1000,
"on_arrival": {
"event": "minecraft:resupply_trades",
"target": "self"
}
}
```
### Gathering
Allows the entity to gather.
Requires "dweller_role" set to be "inhabitant".
```json
"minecraft:behavior.mingle": {
"priority": 4,
"speed_multiplier": 0.5,
"duration": 30,
"cooldown_time": 10,
"mingle_partner_type": "my:custom_entity",
"mingle_distance": 2.0
}
```
### Scheduler
Now you know everything about needed mechanic, let's try to put all of this together in "minecraft:scheduler"
First let's do something simple.
Put work behavior in component group work like this:
<CodeHeader></CodeHeader>
```json
"component_groups":{
"work_schedule":{
"minecraft:behavior.work":{
"priority":4,
"active_time":250,
"speed_multiplier":0.5,
"goal_cooldown":200,
"sound_delay_min":100,
"sound_delay_max":200,
"can_work_in_rain":true,
"work_in_rain_tolerance":1000,
"on_arrival":{
"event":"minecraft:resupply_trades",
"target":"self"
}
}
},
"gather_schedule":{
"minecraft:behavior.mingle":{
"priority": 5,
"speed_multiplier": 0.8,
"cooldown_time":10.0,
"duration": 30.0,
"mingle_dist": 1.5,
"mingle_partner_type": "my:custom_entity"
}
}
}
```
Next, make your entity work.
<CodeHeader></CodeHeader>
```json
"minecraft:scheduler":{
"min_delay_secs":0,
"max_delay_secs":10,
"scheduled_events":[
{
"filters":{
"all_of":[
{
"test":"hourly_clock_time",
"operator":">=",
"value":0 //Morning
},
{
"test":"hourly_clock_time",
"operator":"<",
"value":12000 //Evening
}
]
},
"event":"work"
},
{
"filters":{
"all_of":[
{
"test":"hourly_clock_time",
"operator":">=",
"value":21000
},
{
"test":"hourly_clock_time",
"operator":"<",
"value":24000
}
]
},
"event":"gather"
}
]
}
```
The events section looks something like this:
<CodeHeader></CodeHeader>
```json
"events":{
"work":{
"remove":{
"component_groups":[
"gather_schedule"
]
},
"add":{
"component_groups":[
"work_schedule"
]
}
},
"gather":{
"remove":{
"component_groups":[
"work_schedule"
]
},
"add":{
"component_groups":[
"gather_schedule"
]
}
}
}
```
Open your world, spawn entity then put a bed and you should see green particle.
## Other Behavior
All of this is usable by custom entities:
- `minecraft:behavior.move_to_village`
Used by Pillager this may keep the entity to stay in the village.
- `minecraft:behavior.stroll_towards_village`
Used by fox to search a village and go there.
- `minecraft:behavior.inspect_bookshelf`
Used by librarian villager allows an entity to look at and inspect a bookshelf.
- `minecraft:behavior.explore_outskirts`
Allows entity to explore beyond the bounds of village (use schedule and component group to keep the entity return to the village).
- `minecraft:behavior.defend_village_target`
Use this on melee attack. Ranged attack can accidentally shoot any entity with inhabitant dwelling role.
All of this can be used by custom entities and have relation to villager or village:
| Behavior | Uses | Note |
| ------------------------------------------ | -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `minecraft:behavior.defend_village_target` | Allows entity to attack other entity that hurt the entity who had "dweller_role": "inhabitant". | Recommended to use only on entities with melee attack. |
| `minecraft:behavior.hide` | Used by villager to hide and stay at defined POI. | Currently, there is no documentation for the POI type that's why I recommend not to change `"poi_type": "bed"`. |
| `minecraft:behavior.move_to_village` | Used by Illager and also witch. Allows entity to travel to a random x,y,z coordinate in a village. | - |
| `"minecraft:behavior.nap"` | Used by Fox to take a nap. | Similar with sleep but offers more flexibility also has built-in wake up system by detecting specific entity. |