Advertisement
Guest User

Untitled

a guest
May 19th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. package de.prototype.util;
  2.  
  3. import de.prototype.Client;
  4. import net.minecraft.client.Minecraft;
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.init.Blocks;
  7. import net.minecraft.inventory.Container;
  8. import net.minecraft.potion.Potion;
  9. import net.minecraft.util.*;
  10.  
  11. public class PlayerUtil extends RotationUtil {
  12.  
  13. private Minecraft mc = Minecraft.getMinecraft();
  14.  
  15. /**
  16. * Introducing a method which returns the yaw of the player direction
  17. *
  18. * @return
  19. */
  20. public float getDirection() {
  21. float yaw = mc.thePlayer.rotationYaw;
  22. if (mc.thePlayer.moveForward < 0) yaw += 180;
  23. float forward = 1;
  24. if (mc.thePlayer.moveForward < 0)forward = -0.5F;
  25. else if (mc.thePlayer.moveForward > 0) forward = 0.5F;
  26. if (mc.thePlayer.moveStrafing > 0) yaw -= 90 * forward;
  27. if (mc.thePlayer.moveStrafing < 0) yaw += 90 * forward;
  28. //siehe EntityLivingBase jump()
  29. return yaw * 0.017453292F;
  30. }
  31.  
  32. public void setMoveSpeed(final double moveSpeed) {
  33. float forward = mc.thePlayer.movementInput.moveForward;
  34. float strafe = mc.thePlayer.movementInput.moveStrafe;
  35. float yaw = mc.thePlayer.rotationYaw;
  36. if (forward == 0 && strafe == 0) {
  37. mc.thePlayer.motionX = 0;
  38. mc.thePlayer.motionZ = 0;
  39. }
  40. int i = 45;
  41. if (forward != 0) {
  42. if (strafe > 0) yaw += forward > 0 ? -i : i;
  43. else if (strafe < 0) yaw += forward > 0 ? i : -i;
  44. strafe = 0;
  45. if (forward > 0) forward = 1;
  46. else if (forward < 0) forward = -1;
  47. }
  48. mc.thePlayer.motionX = forward * moveSpeed * Math.cos(Math.toRadians(yaw + 90)) + strafe * moveSpeed * Math.sin(Math.toRadians(yaw + 90));
  49. mc.thePlayer.motionZ = forward * moveSpeed * Math.sin(Math.toRadians(yaw + 90)) - strafe * moveSpeed * Math.cos(Math.toRadians(yaw + 90));
  50. }
  51.  
  52. /**
  53. * Introducing a method which returns the positions in front of the player where the distance from the player is blocks
  54. *
  55. * @param blocks
  56. * @return
  57. */
  58. public double[] getPortPositions(double blocks) {
  59. return new double[]{-(MathHelper.sin(getDirection()) * blocks), (MathHelper.cos(getDirection()) * blocks)};
  60. }
  61.  
  62. /**
  63. * Introducing a method which teleports the player to the position, where addedX, addedY, addedZ gets added to his position
  64. *
  65. * @param addedX
  66. * @param addedY
  67. * @param addedZ
  68. */
  69. public void teleportPlayer(double addedX, double addedY, double addedZ) {
  70. mc.thePlayer.setPositionAndUpdate(mc.thePlayer.posX + addedX, mc.thePlayer.posY + addedY, mc.thePlayer.posZ + addedZ);
  71. }
  72.  
  73. public void teleportPlayerSmooth(double addedX, double addedY, double addedZ) {
  74. mc.thePlayer.setPosition(mc.thePlayer.posX + addedX, mc.thePlayer.posY + addedY, mc.thePlayer.posZ + addedZ);
  75. }
  76.  
  77. /**
  78. * Introducing a method which sets the speed of the game
  79. *
  80. * @param timerSpeed
  81. */
  82. public void setTimerSpeed(float timerSpeed) {
  83. mc.timer.timerSpeed = timerSpeed;
  84. }
  85.  
  86. /**
  87. * Introducing a method which set's the speed(motion) of the player
  88. *
  89. * @param speed
  90. */
  91. public void setSpeed(final float speed) {
  92. mc.thePlayer.motionX *= speed;
  93. mc.thePlayer.motionZ *= speed;
  94. }
  95.  
  96. public void setStrafingSpeed(double speed) {
  97. mc.thePlayer.motionX = (-(Math.sin(getDirection()) * speed));
  98. mc.thePlayer.motionZ = (Math.cos(getDirection()) * speed);
  99. }
  100.  
  101. /**
  102. * Introducing a method which set's the speed(motion) of the player
  103. *
  104. * @param speedX
  105. * @param speedZ
  106. */
  107. public void setSpeed(final double speedX, final double speedZ) {
  108. mc.thePlayer.motionX *= speedX;
  109. mc.thePlayer.motionZ *= speedZ;
  110. }
  111.  
  112. /**
  113. * Introducing a method which returns if the player is moving
  114. *
  115. * @return
  116. */
  117. public boolean isMoving() {
  118. return mc.thePlayer.movementInput.moveForward != 0 || mc.thePlayer.movementInput.moveStrafe != 0;
  119. }
  120.  
  121. /**
  122. * Introducing a method which returns true if the inventory is full
  123. *
  124. * @return
  125. */
  126. public boolean isInventoryFull() {
  127. Container container = mc.thePlayer.inventoryContainer;
  128. for (int i = 0; i < container.getInventory().size(); i++)
  129. if (container.getSlot(i).getStack() == null) return true;
  130. return false;
  131. }
  132.  
  133. /**
  134. * Introducing a method which send a chat message for me(clientSide or for everyone)
  135. *
  136. * @param message
  137. * @param forEveryone
  138. */
  139. public void sendChatMessage(final String message, final boolean forEveryone) {
  140. if (forEveryone) this.mc.thePlayer.sendChatMessage(message);
  141. else
  142. this.mc.thePlayer.addChatMessage(new ChatComponentText("§f[§6" + Client.getINSTANCE().getCLIENT_NAME() + "§f] §7" + message));
  143. }
  144.  
  145. /**
  146. * Introducing a method which checks ob i can step true or false
  147. *
  148. * @param stepHeight
  149. * @return
  150. */
  151. public int isAllowedToStep(double stepHeight) {
  152. int toBlock = -1;
  153. final double[] positions = this.getPortPositions(0.4);
  154. for (int i = 0; i < stepHeight; i++) {
  155. final BlockPos pos = new BlockPos(mc.thePlayer.posX + positions[0], mc.thePlayer.posY + i, mc.thePlayer.posZ + positions[1]);
  156. if (mc.theWorld.getBlockState(pos) != null && mc.theWorld.getBlockState(pos).getBlock() != Blocks.air)
  157. if (mc.theWorld.getBlockState(pos.add(0, 1, 0)).getBlock() == Blocks.air && mc.theWorld.getBlockState(pos.add(0, 2, 0)).getBlock() == Blocks.air)
  158. toBlock = i;
  159. }
  160. return toBlock + 1;
  161. }
  162.  
  163. /**
  164. * Introducing a method which returns the default speed of the player
  165. *
  166. * @return
  167. */
  168.  
  169. public double getDefaultSpeed() {
  170. double defaultSpeed = 0.2873;
  171. if (mc.thePlayer.isPotionActive(Potion.moveSpeed)) {
  172. int speed = mc.thePlayer.getActivePotionEffect(Potion.moveSpeed).getAmplifier();
  173. defaultSpeed *= 1 + 0.2 * (speed + 1);
  174. }
  175. return defaultSpeed;
  176. }
  177.  
  178. /**
  179. * Introducing a method which can see if the entity is in the same team
  180. *
  181. * @param entityPlayer
  182. * @return
  183. */
  184.  
  185. public boolean isEnemy(EntityPlayer entityPlayer) {
  186. return (mc.thePlayer.getTeam().equals(entityPlayer.getTeam())
  187. || (mc.thePlayer.getDisplayName().getFormattedText().startsWith("§")
  188. && entityPlayer.getDisplayName().getFormattedText().startsWith("§")
  189. && mc.thePlayer.getDisplayName().getFormattedText().substring(0, 2).equals(entityPlayer.getDisplayName().getFormattedText().substring(0, 2))));
  190. }
  191.  
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement