summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/PathfinderGoalMeleeAttack.java
blob: 5c150b05ca4446515daeba23c500a26be3bbca24 (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.event.entity.EntityTargetEvent; // CraftBukkit

public class PathfinderGoalMeleeAttack extends PathfinderGoal {

    World a;
    EntityLiving b;
    EntityLiving c;
    int d;
    float e;
    boolean f;
    PathEntity g;
    Class h;
    private int i;

    public PathfinderGoalMeleeAttack(EntityLiving entityliving, Class oclass, float f, boolean flag) {
        this(entityliving, f, flag);
        this.h = oclass;
    }

    public PathfinderGoalMeleeAttack(EntityLiving entityliving, float f, boolean flag) {
        this.d = 0;
        this.b = entityliving;
        this.a = entityliving.world;
        this.e = f;
        this.f = flag;
        this.a(3);
    }

    public boolean a() {
        EntityLiving entityliving = this.b.aF();

        if (entityliving == null) {
            return false;
        } else if (this.h != null && !this.h.isAssignableFrom(entityliving.getClass())) {
            return false;
        } else {
            this.c = entityliving;
            this.g = this.b.getNavigation().a(this.c);
            return this.g != null;
        }
    }

    public boolean b() {
        EntityLiving entityliving = this.b.aF();

        return entityliving == null ? false : (!this.c.isAlive() ? false : (!this.f ? !this.b.getNavigation().f() : this.b.e(MathHelper.floor(this.c.locX), MathHelper.floor(this.c.locY), MathHelper.floor(this.c.locZ))));
    }

    public void c() {
        this.b.getNavigation().a(this.g, this.e);
        this.i = 0;
    }

    public void d() {
        // CraftBukkit start
        EntityTargetEvent.TargetReason reason = this.c.isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
        org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetEvent(b, null, reason);
        // CraftBukkit end

        this.c = null;
        this.b.getNavigation().g();
    }

    public void e() {
        this.b.getControllerLook().a(this.c, 30.0F, 30.0F);
        if ((this.f || this.b.az().canSee(this.c)) && --this.i <= 0) {
            this.i = 4 + this.b.aA().nextInt(7);
            this.b.getNavigation().a(this.c, this.e);
        }

        this.d = Math.max(this.d - 1, 0);
        double d0 = (double) (this.b.width * 2.0F * this.b.width * 2.0F);

        if (this.b.e(this.c.locX, this.c.boundingBox.b, this.c.locZ) <= d0) {
            if (this.d <= 0) {
                this.d = 20;
                if (this.b.bA() != null) {
                    this.b.bE();
                }

                this.b.l(this.c);
            }
        }
    }
}