Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.gong.bar;
- import java.lang.reflect.Field;
- import java.lang.reflect.Method;
- import java.util.ArrayList;
- import java.util.List;
- import net.minecraft.server.v1_7_R4.Entity;
- import net.minecraft.server.v1_7_R4.EntityWither;
- import net.minecraft.server.v1_7_R4.MathHelper;
- import org.bukkit.World;
- import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
- public class CustomWither extends EntityWither {
- public CustomWither(World w) {
- super(((CraftWorld)w).getHandle());
- }
- @Override
- public void e() {
- this.motY *= 0.6000000238418579D;
- if ((!this.world.isStatic) && (t(0) > 0)) {
- Entity entity = this.world.getEntity(t(0));
- if (entity != null) {
- if ((this.locY < entity.locY) || ((!cb()) && (this.locY < entity.locY + 5.0D))) {
- if (this.motY < 0.0D) {
- this.motY = 0.0D;
- }
- this.motY += (0.5D - this.motY) * 0.6000000238418579D;
- }
- double d3 = entity.locX - this.locX;
- double d0 = entity.locZ - this.locZ;
- double d1 = d3 * d3 + d0 * d0;
- if (d1 > 9.0D) {
- double d2 = MathHelper.sqrt(d1);
- this.motX += (d3 / d2 * 0.5D - this.motX) * 0.6000000238418579D;
- this.motZ += (d0 / d2 * 0.5D - this.motZ) * 0.6000000238418579D;
- }
- }
- }
- if (this.motX * this.motX + this.motZ * this.motZ > 0.0500000007450581D)
- this.yaw = ((float)Math.atan2(this.motZ, this.motX) * 57.295776F - 90.0F);
- super.e();
- for (int i = 0; i < 2; i++) {
- //this.bs[i] = this.bq[i]; original
- setFloatArray("bs", i, getFromFloatArray("bq", i));
- //this.br[i] = this.bp[i]; original
- setFloatArray("br", i, getFromFloatArray("bp", i));
- }
- for (int i = 0; i < 2; i++) {
- int j = t(i + 1);
- Entity entity1 = null;
- if (j > 0)
- entity1 = this.world.getEntity(j);
- if (entity1 != null) {
- double d0 = new MethodGetter<Double>("u", (i+1)).get();
- double d1 = new MethodGetter<Double>("v", (i+1)).get();
- double d2 = new MethodGetter<Double>("w", (i+1)).get();
- double d4 = entity1.locX - d0;
- double d5 = entity1.locY + entity1.getHeadHeight() - d1;
- double d6 = entity1.locZ - d2;
- double d7 = MathHelper.sqrt(d4 * d4 + d6 * d6);
- float f = (float)(Math.atan2(d6, d4) * 180.0D / 3.141592741012573D) - 90.0F;
- float f1 = (float)-(Math.atan2(d5, d7) * 180.0D / 3.141592741012573D);
- //this.bp[i] = b(this.bp[i], f1, 40.0F); original
- setFloatArray("bp", i, new MethodGetter<Float>("b", getFromFloatArray("bp", i), f1, 40.0F).get());
- //this.bq[i] = b(this.bq[i], f, 10.0F); original
- setFloatArray("bq", i, new MethodGetter<Float>("b", getFromFloatArray("bq", i), f, 10.0F).get());
- } else {
- //this.bq[i] = b(this.bq[i], this.aM, 10.0F); original
- setFloatArray("bq", i, new MethodGetter<Float>("b", getFromFloatArray("bq", i), this.aM, 10.0F).get());
- }
- }
- }
- public class MethodGetter<Return> {
- private Object ret = null;
- public MethodGetter(String methodName, Object... params) {
- try{
- Class<?> me = CustomWither.class;
- List<Class<?>> paramTypes2 = new ArrayList<Class<?>>();
- for(Object b:params) paramTypes2.add(b.getClass());
- Class<?>[] paramTypes = paramTypes2.toArray(new Class<?>[paramTypes2.size()]);
- Method meth = me.getDeclaredMethod(methodName, paramTypes);
- meth.setAccessible(true);
- ret = meth.invoke(this, params);
- }catch(Exception ex){}
- }
- @SuppressWarnings("unchecked")
- public Return get() {
- return (Return)ret;
- }
- }
- private void setFloatArray(String floatName, int index, float to) {
- try{
- Class<?> me = CustomWither.class;
- Field b = me.getDeclaredField(floatName);
- b.setAccessible(true);
- float[] get = (float[]) b.get(this);
- get[index] = to;
- b.set(this, get);
- }catch(Exception ex){}
- }
- private float getFromFloatArray(String floatName, int index) {
- try{
- Class<?> me = CustomWither.class;
- Field b = me.getDeclaredField(floatName);
- b.setAccessible(true);
- float[] ret = (float[])b.get(this);
- return ret[index];
- }catch(Exception ex){}
- return 0.0F;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement