summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/EntityTrackerEntry.java
blob: 6fdb67e9f4de2ab1238fb585dbd3a088d8e87a2b (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package net.minecraft.server;

import java.util.*;

public class EntityTrackerEntry {

    public Entity a;
    public int b;
    public int c;
    public int d;
    public int e;
    public int f;
    public int g;
    public int h;
    public double i;
    public double j;
    public double k;
    public int l;
    private double o;
    private double p;
    private double q;
    private boolean r;
    private boolean s;
    public boolean m;
    public Set n;

    public EntityTrackerEntry(Entity entity, int i1, int j1, boolean flag) {
        l = 0;
        r = false;
        m = false;
        n = ((Set) (new HashSet()));
        a = entity;
        b = i1;
        c = j1;
        s = flag;
        d = MathHelper.b(entity.p * 32D);
        e = MathHelper.b(entity.q * 32D);
        f = MathHelper.b(entity.r * 32D);
        g = MathHelper.d((entity.v * 256F) / 360F);
        h = MathHelper.d((entity.w * 256F) / 360F);
    }

    public boolean equals(Object obj) {
        if (obj instanceof EntityTrackerEntry) {
            return ((EntityTrackerEntry) obj).a.g == a.g;
        } else {
            return false;
        }
    }

    public int hashCode() {
        return a.g;
    }

    public void a(List list) {
        m = false;
        if (!r || a.d(o, p, q) > 16D) {
            o = a.p;
            p = a.q;
            q = a.r;
            r = true;
            m = true;
            b(list);
        }
        if (++l % c == 0) {
            int i1 = MathHelper.b(a.p * 32D);
            int j1 = MathHelper.b(a.q * 32D);
            int k1 = MathHelper.b(a.r * 32D);
            int l1 = MathHelper.d((a.v * 256F) / 360F);
            int i2 = MathHelper.d((a.w * 256F) / 360F);
            boolean flag = i1 != d || j1 != e || k1 != f;
            boolean flag1 = l1 != g || i2 != h;
            int j2 = i1 - d;
            int k2 = j1 - e;
            int l2 = k1 - f;
            Object obj = null;

            if (j2 < -128 || j2 >= 128 || k2 < -128 || k2 >= 128 || l2 < -128 || l2 >= 128) {
                obj = ((new Packet34EntityTeleport(a.g, i1, j1, k1, (byte) l1, (byte) i2)));
            } else if (flag && flag1) {
                obj = ((new Packet33RelEntityMoveLook(a.g, (byte) j2, (byte) k2, (byte) l2, (byte) l1, (byte) i2)));
            } else if (flag) {
                obj = ((new Packet31RelEntityMove(a.g, (byte) j2, (byte) k2, (byte) l2)));
            } else if (flag1) {
                obj = ((new Packet32EntityLook(a.g, (byte) l1, (byte) i2)));
            } else {
                obj = ((new Packet30Entity(a.g)));
            }
            if (s) {
                double d1 = a.s - i;
                double d2 = a.t - j;
                double d3 = a.u - k;
                double d4 = 0.02D;
                double d5 = d1 * d1 + d2 * d2 + d3 * d3;

                if (d5 > d4 * d4 || d5 > 0.0D && a.s == 0.0D && a.t == 0.0D && a.u == 0.0D) {
                    i = a.s;
                    j = a.t;
                    k = a.u;
                    a(((Packet) (new Packet28(a.g, i, j, k))));
                }
            }
            if (obj != null) {
                a(((Packet) (obj)));
            }
            DataWatcher datawatcher = a.p();

            if (datawatcher.a()) {
                b(((Packet) (new Packet40(a.g, datawatcher))));
            }
            d = i1;
            e = j1;
            f = k1;
            g = l1;
            h = i2;
        }
        if (a.E) {
            b(((Packet) (new Packet28(a))));
            a.E = false;
        }
    }

    public void a(Packet packet) {
        EntityPlayerMP entityplayermp;

        for (Iterator iterator = n.iterator(); iterator.hasNext(); entityplayermp.a.b(packet)) {
            entityplayermp = (EntityPlayerMP) iterator.next();
        }
    }

    public void b(Packet packet) {
        a(packet);
        if (a instanceof EntityPlayerMP) {
            ((EntityPlayerMP) a).a.b(packet);
        }
    }

    public void a() {
        a(((Packet) (new Packet29DestroyEntity(a.g))));
    }

    public void a(EntityPlayerMP entityplayermp) {
        if (n.contains(((entityplayermp)))) {
            n.remove(((entityplayermp)));
        }
    }

    public void b(EntityPlayerMP entityplayermp) {
        if (entityplayermp == a) {
            return;
        }
        double d1 = entityplayermp.p - (double) (d / 32);
        double d2 = entityplayermp.r - (double) (f / 32);

        if (d1 >= (double) (-b) && d1 <= (double) b && d2 >= (double) (-b) && d2 <= (double) b) {
            if (!n.contains(((entityplayermp)))) {
                n.add(((entityplayermp)));
                entityplayermp.a.b(b());
                if (s) {
                    entityplayermp.a.b(((Packet) (new Packet28(a.g, a.s, a.t, a.u))));
                }
                ItemStack aitemstack[] = a.I();

                if (aitemstack != null) {
                    for (int i1 = 0; i1 < aitemstack.length; i1++) {
                        entityplayermp.a.b(((Packet) (new Packet5PlayerInventory(a.g, i1, aitemstack[i1]))));
                    }
                }
            }
        } else if (n.contains(((entityplayermp)))) {
            n.remove(((entityplayermp)));
            entityplayermp.a.b(((Packet) (new Packet29DestroyEntity(a.g))));
        }
    }

    public void b(List list) {
        for (int i1 = 0; i1 < list.size(); i1++) {
            b((EntityPlayerMP) list.get(i1));
        }
    }

    private Packet b() {
        if (a instanceof EntityItem) {
            EntityItem entityitem = (EntityItem) a;
            Packet21PickupSpawn packet21pickupspawn = new Packet21PickupSpawn(entityitem);

            entityitem.p = (double) packet21pickupspawn.b / 32D;
            entityitem.q = (double) packet21pickupspawn.c / 32D;
            entityitem.r = (double) packet21pickupspawn.d / 32D;
            return ((Packet) (packet21pickupspawn));
        }
        if (a instanceof EntityPlayerMP) {
            return ((Packet) (new Packet20NamedEntitySpawn((EntityPlayer) a)));
        }
        if (a instanceof EntityMinecart) {
            EntityMinecart entityminecart = (EntityMinecart) a;

            if (entityminecart.d == 0) {
                return ((Packet) (new Packet23VehicleSpawn(a, 10)));
            }
            if (entityminecart.d == 1) {
                return ((Packet) (new Packet23VehicleSpawn(a, 11)));
            }
            if (entityminecart.d == 2) {
                return ((Packet) (new Packet23VehicleSpawn(a, 12)));
            }
        }
        if (a instanceof EntityBoat) {
            return ((Packet) (new Packet23VehicleSpawn(a, 1)));
        }
        if (a instanceof IAnimals) {
            return ((Packet) (new Packet24MobSpawn((EntityLiving) a)));
        }
        if (a instanceof EntityFish) {
            return ((Packet) (new Packet23VehicleSpawn(a, 90)));
        }
        if (a instanceof EntityArrow) {
            return ((Packet) (new Packet23VehicleSpawn(a, 60)));
        }
        if (a instanceof EntitySnowball) {
            return ((Packet) (new Packet23VehicleSpawn(a, 61)));
        }
        if (a instanceof EntityEgg) {
            return ((Packet) (new Packet23VehicleSpawn(a, 62)));
        }
        if (a instanceof EntityTNTPrimed) {
            return ((Packet) (new Packet23VehicleSpawn(a, 50)));
        }
        if (a instanceof EntityFallingSand) {
            EntityFallingSand entityfallingsand = (EntityFallingSand) a;

            if (entityfallingsand.a == Block.E.bi) {
                return ((Packet) (new Packet23VehicleSpawn(a, 70)));
            }
            if (entityfallingsand.a == Block.F.bi) {
                return ((Packet) (new Packet23VehicleSpawn(a, 71)));
            }
        }
        if (a instanceof EntityPainting) {
            return ((Packet) (new Packet25((EntityPainting) a)));
        } else {
            throw new IllegalArgumentException((new StringBuilder()).append("Don't know how to add ").append(((((a)).getClass()))).append("!").toString());
        }
    }

    public void c(EntityPlayerMP entityplayermp) {
        if (n.contains(((entityplayermp)))) {
            n.remove(((entityplayermp)));
            entityplayermp.a.b(((Packet) (new Packet29DestroyEntity(a.g))));
        }
    }
}