Package com.binaris.wizardry.api.client
Class ParticleBuilder
java.lang.Object
com.binaris.wizardry.api.client.ParticleBuilder
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classData class for particle properties to be sent over the network and spawned client-side. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionallowServer(boolean allow) Sets whether server-side spawning is allowed for the particle being built.collide(boolean collide) Sets the collisions of the particle being built.color(float r, float g, float b) Sets the color of the particle being built.color(int hex) Sets the color of the particle being built.color(int r, int g, int b) Sets the color of the particle being built.static ParticleBuildercreate(DeferredObject<net.minecraft.core.particles.SimpleParticleType> particle) Start building a particle.static ParticleBuildercreate(DeferredObject<net.minecraft.core.particles.SimpleParticleType> type, net.minecraft.util.RandomSource random, double x, double y, double z, double radius) Creates a particle at a random position within a radius of the given position.static ParticleBuildercreate(DeferredObject<net.minecraft.core.particles.SimpleParticleType> type, net.minecraft.util.RandomSource random, double x, double y, double z, double radius, boolean move) Starts building a particle of the given type and positions it randomly within the given radius of the given position, with velocity proportional to distance from the given position if move is true.static ParticleBuildercreate(DeferredObject<net.minecraft.core.particles.SimpleParticleType> type, net.minecraft.world.entity.Entity entity) Starts building a particle of the given type and positions it randomly within the given entity's bounding box.entity(net.minecraft.world.entity.Entity entity) Sets the entity of the particle being built.face(float yaw, float pitch) Sets the rotation of the particle being built.face(net.minecraft.core.Direction direction) Sets the rotation of the particle being built.fade(float r, float g, float b) Sets the fade color of the particle being built.fade(int hex) Sets the fade color of the particle being built.fade(int r, int g, int b) Sets the fade color of the particle being built.gravity(boolean value) Set the gravity property of the particle.length(double length) Sets the target and target velocity of the particle being built.pos(double x, double y, double z) Sets the position of the particle.pos(net.minecraft.core.BlockPos pos) Sets the position of the particle.pos(net.minecraft.world.phys.Vec3 vec3d) Sets the position of the particle.scale(float scale) set the scale of the particleseed(long seed) Sets the seed of the particle being built.shaded(boolean value) Set the shaded property of the particle.voidspawn(net.minecraft.world.level.Level world) Spawn the particle in the world.static voidspawnHealParticles(net.minecraft.world.level.Level world, net.minecraft.world.entity.LivingEntity entity) static voidspawnShockParticles(net.minecraft.world.level.Level world, double x, double y, double z) spin(double radius, double speed) Sets the spin parameters of the particle being built.target(double x, double y, double z) Sets the target of the particle being built.target(net.minecraft.world.entity.Entity target) Sets the target of the particle being built.target(net.minecraft.world.phys.Vec3 pos) Sets the target of the particle being built.time(int lifetime) Set the max age of the particle.tvel(double vx, double vy, double vz) Sets the target point velocity of the particle being built.tvel(net.minecraft.world.phys.Vec3 vel) Sets the target point velocity of the particle being built.velocity(double velocityX, double velocityY, double velocityZ) Sets the velocity of the particle.velocity(net.minecraft.world.phys.Vec3 vel) Sets the velocity of the particle being built.
-
Constructor Details
-
ParticleBuilder
public ParticleBuilder()
-
-
Method Details
-
create
public static ParticleBuilder create(DeferredObject<net.minecraft.core.particles.SimpleParticleType> particle) Start building a particle. This is just for more readable code with a static function.- Parameters:
particle- The particle type- Returns:
- The ParticleBuilder instance
- Throws:
IllegalStateException- If already building- See Also:
-
particle(DeferredObject)
-
create
public static ParticleBuilder create(DeferredObject<net.minecraft.core.particles.SimpleParticleType> type, net.minecraft.world.entity.Entity entity) Starts building a particle of the given type and positions it randomly within the given entity's bounding box. Equivalent to callingParticleBuilder.create(type).pos(...); users should chain any additional builder methods onto this one and finish with.spawn(world)as normal. Used extensively with summoned creatures; makes code much neater and more concise. N.B. this does not cause the particle to move with the given entity.- Parameters:
type- The type of particle to buildentity- The entity to position the particle at- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is already building.
-
create
public static ParticleBuilder create(DeferredObject<net.minecraft.core.particles.SimpleParticleType> type, net.minecraft.util.RandomSource random, double x, double y, double z, double radius) Creates a particle at a random position within a radius of the given position. Just in case if you need to spawn random particles in a radius. For creating a normal particle, usecreate(DeferredObject)- Parameters:
type- The particle typerandom- The random objectx- The x positiony- The y positionz- The z positionradius- The radius
-
create
public static ParticleBuilder create(DeferredObject<net.minecraft.core.particles.SimpleParticleType> type, net.minecraft.util.RandomSource random, double x, double y, double z, double radius, boolean move) Starts building a particle of the given type and positions it randomly within the given radius of the given position, with velocity proportional to distance from the given position if move is true. Good for making explosion-type effects. Equivalent to callingParticleBuilder.create(type).pos(...).vel(...); users should chain any additional builder methods onto this one and finish with.spawn(world)as normal.- Parameters:
type- The type of particle to buildrandom- An RNG instancex- The x coordinate of the centre of the region in which to position the particley- The y coordinate of the centre of the region in which to position the particlez- The z coordinate of the centre of the region in which to position the particleradius- The radius of the region in which to position the particlemove- Whether the particle should move outwards from the centre (note that if this is false, the particle's default velocity will apply)- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is already building.
-
spawnShockParticles
public static void spawnShockParticles(net.minecraft.world.level.Level world, double x, double y, double z) -
spawnHealParticles
public static void spawnHealParticles(net.minecraft.world.level.Level world, net.minecraft.world.entity.LivingEntity entity) -
pos
Sets the position of the particle.- Parameters:
x- The x positiony- The y positionz- The z position- Throws:
IllegalStateException- If not building yet
-
pos
Sets the position of the particle.- Parameters:
pos- The position- Throws:
IllegalStateException- If not building yet
-
pos
Sets the position of the particle.- Parameters:
vec3d- The position- Throws:
IllegalStateException- If not building yet
-
time
Set the max age of the particle.- Parameters:
lifetime- The lifetime- Throws:
IllegalStateException- If not building yet
-
velocity
Sets the velocity of the particle.- Parameters:
velocityX- The x velocityvelocityY- The y velocityvelocityZ- The z velocity- Throws:
IllegalStateException- If not building yet
-
velocity
Sets the velocity of the particle being built. This is a vector-based alternative tovelocity(double, double, double)( double, double, double)}, allowing for even more concise code when a vector is available. Affects: All particle types- Parameters:
vel- A vector representing the velocity of the particle to be built.- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
scale
set the scale of the particle- Parameters:
scale- The scale- Throws:
IllegalStateException- If not building yet
-
color
Sets the color of the particle being built. If unspecified, this defaults to the particle's default color, specified within its constructor. If all colour components are 0 or 1, at least one must have the float suffix (forF) or the integer overload will be used instead, causing the particle to appear black! Affects: All particle types exceptICE,MAGIC_BUBBLEandMAGIC_FIRE- Parameters:
r- The red color component to set; will be clamped to between zero and oneg- The green color component to set; will be clamped to between zero and oneb- The blue color component to set; will be clamped to between zero and one- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
color
Sets the color of the particle being built. This is an 8-bit (0-255) integer version ofcolor(float, float, float). Affects: All particle types exceptICE,MAGIC_BUBBLEandMAGIC_FIRE- Parameters:
r- The red color component to set; will be clamped to between 0 and 255g- The green color component to set; will be clamped to between 0 and 255b- The blue color component to set; will be clamped to between 0 and 255- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
color
Sets the color of the particle being built. This is a 6-digit hex color version ofcolor(float, float, float). Affects: All particle types exceptICE,MAGIC_BUBBLEandMAGIC_FIRE- Parameters:
hex- The colour to be set, as a packed 6-digit hex integer (e.g. 0xff0000).- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
fade
Sets the fade color of the particle being built. If unspecified, this defaults to whatever the particle's base colour is. If all colour components are 0 or 1, at least one must have the float suffix (forF) or the integer overload will be used instead, causing the particle to appear black! Affects: All particle types exceptICE,MAGIC_BUBBLEandMAGIC_FIRE- Parameters:
r- The red color component to set; will be clamped to between zero and oneg- The green color component to set; will be clamped to between zero and oneb- The blue color component to set; will be clamped to between zero and one- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
fade
Sets the fade color of the particle being built. This is an 8-bit (0-255) integer version offade(float, float, float). Affects: All particle types exceptICE,MAGIC_BUBBLEandMAGIC_FIRE- Parameters:
r- The red colour component to set; will be clamped to between 0 and 255g- The green colour component to set; will be clamped to between 0 and 255b- The blue colour component to set; will be clamped to between 0 and 255- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
fade
Sets the fade color of the particle being built. This is a 6-digit hex color version offade(float, float, float). Affects: All particle types exceptICE,MAGIC_BUBBLEandMAGIC_FIRE- Parameters:
hex- The colour to be set, as a packed 6-digit hex integer (e.g., 0xff0000).- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
seed
Sets the seed of the particle being built. If unspecified, this defaults to the particle's default seed, specified within its constructor (this is normally chosen at random). Pro tip: to get a particle to stay the same while a continuous spell is in use (but change between casts), use.seed(world.getTotalWorldTime() - ticksInUse). Affects: All particle types- Parameters:
seed- The seed to set- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
spin
Sets the spin parameters of the particle being built. If unspecified, these both default to 0. Affects: All particle types- Parameters:
radius- The rotation radius to setspeed- The rotation speed to set, in revolutions per tick- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
collide
Sets the collisions of the particle being built. If unspecified, this defaults to false. Affects: All particle types- Parameters:
collide- True to enable block collisions for the particle, false to disable- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
entity
Sets the entity of the particle being built. This will cause the particle to move with the given entity, and will make the position specified usingpos(double, double, double)relative to that entity's position. Affects: All particle types- Parameters:
entity- The entity to set (passing in null will do nothing but will not cause any problems, so for the sake of conciseness it is not necessary to perform a null check on the passed-in argument)- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
face
Sets the rotation of the particle being built. If unspecified, the particle will use the default behavior and rotate to face the viewer. Affects: All particle types- Parameters:
yaw- The yaw angle to set in degrees, where 0 is south.pitch- The pitch angle to set in degrees, where 0 is horizontal.- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
face
Sets the rotation of the particle being built. This is anEnumFacing-based alternative toface(float, float)which sets the yaw and pitch to the appropriate angles for the given facing. For example, if the given facing isNORTH, the particle will render parallel to the north face of blocks. If unspecified, the particle will use the default behavior and rotate to face the viewer. Affects: All particle types- Parameters:
direction- TheEnumFacingdirection to set.- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
allowServer
Sets whether server-side spawning is allowed for the particle being built. By default this is false.There's no need to allow this for spell casting (normally) as spells handle particle spawning and synchronization themselves, check
Spell.requiresPacket()for more details.- Parameters:
allow- True to allow server-side spawning, false to prevent it- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
shaded
Set the shaded property of the particle.- Parameters:
value- The value- Throws:
IllegalStateException- If not building yet
-
gravity
Set the gravity property of the particle.- Parameters:
value- The value- Throws:
IllegalStateException- If not building yet
-
target
Sets the target of the particle being built. This will cause the particle to stretch to touch the given position. Affects: Targeted particles, namelyBEAM,LIGHTNINGand- Parameters:
x- The target x-coordinate to sety- The target y-coordinate to setz- The target z-coordinate to set- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
target
Sets the target of the particle being built. This is a vector-based alternative totarget(double, double, double), allowing for even more concise code when a vector is available. Affects: Targeted particles, namelyBEAM,LIGHTNINGand- Parameters:
pos- A vector representing the target position of the particle to be built.- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
tvel
Sets the target point velocity of the particle being built. This will cause the position it stretches to touch to move at the given velocity. Has no effect unlesstarget(double, double, double)or one of its overloads is also set. Affects: Targeted particles, namelyBEAM,LIGHTNINGand- Parameters:
vx- The target point x velocity to setvy- The target point y velocity to setvz- The target point z velocity to set- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
tvel
Sets the target point velocity of the particle being built. This is a vector-based alternative totvel(double, double, double), allowing for even more concise code when a vector is available. Affects: Targeted particles, namelyBEAM,LIGHTNINGand- Parameters:
vel- A vector representing the target point velocity of the particle to be built.- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
length
Sets the target and target velocity of the particle being built. This method takes an origin entity and a position and estimates the position of the target point based on the given entity's rotational velocities and its distance from the given position. Affects: Targeted particles, namelyBEAM,LIGHTNINGand- Parameters:
length- The length of the particle being built.- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
target
Sets the target of the particle being built. This will cause the particle to stretch to touch the given entity. Affects: Targeted particles, namelyBEAM,LIGHTNINGand- Parameters:
target- The entity to set- Returns:
- The particle builder instance, allowing other methods to be chained onto this one
- Throws:
IllegalStateException- if the particle builder is not yet building.
-
spawn
public void spawn(net.minecraft.world.level.Level world) Spawn the particle in the world.Use
ParticleWizardry.PROVIDERSto get the particle factory, set the properties and then add the particle to the particle manager.Warn if the particle is being spawned at (0, 0, 0) and the entity is null or ParticleBuilder is being used in server side, as this is likely to be a mistake.
- Parameters:
world- The world- Throws:
IllegalStateException- If not building yet
-