Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. package me.gong.bar;
  2.  
  3. import java.lang.reflect.Field;
  4. import java.lang.reflect.Method;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7.  
  8. import net.minecraft.server.v1_7_R4.Entity;
  9. import net.minecraft.server.v1_7_R4.EntityWither;
  10. import net.minecraft.server.v1_7_R4.MathHelper;
  11.  
  12. import org.bukkit.World;
  13. import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
  14.  
  15. public class CustomWither extends EntityWither {
  16. public CustomWither(World w) {
  17. super(((CraftWorld)w).getHandle());
  18. }
  19.  
  20. @Override
  21. public void e() {
  22. this.motY *= 0.6000000238418579D;
  23. if ((!this.world.isStatic) && (t(0) > 0)) {
  24. Entity entity = this.world.getEntity(t(0));
  25. if (entity != null) {
  26. if ((this.locY < entity.locY) || ((!cb()) && (this.locY < entity.locY + 5.0D))) {
  27. if (this.motY < 0.0D) {
  28. this.motY = 0.0D;
  29. }
  30. this.motY += (0.5D - this.motY) * 0.6000000238418579D;
  31. }
  32. double d3 = entity.locX - this.locX;
  33.  
  34. double d0 = entity.locZ - this.locZ;
  35. double d1 = d3 * d3 + d0 * d0;
  36. if (d1 > 9.0D) {
  37. double d2 = MathHelper.sqrt(d1);
  38. this.motX += (d3 / d2 * 0.5D - this.motX) * 0.6000000238418579D;
  39. this.motZ += (d0 / d2 * 0.5D - this.motZ) * 0.6000000238418579D;
  40. }
  41. }
  42. }
  43. if (this.motX * this.motX + this.motZ * this.motZ > 0.0500000007450581D)
  44. this.yaw = ((float)Math.atan2(this.motZ, this.motX) * 57.295776F - 90.0F);
  45. super.e();
  46. for (int i = 0; i < 2; i++) {
  47. //this.bs[i] = this.bq[i]; original
  48. setFloatArray("bs", i, getFromFloatArray("bq", i));
  49. //this.br[i] = this.bp[i]; original
  50. setFloatArray("br", i, getFromFloatArray("bp", i));
  51. }
  52. for (int i = 0; i < 2; i++) {
  53. int j = t(i + 1);
  54. Entity entity1 = null;
  55. if (j > 0)
  56. entity1 = this.world.getEntity(j);
  57. if (entity1 != null) {
  58. double d0 = new MethodGetter<Double>("u", (i+1)).get();
  59. double d1 = new MethodGetter<Double>("v", (i+1)).get();
  60. double d2 = new MethodGetter<Double>("w", (i+1)).get();
  61. double d4 = entity1.locX - d0;
  62. double d5 = entity1.locY + entity1.getHeadHeight() - d1;
  63. double d6 = entity1.locZ - d2;
  64. double d7 = MathHelper.sqrt(d4 * d4 + d6 * d6);
  65. float f = (float)(Math.atan2(d6, d4) * 180.0D / 3.141592741012573D) - 90.0F;
  66. float f1 = (float)-(Math.atan2(d5, d7) * 180.0D / 3.141592741012573D);
  67.  
  68. //this.bp[i] = b(this.bp[i], f1, 40.0F); original
  69. setFloatArray("bp", i, new MethodGetter<Float>("b", getFromFloatArray("bp", i), f1, 40.0F).get());
  70. //this.bq[i] = b(this.bq[i], f, 10.0F); original
  71. setFloatArray("bq", i, new MethodGetter<Float>("b", getFromFloatArray("bq", i), f, 10.0F).get());
  72. } else {
  73. //this.bq[i] = b(this.bq[i], this.aM, 10.0F); original
  74. setFloatArray("bq", i, new MethodGetter<Float>("b", getFromFloatArray("bq", i), this.aM, 10.0F).get());
  75. }
  76. }
  77. }
  78.  
  79. public class MethodGetter<Return> {
  80. private Object ret = null;
  81. public MethodGetter(String methodName, Object... params) {
  82. try{
  83. Class<?> me = CustomWither.class;
  84. List<Class<?>> paramTypes2 = new ArrayList<Class<?>>();
  85. for(Object b:params) paramTypes2.add(b.getClass());
  86. Class<?>[] paramTypes = paramTypes2.toArray(new Class<?>[paramTypes2.size()]);
  87. Method meth = me.getDeclaredMethod(methodName, paramTypes);
  88. meth.setAccessible(true);
  89. ret = meth.invoke(this, params);
  90. }catch(Exception ex){}
  91. }
  92.  
  93. @SuppressWarnings("unchecked")
  94. public Return get() {
  95. return (Return)ret;
  96. }
  97. }
  98.  
  99. private void setFloatArray(String floatName, int index, float to) {
  100. try{
  101. Class<?> me = CustomWither.class;
  102. Field b = me.getDeclaredField(floatName);
  103. b.setAccessible(true);
  104. float[] get = (float[]) b.get(this);
  105. get[index] = to;
  106. b.set(this, get);
  107. }catch(Exception ex){}
  108. }
  109.  
  110. private float getFromFloatArray(String floatName, int index) {
  111. try{
  112. Class<?> me = CustomWither.class;
  113. Field b = me.getDeclaredField(floatName);
  114. b.setAccessible(true);
  115. float[] ret = (float[])b.get(this);
  116. return ret[index];
  117. }catch(Exception ex){}
  118. return 0.0F;
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement