Перейти к основному содержанию

Particles

Module to work with vanilla and custom particles.

Index

Classes

ParticleAnimator

ParticleAnimator:

Animators allow to change some properties of the specific particle depending on the time. Mostly for internal use, put animators' descriptors into animators parameter of custom particle type instead.

constructor

ParticleEmitter

ParticleEmitter:

Particle emitter allows to change their position after spawn. It represents a coordinate system, where created particles are located and which you can move however you want.

@remarks

Emitter can be moved only while being in world, and it works ONLY for custom particles, not for vanilla!

constructor

  • Constructs new particle emitter with origin in given coords.


    Parameters

    • x: number
    • y: number
    • z: number

    Returns ParticleEmitter

attachTo

  • attachTo(entity: number): void
  • attachTo(entity: number, x: number, y: number, z: number): void
  • Binds the origin to the given entity's position, resets the coordinate system's speed.


    Parameters

    • entity: number

    Returns void

detach

  • detach(): void
  • Detaches the coords system from the entity and leaves it on the current position.


    Returns void

emit

  • emit(type: number, data: number, x: number, y: number, z: number): void
  • emit(type: number, data: number, x: number, y: number, z: number, vx: number, vy: number, vz: number): void
  • emit(type: number, data: number, x: number, y: number, z: number, vx: number, vy: number, vz: number, ax: number, ay: number, az: number): void
  • Spawns particle of given and data on given coords, without specified velocity and acceleration.


    Parameters

    • type: number
    • data: number
    • x: number
    • y: number
    • z: number

    Returns void

getPosition

getPositionArray

  • getPositionArray(): [number, number, number]

  • Returns [number, number, number]

    Origin's coords in float array of 3 elements.

move

  • move(x: number, y: number, z: number): void
  • Moves the coordinate system to given coords, it will cause all particles' transfer.


    Parameters

    • x: number
    • y: number
    • z: number

    Returns void

moveTo

  • moveTo(x: number, y: number, z: number): void
  • Moves the ORIGIN of the coordinate system to given coords.


    Parameters

    • x: number
    • y: number
    • z: number

    Returns void

release

  • release(): void
  • Performs the finalization of the native object of the following emitter. It means that you will no longer be able to use the following emitter after calling this method, and the object itself will be removed from the memory. Can be used for optimization purposes.


    Returns void

setEmitRelatively

  • setEmitRelatively(enable: boolean): void
  • Default is false. It means that the coords of the particles for the following emitter. will be specified in the absolute coordinate system, if enabled, they will need to be set relative to the current position of the emitter. This can be very convenient if you need to make a system of particles completely isolated from the movement of the emitter.


    Parameters

    • enable: boolean

    Returns void

setVelocity

  • setVelocity(x: number, y: number, z: number): void
  • Sets the speed of the coordinate system by each axis in blocks per tick, it can be stopped with emitter.stop() or emitter.setVelocity(0, 0, 0).


    Parameters

    • x: number
    • y: number
    • z: number

    Returns void

stop

  • stop(): void
  • Terminates any movement of the coordinate system.


    Returns void

ParticleSubEmitter

ParticleSubEmitter:

Sub-emitters describe how specific particle can emit other particles, according to some events, that may happen to it. Mostly for internal use, put sub-emitters descriptors into emitters.

constructor

setKeepEmitter

  • setKeepEmitter(keepEmitter: boolean): void
  • @remarks

    In this case we are talking about emitters, not about sub-emitters.


    Parameters

    • keepEmitter: boolean

      If true, the new particle will save the emitter that was used for it's creation if it had been.

    Returns void

setKeepVelocity

  • setKeepVelocity(keepVelocity: boolean): void
  • Parameters

    • keepVelocity: boolean

      If true, the new particle will have the velocity of the particle, that calls the sub-emitter, at the time of invocation; default is false

    Returns void

setRandomVelocity

  • setRandomVelocity(maxRandomVelocity: number): void
  • Emitted particles will receive random initial speed.


    Parameters

    • maxRandomVelocity: number

    Returns void

ParticleType

ParticleType:

Class to create custom particle types. Mostly for internal use, you can use Particles.registerParticleType instead.

constructor

  • new ParticleType(textureName: string, minU: number, minV: number, maxU: number, maxV: number, textureCountHorizontal: number, textureCountVertical: number, isUsingBlockLight: boolean): ParticleType
  • new ParticleType(locationName: string, isUsingBlockLight: boolean, uv: number[], textureCountHorizontal: number, textureCountVertical: number): ParticleType
  • new ParticleType(descriptor: ParticleDescription): ParticleType
  • Constructs new Particles.ParticleType object from given needed params.


    Parameters

    • textureName: string
    • minU: number
    • minV: number
    • maxU: number
    • maxV: number
    • textureCountHorizontal: number
    • textureCountVertical: number
    • isUsingBlockLight: boolean

    Returns ParticleType

getId

  • getId(): number

  • Returns number

    Following particle type's numeric ID.

setAnimator

  • setAnimator(name: size | icon | alpha | color, animator: ParticleAnimator): void
  • Parameters

    Returns void

setCollisionParams

  • setCollisionParams(collision: boolean, keepVelocityAfterImpact: boolean, addLifetimeAfterImpact: number): void
  • Parameters

    • collision: boolean
    • keepVelocityAfterImpact: boolean
    • addLifetimeAfterImpact: number

    Returns void

setColor

  • setColor(r: number, g: number, b: number, a: number): void
  • setColor(r: number, g: number, b: number, a: number, r2: number, g2: number, b2: number, a2: number): void
  • Parameters

    • r: number
    • g: number
    • b: number
    • a: number

    Returns void

setDefaultAcceleration

  • setDefaultAcceleration(x: number, y: number, z: number): void
  • Parameters

    • x: number
    • y: number
    • z: number

    Returns void

setDefaultVelocity

  • setDefaultVelocity(x: number, y: number, z: number): void
  • Parameters

    • x: number
    • y: number
    • z: number

    Returns void

setFriction

  • setFriction(air: number, block: number): void
  • Parameters

    • air: number
    • block: number

    Returns void

setLifetime

  • setLifetime(min: number, max: number): void
  • Parameters

    • min: number
    • max: number

    Returns void

setRebuildDelay

  • setRebuildDelay(delay: number): void
  • Parameters

    • delay: number

    Returns void

setRenderType

  • setRenderType(renderType: 0 | 1 | 2): void
  • Parameters

    • renderType: 0 | 1 | 2

    Returns void

setSize

  • setSize(min: number, max: number): void
  • Parameters

    • min: number
    • max: number

    Returns void

setSubEmitter

Interfaces

AnimatorDescription

AnimatorDescription:

Custom particle's animator params object.

optionalend

end?: number = 0

Ending value.

optionalfadeIn

fadeIn?: number = 0

Appearance moment in the proportions of the period.

optionalfadeOut

fadeOut?: number = 0

Disappearance moment in the proportions of the period.

optionalperiod

period?: number

Animator's period in ticks, if it's less than zero or not listed, it'll be particle's lifetime.

optionalstart

start?: number = 0

Initial value.

ColorAnimatorDescription

ColorAnimatorDescription:

Custom particle's animator params object.

optionalend

end?: [number, number, number, number] = [number, number, number, number]

Ending value.

optionalfadeIn

fadeIn?: number = 0

Appearance moment in the proportions of the period.

optionalfadeOut

fadeOut?: number = 0

Disappearance moment in the proportions of the period.

optionalperiod

period?: number

Animator's period in ticks, if it's less than zero or not listed, it'll be particle's lifetime.

optionalstart

start?: [number, number, number, number] = [number, number, number, number]

Initial value.

IAnimatorDescription

IAnimatorDescription:

Custom particle's animator params object.

optionalfadeIn

fadeIn?: number = 0

Appearance moment in the proportions of the period.

optionalfadeOut

fadeOut?: number = 0

Disappearance moment in the proportions of the period.

optionalperiod

period?: number

Animator's period in ticks, if it's less than zero or not listed, it'll be particle's lifetime.

ParticleDescription

ParticleDescription:

Custom particle type params object.

optionalacceleration

acceleration?: [number, number, number] = [number, number, number]

Particle's acceleration, if it's spawned without this parameter.

optionaladdLifetimeAfterImpact

addLifetimeAfterImpact?: number = 0

Particle will lose given number of ticks from it's maximum lifetime, when touching a block.

@remarks

This value makes sense only if collision param is true.

optionalanimators

Animators allow to change some properties of the specific particle depending on the time, each animator is described as an object of definite format and can be not described, if it's not needed.


Type declaration

  • optionalalpha?: AnimatorDescription

    Describes the particle's opacity, for the unit value the alpha in the color parameter from the type's description is taken.

  • optionalcolor?: ColorAnimatorDescription

    Describes the animated color value, if particle supports it. Accepts values in RGBA ranges, like color property in descriptor.

    @since

    2.0.4b38

  • optionalicon?: AnimatorDescription

    Describes the animation frame, if particle supports it. Must have the value between 0 and 1.

  • optionalsize?: AnimatorDescription

    Describes the behavior of particle's size, for the unit size the size from the type's description is taken.

  • optionaltexture?: AnimatorDescription

    Describes the animation frame, if particle supports it. Must have the value between 0 and 1.

    @deprecated

    Use icon instead.

optionalcollision

collision?: boolean = false.

If true, particle won't go through blocks. It reduces performance if there are lots of these particles.

optionalcolor

color?: [number, number, number, number] = [number, number, number, number]

Four component color of the particle (RGBA).

optionalcolor2

color2?: [number, number, number, number]
@since

2.0.4b38

optionalemitters

emitters?: { death?: SubEmitterDescription; idle?: SubEmitterDescription; impact?: SubEmitterDescription }

Sub-emitters (don't confuse with emitters) describe how specific particle can emit other particles, according to some events, that may happen to it. Each sub-emitter is described as an object of definite format and can be not described if it's not needed.


Type declaration

optionalframesX

framesX?: number

Animation frame grid size around width.

@since

2.0.4b38

optionalframesY

framesY?: number

Animation frame grid size around height.

@since

2.0.4b38

optionalfriction

friction?: { air?: number; block?: number }

Particle's speed modifier in the air and when touching a block. Usually it's a number between 0 and 1, close to 1, but in fact it can be any value. Both values are 1 by default.


Type declaration

  • optionalair?: number
  • optionalblock?: number
    @remarks

    This value makes sense only if collision param is true.

optionalisUsingBlockLight

isUsingBlockLight?: boolean = false.

If true, the particle will be exposed to the world's lighting. If false, the particle will always have maximum brightness. Enabling this parameter may reduce the performance when having lots of particles.

optionalkeepVelocityAfterImpact

keepVelocityAfterImpact?: boolean

If false, particle's speed will be set to zero when touching a block. If true, the speed will be saved.

@remarks

This value makes sense only if collision param is true.

lifetime

lifetime: [number, number]

Minimum and maximum particle's lifetime in ticks.

optionalrebuildDelay

rebuildDelay?: number

Time in ticks between particle mesh updates.

@since

2.0.4b38

optionalrender

render?: number

Particle's render type:

  • 0 - additive
  • 1 - without blending
  • 2 - with blending

size

size: [number, number]

Minimum and maximum size of the particle.

texture

texture: string

Particle's texture name from /particle-atlas resource directory.

optionalvelocity

velocity?: [number, number, number] = [number, number, number]

Particle's initial velocity, if it's spawned without initial speed parameter.

SubEmitterDescription

SubEmitterDescription:

Custom particle's sub-emitter params object.

optionalchance

chance?: number = 1

Triggering float chance from 0 to 1.

optionalcount

count?: number = 1

Particles count for the single emit time.

optionaldata

data?: number = 0

Additional data of the emitted particle.

optionalkeepEmitter

keepEmitter?: boolean

If true, the new particle will save the emitter that was used for it's creation if it had been.

@remarks

In this case we are talking about emitters, not about sub-emitters.

optionalkeepVelocity

keepVelocity?: boolean = false

If true, the new particle will have the velocity of the particle, that calls the sub-emitter, at the time of invocation.

optionalrandomize

randomize?: number

If this value is listed, emitted particles will receive random initial speed, that isn't more than value * sqrt(3).

type

type: number

Emitted particle's type numeric ID.

Functions

addBreakingItemParticle

  • addBreakingItemParticle(id: number, data: number, x: number, y: number, z: number): void
  • Spawns EParticleType.ITEM_BREAK particles at a given location with a given item in world.

    @remarks

    Called only on the client side! Use packets to spawn particles for multiple players.

    @since

    2.4.0b119


    Parameters

    • id: number

      numeric item ID

    • data: number

      item data

    • x: number
    • y: number
    • z: number

    Returns void

addFarParticle

  • addFarParticle(type: number, x: number, y: number, z: number, vx: number, vy: number, vz: number, data?: number): void
  • Same as Particles.addParticle, but applies far shader to the particle.


    Parameters

    • type: number
    • x: number
    • y: number
    • z: number
    • vx: number
    • vy: number
    • vz: number
    • optionaldata: number

    Returns void

addParticle

  • addParticle(type: number, x: number, y: number, z: number, vx: number, vy: number, vz: number, data?: number): void
  • Spawns particle of given type on given coords with given velocity and additional parameters in the world.

    @remarks

    Called only on the client side! Use packets to spawn particles for multiple players.


    Parameters

    • type: number

      particle type's numeric ID; if you want to spawn vanilla particles, see EParticleType enums

    • x: number
    • y: number
    • z: number
    • vx: number

      velocity for the particle by X-axis

    • vy: number

      velocity for the particle by Y-axis

    • vz: number

      velocity for the particle by Z-axis

    • optionaldata: number

      additional params, currently don't know how to use, just put 0

    Returns void

getParticleTypeById

line

  • line(type: number, coords1: Vector, coords2: Vector, gap?: number, vel?: Vector, data?: number): void
  • Spawnds particles in line with specified gapness.


    Parameters

    • type: number

      particle type's numeric ID; if you want to spawn vanilla particles, see EParticleType enums

    • coords1: Vector

      start location of line

    • coords2: Vector

      end location of line

    • optionalgap: number

      gapness means step of particles, values more than 1 will increase offsets between particles; randomized

    • optionalvel: Vector

      velocity of spawned particles

    • optionaldata: number

      variant of spawned particles or properties

    Returns void

registerParticleType

  • Registers new custom particle type of given params object.


    Parameters

    Returns number

    Created particle type's numeric ID.