Advertisement
Guest User

EntityLaserBeam.java

a guest
Apr 26th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.33 KB | None | 0 0
  1. package com.robotsquid.moltencraft.entity;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.entity.Entity;
  5. import net.minecraft.entity.EntityLivingBase;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.entity.projectile.EntityArrow;
  8. import net.minecraft.util.*;
  9. import net.minecraft.world.World;
  10.  
  11. import java.util.List;
  12.  
  13. public class EntityTempLaserBeam extends EntityArrow
  14. {
  15.     public Entity shootingEntity;
  16.  
  17.     public EntityTempLaserBeam(World world, EntityLivingBase player, float p_i1756_3_)
  18.     {
  19.         super(world, player, p_i1756_3_);
  20.     }
  21.  
  22.     @Override
  23.     public void onUpdate()
  24.     {
  25.         int field_145791_d = -1;
  26.         int field_145792_e = -1;
  27.         int field_145789_f = -1;
  28.  
  29.         this.onEntityUpdate();
  30.  
  31.         if (this.prevRotationYaw == 0.0F)
  32.         {
  33.             float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
  34.             this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  35.         }
  36.  
  37.         Block block = this.worldObj.getBlock(field_145791_d, field_145792_e, field_145789_f);
  38.  
  39.         Vec3 vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
  40.         Vec3 vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  41.         MovingObjectPosition movingobjectposition = this.worldObj.func_147447_a(vec31, vec3, false, true, false);
  42.         vec31 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
  43.         vec3 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  44.  
  45.         if (movingobjectposition != null)
  46.         {
  47.             vec3 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  48.         }
  49.  
  50.         Entity entity = null;
  51.         List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(1.0D, 1.0D, 1.0D));
  52.         double d0 = 0.0D;
  53.         int i;
  54.         float f1;
  55.  
  56.         for (i = 0; i < list.size(); ++i)
  57.         {
  58.             Entity entity1 = (Entity)list.get(i);
  59.  
  60.             if (entity1.canBeCollidedWith() && (entity1 != this.shootingEntity))
  61.             {
  62.                 f1 = 0.3F;
  63.                 AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand((double)f1, (double)f1, (double)f1);
  64.                 MovingObjectPosition movingobjectposition1 = axisalignedbb1.calculateIntercept(vec31, vec3);
  65.  
  66.                 if (movingobjectposition1 != null)
  67.                 {
  68.                     double d1 = vec31.distanceTo(movingobjectposition1.hitVec);
  69.  
  70.                     if (d1 < d0 || d0 == 0.0D)
  71.                     {
  72.                         entity = entity1;
  73.                         d0 = d1;
  74.                     }
  75.                 }
  76.             }
  77.         }
  78.  
  79.         if (entity != null)
  80.         {
  81.             movingobjectposition = new MovingObjectPosition(entity);
  82.         }
  83.  
  84.         if (movingobjectposition != null && movingobjectposition.entityHit != null && movingobjectposition.entityHit instanceof EntityPlayer)
  85.         {
  86.             EntityPlayer entityplayer = (EntityPlayer)movingobjectposition.entityHit;
  87.  
  88.             if (entityplayer.capabilities.disableDamage || this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
  89.             {
  90.                 movingobjectposition = null;
  91.             }
  92.         }
  93.  
  94.         float f2;
  95.         float f4;
  96.  
  97.         //Hits something
  98.         if (movingobjectposition != null)
  99.         {
  100.             if (movingobjectposition.entityHit != null)
  101.             {
  102.                 DamageSource damagesource = null;
  103.  
  104.                 if (this.shootingEntity == null)
  105.                 {
  106.                     damagesource = DamageSource.causeArrowDamage(this, this);
  107.                 }
  108.                 else
  109.                 {
  110.                     damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity);
  111.                 }
  112.  
  113.                 movingobjectposition.entityHit.setFire(5);
  114.                 movingobjectposition.entityHit.attackEntityFrom(damagesource, 10.0F);
  115.  
  116.             }
  117.  
  118.             this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, 1.0F, true);
  119.             this.setDead();
  120.         }
  121.  
  122.         this.posX += this.motionX;
  123.         this.posY += this.motionY;
  124.         this.posZ += this.motionZ;
  125.         f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
  126.         this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  127.  
  128.         while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  129.         {
  130.             this.prevRotationYaw -= 360.0F;
  131.         }
  132.  
  133.         while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  134.         {
  135.             this.prevRotationYaw += 360.0F;
  136.         }
  137.  
  138.         this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  139.         float f3 = 0.99F;
  140.         f1 = 0.05F;
  141.  
  142.         this.motionX *= (double)f3;
  143.         this.motionY *= (double)f3;
  144.         this.motionZ *= (double)f3;
  145.         this.setPosition(this.posX, this.posY, this.posZ);
  146.         this.func_145775_I();
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement