Spell hierarchisation and refactoring, plus miscellaneous renaming and minor refactoring
- Adds new generic spell superclasses which aim to group spells such that duplicate code is eliminated, and functions standardised, as much as possible. - Removes numerous spell classes which are no longer required as a result of this change, and replaces them with instances of the relevant generic spell classes. - Changes the remaining spell classes to fit with the new system, mostly by having them extend the generic spell classes. - Completes the transfer of particle spawning to the ParticleBuilder system.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package electroblob.wizardry.spell;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.constants.Element;
|
||||
import electroblob.wizardry.constants.SpellType;
|
||||
import electroblob.wizardry.constants.Tier;
|
||||
@@ -8,106 +7,71 @@ import electroblob.wizardry.registry.WizardryItems;
|
||||
import electroblob.wizardry.registry.WizardrySounds;
|
||||
import electroblob.wizardry.util.MagicDamage;
|
||||
import electroblob.wizardry.util.MagicDamage.DamageType;
|
||||
import electroblob.wizardry.util.SpellModifiers;
|
||||
import electroblob.wizardry.util.ParticleBuilder;
|
||||
import electroblob.wizardry.util.ParticleBuilder.Type;
|
||||
import electroblob.wizardry.util.SpellModifiers;
|
||||
import electroblob.wizardry.util.WizardryUtilities;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class FlameRay extends Spell {
|
||||
public class FlameRay extends SpellRay {
|
||||
|
||||
private static final float BASE_DAMAGE = 3;
|
||||
/** The base duration for which entities are set on fire by this spell. */
|
||||
private static final int BASE_DURATION = 10;
|
||||
|
||||
public FlameRay(){
|
||||
super(Tier.APPRENTICE, 5, Element.FIRE, "flame_ray", SpellType.ATTACK, 0, EnumAction.NONE, true);
|
||||
super("flame_ray", Tier.APPRENTICE, Element.FIRE, SpellType.ATTACK, 5, 0, true, 10, null);
|
||||
this.particleVelocity(1);
|
||||
this.particleSpacing(0.5);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){
|
||||
|
||||
Vec3d look = caster.getLookVec();
|
||||
|
||||
RayTraceResult rayTrace = WizardryUtilities.standardEntityRayTrace(world, caster,
|
||||
10 * modifiers.get(WizardryItems.range_upgrade));
|
||||
|
||||
// Fire can damage armour stands
|
||||
if(rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.ENTITY && rayTrace.entityHit instanceof EntityLivingBase){
|
||||
|
||||
EntityLivingBase target = (EntityLivingBase)rayTrace.entityHit;
|
||||
|
||||
if(!MagicDamage.isEntityImmune(DamageType.FIRE, target)){
|
||||
target.setFire(10);
|
||||
WizardryUtilities.attackEntityWithoutKnockback(target,
|
||||
MagicDamage.causeDirectMagicDamage(caster, DamageType.FIRE),
|
||||
3.0f * modifiers.get(SpellModifiers.DAMAGE));
|
||||
}else{
|
||||
if(!world.isRemote && ticksInUse == 1) caster.sendMessage(new TextComponentTranslation("spell.resist",
|
||||
target.getName(), this.getNameForTranslationFormatted()));
|
||||
// TODO: Temporary solution until I implement a better continuous sound system
|
||||
boolean flag = super.cast(world, caster, hand, ticksInUse, modifiers);
|
||||
if(flag){
|
||||
if(ticksInUse % 16 == 0){
|
||||
if(ticksInUse == 0) WizardryUtilities.playSoundAtPlayer(caster, SoundEvents.ENTITY_BLAZE_SHOOT, 1, 1);
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LOOP_FIRE, 0.5f, 1.0f);
|
||||
}
|
||||
}
|
||||
if(world.isRemote){
|
||||
for(int i = 0; i < 20; i++){
|
||||
// I figured it out! when on client side, entityplayer.posY is at the eyes, not the feet!
|
||||
double x1 = caster.posX + look.x * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
|
||||
double y1 = WizardryUtilities.getPlayerEyesPos(caster) - 0.4f + look.y * i / 2
|
||||
+ world.rand.nextFloat() / 5 - 0.1f;
|
||||
double z1 = caster.posZ + look.z * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
|
||||
Wizardry.proxy.spawnParticle(Type.MAGIC_FIRE, world, x1, y1, z1,
|
||||
look.x * modifiers.get(WizardryItems.range_upgrade),
|
||||
look.y * modifiers.get(WizardryItems.range_upgrade),
|
||||
look.z * modifiers.get(WizardryItems.range_upgrade), 0);
|
||||
Wizardry.proxy.spawnParticle(Type.MAGIC_FIRE, world, x1, y1, z1,
|
||||
look.x * modifiers.get(WizardryItems.range_upgrade),
|
||||
look.y * modifiers.get(WizardryItems.range_upgrade),
|
||||
look.z * modifiers.get(WizardryItems.range_upgrade), 0);
|
||||
}
|
||||
}
|
||||
if(ticksInUse % 16 == 0){
|
||||
if(ticksInUse == 0) WizardryUtilities.playSoundAtPlayer(caster, SoundEvents.ENTITY_BLAZE_SHOOT, 1, 1);
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LOOP_FIRE, 0.5F, 1.0f);
|
||||
}
|
||||
return true;
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cast(World world, EntityLiving caster, EnumHand hand, int ticksInUse, EntityLivingBase target,
|
||||
SpellModifiers modifiers){
|
||||
|
||||
if(target != null){
|
||||
|
||||
Vec3d vec = new Vec3d(target.posX - caster.posX, target.posY - caster.posY, target.posZ - caster.posZ).normalize();
|
||||
|
||||
target.setFire(10);
|
||||
WizardryUtilities.attackEntityWithoutKnockback(target,
|
||||
MagicDamage.causeDirectMagicDamage(caster, DamageType.FIRE),
|
||||
3.0f * modifiers.get(SpellModifiers.DAMAGE));
|
||||
|
||||
if(world.isRemote){
|
||||
for(int i = 0; i < 20; i++){
|
||||
double x1 = caster.posX + vec.x * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
|
||||
double y1 = caster.posY + caster.getEyeHeight() - 0.4f + vec.y * i / 2 + world.rand.nextFloat() / 5
|
||||
- 0.1f;
|
||||
double z1 = caster.posZ + vec.z * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
|
||||
Wizardry.proxy.spawnParticle(Type.MAGIC_FIRE, world, x1, y1, z1,
|
||||
vec.x * modifiers.get(WizardryItems.range_upgrade),
|
||||
vec.y * modifiers.get(WizardryItems.range_upgrade),
|
||||
vec.z * modifiers.get(WizardryItems.range_upgrade), 0);
|
||||
Wizardry.proxy.spawnParticle(Type.MAGIC_FIRE, world, x1, y1, z1,
|
||||
vec.x * modifiers.get(WizardryItems.range_upgrade),
|
||||
vec.y * modifiers.get(WizardryItems.range_upgrade),
|
||||
vec.z * modifiers.get(WizardryItems.range_upgrade), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean cast(World world, EntityLiving caster, EnumHand hand, int ticksInUse, EntityLivingBase target, SpellModifiers modifiers){
|
||||
boolean flag = super.cast(world, caster, hand, ticksInUse, target, modifiers);
|
||||
if(flag){
|
||||
if(ticksInUse % 16 == 0){
|
||||
if(ticksInUse == 0) caster.playSound(SoundEvents.ENTITY_BLAZE_SHOOT, 1, 1);
|
||||
caster.playSound(WizardrySounds.SPELL_LOOP_FIRE, 0.5F, 1.0f);
|
||||
caster.playSound(WizardrySounds.SPELL_LOOP_FIRE, 0.5f, 1.0f);
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onEntityHit(World world, Entity target, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
|
||||
// Fire can damage armour stands
|
||||
if(target instanceof EntityLivingBase){
|
||||
|
||||
if(MagicDamage.isEntityImmune(DamageType.FIRE, target)){
|
||||
if(!world.isRemote && ticksInUse == 1) caster.sendMessage(new TextComponentTranslation("spell.resist",
|
||||
target.getName(), this.getNameForTranslationFormatted()));
|
||||
}else {
|
||||
target.setFire((int)(BASE_DURATION * modifiers.get(WizardryItems.duration_upgrade)));
|
||||
WizardryUtilities.attackEntityWithoutKnockback(target,
|
||||
MagicDamage.causeDirectMagicDamage(caster, DamageType.FIRE),
|
||||
BASE_DAMAGE * modifiers.get(SpellModifiers.POTENCY));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -117,8 +81,19 @@ public class FlameRay extends Spell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeCastByNPCs(){
|
||||
protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onMiss(World world, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void spawnParticle(World world, double x, double y, double z, double vx, double vy, double vz){
|
||||
ParticleBuilder.create(Type.MAGIC_FIRE).pos(x, y, z).vel(vx, vy, vz).spawn(world);
|
||||
ParticleBuilder.create(Type.MAGIC_FIRE).pos(x, y, z).vel(vx, vy, vz).spawn(world);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user