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:
Electroblob
2018-06-20 22:25:54 +01:00
parent b6400c72a7
commit 29261082f1
222 changed files with 4412 additions and 9016 deletions
@@ -8,107 +8,52 @@ import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.SpellModifiers;
import electroblob.wizardry.util.WizardryUtilities;
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.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
public class IceSpikes extends Spell {
public class IceSpikes extends SpellConstructRanged<EntityIceSpike> {
private static final int BASE_SPAWN_COUNT = 17; // Was 18, reduced to 17 to account for the extra one in the middle.
public IceSpikes(){
super(Tier.ADVANCED, 30, Element.ICE, "ice_spikes", SpellType.ATTACK, 75, EnumAction.NONE, false);
// Base duration is set to -1 so that the superclass doesn't waste time retrieving the duration multiplier
super("ice_spikes", Tier.ADVANCED, Element.ICE, SpellType.ATTACK, 30, 75, EntityIceSpike::new, -1, 20, WizardrySounds.SPELL_ICE);
}
@Override
public boolean doesSpellRequirePacket(){
return false;
}
protected boolean spawnConstruct(World world, double x, double y, double z, EntityLivingBase caster, SpellModifiers modifiers){
if(world.getBlockState(new BlockPos(x, y, z)).isNormalCube()) return false;
// Now always spawns a spike exactly at the position aimed at
super.spawnConstruct(world, x, y-1, z, caster, modifiers);
int quantity = (int)(BASE_SPAWN_COUNT * modifiers.get(WizardryItems.blast_upgrade));
@Override
public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){
for(int i=0; i<quantity; i++){
float angle = (float)(world.rand.nextFloat() * Math.PI * 2);
double radius = 0.5 + world.rand.nextDouble() * 2 * modifiers.get(WizardryItems.blast_upgrade);
RayTraceResult rayTrace = WizardryUtilities.rayTrace(20 * modifiers.get(WizardryItems.range_upgrade), world,
caster, false);
double x1 = x + radius * MathHelper.sin(angle);
double z1 = z + radius * MathHelper.cos(angle);
double y1 = WizardryUtilities.getNearestFloorLevel(world,
new BlockPos(MathHelper.floor(x1), (int)y, MathHelper.floor(z1)), 2) - 1;
if(rayTrace != null && rayTrace.typeOfHit == RayTraceResult.Type.BLOCK && rayTrace.sideHit == EnumFacing.UP){
if(!world.isRemote){
double x = rayTrace.hitVec.x;
double y = rayTrace.hitVec.y;
double z = rayTrace.hitVec.z;
for(int i = 0; i < (int)(18 * modifiers.get(WizardryItems.blast_upgrade)); i++){
float angle = (float)(world.rand.nextFloat() * Math.PI * 2);
double radius = 0.5 + world.rand.nextDouble() * 2 * modifiers.get(WizardryItems.blast_upgrade);
double x1 = x + radius * MathHelper.sin(angle);
double z1 = z + radius * MathHelper.cos(angle);
double y1 = WizardryUtilities.getNearestFloorLevel(world,
new BlockPos(MathHelper.floor(x1), (int)y, MathHelper.floor(z1)), 2) - 1;
if(y1 > -1){
EntityIceSpike icespike = new EntityIceSpike(world, x1, y1, z1, caster,
30 + world.rand.nextInt(15), modifiers.get(SpellModifiers.DAMAGE));
world.spawnEntity(icespike);
}
}
if(y1 > -1){
super.spawnConstruct(world, x1, y1, z1, caster, modifiers);
}
caster.swingArm(hand);
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_ICE, 1.0F, 1.0F);
return true;
}
return false;
}
@Override
public boolean cast(World world, EntityLiving caster, EnumHand hand, int ticksInUse, EntityLivingBase target,
SpellModifiers modifiers){
if(target != null){
if(!world.isRemote){
double x = target.posX;
double y = target.posY;
double z = target.posZ;
for(int i = 0; i < (int)(18 * modifiers.get(WizardryItems.blast_upgrade)); i++){
float angle = (float)(world.rand.nextFloat() * Math.PI * 2);
double radius = 0.5 + world.rand.nextDouble() * 2 * modifiers.get(WizardryItems.blast_upgrade);
double x1 = x + radius * MathHelper.sin(angle);
double z1 = z + radius * MathHelper.cos(angle);
double y1 = WizardryUtilities.getNearestFloorLevel(world,
new BlockPos(MathHelper.floor(x1), (int)y, MathHelper.floor(z1)), 2) - 1;
if(y1 > -1){
EntityIceSpike icespike = new EntityIceSpike(world, x1, y1, z1, caster,
30 + world.rand.nextInt(15), modifiers.get(SpellModifiers.DAMAGE));
world.spawnEntity(icespike);
}
}
}
caster.swingArm(hand);
caster.playSound(WizardrySounds.SPELL_ICE, 1.0F, 1.0F);
return true;
}
return false;
}
@Override
public boolean canBeCastByNPCs(){
return true;
}
@Override
protected void addConstructExtras(EntityIceSpike construct, EntityLivingBase caster, SpellModifiers modifiers){
// In this particular case, lifetime is implemented as a delay instead so is treated differently.
construct.lifetime = 30 + construct.world.rand.nextInt(15);
}
}