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
@@ -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,119 +7,87 @@ import electroblob.wizardry.entity.living.EntityMagicSlime;
import electroblob.wizardry.registry.WizardryAdvancementTriggers;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.registry.WizardrySounds;
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.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySlime;
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.EnumParticleTypes;
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 Slime extends Spell {
public class Slime extends SpellRay {
private static final int BASE_DURATION = 200;
public Slime(){
super(Tier.ADVANCED, 20, Element.EARTH, "slime", SpellType.ATTACK, 50, EnumAction.NONE, false);
super("slime", Tier.ADVANCED, Element.EARTH, SpellType.ATTACK, 20, 50, false, 8, WizardrySounds.SPELL_ICE);
}
@Override
public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, SpellModifiers modifiers){
// This spell uses more than one sound, so this is required...
boolean flag = super.cast(world, caster, hand, ticksInUse, modifiers);
if(flag) WizardryUtilities.playSoundAtPlayer(caster, SoundEvents.ENTITY_SLIME_ATTACK, 1.0F, 0.5F);
return flag;
}
Vec3d look = caster.getLookVec();
@Override
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) caster.playSound(SoundEvents.ENTITY_SLIME_ATTACK, 1.0F, 0.5F);
return flag;
}
RayTraceResult rayTrace = WizardryUtilities.standardEntityRayTrace(world, caster,
8 * modifiers.get(WizardryItems.range_upgrade));
if(rayTrace != null && rayTrace.entityHit != null && WizardryUtilities.isLiving(rayTrace.entityHit)){
EntityLivingBase target = (EntityLivingBase)rayTrace.entityHit;
@Override
protected boolean onEntityHit(World world, Entity target, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
if(WizardryUtilities.isLiving(target) && !(target instanceof EntityMagicSlime)){
if(target instanceof EntitySlime){
if(!world.isRemote) caster.sendMessage(new TextComponentTranslation("spell.resist", target.getName(),
this.getNameForTranslationFormatted()));
}else if(!(target instanceof EntityMagicSlime)){
}else{
if(target instanceof EntitySkeleton) WizardryAdvancementTriggers.slime_skeleton.triggerFor(caster);
if(target instanceof EntitySkeleton && caster instanceof EntityPlayer)
WizardryAdvancementTriggers.slime_skeleton.triggerFor((EntityPlayer)caster);
if(!world.isRemote){
EntityMagicSlime slime = new EntityMagicSlime(world, caster, target,
(int)(200 * modifiers.get(WizardryItems.duration_upgrade)));
EntityMagicSlime slime = new EntityMagicSlime(world, caster, (EntityLivingBase)target,
(int)(BASE_DURATION * modifiers.get(WizardryItems.duration_upgrade)));
world.spawnEntity(slime);
}
}
}
if(world.isRemote){
for(int i = 1; i < (int)(25 * modifiers.get(WizardryItems.range_upgrade)); i += 2){
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;
world.spawnParticle(EnumParticleTypes.SLIME, x1, y1, z1, 0.0d, 0.0d, 0.0d);
Wizardry.proxy.spawnParticle(Type.DARK_MAGIC, world, x1, y1, z1, 0.0d, 0.0d, 0.0d, 0,
0.2f, 0.8f, 0.1f);
}
}
caster.swingArm(hand);
WizardryUtilities.playSoundAtPlayer(caster, SoundEvents.ENTITY_SLIME_ATTACK, 1.0F, 0.5F);
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_ICE, 1.0F, 1.0F);
return true;
}
@Override
public boolean cast(World world, EntityLiving caster, EnumHand hand, int ticksInUse, EntityLivingBase target,
SpellModifiers modifiers){
if(target != null && !(target instanceof EntitySlime) && !(target instanceof EntityMagicSlime)){
if(!world.isRemote){
EntityMagicSlime slime = new EntityMagicSlime(world, caster, target,
(int)(200 * modifiers.get(WizardryItems.duration_upgrade)));
world.spawnEntity(slime);
}
if(world.isRemote){
double dx = (target.posX - caster.posX) / caster.getDistance(target);
double dy = (target.posY - caster.posY) / caster.getDistance(target);
double dz = (target.posZ - caster.posZ) / caster.getDistance(target);
for(int i = 1; i < (int)(25 * modifiers.get(WizardryItems.range_upgrade)); i += 2){
double x1 = caster.posX + dx * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
double y1 = caster.posY + caster.getEyeHeight() - 0.4f + dy * i / 2 + world.rand.nextFloat() / 5
- 0.1f;
double z1 = caster.posZ + dz * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
world.spawnParticle(EnumParticleTypes.SLIME, x1, y1, z1, 0.0d, 0.0d, 0.0d);
Wizardry.proxy.spawnParticle(Type.DARK_MAGIC, world, x1, y1, z1, 0.0d, 0.0d, 0.0d,
0, 0.2f, 0.8f, 0.1f);
}
}
caster.swingArm(hand);
caster.playSound(SoundEvents.ENTITY_SLIME_ATTACK, 1.0F, 0.5F);
caster.playSound(WizardrySounds.SPELL_ICE, 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){
return true;
}
@Override
protected void spawnParticle(World world, double x, double y, double z, double vx, double vy, double vz){
world.spawnParticle(EnumParticleTypes.SLIME, x, y, z, 0, 0, 0);
ParticleBuilder.create(Type.DARK_MAGIC).pos(x, y, z).colour(0.2f, 0.8f, 0.1f).spawn(world);
}
}