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,103 +1,137 @@
|
||||
package electroblob.wizardry.spell;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.block.BlockStatue;
|
||||
import electroblob.wizardry.constants.Element;
|
||||
import electroblob.wizardry.constants.SpellType;
|
||||
import electroblob.wizardry.constants.Tier;
|
||||
import electroblob.wizardry.registry.WizardryBlocks;
|
||||
import electroblob.wizardry.registry.WizardryItems;
|
||||
import electroblob.wizardry.registry.WizardrySounds;
|
||||
import electroblob.wizardry.tileentity.TileEntityStatue;
|
||||
import electroblob.wizardry.util.ParticleBuilder;
|
||||
import electroblob.wizardry.util.SpellModifiers;
|
||||
import electroblob.wizardry.util.ParticleBuilder.Type;
|
||||
import electroblob.wizardry.util.WizardryUtilities;
|
||||
import electroblob.wizardry.util.ParticleBuilder.Type;
|
||||
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.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class WallOfFrost extends Spell {
|
||||
public class WallOfFrost extends SpellRay {
|
||||
|
||||
private static final int BASE_DURATION = 600;
|
||||
|
||||
public WallOfFrost(){
|
||||
super(Tier.MASTER, 15, Element.ICE, "wall_of_frost", SpellType.UTILITY, 0, EnumAction.NONE, true);
|
||||
super("wall_of_frost", Tier.MASTER, Element.ICE, SpellType.UTILITY, 15, 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){
|
||||
// TODO: Temporary solution until I implement a better continuous sound system
|
||||
boolean flag = super.cast(world, caster, hand, ticksInUse, modifiers);
|
||||
if(flag){
|
||||
if(ticksInUse % 12 == 0){
|
||||
if(ticksInUse == 0) WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_ICE, 0.5f, 1);
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LOOP_ICE, 0.5f, 1);
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cast(World world, EntityPlayer caster, EnumHand hand, int ticksInUse, 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 % 12 == 0){
|
||||
if(ticksInUse == 0) caster.playSound(WizardrySounds.SPELL_ICE, 0.5f, 1);
|
||||
caster.playSound(WizardrySounds.SPELL_LOOP_ICE, 0.5f, 1);
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
// IDEA: Use frosted ice instead of ice statue
|
||||
@Override
|
||||
protected boolean onEntityHit(World world, Entity target, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
|
||||
// Wall of frost now freezes entities solid too!
|
||||
if(target instanceof EntityLiving && !world.isRemote){
|
||||
// Unchecked cast is fine because the block is a static final field
|
||||
if(((BlockStatue)WizardryBlocks.ice_statue).convertToStatue((EntityLiving)target,
|
||||
(int)(BASE_DURATION * modifiers.get(WizardryItems.duration_upgrade)))){
|
||||
|
||||
target.playSound(WizardrySounds.SPELL_FREEZE, 1.0F, world.rand.nextFloat() * 0.4F + 0.8F);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Vec3d look = caster.getLookVec();
|
||||
|
||||
RayTraceResult rayTrace = WizardryUtilities.rayTrace(10 * modifiers.get(WizardryItems.range_upgrade), world,
|
||||
caster, true);
|
||||
|
||||
if(rayTrace != null && !world.isRemote){
|
||||
|
||||
BlockPos pos = rayTrace.getBlockPos();
|
||||
@Override
|
||||
protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
|
||||
|
||||
// IDEA: Use frosted ice instead of ice statue blocks
|
||||
|
||||
if(!world.isRemote){
|
||||
|
||||
// Stops the ice being placed floating above snow and grass. Directions other than up included for
|
||||
// completeness.
|
||||
if(WizardryUtilities.canBlockBeReplaced(world, pos)){
|
||||
// Moves the blockpos back into the block
|
||||
pos = pos.offset(rayTrace.sideHit.getOpposite());
|
||||
pos = pos.offset(side.getOpposite());
|
||||
}
|
||||
|
||||
if(caster.getDistance(pos.getX(), pos.getY(), pos.getZ()) > 2
|
||||
&& world.getBlockState(pos).getBlock() != WizardryBlocks.ice_statue){
|
||||
|
||||
pos = pos.offset(rayTrace.sideHit);
|
||||
pos = pos.offset(side);
|
||||
|
||||
int duration = (int)(BASE_DURATION * modifiers.get(WizardryItems.duration_upgrade));
|
||||
|
||||
if(WizardryUtilities.canBlockBeReplaced(world, pos)){
|
||||
|
||||
world.setBlockState(pos, WizardryBlocks.ice_statue.getDefaultState());
|
||||
|
||||
if(world.getTileEntity(pos) instanceof TileEntityStatue){
|
||||
((TileEntityStatue)world.getTileEntity(pos)).setLifetime(duration);
|
||||
}
|
||||
}
|
||||
|
||||
// Builds a 2 block high wall if it hits the ground
|
||||
if(rayTrace.sideHit == EnumFacing.UP){
|
||||
pos = pos.offset(rayTrace.sideHit);
|
||||
if(side == EnumFacing.UP){
|
||||
pos = pos.offset(side);
|
||||
|
||||
if(WizardryUtilities.canBlockBeReplaced(world, pos)){
|
||||
|
||||
world.setBlockState(pos, WizardryBlocks.ice_statue.getDefaultState());
|
||||
|
||||
if(world.getTileEntity(pos) instanceof TileEntityStatue){
|
||||
((TileEntityStatue)world.getTileEntity(pos)).setLifetime(duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 20; i++){
|
||||
|
||||
if(world.isRemote){
|
||||
|
||||
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.SPARKLE, 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), 8 + world.rand.nextInt(12), 0.4f,
|
||||
0.6f, 1.0f);
|
||||
|
||||
x1 = caster.posX + look.x * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
|
||||
y1 = WizardryUtilities.getPlayerEyesPos(caster) - 0.4f + look.y * i / 2
|
||||
+ world.rand.nextFloat() / 5 - 0.1f;
|
||||
z1 = caster.posZ + look.z * i / 2 + world.rand.nextFloat() / 5 - 0.1f;
|
||||
Wizardry.proxy.spawnParticle(Type.SPARKLE, 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), 8 + world.rand.nextInt(12), 1.0f,
|
||||
1.0f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
if(ticksInUse % 12 == 0){
|
||||
if(ticksInUse == 0) WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_ICE, 0.5F, 1.0f);
|
||||
WizardryUtilities.playSoundAtPlayer(caster, WizardrySounds.SPELL_LOOP_ICE, 0.5F, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@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){
|
||||
float brightness = world.rand.nextFloat();
|
||||
ParticleBuilder.create(Type.SPARKLE).pos(x, y, z).vel(vx, vy, vz).lifetime(8 + world.rand.nextInt(12))
|
||||
.colour(0.4f + 0.6f * brightness, 0.6f + 0.4f*brightness, 1).spawn(world);
|
||||
ParticleBuilder.create(Type.SNOW).pos(x, y, z).vel(vx, vy, vz).lifetime(8 + world.rand.nextInt(12)).spawn(world);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user