/
PlayerLookControl.java
140 lines (123 loc) · 4.19 KB
/
PlayerLookControl.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
135
136
137
138
139
140
package net.citizensnpcs.nms.v1_18_R1.util;
import net.citizensnpcs.nms.v1_18_R1.entity.EntityHumanNPC;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
public class PlayerLookControl {
private final EntityHumanNPC a;
private final PlayerBodyControl control;
protected boolean looking;
protected float tpitch;
protected double tx;
protected double ty;
protected float tyaw;
protected double tz;
public PlayerLookControl(EntityHumanNPC entityinsentient) {
this.a = entityinsentient;
this.control = new PlayerBodyControl(this.a);
}
public void a() {
if (!NMSImpl.isNavigationFinished(this.a.getNavigation())) {
// TODO: use Citizens AI?
// this.a.yHeadRot = Mth.rotateIfNecessary(this.a.yHeadRot, this.a.yBodyRot, 75);
return;
}
if (this.b()) {
// this.a.setXRot(0.0F);
}
if (this.looking) {
this.looking = false;
this.a.setXRot(this.rotateTowards(this.a.getXRot(), this.g(), this.tpitch));
this.a.yHeadRot = this.rotateTowards(this.a.yHeadRot, this.h(), this.tyaw);
while (this.a.yHeadRot >= 180F) {
this.a.yHeadRot -= 360F;
}
while (this.a.yHeadRot < -180F) {
this.a.yHeadRot += 360F;
}
double d = this.a.yHeadRot - 40;
while (d >= 180F) {
d -= 360F;
}
while (d < -180F) {
d += 360F;
}
if (d > this.a.getYRot()) {
this.a.setYRot((float) d);
}
if (d != this.a.getYRot()) {
d = this.a.yHeadRot + 40;
while (d >= 180F) {
d -= 360F;
}
while (d < -180F) {
d += 360F;
}
if (d < this.a.getYRot()) {
this.a.setYRot((float) d);
}
}
// this.a.setYRot(this.a(this.a.yHeadRot, this.h(), this.b));
} else {
// this.a.yHeadRot = rotateTowards(this.a.yHeadRot, this.a.yBodyRot, 10.0F);
}
}
public void a(double var0, double var2, double var4) {
this.a(var0, var2, var4, 10, 40);
}
public void a(double var0, double var2, double var4, float var6, float var7) {
double d = Math.pow(this.tx - var0, 2) + Math.pow(this.ty - var2, 2) + Math.pow(this.tz - var4, 2);
if (d < 0.01) {
// return;
}
this.tx = var0;
this.ty = var2;
this.tz = var4;
this.tyaw = var6;
this.tpitch = var7;
this.looking = true;
}
public void a(Entity var0, float var1, float var2) {
this.a(var0.getX(), b(var0), var0.getZ(), var1, var2);
}
public void a(Vec3 var0) {
this.a(var0.x, var0.y, var0.z);
}
protected boolean b() {
return true;
}
public boolean c() {
return this.looking;
}
public double d() {
return this.tx;
}
public double e() {
return this.ty;
}
public double f() {
return this.tz;
}
protected float g() {
double var0 = this.tx - this.a.getX();
double var2 = this.ty - (this.a.getY() + this.a.getEyeY());
double var4 = this.tz - this.a.getZ();
double var6 = Mth.sqrt((float) (var0 * var0 + var4 * var4));
return (float) (-(Mth.atan2(var2, var6) * 57.2957763671875D));
}
protected float h() {
double var0 = this.tx - this.a.getX();
double var2 = this.tz - this.a.getZ();
return (float) (Mth.atan2(var2, var0) * 57.2957763671875D) - 90.0F;
}
protected float rotateTowards(float var0, float var1, float var2) {
float var3 = Mth.degreesDifference(var0, var1);
float var4 = Mth.clamp(var3, -var2, var2);
return var0 + var4;
}
private static double b(Entity var0) {
return var0 instanceof LivingEntity ? var0.getY() + var0.getEyeY()
: (var0.getBoundingBox().minY + var0.getBoundingBox().maxY) / 2.0D;
}
}