summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/ControllerLook.java
blob: 525954284c02354a1102bbbab195b701587f3b16 (plain)
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
package net.minecraft.server;

import org.bukkit.craftbukkit.TrigMath; // CraftBukkit

public class ControllerLook {

    private EntityLiving a;
    private float b;
    private float c;
    private boolean d = false;
    private double e;
    private double f;
    private double g;

    public ControllerLook(EntityLiving entityliving) {
        this.a = entityliving;
    }

    public void a(Entity entity, float f, float f1) {
        this.e = entity.locX;
        if (entity instanceof EntityLiving) {
            this.f = entity.locY + (double) entity.getHeadHeight();
        } else {
            this.f = (entity.boundingBox.b + entity.boundingBox.e) / 2.0D;
        }

        this.g = entity.locZ;
        this.b = f;
        this.c = f1;
        this.d = true;
    }

    public void a(double d0, double d1, double d2, float f, float f1) {
        this.e = d0;
        this.f = d1;
        this.g = d2;
        this.b = f;
        this.c = f1;
        this.d = true;
    }

    public void a() {
        this.a.pitch = 0.0F;
        if (this.d) {
            this.d = false;
            double d0 = this.e - this.a.locX;
            double d1 = this.f - (this.a.locY + (double) this.a.getHeadHeight());
            double d2 = this.g - this.a.locZ;
            double d3 = (double) MathHelper.sqrt(d0 * d0 + d2 * d2);
            // CraftBukkit start - Math -> TrigMath
            float f = (float) (TrigMath.atan2(d2, d0) * 180.0D / 3.1415927410125732D) - 90.0F;
            float f1 = (float) (-(TrigMath.atan2(d1, d3) * 180.0D / 3.1415927410125732D));
            // CraftBukkit end

            this.a.pitch = this.a(this.a.pitch, f1, this.c);
            this.a.ay = this.a(this.a.ay, f, this.b);
        } else {
            this.a.ay = this.a(this.a.ay, this.a.aw, 10.0F);
        }

        float f2 = MathHelper.g(this.a.ay - this.a.aw);

        if (!this.a.getNavigation().f()) {
            if (f2 < -75.0F) {
                this.a.ay = this.a.aw - 75.0F;
            }

            if (f2 > 75.0F) {
                this.a.ay = this.a.aw + 75.0F;
            }
        }
    }

    private float a(float f, float f1, float f2) {
        float f3 = MathHelper.g(f1 - f);

        if (f3 > f2) {
            f3 = f2;
        }

        if (f3 < -f2) {
            f3 = -f2;
        }

        return f + f3;
    }
}