Advertisement
HalestormXV

Untitled

Jul 17th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.67 KB | None | 0 0
  1. package halestormxv.eAngelus.mobs.entitys;
  2.  
  3. import net.minecraft.entity.Entity;
  4. import net.minecraft.entity.EntityLiving;
  5. import net.minecraft.entity.EntityLivingBase;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.entity.projectile.EntityThrowable;
  8. import net.minecraft.util.DamageSource;
  9. import net.minecraft.util.EnumParticleTypes;
  10.  
  11. import net.minecraft.util.math.MathHelper;
  12. import net.minecraft.util.math.RayTraceResult;
  13. import net.minecraft.world.World;
  14. import net.minecraftforge.fml.relauncher.Side;
  15. import net.minecraftforge.fml.relauncher.SideOnly;
  16.  
  17.  
  18. public class EntityCelestialBolt extends EntityThrowable {
  19.     private float explosionRadius = 1.3F;
  20.     private double orbPower;
  21.  
  22.     public EntityCelestialBolt(World world)
  23.     {
  24.         super(world);
  25.     }
  26.  
  27.     public EntityCelestialBolt(World world, EntityLivingBase entity) {
  28.         super(world, entity);
  29.         this.isInRangeToRenderDist(1.0);
  30.         if (entity instanceof EntityPlayer)
  31.         {
  32.             orbPower = (float)(((EntityPlayer) entity).experienceLevel) / 3;
  33.         }
  34.     }
  35.  
  36.     private void explode() {
  37.         int bx = (int) posX;
  38.         int by = (int) posY;
  39.         int bz = (int) posZ;
  40.         world.createExplosion(this, posX, posY, posZ, 0.75F, true);
  41.         setDead();
  42.     }
  43.  
  44.     @Override
  45.     public void onUpdate() {
  46.         super.onUpdate();
  47.         if (ticksExisted > 20) {
  48.             explode();
  49.         }
  50.  
  51.         for (int i = 0; i < 10; i++) {
  52.             double x = (double) (rand.nextInt(10) - 5) / 8.0D;
  53.             double y = (double) (rand.nextInt(10) - 5) / 8.0D;
  54.             double z = (double) (rand.nextInt(10) - 5) / 8.0D;
  55.             world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, posX, posY, posZ, x, y, z);
  56.         }
  57.     }
  58.  
  59.     @Override
  60.     protected float getGravityVelocity() {
  61.         return 0.01F;
  62.     }
  63.  
  64.     @Override
  65.     protected void onImpact(RayTraceResult result) {
  66.         {
  67.             if(result.entityHit instanceof EntityLiving && !this.world.isRemote)
  68.             {
  69.                 float f2;
  70.                 f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  71.                 int k = MathHelper.ceil((double)f2 * this.orbPower);
  72.                 result.entityHit.attackEntityFrom(DamageSource.GENERIC, (float)k);
  73.                 //System.out.println(k / 2 + " hearts of damage from Celestial Gunblade.");
  74.             }
  75.             else
  76.             {
  77.                 if(!this.world.isRemote)
  78.                 {
  79.                     this.world.createExplosion(this, this.posX, this.posY, this.posZ, (float)this.explosionRadius, true);
  80.                 }
  81.             }
  82.             this.setDead();
  83.         }
  84.     }
  85.  
  86.     public void setHeadingFromThrower(Entity entityThrower, float rotationPitchIn, float rotationYawIn, float pitchOffset, float velocity, float inaccuracy) {
  87.         float f = -MathHelper.sin(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F);
  88.         float f1 = -MathHelper.sin((rotationPitchIn + pitchOffset) * 0.017453292F);
  89.         float f2 = MathHelper.cos(rotationYawIn * 0.017453292F) * MathHelper.cos(rotationPitchIn * 0.017453292F);
  90.         this.setThrowableHeading((double) f, (double) f1, (double) f2, velocity, inaccuracy);
  91.         this.motionX += entityThrower.motionX;
  92.         this.motionZ += entityThrower.motionZ;
  93.  
  94.         if (!entityThrower.onGround) {
  95.             this.motionY += entityThrower.motionY;
  96.         }
  97.     }
  98.  
  99.     /**
  100.      * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
  101.      */
  102.     public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy) {
  103.         float f = MathHelper.sqrt(x * x + y * y + z * z);
  104.         x = x / (double) f;
  105.         y = y / (double) f;
  106.         z = z / (double) f;
  107.         x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
  108.         y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
  109.         z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double) inaccuracy;
  110.         x = x * (double) velocity;
  111.         y = y * (double) velocity;
  112.         z = z * (double) velocity;
  113.         this.motionX = x;
  114.         this.motionY = y;
  115.         this.motionZ = z;
  116.         float f1 = MathHelper.sqrt(x * x + z * z);
  117.         this.rotationYaw = (float) (MathHelper.atan2(x, z) * (180D / Math.PI));
  118.         this.rotationPitch = (float) (MathHelper.atan2(y, (double) f1) * (180D / Math.PI));
  119.         this.prevRotationYaw = this.rotationYaw;
  120.         this.prevRotationPitch = this.rotationPitch;
  121.         //this.ticksInGround = 0;
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement