The great particle refactoring part 1: Introducing ParticleBuilder!

Adds ParticleBuilder to replace the particle spawning methods in the proxies, and changes all particle spawning to use the builder except for in the spell classes, which are to be reorganised first.
This commit is contained in:
Electroblob
2018-06-05 21:13:41 +01:00
parent 466b3bbc27
commit d91a3e056a
119 changed files with 722 additions and 972 deletions
@@ -2,12 +2,12 @@ package electroblob.wizardry.entity.construct;
import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.PotionEffect;
@@ -61,16 +61,23 @@ public class EntityBlizzard extends EntityMagicConstruct {
target.addPotionEffect(new PotionEffect(WizardryPotions.frost, 20, 0));
}
}else{
// For some reason this number of particles now causes the game to lag significantly, despite it being fine
// in 1.7.10. I thought particles were supposed to be LESS laggy now...
for(int i = 1; i < 6; i++){
for(int i=1; i<6; i++){
float brightness = 0.5f + (rand.nextFloat() / 2);
Wizardry.proxy.spawnParticle(WizardryParticleType.BLIZZARD, world, this.posX,
this.posY + rand.nextDouble() * 3, this.posZ, 0, 0, 0, 100, brightness, brightness + 0.1f, 1.0f,
false, rand.nextDouble() * 2.5d + 0.5d);
Wizardry.proxy.spawnParticle(WizardryParticleType.BLIZZARD, world, this.posX,
this.posY + rand.nextDouble() * 3, this.posZ, 0, 0, 0, 100, 1.0f, 1.0f, 1.0f, false,
rand.nextDouble() * 2.5d + 0.5d);
ParticleBuilder.create(Type.BLIZZARD)
.pos(this.posX, this.posY + rand.nextDouble() * 3, this.posZ)
.lifetime(100)
.colour(brightness, brightness + 0.1f, 1.0f)
.radius(rand.nextDouble() * 2.5d + 0.5d)
.spawn(world);
ParticleBuilder.create(Type.BLIZZARD)
.pos(this.posX, this.posY + rand.nextDouble() * 3, this.posZ)
.lifetime(100)
.colour(1, 1, 1)
.radius(rand.nextDouble() * 2.5d + 0.5d)
.spawn(world);
}
}
}
@@ -2,9 +2,9 @@ package electroblob.wizardry.entity.construct;
import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.SoundEvents;
@@ -53,12 +53,17 @@ public class EntityDecay extends EntityMagicConstruct {
target.addPotionEffect(new PotionEffect(WizardryPotions.decay, LIFETIME, 0));
}
}
}else if(this.rand.nextInt(15) == 0){
double radius = rand.nextDouble() * 0.8;
double angle = rand.nextDouble() * Math.PI * 2;
float brightness = rand.nextFloat() * 0.4f;
Wizardry.proxy.spawnParticle(WizardryParticleType.DARK_MAGIC, world, this.posX + radius * Math.cos(angle),
this.posY, this.posZ + radius * Math.sin(angle), 0, 0, 0, 0, brightness, 0, brightness + 0.1f);
ParticleBuilder.create(Type.DARK_MAGIC)
.pos(this.posX + radius * Math.cos(angle), this.posY, this.posZ + radius * Math.sin(angle))
.colour(brightness, 0, brightness + 0.1f)
.spawn(world);
}
}
@@ -2,9 +2,9 @@ package electroblob.wizardry.entity.construct;
import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -62,15 +62,18 @@ public class EntityForcefield extends EntityMagicConstruct {
}
}else{
for(int i = 1; i < 40; i++){
// Generates a spherical pattern of particles
float brightness = 0.5f + (rand.nextFloat() * 0.5f);
double radius = 3;
double yaw = rand.nextDouble() * Math.PI * 2;
double pitch = (rand.nextDouble() - 0.5) * Math.PI;
// Generates a spherical pattern of particles
Wizardry.proxy.spawnParticle(WizardryParticleType.BRIGHT_DUST, world,
this.posX + radius * Math.cos(yaw) * Math.cos(pitch), this.posY + 3 + radius * Math.sin(pitch),
this.posZ + radius * Math.sin(yaw) * Math.cos(pitch), 0, 0, 0, 48 + this.rand.nextInt(12),
brightness, brightness, 1.0f);
ParticleBuilder.create(Type.DUST)
.pos(this.posX + radius * Math.cos(yaw) * Math.cos(pitch), this.posY + 3 + radius * Math.sin(pitch),
this.posZ + radius * Math.sin(yaw) * Math.cos(pitch))
.lifetime(48 + this.rand.nextInt(12))
.colour(brightness, brightness, 1.0f);
}
}
}
@@ -2,12 +2,12 @@ package electroblob.wizardry.entity.construct;
import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.potion.PotionEffect;
@@ -74,8 +74,10 @@ public class EntityFrostSigil extends EntityMagicConstruct {
}else if(this.rand.nextInt(15) == 0){
double radius = 0.5 + rand.nextDouble() * 0.3;
double angle = rand.nextDouble() * Math.PI * 2;
Wizardry.proxy.spawnParticle(WizardryParticleType.SNOW, world, this.posX + radius * Math.cos(angle),
this.posY + 0.1, this.posZ + radius * Math.sin(angle), 0, 0, 0, 40 + rand.nextInt(10));
ParticleBuilder.create(Type.SNOW)
.pos(this.posX + radius * Math.cos(angle), this.posY + 0.1, this.posZ + radius * Math.sin(angle))
.vel(0, 0, 0) // Required since default for snow is not stationary
.spawn(world);
}
}
@@ -7,7 +7,8 @@ import electroblob.wizardry.entity.EntityArc;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
@@ -69,8 +70,9 @@ public class EntityHammer extends EntityMagicConstruct {
}
if(this.world.isRemote && this.ticksExisted % 3 == 0){
Wizardry.proxy.spawnParticle(WizardryParticleType.SPARK, world, this.posX - 0.5d + rand.nextDouble(),
this.posY + 2 * rand.nextDouble(), this.posZ - 0.5d + rand.nextDouble(), 0, 0, 0, 3);
ParticleBuilder.create(Type.SPARK)
.pos(this.posX - 0.5d + rand.nextDouble(), this.posY + 2 * rand.nextDouble(), this.posZ - 0.5d + rand.nextDouble())
.spawn(world);
}
if(!this.world.isRemote){
@@ -109,12 +111,14 @@ public class EntityHammer extends EntityMagicConstruct {
target.posY + target.height / 2, target.posZ);
world.spawnEntity(arc);
}else{
for(int j = 0; j < 8; j++){
Wizardry.proxy.spawnParticle(WizardryParticleType.SPARK, world,
target.posX + world.rand.nextFloat() - 0.5,
target.getEntityBoundingBox().minY + target.height / 2
+ world.rand.nextFloat() * 2 - 1,
target.posZ + world.rand.nextFloat() - 0.5, 0, 0, 0, 3);
// TODO: Move all the arc particle (and sound?) stuff into a method in WizardryUtilities
for(int j=0; j<8; j++){
ParticleBuilder.create(Type.SPARK)
.pos(target.posX + world.rand.nextFloat() - 0.5,
target.getEntityBoundingBox().minY + target.height / 2 + world.rand.nextFloat() * 2 - 1,
target.posZ + world.rand.nextFloat() - 0.5)
.spawn(world);
world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, target.posX + rand.nextFloat(),
target.getEntityBoundingBox().minY + target.height / 2 + rand.nextFloat(),
target.posZ + rand.nextFloat(), 0, 0, 0);
@@ -2,11 +2,11 @@ package electroblob.wizardry.entity.construct;
import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.DamageSource;
@@ -69,13 +69,16 @@ public class EntityHealAura extends EntityMagicConstruct {
}
}
}else{
for(int i = 1; i < 3; i++){
for(int i=1; i<3; i++){
float brightness = 0.5f + (rand.nextFloat() * 0.5f);
double radius = rand.nextDouble() * 2.0;
double angle = rand.nextDouble() * Math.PI * 2;
Wizardry.proxy.spawnParticle(WizardryParticleType.SPARKLE, world, this.posX + radius * Math.cos(angle),
this.posY, this.posZ + radius * Math.sin(angle), 0, 0.05f, 0, 48 + this.rand.nextInt(12), 1.0f,
1.0f, brightness);
ParticleBuilder.create(Type.SPARKLE)
.pos(this.posX + radius * Math.cos(angle), this.posY, this.posZ + radius * Math.sin(angle))
.vel(0, 0.05, 0)
.lifetime(48 + this.rand.nextInt(12))
.colour(1.0f, 1.0f, brightness)
.spawn(world);
}
}
}
@@ -2,12 +2,12 @@ package electroblob.wizardry.entity.construct;
import java.util.List;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.entity.EntityArc;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.DamageSource;
@@ -44,8 +44,6 @@ public class EntityLightningSigil extends EntityMagicConstruct {
this.setDead();
}
// if(!this.world.isRemote){
List<EntityLivingBase> targets = WizardryUtilities.getEntitiesWithinRadius(1.0d, this.posX, this.posY,
this.posZ, this.world);
@@ -90,11 +88,11 @@ public class EntityLightningSigil extends EntityMagicConstruct {
world.spawnEntity(arc);
}else{
for(int k = 0; k < 8; k++){
Wizardry.proxy.spawnParticle(WizardryParticleType.SPARK, world,
secondaryTarget.posX + world.rand.nextFloat() - 0.5,
secondaryTarget.getEntityBoundingBox().minY + secondaryTarget.height / 2
+ world.rand.nextFloat() * 2 - 1,
secondaryTarget.posZ + world.rand.nextFloat() - 0.5, 0, 0, 0, 3);
ParticleBuilder.create(Type.SPARK)
.pos(secondaryTarget.posX + world.rand.nextFloat() - 0.5,
secondaryTarget.getEntityBoundingBox().minY + secondaryTarget.height / 2 + world.rand.nextFloat() * 2 - 1,
secondaryTarget.posZ + world.rand.nextFloat() - 0.5)
.spawn(world);
world.spawnParticle(EnumParticleTypes.SMOKE_LARGE,
secondaryTarget.posX + world.rand.nextFloat() - 0.5,
secondaryTarget.getEntityBoundingBox().minY + secondaryTarget.height / 2
@@ -116,13 +114,13 @@ public class EntityLightningSigil extends EntityMagicConstruct {
}
}
}
// }
if(this.world.isRemote && this.rand.nextInt(15) == 0){
double radius = 0.5 + rand.nextDouble() * 0.3;
double angle = rand.nextDouble() * Math.PI * 2;
Wizardry.proxy.spawnParticle(WizardryParticleType.SPARK, world, this.posX + radius * Math.cos(angle),
this.posY + 0.1, this.posZ + radius * Math.sin(angle), 0, 0, 0, 3);
ParticleBuilder.create(Type.SPARK)
.pos(this.posX + radius * Math.cos(angle), this.posY + 0.1, this.posZ + radius * Math.sin(angle))
.spawn(world);
}
}
@@ -7,7 +7,8 @@ import electroblob.wizardry.registry.WizardryAdvancementTriggers;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.MagicDamage;
import electroblob.wizardry.util.MagicDamage.DamageType;
import electroblob.wizardry.util.WizardryParticleType;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.WizardryUtilities;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.material.Material;
@@ -133,24 +134,22 @@ public class EntityTornado extends EntityMagicConstruct {
yPos / 3 + 0.5d, 100, block, pos1);
Wizardry.proxy.spawnTornadoParticle(world, this.posX, this.posY + yPos, this.posZ, this.velX, this.velZ,
yPos / 3 + 0.5d, 100, block, pos1);
// Sometimes spawns leaf particles if the block is leaves, or snow particles if the block is snow
if(this.rand.nextInt(3) == 0){
// Sometimes spawns leaf particles if the block is leaves
if(block.getMaterial() == Material.LEAVES && this.rand.nextInt(3) == 0){
Type type = null;
if(block.getMaterial() == Material.LEAVES) type = Type.LEAF;
if(block.getMaterial() == Material.SNOW || block.getMaterial() == Material.CRAFTED_SNOW)
type = Type.SNOW;
double yPos1 = rand.nextDouble() * 8;
Wizardry.proxy.spawnParticle(WizardryParticleType.LEAF, world,
this.posX + (rand.nextDouble() * 2 - 1) * (yPos1 / 3 + 0.5d), this.posY + yPos1,
this.posZ + (rand.nextDouble() * 2 - 1) * (yPos1 / 3 + 0.5d), 0, -0.05, 0,
40 + rand.nextInt(10));
}
// Sometimes spawns snow particles if the block is snow
if(block.getMaterial() == Material.SNOW
|| block.getMaterial() == Material.CRAFTED_SNOW && this.rand.nextInt(3) == 0){
double yPos1 = rand.nextDouble() * 8;
Wizardry.proxy.spawnParticle(WizardryParticleType.SNOW, world,
this.posX + (rand.nextDouble() * 2 - 1) * (yPos1 / 3 + 0.5d), this.posY + yPos1,
this.posZ + (rand.nextDouble() * 2 - 1) * (yPos1 / 3 + 0.5d), 0, -0.02, 0,
40 + rand.nextInt(10));
ParticleBuilder.create(type)
.pos(this.posX + (rand.nextDouble() * 2 - 1) * (yPos1 / 3 + 0.5d), this.posY + yPos1,
this.posZ + (rand.nextDouble() * 2 - 1) * (yPos1 / 3 + 0.5d))
.lifetime(40 + rand.nextInt(10))
.spawn(world);
}
}
}