summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/PathfinderGoalHurtByTarget.java
blob: 4f476e6f43d76eb626dcfac35884432210c12bde (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
package net.minecraft.server;

import java.util.Iterator;
import java.util.List;

public class PathfinderGoalHurtByTarget extends PathfinderGoalTarget {

    boolean a;
    private int b;

    public PathfinderGoalHurtByTarget(EntityCreature entitycreature, boolean flag) {
        super(entitycreature, false);
        this.a = flag;
        this.a(1);
    }

    public boolean a() {
        int i = this.c.aK();

        return i != this.b && this.a(this.c.getLastDamager(), false);
    }

    public void c() {
        this.c.setGoalTarget(this.c.getLastDamager());
        this.b = this.c.aK();
        if (this.a) {
            double d0 = this.f();
            List list = this.c.world.a(this.c.getClass(), AxisAlignedBB.a(this.c.locX, this.c.locY, this.c.locZ, this.c.locX + 1.0D, this.c.locY + 1.0D, this.c.locZ + 1.0D).grow(d0, 10.0D, d0));
            Iterator iterator = list.iterator();

            while (iterator.hasNext()) {
                EntityCreature entitycreature = (EntityCreature) iterator.next();

                if (this.c != entitycreature && entitycreature.getGoalTarget() == null && !entitycreature.c(this.c.getLastDamager())) {
                    // CraftBukkit start - call EntityTargetEvent
                    org.bukkit.event.entity.EntityTargetLivingEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTargetLivingEvent(entitycreature, this.c.getLastDamager(), org.bukkit.event.entity.EntityTargetEvent.TargetReason.TARGET_ATTACKED_NEARBY_ENTITY);
                    if (event.isCancelled()) {
                        continue;
                    }
                    entitycreature.setGoalTarget(event.getTarget() == null ? null : ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getTarget()).getHandle());
                    // CraftBukkit end
                }
            }
        }

        super.c();
    }
}