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

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

import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit

public class EntityLeash extends EntityHanging {

    public EntityLeash(World world) {
        super(world);
    }

    public EntityLeash(World world, int i, int j, int k) {
        super(world, i, j, k, 0);
        this.setPosition((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D);
    }

    protected void c() {
        super.c();
    }

    public void setDirection(int i) {}

    public int f() {
        return 9;
    }

    public int i() {
        return 9;
    }

    public void b(Entity entity) {}

    public boolean d(NBTTagCompound nbttagcompound) {
        return false;
    }

    public void b(NBTTagCompound nbttagcompound) {}

    public void a(NBTTagCompound nbttagcompound) {}

    public boolean c(EntityHuman entityhuman) {
        ItemStack itemstack = entityhuman.be();
        boolean flag = false;
        double d0;
        List list;
        Iterator iterator;
        EntityInsentient entityinsentient;

        if (itemstack != null && itemstack.getItem() == Items.LEASH && !this.world.isStatic) {
            d0 = 7.0D;
            list = this.world.a(EntityInsentient.class, AxisAlignedBB.a().a(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + d0, this.locZ + d0));
            if (list != null) {
                iterator = list.iterator();

                while (iterator.hasNext()) {
                    entityinsentient = (EntityInsentient) iterator.next();
                    if (entityinsentient.bL() && entityinsentient.getLeashHolder() == entityhuman) {
                        // CraftBukkit start
                        if (CraftEventFactory.callPlayerLeashEntityEvent(entityinsentient, this, entityhuman).isCancelled()) {
                            ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(1, entityinsentient, entityinsentient.getLeashHolder()));
                            continue;
                        }
                        // CraftBukkit end
                        entityinsentient.setLeashHolder(this, true);
                        flag = true;
                    }
                }
            }
        }

        if (!this.world.isStatic && !flag) {
            // CraftBukkit start - Move below
            // this.die();
            boolean die = true;
            // CraftBukkit end
            if (true || entityhuman.abilities.canInstantlyBuild) { // CraftBukkit - Process for non-creative as well
                d0 = 7.0D;
                list = this.world.a(EntityInsentient.class, AxisAlignedBB.a().a(this.locX - d0, this.locY - d0, this.locZ - d0, this.locX + d0, this.locY + d0, this.locZ + d0));
                if (list != null) {
                    iterator = list.iterator();

                    while (iterator.hasNext()) {
                        entityinsentient = (EntityInsentient) iterator.next();
                        if (entityinsentient.bL() && entityinsentient.getLeashHolder() == this) {
                            // CraftBukkit start
                            if (CraftEventFactory.callPlayerUnleashEntityEvent(entityinsentient, entityhuman).isCancelled()) {
                                die = false;
                                continue;
                            }
                            entityinsentient.unleash(true, !entityhuman.abilities.canInstantlyBuild); // false -> survival mode boolean
                            // CraftBukkit end
                        }
                    }
                }
            }
            // CraftBukkit start
            if (die) {
                this.die();
            }
            // CraftBukkit end
        }

        return true;
    }

    public boolean survives() {
        return this.world.getType(this.x, this.y, this.z).b() == 11;
    }

    public static EntityLeash a(World world, int i, int j, int k) {
        EntityLeash entityleash = new EntityLeash(world, i, j, k);

        entityleash.o = true;
        world.addEntity(entityleash);
        return entityleash;
    }

    public static EntityLeash b(World world, int i, int j, int k) {
        List list = world.a(EntityLeash.class, AxisAlignedBB.a().a((double) i - 1.0D, (double) j - 1.0D, (double) k - 1.0D, (double) i + 1.0D, (double) j + 1.0D, (double) k + 1.0D));

        if (list != null) {
            Iterator iterator = list.iterator();

            while (iterator.hasNext()) {
                EntityLeash entityleash = (EntityLeash) iterator.next();

                if (entityleash.x == i && entityleash.y == j && entityleash.z == k) {
                    return entityleash;
                }
            }
        }

        return null;
    }
}