Vinetos

[1.8] WASD Entity

Dec 31st, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1.  @Override
  2.         public void g(float sideMot, float forMot) {
  3.             if(this.passenger != null && this.passenger instanceof EntityHuman) {
  4.                 this.lastYaw = this.yaw = this.passenger.yaw;
  5.                 this.pitch = this.passenger.pitch * 0.5F;
  6.                 this.setYawPitch(this.yaw, this.pitch);//Update the pitch and yaw
  7.                 this.aI = this.aG = this.yaw;
  8.                 sideMot = ((EntityLiving)this.passenger).aX * 0.5F;
  9.                 forMot = ((EntityLiving)this.passenger).aY;
  10.                 if(forMot <= 0.0F) {
  11.                     forMot *= 0.25F;// Make backwards slower
  12.                 }
  13.      
  14.                 Field jump = null; //Jumping
  15.                 try {
  16.                     jump = EntityLiving.class.getDeclaredField("aW");
  17.                 } catch (NoSuchFieldException e1) {
  18.                     // TODO Auto-generated catch block
  19.                     e1.printStackTrace();
  20.                 } catch (SecurityException e1) {
  21.                     // TODO Auto-generated catch block
  22.                     e1.printStackTrace();
  23.                 }
  24.                 jump.setAccessible(true);
  25.      
  26.                 if (jump != null && this.onGround) {    // Wouldn't want it jumping while on the ground would we?
  27.                     try {
  28.                         if (jump.getBoolean(this.passenger)) {
  29.                             double jumpHeight = 0.5D;//Here you can set the jumpHeight
  30.                             this.motY = jumpHeight;    // Used all the time in NMS for entity jumping
  31.                         }
  32.                     } catch (IllegalAccessException e) {
  33.                         e.printStackTrace();
  34.                     }
  35.                 }
  36.      
  37.                 this.S = 1.0F;// The custom entity will now automatically climb up 1 high blocks
  38.                 this.aK = this.bH() * 0.1F;
  39.                 if(!this.world.isStatic) {
  40.                     this.j(0.35F);//Here is the speed the entity will walk.
  41.                     super.g(sideMot, forMot);
  42.                 }
  43.      
  44.      
  45.                 this.ay = this.az;//Some extra things
  46.                 double d0 = this.locX - this.lastX;
  47.                 double d1 = this.locZ - this.lastZ;
  48.                 float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
  49.                 if(f4 > 1.0F) {
  50.                     f4 = 1.0F;
  51.                 }
  52.      
  53.                 this.az += (f4 - this.az) * 0.4F;
  54.                 this.aA += this.az;
  55.             } else {
  56.                 this.S = 0.5F;
  57.                 this.aK = 0.02F;
  58.                 super.g(sideMot, forMot);
  59.             }
  60.      
  61.      
  62.         }
Advertisement
Add Comment
Please, Sign In to add comment