Advertisement
Ak8D

Attack.java

May 25th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.75 KB | None | 0 0
  1. package org.alureon.overdrive.aura;
  2.  
  3. import java.util.concurrent.ExecutorService;
  4. import java.util.concurrent.Executors;
  5.  
  6. import org.alureon.overdrive.Overdrive;
  7.  
  8. import net.minecraft.src.Entity;
  9. import net.minecraft.src.EntityLiving;
  10. import net.minecraft.src.MathHelper;
  11. import net.minecraft.src.Packet12PlayerLook;
  12.  
  13. /**
  14.  * Allows us to attack an entity.
  15.  * @author Alureon
  16.  */
  17. public class Attack implements Runnable {
  18.  
  19.     private boolean look;
  20.     private boolean silent;
  21.     private Entity entity;
  22.  
  23.     /**
  24.      * @param e
  25.      *    The entity to attack.
  26.      * @param look
  27.      *    Shall we look at the entity?
  28.      * @param silent
  29.      *    Shall we face the entity server-sided?
  30.      */
  31.     public Attack(Entity e, boolean look, boolean silent) {
  32.         this.entity = e;
  33.         this.look = look;
  34.         this.silent = silent;
  35.         ExecutorService es1 = Executors.newSingleThreadExecutor();
  36.         es1.submit(this);
  37.     }
  38.  
  39.     /**
  40.      * Changes pitch and yaw so that the entity calling the function is facing the entity provided as an argument. Taken from EntityLiving.java.
  41.      * @param par1Entity
  42.      *    The entity to face
  43.      */
  44.     public void faceEntity(Entity par1Entity, float par2, float par3)
  45.     {
  46.         double var4 = par1Entity.posX - Overdrive.getWrapper().getPlayer().posX;
  47.         double var6 = par1Entity.posZ - Overdrive.getWrapper().getPlayer().posZ;
  48.         double var8;
  49.  
  50.         if (par1Entity instanceof EntityLiving)
  51.         {
  52.             EntityLiving var10 = (EntityLiving)par1Entity;
  53.             var8 = var10.posY + (double)var10.getEyeHeight() - (Overdrive.getWrapper().getPlayer().posY + (double)Overdrive.getWrapper().getPlayer().getEyeHeight());
  54.         }
  55.         else
  56.         {
  57.             var8 = (par1Entity.boundingBox.minY + par1Entity.boundingBox.maxY) / 2.0D - (Overdrive.getWrapper().getPlayer().posY + (double)Overdrive.getWrapper().getPlayer().getEyeHeight());
  58.         }
  59.  
  60.         double var14 = (double)MathHelper.sqrt_double(var4 * var4 + var6 * var6);
  61.         float var12 = (float)(Math.atan2(var6, var4) * 180.0D / Math.PI) - 90.0F;
  62.         float var13 = (float)(-(Math.atan2(var8, var14) * 180.0D / Math.PI));
  63.         if(!silent) {
  64.             Overdrive.getWrapper().getPlayer().rotationPitch = Overdrive.getWrapper().getPlayer().updateRotation(Overdrive.getWrapper().getPlayer().rotationPitch, var13, par3);
  65.             Overdrive.getWrapper().getPlayer().rotationYaw = Overdrive.getWrapper().getPlayer().updateRotation(Overdrive.getWrapper().getPlayer().rotationYaw, var12, par2);
  66.         } else {
  67.             Overdrive.getWrapper().getSendQueue().addToSendQueue(new Packet12PlayerLook(var12, var13, Overdrive.getWrapper().getPlayer().onGround));
  68.         }
  69.     }
  70.  
  71.  
  72.     @Override
  73.     public void run() {
  74.         if(look) {
  75.             faceEntity(entity, 100F, 100F);
  76.         }
  77.         Overdrive.getWrapper().getPlayer().swingItem();
  78.         Overdrive.getWrapper().getPlayerController().attackEntity(Overdrive.getWrapper().getPlayer(), entity);
  79.     }
  80.  
  81.  
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement