Fix construct spells crashing the game when cast by dispensers, fixes #182
This commit is contained in:
@@ -18,11 +18,14 @@ public class ArrowRain extends SpellConstructRanged<EntityArrowRain> {
|
||||
|
||||
// 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<EntityArrowRain> {
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,10 @@ public class Decay extends SpellConstructRanged<EntityDecay> {
|
||||
|
||||
@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<EntityDecay> {
|
||||
int verticalRange = (int)(6 * modifiers.get(WizardryItems.blast_upgrade));
|
||||
|
||||
for(int i=0; i<quantity; i++){
|
||||
BlockPos pos = WizardryUtilities.findNearbyFloorSpace(caster, horizontalRange, verticalRange);
|
||||
BlockPos pos = WizardryUtilities.findNearbyFloorSpace(world, origin, horizontalRange, verticalRange);
|
||||
if(pos == null) break;
|
||||
super.spawnConstruct(world, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, side, caster, modifiers);
|
||||
}
|
||||
|
||||
@@ -40,20 +40,18 @@
|
||||
|
||||
if(world.isRemote){
|
||||
|
||||
world.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, caster.posX,
|
||||
caster.getEntityBoundingBox().minY + 0.1, caster.posZ, 0, 0, 0);
|
||||
world.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, x, y + 0.1, z, 0, 0, 0);
|
||||
|
||||
double particleX, particleZ;
|
||||
|
||||
for(int i=0; i<40; i++){
|
||||
|
||||
particleX = caster.posX - 1.0d + 2 * world.rand.nextDouble();
|
||||
particleZ = caster.posZ - 1.0d + 2 * world.rand.nextDouble();
|
||||
particleX = x - 1.0d + 2 * world.rand.nextDouble();
|
||||
particleZ = z - 1.0d + 2 * world.rand.nextDouble();
|
||||
|
||||
IBlockState block = WizardryUtilities.getBlockEntityIsStandingOn(caster);
|
||||
world.spawnParticle(EnumParticleTypes.BLOCK_DUST, particleX, caster.getEntityBoundingBox().minY,
|
||||
particleZ, particleX - caster.posX, 0, particleZ - caster.posZ,
|
||||
Block.getStateId(block));
|
||||
world.spawnParticle(EnumParticleTypes.BLOCK_DUST, particleX, y,
|
||||
particleZ, particleX - x, 0, particleZ - z, Block.getStateId(block));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class Hailstorm extends SpellConstructRanged<EntityHailstorm> {
|
||||
|
||||
public Hailstorm(){
|
||||
@@ -14,15 +16,18 @@ public class Hailstorm extends SpellConstructRanged<EntityHailstorm> {
|
||||
}
|
||||
|
||||
@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<EntityHailstorm> {
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class SpellConstruct<T extends EntityMagicConstruct> 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
|
||||
|
||||
@@ -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<EntityTornado> {
|
||||
|
||||
@@ -19,7 +23,8 @@ public class Tornado extends SpellConstruct<EntityTornado> {
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user