-
-
Notifications
You must be signed in to change notification settings - Fork 315
/
PlayerControllerMove.java
134 lines (115 loc) · 3.53 KB
/
PlayerControllerMove.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package net.citizensnpcs.util.nms;
import java.util.Random;
import net.citizensnpcs.npc.entity.EntityHumanNPC;
import net.citizensnpcs.util.NMS;
import net.minecraft.server.v1_9_R2.AttributeInstance;
import net.minecraft.server.v1_9_R2.ControllerMove;
import net.minecraft.server.v1_9_R2.EntityInsentient;
import net.minecraft.server.v1_9_R2.EntityLiving;
import net.minecraft.server.v1_9_R2.EntitySlime;
import net.minecraft.server.v1_9_R2.GenericAttributes;
import net.minecraft.server.v1_9_R2.MathHelper;
public class PlayerControllerMove extends ControllerMove {
protected EntityLiving a;
protected double b;
protected double c;
protected double d;
protected double e;
protected boolean f;
private int h;
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;
}
@Override
public boolean a() {
return this.f;
}
@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;
}
@Override
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;
}
float f4 = f + f3;
if (f4 < 0.0F)
f4 += 360.0F;
else if (f4 > 360.0F) {
f4 -= 360.0F;
}
return f4;
}
@Override
public double b() {
return this.e;
}
@Override
public void c() {
this.a.be = 0F;
if (this.f) {
this.f = false;
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;
if (d3 < 2.500000277905201E-007D)
return;
float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
this.a.yaw = a(this.a.yaw, f, 30.0F);
NMS.setHeadYaw(a, this.a.yaw);
AttributeInstance speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
speed.setValue(0.1D * this.e);
float movement = (float) (this.e * speed.getValue()) * 10;
this.a.bf = movement;
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();
}
}
}
}
protected int cg() {
return new Random().nextInt(20) + 10;
}
@Override
public double d() {
return this.b;
}
@Override
public double e() {
return this.c;
}
@Override
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
}