Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. @EventTarget
  2. public void onMove(EventMove event)
  3. {
  4. if (!mc.thePlayer.onGround) {
  5. this.timer.reset();
  6. }
  7. if (roundToPlace(mc.thePlayer.posY - (int)mc.thePlayer.posY, 3) == roundToPlace(0.481D, 3))
  8. {
  9. mc.thePlayer.motionY -= 0.075D;
  10. event.setMotionY(-0.075D);
  11. }
  12. else if (roundToPlace(mc.thePlayer.posY - (int)mc.thePlayer.posY, 3) == roundToPlace(0.406D, 3))
  13. {
  14. mc.thePlayer.motionY = -0.1D;
  15. event.setMotionY(-0.1D);
  16. }
  17. else if (roundToPlace(mc.thePlayer.posY - (int)mc.thePlayer.posY, 3) == roundToPlace(0.306D, 3))
  18. {
  19. mc.thePlayer.motionY = -9.E-006D;
  20. event.setMotionY(-9.E-006D);
  21. }
  22. else if (roundToPlace(mc.thePlayer.posY - (int)mc.thePlayer.posY, 3) == roundToPlace(0.305D, 3))
  23. {
  24. this.stage = 0;
  25. }
  26. if ((this.stage == 1) && ((mc.thePlayer.moveForward != 0.0F) || (mc.thePlayer.moveStrafing != 0.0F)))
  27. {
  28. this.stage = 2;
  29. this.moveSpeed = (!mc.thePlayer.isPotionActive(1) ? 4.48D * getBaseMoveSpeed() - 0.01D : 3.5D * getBaseMoveSpeed() - 0.01D);
  30. }
  31. else if (this.stage == 2)
  32. {
  33. this.stage = 3;
  34. mc.thePlayer.motionY = 0.42D;
  35. event.setMotionY(0.42D);
  36. this.moveSpeed *= 1.987D;
  37. }
  38. else if (this.stage == 3)
  39. {
  40. this.stage = 4;
  41. double difference = 0.67D * (this.lastDist - getBaseMoveSpeed());
  42. this.moveSpeed = (this.lastDist - difference);
  43. }
  44. else
  45. {
  46. if ((mc.theWorld.getCollidingBoundingBoxes(mc.thePlayer, mc.thePlayer.boundingBox.offset(0.0D, mc.thePlayer.motionY, 0.0D)).size() > 0) || (mc.thePlayer.isCollidedVertically)) {
  47. if (this.timer.delay(275.0F)) {
  48. this.stage = 1;
  49. } else {
  50. this.stage = 0;
  51. }
  52. }
  53. this.moveSpeed = (this.lastDist - this.lastDist / 159.0D);
  54. }
  55. if ((this.stage == 0) &&
  56. (mc.thePlayer.isSprinting())) {
  57. mc.thePlayer.setSprinting(false);
  58. }
  59. setMoveSpeed(event, this.stage != 0 ? (this.moveSpeed = Math.max(this.moveSpeed, getBaseMoveSpeed())) : 0.15D);
  60. }
  61.  
  62. public double getBaseMoveSpeed()
  63. {
  64. double baseSpeed = 0.287D;
  65. if (mc.thePlayer.isPotionActive(Potion.moveSpeed))
  66. {
  67. int amplifier = mc.thePlayer.getActivePotionEffect(Potion.moveSpeed).getAmplifier();
  68. baseSpeed *= (1.0D + 0.2D * (amplifier + 1));
  69. }
  70. return baseSpeed;
  71. }
  72.  
  73. @EventTarget
  74. public void onUpdate(EventPreTick event)
  75. {
  76. double xDist = mc.thePlayer.posX - mc.thePlayer.prevPosX;
  77. double zDist = mc.thePlayer.posZ - mc.thePlayer.prevPosZ;
  78. this.lastDist = Math.sqrt(xDist * xDist + zDist * zDist);
  79. }
  80.  
  81. public static double roundToPlace(double value, int places)
  82. {
  83. if (places < 0) {
  84. throw new IllegalArgumentException();
  85. }
  86. BigDecimal bd = new BigDecimal(value);
  87. bd = bd.setScale(places, RoundingMode.HALF_UP);
  88. return bd.doubleValue();
  89. }
  90.  
  91. public void setMoveSpeed(EventMove event, double speed)
  92. {
  93. double forward = mc.thePlayer.movementInput.moveForward;
  94. double strafe = mc.thePlayer.movementInput.moveStrafe;
  95. float yaw = mc.thePlayer.rotationYaw;
  96. if ((forward == 0.0D) && (strafe == 0.0D))
  97. {
  98. event.setMotionX(0.0D);
  99. event.setMotionZ(0.0D);
  100. }
  101. else
  102. {
  103. if (forward != 0.0D)
  104. {
  105. if (strafe > 0.0D) {
  106. yaw += (forward > 0.0D ? -50 : 50);
  107. } else if (strafe < 0.0D) {
  108. yaw += (forward > 0.0D ? 50 : -50);
  109. }
  110. strafe = 0.0D;
  111. if (forward > 0.0D) {
  112. forward = 1.0D;
  113. } else if (forward < 0.0D) {
  114. forward = -1.0D;
  115. }
  116. }
  117. event.setMotionX(forward * speed * Math.cos(Math.toRadians(yaw + 90.0F)) + strafe * speed * Math.sin(Math.toRadians(yaw + 90.0F)));
  118. event.setMotionZ(forward * speed * Math.sin(Math.toRadians(yaw + 90.0F)) - strafe * speed * Math.cos(Math.toRadians(yaw + 90.0F)));
  119. }
  120. }
  121.  
  122. public class Timer
  123. {
  124. private long prevMS;
  125.  
  126. public Timer()
  127. {
  128. this.prevMS = 0L;
  129. }
  130.  
  131. public boolean delay(float milliSec)
  132. {
  133. return (float)(getTime() - this.prevMS) >= milliSec;
  134. }
  135.  
  136. public void reset()
  137. {
  138. this.prevMS = getTime();
  139. }
  140.  
  141. public long getTime()
  142. {
  143. return System.nanoTime() / 1000000L;
  144. }
  145.  
  146. public long getDifference()
  147. {
  148. return getTime() - this.prevMS;
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement