Advertisement
gegy1000

Motion Manager

Jan 16th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.46 KB | None | 0 0
  1. package fiskfille.tf.misc;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import java.util.Random;
  6.  
  7. import net.minecraft.client.Minecraft;
  8. import net.minecraft.client.renderer.EntityRenderer;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.init.Blocks;
  11. import net.minecraft.util.MathHelper;
  12. import net.minecraft.util.Vec3;
  13. import fiskfille.tf.TFHelper;
  14. import fiskfille.tf.config.TFConfig;
  15. import fiskfille.tf.data.TFDataManager;
  16. import fiskfille.tf.proxy.ClientProxy;
  17.  
  18. public class TFMotionManager
  19. {
  20. public static Map<EntityPlayer, TransformedPlayer> transformedPlayerMap = new HashMap<EntityPlayer, TransformedPlayer>();
  21.  
  22. private static float prevYaw;
  23.  
  24. public static void motionJet(EntityPlayer player)
  25. {
  26. Minecraft minecraft = Minecraft.getMinecraft();
  27. boolean moveForward = minecraft.gameSettings.keyBindForward.getIsKeyPressed();
  28. boolean nitroPressed = ClientProxy.keyBindingNitro.getIsKeyPressed() || minecraft.gameSettings.keyBindSprint.getIsKeyPressed();
  29. TransformedPlayer transformedPlayer = transformedPlayerMap.get(player);
  30. int nitro = 0;
  31. double vel = 0;
  32.  
  33. if(transformedPlayer != null)
  34. {
  35. nitro = transformedPlayer.getNitro();
  36. vel = transformedPlayer.getVelocity();
  37.  
  38. double increment = ((nitroPressed && nitro > 0 ? 6.84D : 1.36D) - vel) / 10 + 0.001D;
  39.  
  40. if (moveForward && vel <= 1.41D)
  41. {
  42. vel += increment;
  43. }
  44. if (vel > 0.14D && !moveForward)
  45. {
  46. vel -= 0.14D;
  47. }
  48. if (vel <= 0.14D)
  49. {
  50. vel = 0.14D;
  51. }
  52.  
  53. if ((player.worldObj.getBlock((int)player.posX, (int)player.posY - 1, (int)player.posZ) != Blocks.air || player.worldObj.getBlock((int)player.posX, (int)player.posY - 2, (int)player.posZ) != Blocks.air || player.worldObj.getBlock((int)player.posX, (int)player.posY - 3, (int)player.posZ) != Blocks.air))
  54. {
  55. player.setPosition(player.posX, player.posY + 0.8, player.posZ);
  56. }
  57.  
  58. Vec3 vec3 = getFrontCoords(player, vel);
  59. player.motionX = (vec3.xCoord - player.posX);
  60. player.motionY = (vec3.yCoord - player.posY);
  61. player.motionZ = (vec3.zCoord - player.posZ);
  62. if (vel <= 0.09F) {vel = 0.09F;}
  63. if (vel > 1.41F) {vel = 1.41F;}
  64.  
  65. if(player == Minecraft.getMinecraft().thePlayer)
  66. {
  67. if (nitro > 0 && nitroPressed && moveForward)
  68. {
  69. --nitro;
  70.  
  71. for (int i = 0; i < 4; ++i)
  72. {
  73. Vec3 side = getBackSideCoords(player, 0.15F, i < 2, -2.5);
  74. Random rand = new Random();
  75. player.worldObj.spawnParticle("flame", side.xCoord, side.yCoord - 0.1F, side.zCoord, rand.nextFloat() / 20, -0.2F + rand.nextFloat() / 20, rand.nextFloat() / 20);
  76. }
  77. }
  78.  
  79.  
  80. try
  81. {
  82. if(TFConfig.rollWithJet && TFHelper.isPlayerJet(player))
  83. {
  84. EntityRenderer entityRenderer = Minecraft.getMinecraft().entityRenderer;
  85.  
  86. float yaw = ((ClientProxy.modelBipedMain.bipedHead.rotateAngleY - ClientProxy.modelBipedMain.bipedBody.rotateAngleY) / 100) * 10000;
  87. float beforeMod = yaw;
  88.  
  89. if(yaw - prevYaw > 100)
  90. {
  91. yaw = prevYaw + 100;
  92. }
  93. else if (yaw - prevYaw < -100)
  94. {
  95. yaw = prevYaw - 100;
  96. }
  97.  
  98. prevYaw = beforeMod;
  99. ClientProxy.camRollField.set(entityRenderer, yaw);
  100. }
  101. }
  102. catch (IllegalArgumentException e)
  103. {
  104. e.printStackTrace();
  105. }
  106. catch (IllegalAccessException e)
  107. {
  108. e.printStackTrace();
  109. }
  110. }
  111.  
  112. transformedPlayer.setNitro(nitro);
  113. transformedPlayer.setVelocity(vel);
  114. }
  115. }
  116.  
  117. public static void motionTank(EntityPlayer player)
  118. {
  119. Minecraft minecraft = Minecraft.getMinecraft();
  120. boolean moveForward = minecraft.gameSettings.keyBindForward.getIsKeyPressed();
  121. boolean nitroPressed = ClientProxy.keyBindingNitro.getIsKeyPressed() || minecraft.gameSettings.keyBindSprint.getIsKeyPressed();
  122.  
  123. player.stepHeight = 1.0F;
  124. TransformedPlayer transformedPlayer = transformedPlayerMap.get(player);
  125.  
  126. int nitro = 0;
  127. double vel = 0;
  128.  
  129. if(transformedPlayer != null)
  130. {
  131. nitro = transformedPlayer.getNitro();
  132. vel = transformedPlayer.getVelocity();
  133. double increment = ((nitroPressed && nitro > 0 ? 0.15D : 0.035D) - vel) / 10 + 0.001D;
  134.  
  135. if (moveForward && vel <= 1.0D)
  136. {
  137. vel += increment * 0.5F;
  138. }
  139. if (vel > 0.02D && !moveForward)
  140. {
  141. vel -= 0.02D;
  142. }
  143. if (vel < 0.01D && !moveForward)
  144. {
  145. vel = 0.0D;
  146. }
  147.  
  148. Vec3 vec3 = getFrontCoords(player, 0, vel);
  149. player.motionX = (vec3.xCoord - player.posX);
  150. player.motionZ = (vec3.zCoord - player.posZ);
  151. if (vel <= 0) {vel = 0;}
  152. if (vel > 0.2D) {vel = 0.2D;}
  153. if (vel < 0.02D && !moveForward) {vel = 0;}
  154.  
  155. if (nitro > 0 && nitroPressed && moveForward && player == Minecraft.getMinecraft().thePlayer)
  156. {
  157. --nitro;
  158.  
  159. for (int i = 0; i < 4; ++i)
  160. {
  161. Vec3 side = getBackSideCoords(player, 0.15F, i < 2, -1.5);
  162. Random rand = new Random();
  163. player.worldObj.spawnParticle("smoke", side.xCoord, player.posY - 1.6F, side.zCoord, rand.nextFloat() / 20, rand.nextFloat() / 20, rand.nextFloat() / 20);
  164. }
  165. }
  166.  
  167. transformedPlayer.setNitro(nitro);
  168. transformedPlayer.setVelocity(vel);
  169.  
  170. if (player.isInWater())
  171. {
  172. player.motionY = -0.1F;
  173. }
  174. }
  175. }
  176.  
  177. public static void motionCar(EntityPlayer player)
  178. {
  179. Minecraft mc = Minecraft.getMinecraft();
  180. boolean moveForward = mc.gameSettings.keyBindForward.getIsKeyPressed();
  181. boolean nitroPressed = ClientProxy.keyBindingNitro.getIsKeyPressed() || mc.gameSettings.keyBindSprint.getIsKeyPressed();
  182. boolean driftPressed = ClientProxy.keyBindingBrake.getIsKeyPressed();
  183. int nitro = 0;
  184. double vel = 0;
  185.  
  186. player.stepHeight = 1.0F;
  187.  
  188. TransformedPlayer transformedPlayer = transformedPlayerMap.get(player);
  189.  
  190. if(transformedPlayer != null)
  191. {
  192. nitro = transformedPlayer.getNitro();
  193. vel = transformedPlayer.getVelocity();
  194. double increment;
  195.  
  196. boolean inStealthMode = TFDataManager.isInStealthMode(player);
  197.  
  198. if(inStealthMode)
  199. {
  200. increment = (0.328D - vel) / 10 + 0.001D;
  201. }
  202. else
  203. {
  204. increment = ((nitroPressed && nitro > 0 ? 5.5D : 0.74D) - vel) / 10 + 0.001D;
  205. }
  206.  
  207. if (moveForward && vel <= 1.0D)
  208. {
  209. vel += increment * 0.5F;
  210. }
  211. else if(vel > 0.02D)
  212. {
  213. vel-= 0.02D;
  214. }
  215. else if(vel <= 0.02D)
  216. {
  217. vel = 0;
  218. }
  219.  
  220. if (driftPressed && vel > 0 && player.onGround)
  221. {
  222. float f = ClientProxy.modelBipedMain.bipedHead.rotateAngleY - (ClientProxy.modelBipedMain.bipedBody.rotateAngleY - ClientProxy.modelBipedMain.bipedHead.rotateAngleY) / 3;
  223. vel -= 0.03D;
  224.  
  225. Vec3 vec3 = getSideCoords(player, vel, -(int)(f * 45)/*f > -0.25D && f < 0.25D ? 0 : (f > 0 ? -45 : 30)*/);
  226. player.motionX = (vec3.xCoord - player.posX);
  227. player.motionZ = (vec3.zCoord - player.posZ);
  228.  
  229. if (vel > 0.1D)
  230. {
  231. for (int i = 0; i < 10; ++i)
  232. {
  233. Vec3 side = getBackSideCoords(player, 0.15F, i < 2, -1.5);
  234. player.worldObj.spawnParticle("reddust", side.xCoord, player.posY - 1.5F, side.zCoord, -1, 0, 0);
  235. }
  236. }
  237.  
  238. float decrement = (float) (1.0F - (increment * 0.5F));
  239.  
  240. if (f > 1.0F && vel > 0.0F)
  241. {
  242. player.rotationYaw += decrement;
  243. }
  244. if (f < -1.0F && vel > 0.0F)
  245. {
  246. player.rotationYaw -= decrement;
  247. }
  248. }
  249. else
  250. {
  251. Vec3 vec3 = getFrontCoords(player, 0, vel);
  252. player.motionX = (vec3.xCoord - player.posX);
  253. player.motionZ = (vec3.zCoord - player.posZ);
  254. }
  255.  
  256. if (vel <= 0) {vel = 0;}
  257. if (vel > 1) {vel = 1;}
  258.  
  259. if (nitro > 0 && nitroPressed && moveForward && player == mc.thePlayer && !inStealthMode)
  260. {
  261. --nitro;
  262.  
  263. for (int i = 0; i < 4; ++i)
  264. {
  265. Vec3 side = getBackSideCoords(player, 0.15F, i < 2, -1.5);
  266. Random rand = new Random();
  267. player.worldObj.spawnParticle("smoke", side.xCoord, player.posY - 1.6F, side.zCoord, rand.nextFloat() / 20, rand.nextFloat() / 20, rand.nextFloat() / 20);
  268. }
  269.  
  270. for (int i = 0; i < 10; ++i)
  271. {
  272. Vec3 side = getBackSideCoords(player, 0.15F, i < 2, -1.5);
  273. Random rand = new Random();
  274. player.worldObj.spawnParticle("smoke", side.xCoord, player.posY - 1.6F, side.zCoord, rand.nextFloat() / 10, rand.nextFloat() / 10 + 0.05F, rand.nextFloat() / 10);
  275. }
  276. }
  277.  
  278. transformedPlayer.setNitro(nitro);
  279. transformedPlayer.setVelocity(vel);
  280.  
  281. if (player.isInWater())
  282. {
  283. player.motionY = -0.1F;
  284. }
  285. }
  286. }
  287.  
  288. public static Vec3 getBackSideCoords(EntityPlayer player, double amount, boolean side, double backAmount)
  289. {
  290. Vec3 front = getFrontCoords(player, backAmount).addVector(-player.posX, -player.posY, -player.posZ);
  291. return getSideCoords(player, amount, side).addVector(front.xCoord, front.yCoord, front.zCoord);
  292. }
  293.  
  294. public static Vec3 getSideCoords(EntityPlayer player, double amount, int side)
  295. {
  296. float f = 1.0F;
  297. float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
  298. float f2 = (player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) + side);
  299. double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double)f;
  300. double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double)f + (double)(player.worldObj.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight());
  301. double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double)f;
  302. Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
  303. float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
  304. float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
  305. float f5 = -MathHelper.cos(-f1 * 0.017453292F);
  306. float f6 = MathHelper.sin(-f1 * 0.017453292F);
  307. float f7 = f4 * f5;
  308. float f8 = f3 * f5;
  309. Vec3 vec31 = vec3.addVector(f7 * amount, f6 * amount, f8 * amount);
  310. return vec31;
  311. }
  312.  
  313. public static Vec3 getSideCoords(EntityPlayer player, double amount, boolean side)
  314. {
  315. float f = 1.0F;
  316. float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
  317. float f2 = (player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) + (side ? -90 : 90));
  318. double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double)f;
  319. double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double)f + (double)(player.worldObj.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight());
  320. double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double)f;
  321. Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
  322. float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
  323. float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
  324. float f5 = -MathHelper.cos(-f1 * 0.017453292F);
  325. float f6 = MathHelper.sin(-f1 * 0.017453292F);
  326. float f7 = f4 * f5;
  327. float f8 = f3 * f5;
  328. Vec3 vec31 = vec3.addVector(f7 * amount, f6 * amount, f8 * amount);
  329. return vec31;
  330. }
  331.  
  332. public static Vec3 getFrontCoords(EntityPlayer player, double amount)
  333. {
  334. float f = 1.0F;
  335. float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
  336. float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;
  337. double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double)f;
  338. double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double)f + (double)(player.worldObj.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight());
  339. double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double)f;
  340. Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
  341. float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
  342. float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
  343. float f5 = -MathHelper.cos(-f1 * 0.017453292F);
  344. float f6 = MathHelper.sin(-f1 * 0.017453292F);
  345. float f7 = f4 * f5;
  346. float f8 = f3 * f5;
  347. Vec3 vec31 = vec3.addVector(f7 * amount, f6 * amount, f8 * amount);
  348. return vec31;
  349. }
  350.  
  351. public static Vec3 getFrontCoords(EntityPlayer player, float angle, double amount)
  352. {
  353. float f = 1.0F;
  354. float f1 = angle * f;
  355. float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;
  356. double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double)f;
  357. double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double)f + (double)(player.worldObj.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight());
  358. double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double)f;
  359. Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
  360. float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
  361. float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
  362. float f5 = -MathHelper.cos(-f1 * 0.017453292F);
  363. float f6 = MathHelper.sin(-f1 * 0.017453292F);
  364. float f7 = f4 * f5;
  365. float f8 = f3 * f5;
  366. Vec3 vec31 = vec3.addVector(f7 * amount, f6 * amount, f8 * amount);
  367. return vec31;
  368. }
  369.  
  370. public static Vec3 getAboveCoords(EntityPlayer player, float angle, double amount)
  371. {
  372. float f = 1.0F;
  373. float f1 = angle * f;
  374. float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;
  375. double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double)f;
  376. double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double)f + (double)(player.worldObj.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight());
  377. double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double)f;
  378. Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
  379. float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
  380. float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
  381. float f5 = -MathHelper.cos(-f1 * 0.017453292F);
  382. float f6 = MathHelper.sin(-f1 * 0.017453292F);
  383. float f7 = f4 * f5;
  384. float f8 = f3 * f5;
  385. Vec3 vec31 = vec3.addVector(f7 * amount, f6 * amount, f8 * amount);
  386. return vec31;
  387. }
  388.  
  389. public static Vec3 getVerticalCoords(EntityPlayer player, float angle, double amount)
  390. {
  391. float f = 1.0F;
  392. float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f - angle;
  393. float f2 = angle * f;
  394. double d0 = player.prevPosX + (player.posX - player.prevPosX) * (double)f;
  395. double d1 = player.prevPosY + (player.posY - player.prevPosY) * (double)f + (double)(player.worldObj.isRemote ? player.getEyeHeight() - player.getDefaultEyeHeight() : player.getEyeHeight());
  396. double d2 = player.prevPosZ + (player.posZ - player.prevPosZ) * (double)f;
  397. Vec3 vec3 = Vec3.createVectorHelper(d0, d1, d2);
  398. float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
  399. float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
  400. float f5 = -MathHelper.cos(-f1 * 0.017453292F);
  401. float f6 = MathHelper.sin(-f1 * 0.017453292F);
  402. float f7 = f4 * f5;
  403. float f8 = f3 * f5;
  404. Vec3 vec31 = vec3.addVector(f7 * amount, f6 * amount, f8 * amount);
  405. return vec31;
  406. }
  407. public static void setVelocity(EntityPlayer player, double vel)
  408. {
  409. TransformedPlayer transformedPlayer = transformedPlayerMap.get(player);
  410.  
  411. if(transformedPlayer != null)
  412. {
  413. transformedPlayer.setVelocity(vel);
  414. }
  415. else
  416. {
  417. transformedPlayerMap.put(player, new TransformedPlayer(0, vel));
  418. }
  419. }
  420.  
  421. public static void setNitro(EntityPlayer player, int nitro)
  422. {
  423. TransformedPlayer transformedPlayer = transformedPlayerMap.get(player);
  424.  
  425. if(transformedPlayer != null)
  426. {
  427. transformedPlayer.setNitro(nitro);
  428. }
  429. else
  430. {
  431. transformedPlayerMap.put(player, new TransformedPlayer(nitro, 0));
  432. }
  433. }
  434.  
  435. public static void resetPlayer(EntityPlayer player)
  436. {
  437. transformedPlayerMap.get(player).setRoll(0);
  438. }
  439. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement