diff --git a/src/main/java/electroblob/wizardry/spell/ArrowRain.java b/src/main/java/electroblob/wizardry/spell/ArrowRain.java index 11f598ae..aeb1ef78 100644 --- a/src/main/java/electroblob/wizardry/spell/ArrowRain.java +++ b/src/main/java/electroblob/wizardry/spell/ArrowRain.java @@ -18,11 +18,14 @@ public class ArrowRain extends SpellConstructRanged { // Moves the entity back towards the caster a bit, so the area of effect is better centred on the position. // 3 is the distance to move the entity back towards the caster. - double dx = caster.posX - x; - double dz = caster.posZ - z; - double distRatio = 3 / Math.sqrt(dx * dx + dz * dz); - x += dx * distRatio; - z += dz * distRatio; + double dx = caster == null ? side.getDirectionVec().getX() : caster.posX - x; + double dz = caster == null ? side.getDirectionVec().getZ() : caster.posZ - z; + double dist = Math.sqrt(dx * dx + dz * dz); + if(dist != 0){ + double distRatio = 3 / dist; + x += dx * distRatio; + z += dz * distRatio; + } // Moves the entity up 5 blocks so that it is above mobs' heads. y += 5; @@ -32,7 +35,11 @@ public class ArrowRain extends SpellConstructRanged { @Override protected void addConstructExtras(EntityArrowRain construct, EnumFacing side, EntityLivingBase caster, SpellModifiers modifiers){ // Makes the arrows shoot in the direction the caster was looking when they cast the spell. - construct.rotationYaw = caster.rotationYawHead; + if(caster != null){ + construct.rotationYaw = caster.rotationYawHead; + }else{ + construct.rotationYaw = side.getHorizontalAngle(); + } } } diff --git a/src/main/java/electroblob/wizardry/spell/Decay.java b/src/main/java/electroblob/wizardry/spell/Decay.java index dc6e9f41..afca662c 100644 --- a/src/main/java/electroblob/wizardry/spell/Decay.java +++ b/src/main/java/electroblob/wizardry/spell/Decay.java @@ -23,8 +23,10 @@ public class Decay extends SpellConstructRanged { @Override protected boolean spawnConstruct(World world, double x, double y, double z, EnumFacing side, EntityLivingBase caster, SpellModifiers modifiers){ - - if(world.getBlockState(new BlockPos(x, y, z)).isNormalCube()) return false; + + BlockPos origin = new BlockPos(x, y, z); + + if(world.getBlockState(origin).isNormalCube()) return false; super.spawnConstruct(world, x, y, z, side, caster, modifiers); @@ -35,7 +37,7 @@ public class Decay extends SpellConstructRanged { int verticalRange = (int)(6 * modifiers.get(WizardryItems.blast_upgrade)); for(int i=0; i { public Hailstorm(){ @@ -14,15 +16,18 @@ public class Hailstorm extends SpellConstructRanged { } @Override - protected boolean spawnConstruct(World world, double x, double y, double z, EnumFacing side, EntityLivingBase caster, SpellModifiers modifiers){ + protected boolean spawnConstruct(World world, double x, double y, double z, EnumFacing side, @Nullable EntityLivingBase caster, SpellModifiers modifiers){ // Moves the entity back towards the caster a bit, so the area of effect is better centred on the position. // 3 is the distance to move the entity back towards the caster. - double dx = caster.posX - x; - double dz = caster.posZ - z; - double distRatio = 3 / Math.sqrt(dx * dx + dz * dz); - x += dx * distRatio; - z += dz * distRatio; + double dx = caster == null ? side.getDirectionVec().getX() : caster.posX - x; + double dz = caster == null ? side.getDirectionVec().getZ() : caster.posZ - z; + double dist = Math.sqrt(dx * dx + dz * dz); + if(dist != 0){ + double distRatio = 3 / dist; + x += dx * distRatio; + z += dz * distRatio; + } // Moves the entity up 5 blocks so that it is above mobs' heads. y += 5; @@ -32,7 +37,11 @@ public class Hailstorm extends SpellConstructRanged { @Override protected void addConstructExtras(EntityHailstorm construct, EnumFacing side, EntityLivingBase caster, SpellModifiers modifiers){ // Makes the arrows shoot in the direction the caster was looking when they cast the spell. - if(caster != null) construct.rotationYaw = caster.rotationYawHead; + if(caster != null){ + construct.rotationYaw = caster.rotationYawHead; + }else{ + construct.rotationYaw = side.getHorizontalAngle(); + } } } diff --git a/src/main/java/electroblob/wizardry/spell/SpellConstruct.java b/src/main/java/electroblob/wizardry/spell/SpellConstruct.java index 62483f62..4428aed8 100644 --- a/src/main/java/electroblob/wizardry/spell/SpellConstruct.java +++ b/src/main/java/electroblob/wizardry/spell/SpellConstruct.java @@ -149,7 +149,7 @@ public class SpellConstruct extends Spell { * @param modifiers The modifiers with which the spell was cast. * @return false to cause the spell to fail, true to continue with casting. */ - protected boolean spawnConstruct(World world, double x, double y, double z, @Nullable EnumFacing side, EntityLivingBase caster, SpellModifiers modifiers){ + protected boolean spawnConstruct(World world, double x, double y, double z, @Nullable EnumFacing side, @Nullable EntityLivingBase caster, SpellModifiers modifiers){ if(!world.isRemote){ // Creates a new construct using the supplied factory diff --git a/src/main/java/electroblob/wizardry/spell/Tornado.java b/src/main/java/electroblob/wizardry/spell/Tornado.java index f5045b05..3cd3d9ea 100644 --- a/src/main/java/electroblob/wizardry/spell/Tornado.java +++ b/src/main/java/electroblob/wizardry/spell/Tornado.java @@ -5,6 +5,10 @@ import electroblob.wizardry.util.SpellModifiers; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.EnumAction; import net.minecraft.util.EnumFacing; +import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + +import javax.annotation.Nullable; public class Tornado extends SpellConstruct { @@ -19,7 +23,8 @@ public class Tornado extends SpellConstruct { @Override protected void addConstructExtras(EntityTornado construct, EnumFacing side, EntityLivingBase caster, SpellModifiers modifiers){ float speed = getProperty(SPEED).floatValue(); - construct.setHorizontalVelocity(caster.getLookVec().x * speed, caster.getLookVec().z * speed); + Vec3d direction = caster == null ? new Vec3d(side.getDirectionVec()) : caster.getLookVec(); + construct.setHorizontalVelocity(direction.x * speed, direction.z * speed); } }