Guest User

Untitled

a guest
Mar 19th, 2014
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.58 KB | None | 0 0
  1. package hoopawolf.MTM.projectiles;
  2.  
  3. import hoopawolf.MTM.registry.TalismansItems;
  4. import net.minecraft.entity.Entity;
  5. import net.minecraft.entity.item.EntityItem;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.nbt.NBTTagCompound;
  8. import net.minecraft.util.MathHelper;
  9. import net.minecraft.world.World;
  10. import cpw.mods.fml.relauncher.Side;
  11. import cpw.mods.fml.relauncher.SideOnly;
  12.  
  13. public class EntitySeeker extends Entity
  14. {
  15.     /** 'x' location the eye should float towards. */
  16.     private double targetX;
  17.  
  18.     /** 'y' location the eye should float towards. */
  19.     private double targetY;
  20.  
  21.     /** 'z' location the eye should float towards. */
  22.     private double targetZ;
  23.     private int despawnTimer;
  24.     private boolean shatterOrDrop;
  25.  
  26.     public EntitySeeker(World par1World)
  27.     {
  28.         super(par1World);
  29.         this.setSize(0.25F, 0.25F);
  30.     }
  31.  
  32.     protected void entityInit() {}
  33.  
  34.     @SideOnly(Side.CLIENT)
  35.  
  36.     /**
  37.      * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
  38.      * length * 64 * renderDistanceWeight Args: distance
  39.      */
  40.     public boolean isInRangeToRenderDist(double par1)
  41.     {
  42.         double d1 = this.boundingBox.getAverageEdgeLength() * 4.0D;
  43.         d1 *= 64.0D;
  44.         return par1 < d1 * d1;
  45.     }
  46.  
  47.     public EntitySeeker(World par1World, double par2, double par4, double par6)
  48.     {
  49.         super(par1World);
  50.         this.despawnTimer = 0;
  51.         this.setSize(0.25F, 0.25F);
  52.         this.setPosition(par2, par4, par6);
  53.         this.yOffset = 0.0F;
  54.     }
  55.  
  56.     /**
  57.      * The location the eye should float/move towards. Currently used for moving towards the nearest stronghold. Args:
  58.      * strongholdX, strongholdY, strongholdZ
  59.      */
  60.     public void moveTowards(double par1, int par3, double par4)
  61.     {
  62.         double d2 = par1 - this.posX;
  63.         double d3 = par4 - this.posZ;
  64.         float f = MathHelper.sqrt_double(d2 * d2 + d3 * d3);
  65.  
  66.         if (f > 12.0F)
  67.         {
  68.             this.targetX = this.posX + d2 / (double)f * 12.0D;
  69.             this.targetZ = this.posZ + d3 / (double)f * 12.0D;
  70.             this.targetY = this.posY + 8.0D;
  71.         }
  72.         else
  73.         {
  74.             this.targetX = par1;
  75.             this.targetY = (double)par3;
  76.             this.targetZ = par4;
  77.         }
  78.  
  79.         this.despawnTimer = 0;
  80.         this.shatterOrDrop = this.rand.nextInt(5) > 0;
  81.     }
  82.  
  83.     @SideOnly(Side.CLIENT)
  84.  
  85.     /**
  86.      * Sets the velocity to the args. Args: x, y, z
  87.      */
  88.     public void setVelocity(double par1, double par3, double par5)
  89.     {
  90.         this.motionX = par1;
  91.         this.motionY = par3;
  92.         this.motionZ = par5;
  93.  
  94.         if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  95.         {
  96.             float f = MathHelper.sqrt_double(par1 * par1 + par5 * par5);
  97.             this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(par1, par5) * 180.0D / Math.PI);
  98.             this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(par3, (double)f) * 180.0D / Math.PI);
  99.         }
  100.     }
  101.  
  102.     /**
  103.      * Called to update the entity's position/logic.
  104.      */
  105.     public void onUpdate()
  106.     {
  107.         this.lastTickPosX = this.posX;
  108.         this.lastTickPosY = this.posY;
  109.         this.lastTickPosZ = this.posZ;
  110.         super.onUpdate();
  111.         this.posX += this.motionX;
  112.         this.posY += this.motionY;
  113.         this.posZ += this.motionZ;
  114.         float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
  115.         this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  116.  
  117.         for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
  118.         {
  119.             ;
  120.         }
  121.  
  122.         while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
  123.         {
  124.             this.prevRotationPitch += 360.0F;
  125.         }
  126.  
  127.         while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  128.         {
  129.             this.prevRotationYaw -= 360.0F;
  130.         }
  131.  
  132.         while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  133.         {
  134.             this.prevRotationYaw += 360.0F;
  135.         }
  136.  
  137.         this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  138.         this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  139.  
  140.         if (!this.worldObj.isRemote)
  141.         {
  142.             double d0 = this.targetX - this.posX;
  143.             double d1 = this.targetZ - this.posZ;
  144.             float f1 = (float)Math.sqrt(d0 * d0 + d1 * d1);
  145.             float f2 = (float)Math.atan2(d1, d0);
  146.             double d2 = (double)f + (double)(f1 - f) * 0.0025D;
  147.  
  148.             if (f1 < 1.0F)
  149.             {
  150.                 d2 *= 0.8D;
  151.                 this.motionY *= 0.8D;
  152.             }
  153.  
  154.             this.motionX = Math.cos((double)f2) * d2;
  155.             this.motionZ = Math.sin((double)f2) * d2;
  156.  
  157.             if (this.posY < this.targetY)
  158.             {
  159.                 this.motionY += (1.0D - this.motionY) * 0.014999999664723873D;
  160.             }
  161.             else
  162.             {
  163.                 this.motionY += (-1.0D - this.motionY) * 0.014999999664723873D;
  164.             }
  165.         }
  166.  
  167.         float f3 = 0.25F;
  168.  
  169.         if (this.isInWater())
  170.         {
  171.             for (int i = 0; i < 4; ++i)
  172.             {
  173.                 this.worldObj.spawnParticle("lava", this.posX - this.motionX * (double)f3, this.posY - this.motionY * (double)f3, this.posZ - this.motionZ * (double)f3, this.motionX, this.motionY, this.motionZ);
  174.             }
  175.         }
  176.         else
  177.         {
  178.             this.worldObj.spawnParticle("fire", this.posX - this.motionX * (double)f3 + this.rand.nextDouble() * 0.6D - 0.3D, this.posY - this.motionY * (double)f3 - 0.5D, this.posZ - this.motionZ * (double)f3 + this.rand.nextDouble() * 0.6D - 0.3D, this.motionX, this.motionY, this.motionZ);
  179.         }
  180.  
  181.         if (!this.worldObj.isRemote)
  182.         {
  183.             this.setPosition(this.posX, this.posY, this.posZ);
  184.             ++this.despawnTimer;
  185.  
  186.             if (this.despawnTimer > 80 && !this.worldObj.isRemote)
  187.             {
  188.                 this.setDead();
  189.  
  190.                 if (this.shatterOrDrop)
  191.                 {
  192.                     this.worldObj.spawnEntityInWorld(new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(TalismansItems.seeker)));
  193.                 }
  194.                 else
  195.                 {
  196.                     this.worldObj.playAuxSFX(2003, (int)Math.round(this.posX), (int)Math.round(this.posY), (int)Math.round(this.posZ), 0);
  197.                 }
  198.             }
  199.         }
  200.     }
  201.  
  202.     /**
  203.      * (abstract) Protected helper method to write subclass entity data to NBT.
  204.      */
  205.     public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {}
  206.  
  207.     /**
  208.      * (abstract) Protected helper method to read subclass entity data from NBT.
  209.      */
  210.     public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
  211.  
  212.     @SideOnly(Side.CLIENT)
  213.     public float getShadowSize()
  214.     {
  215.         return 0.0F;
  216.     }
  217.  
  218.     /**
  219.      * Gets how bright this entity is.
  220.      */
  221.     public float getBrightness(float par1)
  222.     {
  223.         return 1.0F;
  224.     }
  225.  
  226.     @SideOnly(Side.CLIENT)
  227.     public int getBrightnessForRender(float par1)
  228.     {
  229.         return 15728880;
  230.     }
  231.  
  232.     /**
  233.      * If returns false, the item will not inflict any damage against entities.
  234.      */
  235.     public boolean canAttackWithItem()
  236.     {
  237.         return false;
  238.     }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment