summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/EntityBoat.java
blob: 1cc034709e9b5e306eb32315ce06404858096578 (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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
package net.minecraft.server;

import java.util.List;
import java.util.Random;

// CraftBukkit start
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftArrow;
import org.bukkit.craftbukkit.entity.CraftBoat;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.CraftMappable;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.Event.Type;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;
// CraftBukkit end

public class EntityBoat extends Entity implements CraftMappable { // CraftBukkit

    public int a;
    public int b;
    public int c;
    private int d;
    private double e;
    private double f;
    private double ak;
    private double al;
    private double am;

    // CraftBukkit start
    /**@deprecated*/
    private CraftBoat boat;
    /**@deprecated*/
    public CraftEntity getCraftEntity() {
        return boat;
    }
    // CraftBukkit end

    public EntityBoat(World world) {
        super(world);
        a = 0;
        b = 0;
        c = 1;
        i = true;
        a(1.5F, 0.6F);
        H = J / 2.0F;
        M = false;

        handleCreation(world); // CraftBukkit
        //CraftBukkit start
        CraftServer server = ((WorldServer) this.l).getServer();
        this.bukkitEntity = new CraftBoat(server, this);
        //CraftBukkit end
    }

    protected void a() {}

    public AxisAlignedBB d(Entity entity) {
        return entity.z;
    }

    public AxisAlignedBB u() {
        return z;
    }

    public boolean z() {
        return true;
    }

    public EntityBoat(World world, double d1, double d2, double d3) {
        this(world);
        a(d1, d2 + (double) H, d3);
        s = 0.0D;
        t = 0.0D;
        u = 0.0D;
        m = d1;
        n = d2;
        o = d3;

        handleCreation(world); // CraftBukkit
    }

    // CraftBukkit start
    private void handleCreation(World world) {
        CraftServer server = ((WorldServer) world).getServer();
        VehicleCreateEvent event = new VehicleCreateEvent( Type.VEHICLE_CREATE, (Vehicle) this.getBukkitEntity());
        server.getPluginManager().callEvent(event);
    }
    // CraftBukkit end

    public double k() {
        return (double) J * 0.0D - 0.30000001192092896D;
    }

    public boolean a(Entity entity, int i) {
        // CraftBukkit start
        VehicleDamageEvent event = new VehicleDamageEvent( Type.VEHICLE_DAMAGE, (Vehicle) this.getBukkitEntity(), entity.getBukkitEntity(), i);
        ((WorldServer) l).getServer().getPluginManager().callEvent(event);

        if (event.isCancelled()) {
            return true;
        }
        // CraftBukkit end

        if (this.l.z || G) {
            return true;
        }
        c = -c;
        b = 10;
        a += i * 10;
        y();
        if (a > 40) {
            for (int j = 0; j < 3; j++) {
                a(Block.x.bi, 1, 0.0F);
            }

            for (int l = 0; l < 2; l++) {
                a(Item.B.ba, 1, 0.0F);
            }

            q();
        }
        return true;
    }

    public boolean c_() {
        return !G;
    }

    public void b_() {
        // CraftBukkit start
        double prevX = p;
        double prevY = q;
        double prevZ = r;
        float prevYaw = v;
        float prevPitch = w;
        // CraftBukkit end

        super.b_();
        if (b > 0) {
            b--;
        }
        if (a > 0) {
            a--;
        }
        m = p;
        n = q;
        o = r;
        int i = 5;
        double d1 = 0.0D;

        for (int j = 0; j < i; j++) {
            double d2 = (z.b + ((z.e - z.b) * (double) (j + 0)) / (double) i) - 0.125D;
            double d3 = (z.b + ((z.e - z.b) * (double) (j + 1)) / (double) i) - 0.125D;
            AxisAlignedBB axisalignedbb = AxisAlignedBB.b(z.a, d2, z.c, z.d, d3, z.f);

            if (this.l.b(axisalignedbb, Material.f)) {
                d1 += 1.0D / (double) i;
            }
        }

        if (this.l.z) {
            if (d > 0) {
                double d4 = p + (e - p) / (double) d;
                double d7 = q + (f - q) / (double) d;
                double d10 = r + (ak - r) / (double) d;
                double d13;

                for (d13 = al - (double) v; d13 < -180D; d13 += 360D) {
                    ;
                }
                for (; d13 >= 180D; d13 -= 360D) {
                    ;
                }
                v += ((float) (d13 / (double) d));
                w += ((float) ((am - (double) w) / (double) d));
                d--;
                a(d4, d7, d10);
                b(v, w);
            } else {
                double d5 = p + s;
                double d8 = q + t;
                double d11 = r + u;

                a(d5, d8, d11);
                if (A) {
                    s *= 0.5D;
                    t *= 0.5D;
                    u *= 0.5D;
                }
                s *= 0.99000000953674316D;
                t *= 0.94999998807907104D;
                u *= 0.99000000953674316D;
            }
            return;
        }
        double d6 = d1 * 2D - 1.0D;

        t += 0.039999999105930328D * d6;
        if (this.j != null) {
            s += this.j.s * 0.20000000000000001D;
            u += this.j.u * 0.20000000000000001D;
        }
        double d9 = 0.40000000000000002D;

        if (s < -d9) {
            s = -d9;
        }
        if (s > d9) {
            s = d9;
        }
        if (u < -d9) {
            u = -d9;
        }
        if (u > d9) {
            u = d9;
        }
        if (A) {
            s *= 0.5D;
            t *= 0.5D;
            u *= 0.5D;
        }
        c(s, t, u);
        double d12 = Math.sqrt(s * s + u * u);

        if (d12 > 0.14999999999999999D) {
            double d14 = Math.cos(((double) v * 3.1415926535897931D) / 180D);
            double d16 = Math.sin(((double) v * 3.1415926535897931D) / 180D);

            for (int l = 0; (double) l < 1.0D + d12 * 60D; l++) {
                double d18 = W.nextFloat() * 2.0F - 1.0F;
                double d19 = (double) (W.nextInt(2) * 2 - 1) * 0.69999999999999996D;

                if (W.nextBoolean()) {
                    double d20 = (p - d14 * d18 * 0.80000000000000004D) + d16 * d19;
                    double d22 = r - d16 * d18 * 0.80000000000000004D - d14 * d19;

                    this.l.a("splash", d20, q - 0.125D, d22, s, t, u);
                } else {
                    double d21 = p + d14 + d16 * d18 * 0.69999999999999996D;
                    double d23 = (r + d16) - d14 * d18 * 0.69999999999999996D;

                    this.l.a("splash", d21, q - 0.125D, d23, s, t, u);
                }
            }
        }
        if (B && d12 > 0.14999999999999999D) {
            if (!this.l.z) {
                q();
                for (int i1 = 0; i1 < 3; i1++) {
                    a(Block.x.bi, 1, 0.0F);
                }

                for (int j1 = 0; j1 < 2; j1++) {
                    a(Item.B.ba, 1, 0.0F);
                }
            }
        } else {
            s *= 0.99000000953674316D;
            t *= 0.94999998807907104D;
            u *= 0.99000000953674316D;
        }
        w = 0.0F;
        double d15 = v;
        double d17 = m - p;
        double d24 = o - r;

        if (d17 * d17 + d24 * d24 > 0.001D) {
            d15 = (float) ((Math.atan2(d24, d17) * 180D) / 3.1415926535897931D);
        }
        double d25;

        for (d25 = d15 - (double) v; d25 >= 180D; d25 -= 360D) {
            ;
        }
        for (; d25 < -180D; d25 += 360D) {
            ;
        }
        if (d25 > 20D) {
            d25 = 20D;
        }
        if (d25 < -20D) {
            d25 = -20D;
        }
        v += ((float) (d25));
        b(v, w);

        // CraftBukkit start
        CraftServer server = ((WorldServer)l).getServer();
        VehicleMoveEvent event = new VehicleMoveEvent(Type.VEHICLE_MOVE, (Vehicle) this.getBukkitEntity(), new Location(((WorldServer)l).getWorld(), prevX, prevY, prevZ, prevYaw, prevPitch), new Location(((WorldServer)l).getWorld(), p, q, r, v, w));
        server.getPluginManager().callEvent(event);
        // CraftBukkit end

        List list = this.l.b(((Entity) (this)), z.b(0.20000000298023224D, 0.0D, 0.20000000298023224D));

        if (list != null && list.size() > 0) {
            for (int k1 = 0; k1 < list.size(); k1++) {
                Entity entity = (Entity) list.get(k1);

                if (entity != this.j && entity.z() && (entity instanceof EntityBoat)) {
                    entity.c(((Entity) (this)));
                }
            }
        }
        if (this.j != null && this.j.G) {
            this.j = null;
        }
    }

    public void E() {
        if (j == null) {
            return;
        } else {
            double d1 = Math.cos(((double) v * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
            double d2 = Math.sin(((double) v * 3.1415926535897931D) / 180D) * 0.40000000000000002D;

            j.a(p + d1, q + k() + j.F(), r + d2);
            return;
        }
    }

    // CraftBukkit start
    public void c(Entity entity) {
        CraftServer server = ((WorldServer)l).getServer();
        VehicleEntityCollisionEvent collsionEvent = new VehicleEntityCollisionEvent( Type.VEHICLE_COLLISION_ENTITY, (Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
        server.getPluginManager().callEvent(collsionEvent);

        if (collsionEvent.isCancelled()) {
            return;
        }

        super.c(entity);
    }
    // CraftBukkit end

    protected void a(NBTTagCompound nbttagcompound) {}

    protected void b(NBTTagCompound nbttagcompound) {}

    public boolean a(EntityPlayer entityplayer) {
        if (j != null && (j instanceof EntityPlayer) && j != entityplayer) {
            return true;
        }
        if (!l.z) {
            // CraftBukkit start
            CraftServer server = ((WorldServer)l).getServer();
            VehicleEnterEvent event = new VehicleEnterEvent( Type.VEHICLE_ENTER, (Vehicle) this.getBukkitEntity(), entityplayer.getBukkitEntity());
            server.getPluginManager().callEvent(event);

            if (event.isCancelled()) {
                return true;
            }
            // CraftBukkit end

            entityplayer.e(((Entity) (this)));
        }
        return true;
    }
}