Template:Bedrock Edition Developer Documentation
你可以帮助我们来翻译此条目,但请勿使用机器翻译。
组件
颗粒系统是基于组件的,也就是说颗粒系统是由一系列组件组合而成的。要使颗粒效果运作,你需要加入处理某方面效果的组件。例如,颗粒发射容器需要定义其寿命规则,因此效果应该有一条或以上处理发射容器(emitter)和发射颗粒的寿命规则。
新组件可以在晚些时候加进来,开发者可把组件合并以获得不同的行为。例如,颗粒可以拥有四处移动的动态(Dynamic)组件以及处理与地形之间的互动的碰撞(Collision)组件。这些组件会告知颗粒系统开发者想让释放器或颗粒做的事情,而不是给出一个颗粒参数列表并不断调整这些参数而获得所需实现的行为。
命名空间
所有颗粒系统都必须在其名称中命名空间化。在效果标签前应该加上“<string:命名空间名称>:”命名空间。原版Minecraft使用“minecraft:”前缀。
查看§示例来获取示例名称。
与MoLang的交互
任何可用的字段都能使用MoLang表达式。MoLang表达式是一个字符串,并在MoLang文档中定义。颗粒系统使用一些特殊的MoLang变量以供颗粒MoLang表达式使用。另外,设置自定义MoLang参数的方法有很多,它也用在效果中的MoLang表达式里。
- 参数
名称 描述 variable.particle_lifetime 颗粒持续时间。 variable.particle_age 颗粒当前寿命。 variable.particle_random_1 一个从0.0到1.0的随机数,在颗粒的持续时间内保持不变。 variable.particle_random_2 另一个从0.0到1.0的随机数,在颗粒的持续时间内保持不变。 variable.particle_random_3 第三个从0.0到1.0的随机数,在颗粒的持续时间内保持不变。 variable.particle_random_4 第四个从0.0到1.0的随机数,在颗粒的持续时间内保持不变。 variable.emitter_lifetime 发射容器的当前循环持续多长时间。 variable.emitter_age 发射容器当前循环启动后的寿命。 variable.emitter_random_1 一个从0.0到1.0的随机数,在发射容器的当前循环内保持不变。 variable.emitter_random_2 另一个从0.0到1.0的随机数,在发射容器的当前循环内保持不变。 variable.emitter_random_3 第三个从0.0到1.0的随机数,在发射容器的当前循环内保持不变。 variable.emitter_random_4 第四个从0.0到1.0的随机数,在发射容器的当前循环内保持不变。 variable.entity_scale 当效果附加到一个实体时,此值是实体的大小比例
基础结构概览
颗粒效果由基本渲染参数和一系列组件组成。组件的放置顺序没有限制。
- 概要:
{
"format_version": "1.10.0",
"particle_effect": {
"description": {
"identifier": <string>,
// 如:“minecraft:test_effect”为要引用的颗粒
"basic_render_parameters": {
"material": <string>
// 发射容器要引用的材料
"texture": <string>
// 发射容器要引用的材质
}
},
"curves": {
// 曲线的详细定义
},
"components":
// 发射频率组件
// 发射寿命组件
// 发射形状(或通过颗粒发射位置和方向定义其形状的)组件
// 发射容器本地空间组件
// 控制颗粒初始状态的组件
// 控制/引导颗粒行为的组件
// 影响颗粒渲染方式的组件
// 影响颗粒寿命的组件
}
}
}
结构详细内容
- 概要:
{
// specifies the format version of the particle. Only particles of a particular set of versions
// will work with the game
"format_version": "1.10.0",
"particle_effect": {
// general data for the particle effect
"description": {
// e.g. "minecraft:test_mule", this is the name the particle emitter is referred to as
"identifier": <string>,
// Basic render parameters are basic rendering
// properties like the texture used, or the material used.
// All particles require a material to render, and (for now) a
// texture to draw. Future changes might be to make the texture
// optional, or to specify more than one texture, to facilitate
// custom shader-driven particle effects
"basic_render_parameters": {
"material": <string>
"texture": <string>
},
},
// this section describes curves that can be used later by components
// Curves are interpolation values, with inputs from 0 to 1, and
// outputs based on the curve
//
// the result of the curve is a molang variable of the same name
// that can be referenced in molang in components
//
// each frame for each particle, the curves are evaluated
// and the result is placed in a molang variable of the name of the
// curve
"curves": {
// "molangvar" is the molang variable to be used alter in molang expression
// for example "variable.mycurve" here would make the result of the curve
// available in MoLang as "variable.mycurve"
"molangvar": {
// type can be "linear", "bezier", or "catmull_rom"
"type": type,
// control nodes for curve. These are assumed to be equally
// spaced, e.g. first node is at input value 0, second at 0.25, etc
"nodes": [<float/molang>, <float/molang>, <float/molang>, <float/molang>],
// what is the input value to use
"input": <float/molang>,
// what is the range the input is mapped onto
// between 0 and this value
"horizontal_range": <float/molang>
}
},
"components: {
/////////////////////////////////////////////////////////////////////
// Emitter related components
// these components primarily affect the emitter bevahior
// emitter initial state components set up the emitter with
// particular properties
// emitter rate components control when particles get emitted
// these will be run every frame for the emitter to determine if any
// particles need to be spawned
// emitter lifetime components control the lifetime of the emitter
// and the "enabled/disabled" state of the emitter.
// Emitters can only spawn particles if enabled.
// emitter shapecomponents control where a particle gets emitted
// and initial shape-driven state such as particle direction
// emitter local space components
// this component specifies whether entity-based emitters
// simulate in local or global space
/////////////////////////////////////////////////////////////////////
// Particle related components
// these components primarily affect the particle behavior
// particle initial condition components control what the initial state
// of the particles is, such as initial speed, rotation, etc.
// These are run once at particle creation
// particle motion components control what happens to the particle
// on frames after creation, such as it's position (for
// a parametric particle), drag/acceleration (for a dynamic
// particle), etc.
// These are run once per frame per particle
// particle appearance components control how the particle is rendered
// such as what UV coortinates to use, size of the particle,
// billboard orientation, color tinting, etc.
// These are run once per frame for visible particles
// these components handle when the particle expires
}
}
}
现行的组件列表
在这些组件的字段里可使用下列标记:
- <float> - 接受浮点数输入的字段
- <float/molang> - 接受浮点数或MoLang表达式输入的字段
- <default:val> - 如果字段未指定输入则使用指定的默认值
- <bool> - true或false
- <string> - 字符串
- <default> - 不属于特定行的部分,如果字段未指定输入则使用其默认值
发射容器类组件(Emitter Components)
发射容器寿命类组件(Emitter Lifetime Components)
- 发射容器寿命表达式组件(Emitter Lifetime Expression component)
当表达式为非0时释放器将打开,当为0时关闭。这对于形如以一个行为变量来驱动一个物品关联性粒子释放器一类的情况用途显著。
"minecraft:emitter_lifetime_expression": {
// When the expression is non-zero, the emitter will emit particles.
// Evaluated every frame
"activation_expression": <float/molang> <default:1>
// Emitter will expire if the expression is non-zero.
// Evaluated every frame
"expiration_expression": <float/molang> <default:0>
}
- 发射容器循环执行组件(Emitter Lifetime Looping component)
粒子释放器将循环工作直到其被去除。
"minecraft:emitter_lifetime_looping": {
// emitter will emit particles for this time per loop
// evaluated once per particle emitter loop
"active_time": <float/molang> <default:10>
// emitter will pause emitting particles for this time per loop
// evaluated once per particle emitter loop
"sleep_time": <float/molang> <default:0>
}
- 发射容器单次执行组件(Emitter Lifetime Once component)
粒子释放器将执行一次。一旦粒子寿命结束或被允许释放的粒子数已被释放,释放器终止。
"minecraft:emitter_lifetime_once": {
// how long the particles emit for
// evaluated once
"active_time": <float/molang> <default:10>
}
发射容频率类组件(Emitter Rate Components)
- 发射容器即时释放组件(Emitter Rate Instant component)
所有粒子被一次释放,接下来除非释放器循环,否则行为结束。
"minecraft:emitter_rate_instant": {
// this many particles are emitted at once
// evaluated once per particle emitter loop
"num_particles": <float/molang> <default:10>
}
- 发射容器手动释放组件(Emitter Rate Manual component)
粒子仅在其释放器被指示通过游戏来自主工作时被释放。这被那些已非现役的粒子效果广泛运用。
"minecraft:emitter_rate_manual": {
// evaluated once per particle emitted
"max_particles": <float/molang> <default:50>
}
- 发射容器稳定释放组件(Emitter Rate Steady component)
粒子随时间以一个稳定或合乎MoLang的比率被释放。
"minecraft:emitter_rate_steady": {
// how often a particle is emitted, in particles/sec
// evaluated once per particle emitted
"spawn_rate": <float/molang> <default:1>
// maximum number of particles that can be active at once for this emitter
// evaluated once per particle emitter loop
"max_particles": <float/molang> <default:50>
}
发射容器形状类组件(Emitter Shape Components)
形状控制粒子释放源的朝向及粒子的初始朝向。
- 发射容器自定义形状组件(Emitter Shape Custom component)
所有粒子都基于一个指定的MoLang表达式被释放。
"minecraft:emitter_shape_custom": {
// specifies the offset from the emitter to emit the particles
// evaluated once per particle emitted
"offset": [<float/molang>, <float/molang>, <float/molang>] <default:[0, 0, 0]>
// specifies the direciton for the particle
// evaluated once per particle emitted
"direction": [<float/molang>, <float/molang>, <float/molang>] <default:[0, 0, 0]>
}
- 发射容器轴向边界盒形状组件(Emitter Shape Entity-AABB component)
所有粒子均从释放器所依附物品(当无物品时为释放点)的轴向边界盒(Axis-Aligned Bounding Box;AABB)被释放出。
"minecraft:emitter_shape_entity_aabb": {
// evaluated once per particle emitted
"direction": [<float/molang>, <float/molang>, <float/molang>] <default:[0, 0, 0]>
}
- 发射容器偏移点组件(Emitter Shape Point component)
所有粒子均释放自来源于释放器的点状偏移。
"minecraft:emitter_shape_point": {
// specifies the offset from the emitter to emit the particles
// evaluated once per particle emitted
"offset": [<float/molang>, <float/molang>, <float/molang>] <default:[0, 0, 0]>
// specifies the direciton of particles.
// evaluated once per particle emitted
"direction": [<float/molang>, <float/molang>, <float/molang>]
}
- 发射容器球体形状组件(Emitter Shape Sphere component)
所有粒子均释放自来源于释放器的球状偏移。
"minecraft:emitter_shape_sphere": {
// specifies the offset from the emitter to emit the particles
// evaluated once per particle emitted
"offset": [<float/molang>, <float/molang>, <float/molang>] <default:[0, 0, 0]>
// sphere radius
// evaluated once per particle emitted
"radius": <float/molang> <default:1>
// emit only from the surface of the sphere
"surface_only": <bool> <default:false>
// specifies the direciton of particles. Defaults to "outwards"
"direction": "inwards" // particle direction towards center of sphere
"direction": "outwards" // particle direction away from center of sphere
// evaluated once per particle emitted
"direction": [<float/molang>, <float/molang>, <float/molang>]
}
初始状态类组件(Initial State components)
- 发射容器本地空间组件(Emitter Local Space component)
这种组件指定了粒子释放器的参考框架,仅在释放器附着于物品时被应用。当“position”的布尔值为“true”时,粒子将模拟物品的形状,否则其将模拟世界的形状。控制转向的“rotation”工作模式相同。两者的默认布尔值均为“false”,使得粒子相对于释放器被释放,接着独立地模拟物品。需要注意的是,“rotation”及“position”的布尔值分别为“true”与“false”是非法设置。
"minecraft:emitter_local_space": {
"position": <bool>
"rotation": <bool>
}
颗粒类组件(Particle Components)
颗粒外形类组件(Particle Appearance Components)
- 颗粒告示牌组件(Particle Appearance Billboard component)
该组件能告知颗粒系统如何显示给玩家一个相对于游戏世界方向的镜头,以及该以怎么样的朝向呈现给该镜头。
"minecraft:particle_appearance_billboard": {
// specifies the x/y size of the billboard
// evaluated every frame
"size": [<float/molang>, <float/molang>],
// used to orient the billboard. Options are:
// "rotate_xyz" - aligned to the camera, perpendicular to the view axis
// "rotate_y" -aligned to camera, but rotating around world y axis
// "lookat_xyz" - aimed at the camera, biased towards world y up
// "lookat_y" - aimed at the camera, but rotating around world y axis
// "direction" - billboard is aligned perpendicular to the direction vector,
// e.g. a direction of [0, 1, 0] would have the particle facing upwards
"face_camera_mode": <string>
// specifies the UVs for the particle.
"uv": {
// specifies the assumed texture width/height
// defaults to 1
// when set to 1, UV's work just like normalized UV's
// when set to the texture width/height, this works like texels
"texturewidth": <int>,
"textureheight": <int>,
// Assuming the specified texture width and height, use these
// uv coordinates.
// evaluated every frame
"uv": [<float/molang>, <float/molang>],
"uv_size": [<float/molang>, <float/molang>],
// alternate way via specifying a flipbook animation
// a flipbook animation uses pieces of the texture to animate, by stepping over time from one
// "frame" to another
"flipbook": {
"base_UV": [ <float/molang>, <float/molang> ], // upper-left corner of starting UV patch
"size_UV": [ <float>, <float> ], // size of UV patch
"step_UV": [ <float>, <float> ], // how far to move the UV patch each frame
"frames_per_second": <float>, // default frames per second
"max_frame": <float/molang>, // maximum frame number, with first frame being frame 1
"stretch_to_lifetime": <bool>, // optional, adjust fps to match lifetime of particle. default=false
"loop": <bool> // optional, makes the animation loop when it reaches the end? default=false
}
}
}
- 颗粒光源组件(Particle Appearance Lighting)
当存在该组件时,颗粒将在游戏中通过局部照明的方式来进行着色
"minecraft:particle_appearance_lighting": {}
- 颗粒外形着色组件(Particle Appearance Tinging component)
// color fields are special, they can be either an RGB, or a "#RRGGBB"
// field (or RGBA or "AARRGGBB"). If RGB(A), the channels are
// from 0 to 1. If the string is "#RRGGBB" or "#AARRGGBB", the values are
// hex from 00 to ff.
//
// this pseudo-type will be denoted by <color>
"minecraft:particle_appearance_tinting": {
// interpolation based color
"color": {
// an array of colors
// it is assumed that the colors are equally spaced for interpolation
// and that the range of the color interpolation values are 0 to 1
//
// for example, a 3 color "color" field with an interpolant value
// of 0.5 would pick the second color
"gradient": [ <color>, <color>, ...],
"interpolant": <float/molang> // hint: use a curve here!
}
// directly set the color
"color": <color>
}
颗粒初始状态类组件(Particle Initial State Components)
- 颗粒初始速度组件(Particle Initial Speed Component)
该组件控制粒子以一个指定的速度以及由释放器形状决定的朝向释放。
// evaluated once "minecraft:particle_initial_speed": <float/molang> <default:0>
- 颗粒初始状态组件(Particle Initial State Component)
该组件控制粒子以一个指定的方位及转角释放。
"minecraft:particle_initial_spin": {
// specifies the initial rotation in degrees
// evaluated once
"rotation": <float/molang> <default:0>
// specifies the spin rate in degrees/second
// evaluated once
"rotation_rate": <float/molang> <default:0>
}
颗粒寿命类组件(Particle Lifetime Components)
- 方块中终止颗粒组件(Particle Expire If In Blocks component)
该组件控制粒子当处在列表列出的方块类型中时终止。注意:该组件可与particle_lifetime_expression并行。
"minecraft:particle_expire_if_in_blocks" [
// minecraft block names, e.g. 'minecraft:water', 'minecraft:air'
// these are typically the same name as in the /setblock command
// except for the minecraft: prefix
"blockname1",
"blockname2",
...
],
- 方块中不终止粒子组件(Particle Expire If Not In Blocks component)
该组件控制粒子当处在列表列出的方块类型中时不终止。注意:该组件可与particle_lifetime_expression并行。
"minecraft:particle_expire_if_not_in_blocks" [
// minecraft block names, e.g. 'minecraft:water', 'minecraft:air'
// these are typically the same name as in the /setblock command
// except for the minecraft: prefix
"blockname1",
"blockname2",
...
],
- 颗粒寿命表达式组件(Particle Lifetime Expression component)
标准的寿命组件。这些表达式控制粒子的寿命。
"minecraft:particle_lifetime_expression": {
// this expression makes the particle expire when true (non-zero)
// The float/expr is evaluated once per particle
// evaluated every frame
"expiration_expression": <float/molang> <default:0>
// alternate way to express lifetime
// particle will expire after this much time
// evaluated once
"max_lifetime": <float/molang>
},
颗粒运动类组件(Particle Motion Components)
- 颗粒运动碰撞组件(Particle Motion Collision component)
该组件使得地形与粒子能够产生碰撞。Minecraft中的碰撞监测包括监测二者的交集,为粒子移动到最近的非交集点(如果可能)并设置导向使其不会瞄准碰撞(通常是与碰撞表面垂直)。注意:若该组件不存在,碰撞将不会发生。
"minecraft:particle_motion_collision": {
// enables collision when true/non-zero.
// evaluated every frame
"enabled": <bool/molang> <default:true>
// alters the speed of the particle when it has collided
// useful for emulating friction/drag when colliding, e.g a particle
// that hits the ground would slow to a stop.
// This drag slows down the particle by this amount in blocks/sec
// when in contact
"collision_drag": <float>
// used for bouncing/not-bouncing
// Set to 0.0 to not bounce, 1.0 to bounce back up to original height
// and in-between to lose speed after bouncing. Set to >1.0 to gain height each bounce
"coefficient_of_restitution": <float>
// used to minimize interpenetration of particles with the environment
// note that this must be less than or equal to 1/2 block
"collision_radius": <float>
}
- 颗粒运动动态组件(Particle Motion Dynamic component)
该组件指定了粒子的动态特性,即促使粒子行动的模拟立点。这些动态会改变由指向与速率共同决定的粒子的速度。粒子的指向将永远是粒子速度的方向。
"minecraft:particle_motion_dynamic": {
// the linear acceleration applied to the particle, defaults to [0, 0, 0].
// Units are blocks/sec/sec
// An example would be gravity which is [0, -9.8, 0]
// evaluated every frame
"linear_acceleration": [<float/molang>, <float/molang>, <float/molang>],
// using the equation:
// acceleration = -linear_drag_coefficient*velocity
// where velocity is the current direction times speed
// Think of this as air-drag. The higher the value, the more drag
// evaluated every frame
"linear_drag_coefficient": <float/molang> <default:0>
// acceleration applies to the rotation speed of the particle
// think of a disc spinning up or a smoke puff that starts rotating
// but slows down over time
// evaluated every frame
// acceleration is in degrees/sec/sec
"rotation_acceleration" <float/molang> <default:0>
// drag applied to retard rotation
// equation is rotation_acceleration += -rotation_rate*rotation_drag_coefficient
// useful to slow a rotation, or to limit the rotation acceleration
// Think of a disc that speeds up (acceleration)
// but reaches a terminal speed (drag)
// Another use is if you have a particle growing in size, having
// the rotation slow down due to drag can add "weight" to the particle's
// motion
"rotation_drag_coefficient" <float/molang> <default:0>
}
- 粒子运动参数组件(Particle Motion Parametric component)
该组件直接控制粒子。注意:该组件不工作于手动释放的粒子及基于物品且不处于本地空间的粒子释放器。
"minecraft:particle_motion_parametric": {
// directly set the position relative to the emitter.
// E.g. a spiral might be:
// "relative_position": ["Math.cos(Params.LifeTime)", 1.0,
// "Math.sin(Params.Lifetime)"]
// defaults to [0, 0, 0]
// evaluated every frame
"relative_position": [<float/molang> <float/molang> <float/molang>]
// directly set the 3d direction of the particle
// doesn't affect direction if not specified
// evaluated every frame
"direction": [<float/molang> <float/molang> <float/molang]
// directly set the rotation of the particle
// evaluated every frame
"rotation": <float/molang> <default:0>
}}
示例
火焰颗粒
这种形似微小火光的粒子见于火把及熔炉来象征火焰。这种粒子很简单,包括一个固定不动的火光,仅有一些变化。注意:粒子行为的变量由MoLang语言创造。
此外,对于告示牌组件的UV节段中材质宽度/高度的运用允许经过材质像素对UV的参考:
{
"format_version": "1.8.0",
"particles": {
"minecraft:basic_flame_particle": {
"basic_render_parameters": {
"material": "particles_alpha",
"texture": "textures/particle/particles"
},
"components": {
"minecraft:emitter_rate_instant": {
"num_particles": 1
},
"minecraft:emitter_lifetime_once": {
"active_time": 0
},
"minecraft:emitter_shape_sphere": {
"radius": 0.025,
"direction": [ 0, 0, 0 ]
},
"minecraft:particle_lifetime_expression": {
"max_lifetime": "Math.random(0.6, 2.0) "
},
"minecraft:particle_appearance_billboard": {
"size": [
"(0.1 + variable.ParticleRandom1*0.1) - (0.1 * variable.ParticleAge)",
"(0.1 + variable.ParticleRandom1*0.1) - (0.1 * variable.ParticleAge)"
],
"facing_camera_mode" : "lookat_xyz",
"uv" : {
"texturewidth": 128,
"textureheight" : 128,
"uv" : [0, 24],
"uv_size" : [8, 8]
}
}
}
}
}
}
烟雾颗粒
该粒子为一种通用的烟雾团,常见于火把、熔炉、烈焰人等。这是一种带有包括上拉的上向加速度的上向运动。
这种粒子的主要特性与火焰颗粒的不同之处在于其翻页式的材质动画。见于下方的粒子细节,但其特效运用了一个告示牌组件中翻页式的子部分来驱动UV坐标随时间推移逐帧变换。
此外,对于告示牌组件的UV节段中材质宽度/高度的运用允许经过翻页式材质像素对UV的参考:
{
"format_version": "1.8.0",
"particles": {
"minecraft:basic_smoke_particle": {
"basic_render_parameters": {
"material": "particles_alpha",
"texture": "textures/particle/particles"
},
"components": {
"minecraft:emitter_rate_instant": {
"num_particles": 1
},
"minecraft:emitter_lifetime_once": {
"active_time": 0
},
"minecraft:emitter_shape_custom": {
"offset": [ 0, 0, 0 ],
"direction": [ "Math.random(-0.1, 0.1)", 1.0, "Math.random(-0.1, 0.1)" ]
},
"minecraft:particle_initial_speed": 1.0,
"minecraft:particle_lifetime_expression" : {
"max_lifetime": "Math.random(0.4, 1.4)"
},
"minecraft:particle_motion_dynamic" : {
"linear_acceleration": [0, 0.4, 0]
},
"minecraft:particle_appearance_billboard" : {
"size": [0.1, 0.1],
"facing_camera_mode" : "lookat_xyz",
"uv" : {
"texturewidth": 128,
"textureheight" : 128,
"flipbook" : {
"base_UV": [56, 0],
"size_UV" : [8, 8],
"step_UV" : [-8, 0],
"frames_per_second" : 8,
"max_frame" : 8,
"stretch_to_lifetime" : true,
"loop" : false
}
}
},
"minecraft:particle_appearance_tinting": {
"color": ["variable.ParticleRandom1*0.5", "variable.ParticleRandom1*0.5", "variable.ParticleRandom1*0.5", 1.0]
},
"minecraft:particle_appearance_lighting" : {}
}
}
}
}
生物火焰效果
该效果运用于烈焰人的火球充能状态中。这也是一种上向翻页式的效果。
这种粒子释放器通常基于物品,因为对火焰萦绕烈焰人周身的需要而允许物品轴向边界盒(AABB)形状的运用。该特效基于物品被创造/破坏,因而特效自身仅需要保持开启。
材质宽度/高度被用以使该效果的材质像素达到”一画一帧“,因此允许了这些帧的推进保持唯一:
{
"format_version": "1.8.0",
"particles": {
"minecraft:mobflame_emitter": {
"basic_render_parameters": {
"material": "particles_alpha",
"texture": "textures/flame_atlas"
},
"components": {
"minecraft:emitter_local_space": {
"position": true,
"rotation": true
},
"minecraft:emitter_rate_steady": {
"spawn_rate": "Math.random(15, 25)",
"max_particles": 50
},
"minecraft:emitter_lifetime_expression": {
"activation_expression": 1,
"expiration_expression": 0
},
"minecraft:emitter_shape_entity_aabb": {
"direction": [ 0, 1, 0 ]
},
"minecraft:particle_initial_speed": "Math.random(0, 1)",
"minecraft:particle_lifetime_expression": {
"max_lifetime": 1.25
},
"minecraft:particle_motion_dynamic": {
"linear_acceleration": [ 0, 1.0, 0 ],
"linear_drag_coefficient": 0.0
},
"minecraft:particle_appearance_billboard": {
"size": [ 0.5, 0.5 ],
"facing_camera_mode": "lookat_xyz",
"uv": {
"texturewidth": 1,
"textureheight": 32,
"flipbook": {
"base_UV": [ 0, 0 ],
"size_UV": [ 1, 1 ],
"step_UV": [ 0, 1 ],
"frames_per_second": 32,
"max_frame": 32,
"stretch_to_lifetime": true,
"loop": false
}
}
}
}
}
}
}
跳动的气泡
该粒子生成一连串四处弹跳的气泡:
{
"format_version": "1.8.0",
"particles": {
"minecraft:bounce": {
"basic_render_parameters": {
"material": "particles_alpha",
"texture": "textures/particle/particles"
},
"components": {
"minecraft:emitter_rate_instant": {
"num_particles": 100
},
"minecraft:emitter_lifetime_once": {
"active_time": 2
},
"minecraft:emitter_shape_sphere": {
"offset": [ "Math.random(-0.5, 0.5)", "Math.random(-0.5, 0.5)", "Math.random(-0.5, 0.5)" ],
"direction": "outwards",
"radius": 1
},
"minecraft:particle_initial_speed": 5.0,
"minecraft:particle_initial_spin": {
"rotation": "Math.random(0, 360)",
"rotation_rate": 0
},
"minecraft:particle_lifetime_expression": {
"max_lifetime": "5"
},
"minecraft:particle_motion_dynamic": {
"linear_acceleration": [ 0, -9.8, 0 ]
},
"minecraft:particle_motion_collision": {
"coefficient_of_restitution": 0.5,
"collision_drag": 4,
"collision_radius": 0.1
},
"minecraft:particle_appearance_billboard": {
"size": [ "0.1", "0.1" ],
"facing_camera_mode": "rotate_xyz",
"uv": {
"texturewidth": 128,
"textureheight": 128,
"uv": [ 0, 16 ],
"uv_size": [ 8, 8 ]
}
},
"minecraft:particle_appearance_lighting": {}
}
}
}
}
}
与颗粒实体的交互
One of the primary uses for emitting particles in the Bedrock engine is particles associated with entities, such as mobs. Examples can be when the Blaze flames-up during it's attack sequence, or the Evoker's spell effect while summoning Vexes. The goal is to allow binding and management of particle effects attached to entities.
The following concepts are important for managing particles with entities via .json:
- Effect lists. These live in the resource definition of the entity's .json, along with textures, etc. These list the effects available to the entity, with an internal entity name for the effect, and the associated effect to play.
- Locators. These live in the geometry files, and specify a location in the geometry. These locators can be associated with bones, and thus follow the bone as it animates.
- Animation controller-based particle management. Using the Animation Controller state machine concept, one can trigger both fire-and-forget and sustained particle effects
- Animation timeline particle management. As part of an animation .json for the entity, one can set up a timeline that triggers particle effects at specified times while the animation is playing. Note that an actual physical animation is not needed, just the animation .json structure.
Particles that are attached to entities are intrinsically tied to those entities. If the entity ceases to exist, the particle effects cease as well. Emitters follow either the entity, or a locator on the entity.
Effect List
The effect list is a list of internal effect names to actual particle effects bindings. This is the general form for adding particle effects to an entity. The effect list consists of a list of shorthand names to actual effects. All references to effects will use the shorthand name in animations and animation controllers. Note that this by itself will not cause the particle effect to appear.
{
"format_version": "1.8.0",
"minecraft:client_entity": {
"description": {
"identifier": "minecraft:entity_name",
...
"particle_effects": {
"shorthand_name1": "effect_name1",
"shorthand_name2": "effect_name2",
},
...
}
}
}
This is an example of the flame-up effect for the Blaze. Inside the "description" section of an entity's resource definition we can add a "particle_effects" section that has a name/value pair. The name is the name that other .json in the entity will refer to, while the value is the name of the particle effect, as specified in the particle effect's .json.
{
"format_version": "1.8.0",
"minecraft:client_entity": {
"description": {
"identifier": "minecraft:blaze",
...
"particle_effects": {
"charged_flames": "minecraft:mobflame_emitter"
},
...
}
}
}
Effect Event
Particle events in the entity have the following properties:
- "effect" is the effect name specified in the entity's resource definition .json (the particle effect list), this specifies what particle effect to start/play
- "locator" is an optional parameter that maps to a locator of the same name in the resource definition. By specifying a locator, the emitter will follow that locator around as the entity animates, including orientation. If this is not specified, the effect will occur at the origin of the entity.
- "pre_effect_script" is an optional parameter that is a MoLang expression run at emitter startup time. This can set up MoLang variables, (for example 'particle color'), which can be then referred to inside the particle effect .json itself.
{
"effect": "internal_name",
"locator": "locator_name", // optional
"pre_effect_script" // optional
}
Animation Controller effects
Animation controllers can specify effect events for their states. This allows for a list of particle effects to be started upon state entry, and for those particle effects to be automatically ended when leaving the state. For particles that don't terminate (or don't terminate prior to state transition), they will be terminated at state exit.
The schema is:
"particle_effects": [
// array of effect events
]
The array syntax allows for more than one effect to be triggered on state entry.
An example is the Blaze's flame-up effect in it's animation controller. This animation controller has two states, "default" and "flaming". It transitions between the two via the "query.is_charged" entity flag check. When in the "flaming" state, the "charged_flames" effect is started (with no locator or initialization MoLang expression), and is terminated when the state exits.
{
"format_version": "1.8.0",
"animation_controllers": {
...
"controller.animation.blaze.flame": {
"states": {
"default": {
"transitions": [
{ "flaming": "query.is_charged" }
]
},
"flaming": {
"particle_effects": [
{
"effect": "charged_flames"
}
],
"transitions": [
{ "default": "!query.is_charged" }
]
}
}
},
...
}
}
Another example for the Evoker's spell effect. This causes the evoker to start up two "spell" effects, using the locator for the left and right hand. The spell effects themselves are continuous, so the emitters will emit particles until the evoker is no longer casting a spell.
{
"format_version": "1.8.0",
"animation_controllers": {
"controller.animation.evoker.general": {
"states": {
"default": {
...
"transitions": [
{ "casting": "query.is_casting" }
]
},
"casting": {
...
"particle_effects": [
{
"effect": "spell",
"locator": "left_hand"
},
{
"effect": "spell",
"locator": "right_hand"
}
],
"transitions": [
{ "default": "!query.is_casting" }
]
}
}
}
}
}
Animation Timeline effects
Animations can also trigger particle effects. These are fire-and-forget effects that are tied to a timeline, when the animation hits that time point, the effect(s) are fired.
"particle_effects": {
"time1" : [
// array of effect events
],
"time2" : [
// array of effect events
],
"time3" : {
// single effect
}
}
time1/time2/etc are numerical time points, e.g. "0.0".
In this example, when the cat sits down, after 3 seconds a smoke puff is generated:
{
"format_version": "1.8.0",
"animations": {
...
"animation.cat.sit": {
"loop": true,
"animation_length": 5.0,
"bones": {
// bone animation stuff
},
"particle_effects": {
"3.0": [
{
"effect": "smoke_puff"
}
]
}
},
...
}
}
}