Citizens2/v1_10_R1/src/main/java/net/citizensnpcs/nms/v1_10_R1/util/PlayerControllerMove.java

134 lines
3.6 KiB
Java
Raw Normal View History

package net.citizensnpcs.nms.v1_10_R1.util;
2015-10-31 17:51:37 +01:00
import java.util.Random;
import net.citizensnpcs.nms.v1_10_R1.entity.EntityHumanNPC;
import net.citizensnpcs.util.NMS;
2016-06-09 12:25:27 +02:00
import net.minecraft.server.v1_10_R1.AttributeInstance;
import net.minecraft.server.v1_10_R1.ControllerMove;
import net.minecraft.server.v1_10_R1.EntityInsentient;
import net.minecraft.server.v1_10_R1.EntityLiving;
import net.minecraft.server.v1_10_R1.EntitySlime;
import net.minecraft.server.v1_10_R1.GenericAttributes;
import net.minecraft.server.v1_10_R1.MathHelper;
2014-11-28 16:22:11 +01:00
2015-10-31 17:51:37 +01:00
public class PlayerControllerMove extends ControllerMove {
protected EntityLiving a;
2014-11-28 16:22:11 +01:00
protected double b;
protected double c;
protected double d;
protected double e;
protected boolean f;
2015-10-31 17:51:37 +01:00
private int h;
2015-10-31 17:51:37 +01:00
public PlayerControllerMove(EntityLiving entityinsentient) {
super(entityinsentient instanceof EntityInsentient ? (EntityInsentient) entityinsentient
: new EntitySlime(entityinsentient.world));
this.a = entityinsentient;
this.b = entityinsentient.locX;
this.c = entityinsentient.locY;
this.d = entityinsentient.locZ;
}
2015-10-31 17:51:37 +01:00
@Override
public boolean a() {
return this.f;
}
2015-10-31 17:51:37 +01:00
@Override
public void a(double d0, double d1, double d2, double d3) {
this.b = d0;
this.c = d1;
this.d = d2;
this.e = d3;
this.f = true;
}
2015-10-31 17:51:37 +01:00
@Override
2014-11-28 16:22:11 +01:00
protected float a(float f, float f1, float f2) {
float f3 = MathHelper.g(f1 - f);
if (f3 > f2) {
f3 = f2;
}
if (f3 < -f2) {
f3 = -f2;
}
2014-11-28 16:22:11 +01:00
float f4 = f + f3;
if (f4 < 0.0F)
f4 += 360.0F;
else if (f4 > 360.0F) {
f4 -= 360.0F;
}
return f4;
}
2015-10-31 17:51:37 +01:00
@Override
public double b() {
return this.e;
}
2015-10-31 17:51:37 +01:00
@Override
public void c() {
2016-06-09 12:25:27 +02:00
this.a.bf = 0F;
if (this.f) {
this.f = false;
2014-11-28 16:22:11 +01:00
int i = MathHelper.floor(this.a.getBoundingBox().b + 0.5D);
double d0 = this.b - this.a.locX;
double d1 = this.d - this.a.locZ;
double d2 = this.c - i;
double d3 = d0 * d0 + d2 * d2 + d1 * d1;
2015-11-23 18:17:06 +01:00
if (d3 < 2.500000277905201E-007D)
return;
float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
2016-12-10 13:20:27 +01:00
this.a.yaw = a(this.a.yaw, f, 90.0F);
NMS.setHeadYaw(a.getBukkitEntity(), this.a.yaw);
2015-11-23 18:17:06 +01:00
AttributeInstance speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
speed.setValue(0.1D * this.e);
float movement = (float) (this.e * speed.getValue()) * 10;
2016-06-09 12:25:27 +02:00
this.a.bg = movement;
2015-11-23 18:17:06 +01:00
if (shouldSlimeJump() || ((d2 > 0.0D) && (d0 * d0 + d1 * d1 < 1.0D))) {
this.h = cg();
this.h /= 3;
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().a();
} else {
((EntityInsentient) this.a).getControllerJump().a();
2015-10-31 17:51:37 +01:00
}
}
}
}
2014-11-28 16:22:11 +01:00
2015-10-31 17:51:37 +01:00
protected int cg() {
return new Random().nextInt(20) + 10;
}
@Override
2014-11-28 16:22:11 +01:00
public double d() {
return this.b;
}
2015-10-31 17:51:37 +01:00
@Override
2014-11-28 16:22:11 +01:00
public double e() {
return this.c;
}
2015-10-31 17:51:37 +01:00
@Override
2014-11-28 16:22:11 +01:00
public double f() {
return this.d;
}
2015-10-31 17:51:37 +01:00
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
2014-11-28 16:22:11 +01:00
}