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
@@ -4,7 +4,8 @@ import electroblob.wizardry.WizardData;
import electroblob.wizardry.Wizardry;
import electroblob.wizardry.item.ItemWand;
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;
@@ -85,17 +86,15 @@ public class EntitySpiritHorse extends EntityHorse {
if(itemstack.getItem() instanceof ItemWand && this.getOwner() == player && player.isSneaking()){
// Prevents accidental double clicking.
if(this.ticksExisted > 20){
for(int i = 0; i < 15; i++){
Wizardry.proxy.spawnParticle(WizardryParticleType.SPARKLE, world,
this.posX - this.width / 2 + this.rand.nextFloat() * width,
this.posY + this.height * this.rand.nextFloat() + 0.2f,
this.posZ - this.width / 2 + this.rand.nextFloat() * width, 0, 0, 0,
48 + this.rand.nextInt(12), 0.8f, 0.8f, 1.0f);
}
this.spawnAppearParticles();
this.setDead();
if(WizardData.get(player) != null){
WizardData.get(player).hasSpiritHorse = false;
}
this.playSound(WizardrySounds.SPELL_HEAL, 0.7F, rand.nextFloat() * 0.4F + 1.0F);
// This is necessary to prevent the wand's spell being cast when performing this action.
return true;
@@ -105,6 +104,15 @@ public class EntitySpiritHorse extends EntityHorse {
return super.processInteract(player, hand);
}
private void spawnAppearParticles(){
for(int i=0; i<15; i++){
double x = this.posX - this.width / 2 + this.rand.nextFloat() * width;
double y = this.posY + this.height * this.rand.nextFloat() + 0.2f;
double z = this.posZ - this.width / 2 + this.rand.nextFloat() * width;
ParticleBuilder.create(Type.SPARKLE).pos(x, y, z).colour(0.8f, 0.8f, 1.0f).spawn(world);
}
}
@Override
public void onDeath(DamageSource par1DamageSource){
@@ -137,10 +145,10 @@ public class EntitySpiritHorse extends EntityHorse {
// Adds a dust particle effect
if(this.world.isRemote){
Wizardry.proxy.spawnParticle(WizardryParticleType.DUST, world,
this.posX - this.width / 2 + this.rand.nextFloat() * width,
this.posY + this.height * this.rand.nextFloat() + 0.2f,
this.posZ - this.width / 2 + this.rand.nextFloat() * width, 0, 0, 0, 0, 0.8f, 0.8f, 1.0f);
double x = this.posX - this.width / 2 + this.rand.nextFloat() * width;
double y = this.posY + this.height * this.rand.nextFloat() + 0.2f;
double z = this.posZ - this.width / 2 + this.rand.nextFloat() * width;
ParticleBuilder.create(Type.DUST).pos(x, y, z).colour(0.8f, 0.8f, 1.0f).shaded(true).spawn(world);
}
// Spirit horse disappears a short time after being dismounted.
@@ -151,20 +159,17 @@ public class EntitySpiritHorse extends EntityHorse {
}
if(this.idleTimer > 200){
if(this.world.isRemote){
for(int i = 0; i < 15; i++){
Wizardry.proxy.spawnParticle(WizardryParticleType.SPARKLE, world,
this.posX - this.width / 2 + this.rand.nextFloat() * width,
this.posY + this.height * this.rand.nextFloat() + 0.2f,
this.posZ - this.width / 2 + this.rand.nextFloat() * width, 0, 0, 0,
48 + this.rand.nextInt(12), 0.8f, 0.8f, 1.0f);
}
this.spawnAppearParticles();
}
this.playSound(WizardrySounds.SPELL_HEAL, 0.7F, rand.nextFloat() * 0.4F + 1.0F);
// Allows player to summon another spirit horse once this one has disappeared.
if(this.getOwner() instanceof EntityPlayer && WizardData.get((EntityPlayer)this.getOwner()) != null){
WizardData.get((EntityPlayer)this.getOwner()).hasSpiritHorse = false;
}
this.setDead();
}
}
@@ -179,13 +184,7 @@ public class EntitySpiritHorse extends EntityHorse {
// Adds Particles on spawn. Due to client/server differences this cannot be done in the item.
if(this.world.isRemote){
for(int i = 0; i < 15; i++){
Wizardry.proxy.spawnParticle(WizardryParticleType.SPARKLE, world,
this.posX - this.width / 2 + this.rand.nextFloat() * width,
this.posY + this.height * this.rand.nextFloat() + 0.2f,
this.posZ - this.width / 2 + this.rand.nextFloat() * width, 0, 0, 0, 48 + this.rand.nextInt(12),
0.8f, 0.8f, 1.0f);
}
this.spawnAppearParticles();
}
return super.onInitialSpawn(difficulty, data);