summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityBoat.patch
blob: d8caf34c87dce462997ff6e13f6094694d30f814 (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
--- /home/matt/mc-dev-private//net/minecraft/server/EntityBoat.java	2015-02-26 22:40:22.483608141 +0000
+++ src/main/java/net/minecraft/server/EntityBoat.java	2015-02-26 22:40:22.487608140 +0000
@@ -2,6 +2,16 @@
 
 import java.util.List;
 
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.entity.Vehicle;
+import org.bukkit.event.vehicle.VehicleDamageEvent;
+import org.bukkit.event.vehicle.VehicleDestroyEvent;
+import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
+import org.bukkit.event.vehicle.VehicleMoveEvent;
+// CraftBukkit end
+
 public class EntityBoat extends Entity {
 
     private boolean a;
@@ -13,12 +23,35 @@
     private double g;
     private double h;
 
+    // CraftBukkit start
+    public double maxSpeed = 0.4D;
+    public double occupiedDeceleration = 0.2D;
+    public double unoccupiedDeceleration = -1;
+    public boolean landBoats = false;
+
+    @Override
+    public void collide(Entity entity) {
+        org.bukkit.entity.Entity hitEntity = (entity == null) ? null : entity.getBukkitEntity();
+
+        VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), hitEntity);
+        this.world.getServer().getPluginManager().callEvent(event);
+
+        if (event.isCancelled()) {
+            return;
+        }
+
+        super.collide(entity);
+    }
+    // CraftBukkit end
+
     public EntityBoat(World world) {
         super(world);
         this.a = true;
         this.b = 0.07D;
         this.k = true;
         this.setSize(1.5F, 0.6F);
+        
+        this.world.getServer().getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleCreateEvent((Vehicle) this.getBukkitEntity())); // CraftBukkit
     }
 
     protected boolean s_() {
@@ -65,6 +98,19 @@
             if (this.passenger != null && this.passenger == damagesource.getEntity() && damagesource instanceof EntityDamageSourceIndirect) {
                 return false;
             } else {
+                // CraftBukkit start
+                Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+                org.bukkit.entity.Entity attacker = (damagesource.getEntity() == null) ? null : damagesource.getEntity().getBukkitEntity();
+
+                VehicleDamageEvent event = new VehicleDamageEvent(vehicle, attacker, (double) f);
+                this.world.getServer().getPluginManager().callEvent(event);
+
+                if (event.isCancelled()) {
+                    return true;
+                }
+                // f = event.getDamage(); // TODO Why don't we do this?
+                // CraftBukkit end
+
                 this.b(-this.m());
                 this.a(10);
                 this.setDamage(this.j() + f * 10.0F);
@@ -72,6 +118,15 @@
                 boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).abilities.canInstantlyBuild;
 
                 if (flag || this.j() > 40.0F) {
+                    // CraftBukkit start
+                    VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker);
+                    this.world.getServer().getPluginManager().callEvent(destroyEvent);
+
+                    if (destroyEvent.isCancelled()) {
+                        this.setDamage(40F); // Maximize damage so this doesn't get triggered again right away
+                        return true;
+                    }
+                    // CraftBukkit end
                     if (this.passenger != null) {
                         this.passenger.mount(this);
                     }
@@ -95,6 +150,13 @@
     }
 
     public void t_() {
+        // CraftBukkit start
+        double prevX = this.locX;
+        double prevY = this.locY;
+        double prevZ = this.locZ;
+        float prevYaw = this.yaw;
+        float prevPitch = this.pitch;
+        // CraftBukkit end
         super.t_();
         if (this.l() > 0) {
             this.a(this.l() - 1);
@@ -196,6 +258,19 @@
                 this.motX += -Math.sin((double) (f * 3.1415927F / 180.0F)) * this.b * (double) entityliving.ba * 0.05000000074505806D;
                 this.motZ += Math.cos((double) (f * 3.1415927F / 180.0F)) * this.b * (double) entityliving.ba * 0.05000000074505806D;
             }
+            // CraftBukkit start - Support unoccupied deceleration
+            else if (unoccupiedDeceleration >= 0) {
+                this.motX *= unoccupiedDeceleration;
+                this.motZ *= unoccupiedDeceleration;
+                // Kill lingering speed
+                if (motX <= 0.00001) {
+                    motX = 0;
+                }
+                if (motZ <= 0.00001) {
+                    motZ = 0;
+                }
+            }
+            // CraftBukkit end
 
             d4 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ);
             if (d4 > 0.35D) {
@@ -230,16 +305,26 @@
                     Block block = this.world.getType(blockposition).getBlock();
 
                     if (block == Blocks.SNOW_LAYER) {
+                        // CraftBukkit start
+                        if (CraftEventFactory.callEntityChangeBlockEvent(this, l, j1, j, Blocks.AIR, 0).isCancelled()) {
+                            continue;
+                        }
+                        // CraftBukkit end
                         this.world.setAir(blockposition);
                         this.positionChanged = false;
                     } else if (block == Blocks.WATERLILY) {
+                        // CraftBukkit start
+                        if (CraftEventFactory.callEntityChangeBlockEvent(this, l, j1, j, Blocks.AIR, 0).isCancelled()) {
+                            continue;
+                        }
+                        // CraftBukkit end
                         this.world.setAir(blockposition, true);
                         this.positionChanged = false;
                     }
                 }
             }
 
-            if (this.onGround) {
+            if (this.onGround && !this.landBoats) { // CraftBukkit
                 this.motX *= 0.5D;
                 this.motY *= 0.5D;
                 this.motZ *= 0.5D;
@@ -248,6 +333,11 @@
             this.move(this.motX, this.motY, this.motZ);
             if (this.positionChanged && d3 > 0.2975D) {
                 if (!this.world.isClientSide && !this.dead) {
+                    // CraftBukkit start
+                    Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+                    VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, null);
+                    this.world.getServer().getPluginManager().callEvent(destroyEvent);
+                    if (!destroyEvent.isCancelled()) {
                     this.die();
                     if (this.world.getGameRules().getBoolean("doEntityDrops")) {
                         for (k = 0; k < 3; ++k) {
@@ -258,6 +348,7 @@
                             this.a(Items.STICK, 1, 0.0F);
                         }
                     }
+                    } // CraftBukkit end
                 }
             } else {
                 this.motX *= 0.9900000095367432D;
@@ -285,6 +376,22 @@
 
             this.yaw = (float) ((double) this.yaw + d12);
             this.setYawPitch(this.yaw, this.pitch);
+
+            // CraftBukkit start
+            org.bukkit.Server server = this.world.getServer();
+            org.bukkit.World bworld = this.world.getWorld();
+
+            Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
+            Location to = new Location(bworld, this.locX, this.locY, this.locZ, this.yaw, this.pitch);
+            Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+
+            server.getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
+
+            if (!from.equals(to)) {
+                VehicleMoveEvent event = new VehicleMoveEvent(vehicle, from, to);
+                server.getPluginManager().callEvent(event);
+            }
+            // CraftBukkit end
             if (!this.world.isClientSide) {
                 List list = this.world.getEntities(this, this.getBoundingBox().grow(0.20000000298023224D, 0.0D, 0.20000000298023224D));
 
@@ -299,6 +406,7 @@
                 }
 
                 if (this.passenger != null && this.passenger.dead) {
+                    this.passenger.vehicle = null; // CraftBukkit
                     this.passenger = null;
                 }
 
@@ -336,6 +444,11 @@
             if (this.fallDistance > 3.0F) {
                 this.e(this.fallDistance, 1.0F);
                 if (!this.world.isClientSide && !this.dead) {
+                    // CraftBukkit start
+                    Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+                    VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, null);
+                    this.world.getServer().getPluginManager().callEvent(destroyEvent);
+                    if (!destroyEvent.isCancelled()) {
                     this.die();
                     if (this.world.getGameRules().getBoolean("doEntityDrops")) {
                         int i;
@@ -348,6 +461,7 @@
                             this.a(Items.STICK, 1, 0.0F);
                         }
                     }
+                    } // CraftBukkit end
                 }
 
                 this.fallDistance = 0.0F;