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,158 +1,123 @@
|
||||
package electroblob.wizardry.spell;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.constants.Element;
|
||||
import electroblob.wizardry.constants.SpellType;
|
||||
import electroblob.wizardry.constants.Tier;
|
||||
import electroblob.wizardry.entity.EntityArc;
|
||||
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.item.EnumAction;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class LightningRay extends Spell {
|
||||
public class LightningRay extends SpellRay {
|
||||
|
||||
private static final float BASE_DAMAGE = 3;
|
||||
|
||||
public LightningRay(){
|
||||
super(Tier.APPRENTICE, 5, Element.LIGHTNING, "lightning_ray", SpellType.ATTACK, 0, EnumAction.NONE, true);
|
||||
super("lightning_ray", Tier.APPRENTICE, Element.LIGHTNING, SpellType.ATTACK, 5, 0, true, 10, null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){
|
||||
|
||||
RayTraceResult rayTrace = WizardryUtilities.standardEntityRayTrace(world, caster,
|
||||
10 * modifiers.get(WizardryItems.range_upgrade), 2.0f);
|
||||
|
||||
if(rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.ENTITY && WizardryUtilities.isLiving(rayTrace.entityHit)){
|
||||
Entity target = rayTrace.entityHit;
|
||||
if(!world.isRemote){
|
||||
// This statement means the arc only spawns every other tick.
|
||||
if(ticksInUse % 2 == 0){
|
||||
|
||||
EntityArc arc = new EntityArc(world);
|
||||
// The look vec stuff performs a translation on the start point to line it up with the wand.
|
||||
// EDIT: removed due to 1st/3rd person render differences.
|
||||
arc.setEndpointCoords(caster.posX, caster.posY + 1.2, caster.posZ, target.posX,
|
||||
target.posY + target.height / 2, target.posZ);
|
||||
|
||||
arc.lifetime = 1;
|
||||
|
||||
world.spawnEntity(arc);
|
||||
}
|
||||
|
||||
if(MagicDamage.isEntityImmune(DamageType.SHOCK, target)){
|
||||
if(!world.isRemote && ticksInUse == 1)
|
||||
caster.sendMessage(new TextComponentTranslation("spell.resist", target.getName(),
|
||||
this.getNameForTranslationFormatted()));
|
||||
}else{
|
||||
WizardryUtilities.attackEntityWithoutKnockback(target,
|
||||
MagicDamage.causeDirectMagicDamage(caster, DamageType.SHOCK),
|
||||
3.0f * modifiers.get(SpellModifiers.DAMAGE));
|
||||
}
|
||||
|
||||
}else{
|
||||
for(int i = 0; i < 5; i++){
|
||||
Wizardry.proxy.spawnParticle(Type.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: Temporary solution until I implement a better continuous sound system
|
||||
boolean flag = super.cast(world, caster, hand, ticksInUse, modifiers);
|
||||
if(flag){
|
||||
if(ticksInUse == 1){
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LIGHTNING, 1.0F, 1.0f);
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LIGHTNING, 1, 1);
|
||||
}else if(ticksInUse > 0 && ticksInUse % 20 == 0){
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LOOP_LIGHTNING, 1.0F, 1.0f);
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LOOP_LIGHTNING, 1, 1);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}else{
|
||||
if(!world.isRemote){
|
||||
// This statement means the arc only spawns every other tick.
|
||||
if(ticksInUse % 2 == 0){
|
||||
|
||||
EntityArc arc = new EntityArc(world);
|
||||
|
||||
arc.setEndpointCoords(caster.posX, caster.posY + 1.2, caster.posZ,
|
||||
caster.posX + caster.getLookVec().x * 8,
|
||||
caster.posY + caster.eyeHeight + caster.getLookVec().y * 8,
|
||||
caster.posZ + caster.getLookVec().z * 8);
|
||||
|
||||
arc.lifetime = 1;
|
||||
|
||||
world.spawnEntity(arc);
|
||||
}
|
||||
}
|
||||
|
||||
if(ticksInUse == 1){
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LIGHTNING, 1.0F, 1.0f);
|
||||
}else if(ticksInUse > 0 && ticksInUse % 20 == 0){
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LOOP_LIGHTNING, 1.0F, 1.0f);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cast(World world, EntityLiving caster, EnumHand hand, int ticksInUse, EntityLivingBase target,
|
||||
SpellModifiers modifiers){
|
||||
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 == 1){
|
||||
caster.playSound(WizardrySounds.SPELL_LIGHTNING, 1, 1);
|
||||
}else if(ticksInUse > 0 && ticksInUse % 20 == 0){
|
||||
caster.playSound(WizardrySounds.SPELL_LOOP_LIGHTNING, 1, 1);
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
if(target != null){
|
||||
@Override
|
||||
protected boolean onEntityHit(World world, Entity target, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
|
||||
|
||||
if(WizardryUtilities.isLiving(target)){
|
||||
|
||||
if(MagicDamage.isEntityImmune(DamageType.SHOCK, target)){
|
||||
if(!world.isRemote && ticksInUse == 1)
|
||||
caster.sendMessage(new TextComponentTranslation("spell.resist", target.getName(),
|
||||
this.getNameForTranslationFormatted()));
|
||||
}else{
|
||||
WizardryUtilities.attackEntityWithoutKnockback(target,
|
||||
MagicDamage.causeDirectMagicDamage(caster, DamageType.SHOCK),
|
||||
BASE_DAMAGE * modifiers.get(SpellModifiers.POTENCY));
|
||||
}
|
||||
|
||||
if(!world.isRemote){
|
||||
// This statement means the arc only spawns every other tick.
|
||||
|
||||
if(ticksInUse % 2 == 0){
|
||||
|
||||
EntityArc arc = new EntityArc(world);
|
||||
// The look vec stuff performs a translation on the start point to line it up with the wand.
|
||||
// EDIT: removed due to 1st/3rd person render differences.
|
||||
arc.setEndpointCoords(caster.posX, caster.posY + 1.2, caster.posZ, target.posX,
|
||||
target.posY + target.height / 2, target.posZ);
|
||||
|
||||
arc.lifetime = 1;
|
||||
|
||||
world.spawnEntity(arc);
|
||||
}
|
||||
|
||||
WizardryUtilities.attackEntityWithoutKnockback(target,
|
||||
MagicDamage.causeDirectMagicDamage(caster, DamageType.SHOCK),
|
||||
3.0f * modifiers.get(SpellModifiers.DAMAGE));
|
||||
|
||||
}else{
|
||||
for(int i = 0; i < 5; i++){
|
||||
Wizardry.proxy.spawnParticle(Type.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);
|
||||
// Particle effect
|
||||
for(int i=0; i<5; i++){
|
||||
ParticleBuilder.create(Type.SPARK, target);
|
||||
}
|
||||
}
|
||||
|
||||
if(ticksInUse == 1){
|
||||
caster.playSound(WizardrySounds.SPELL_LIGHTNING, 1.0F, 1.0f);
|
||||
}else if(ticksInUse > 0 && ticksInUse % 20 == 0){
|
||||
caster.playSound(WizardrySounds.SPELL_LOOP_LIGHTNING, 1.0F, 1.0f);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@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){
|
||||
// This is a nice example of when onMiss is used for more than just returning a boolean
|
||||
if(!world.isRemote){
|
||||
|
||||
if(ticksInUse % 2 == 0){
|
||||
|
||||
double freeRange = 0.8 * baseRange; // The arc does not reach full range when it has a free end
|
||||
|
||||
EntityArc arc = new EntityArc(world);
|
||||
arc.setEndpointCoords(caster.posX, caster.posY + 1.2, caster.posZ,
|
||||
caster.posX + caster.getLookVec().x * freeRange,
|
||||
caster.posY + caster.getEyeHeight() + caster.getLookVec().y * freeRange,
|
||||
caster.posZ + caster.getLookVec().z * freeRange);
|
||||
arc.lifetime = 1;
|
||||
world.spawnEntity(arc);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user