Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 432 lines 14 kB view raw
1package net.minecraft.server; 2 3import org.bukkit.Location; 4import org.bukkit.entity.Vehicle; 5import org.bukkit.event.vehicle.*; 6 7import uk.betacraft.uberbukkit.UberbukkitConfig; 8 9import java.util.List; 10 11// CraftBukkit start 12// CraftBukkit end 13 14public class EntityBoat extends Entity { 15 16 public int damage; 17 public int b; 18 public int c; 19 private int d; 20 private double e; 21 private double f; 22 private double g; 23 private double h; 24 private double i; 25 26 // CraftBukkit start 27 public double maxSpeed = 0.4D; 28 29 @Override 30 public void collide(Entity entity) { 31 org.bukkit.entity.Entity hitEntity = (entity == null) ? null : entity.getBukkitEntity(); 32 33 VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), hitEntity); 34 this.world.getServer().getPluginManager().callEvent(event); 35 36 if (event.isCancelled()) { 37 return; 38 } 39 40 super.collide(entity); 41 } 42 // CraftBukkit end 43 44 public EntityBoat(World world) { 45 super(world); 46 this.damage = 0; 47 this.b = 0; 48 this.c = 1; 49 this.aI = true; 50 this.b(1.5F, 0.6F); 51 this.height = this.width / 2.0F; 52 } 53 54 protected boolean n() { 55 return false; 56 } 57 58 protected void b() { 59 } 60 61 public AxisAlignedBB a_(Entity entity) { 62 return entity.boundingBox; 63 } 64 65 public AxisAlignedBB e_() { 66 return this.boundingBox; 67 } 68 69 public boolean d_() { 70 return true; 71 } 72 73 public EntityBoat(World world, double d0, double d1, double d2) { 74 this(world); 75 this.setPosition(d0, d1 + (double) this.height, d2); 76 this.motX = 0.0D; 77 this.motY = 0.0D; 78 this.motZ = 0.0D; 79 this.lastX = d0; 80 this.lastY = d1; 81 this.lastZ = d2; 82 83 this.world.getServer().getPluginManager().callEvent(new VehicleCreateEvent((Vehicle) this.getBukkitEntity())); // CraftBukkit 84 } 85 86 public double m() { 87 return (double) this.width * 0.0D - 0.30000001192092896D; 88 } 89 90 public boolean damageEntity(Entity entity, int i) { 91 if (!this.world.isStatic && !this.dead) { 92 // CraftBukkit start 93 Vehicle vehicle = (Vehicle) this.getBukkitEntity(); 94 org.bukkit.entity.Entity attacker = (entity == null) ? null : entity.getBukkitEntity(); 95 96 VehicleDamageEvent event = new VehicleDamageEvent(vehicle, attacker, i); 97 this.world.getServer().getPluginManager().callEvent(event); 98 99 if (event.isCancelled()) { 100 return true; 101 } 102 // i = event.getDamage(); // TODO Why don't we do this? 103 // CraftBukkit end 104 105 this.c = -this.c; 106 this.b = 10; 107 this.damage += i * 10; 108 this.af(); 109 if (this.damage > 40) { 110 111 // CraftBukkit start 112 VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker); 113 this.world.getServer().getPluginManager().callEvent(destroyEvent); 114 115 if (destroyEvent.isCancelled()) { 116 this.damage = 40; // Maximize damage so this doesn't get triggered again right away 117 return true; 118 } 119 // CraftBukkit end 120 121 if (this.passenger != null) { 122 this.passenger.mount(this); 123 } 124 125 // uberbukkit - drop boat on damage, not planks & sticks 126 if (!UberbukkitConfig.getInstance().getBoolean("mechanics.boats.drop_boat_not_wood", false)) { 127 int j; 128 129 for (j = 0; j < 3; ++j) { 130 this.a(Block.WOOD.id, 1, 0.0F); 131 } 132 133 for (j = 0; j < 2; ++j) { 134 this.a(Item.STICK.id, 1, 0.0F); 135 } 136 } else { 137 this.a(Item.BOAT.id, 1, 0.0F); 138 } 139 140 this.die(); 141 } 142 143 return true; 144 } else { 145 return true; 146 } 147 } 148 149 public boolean l_() { 150 return !this.dead; 151 } 152 153 public void m_() { 154 // CraftBukkit start 155 double prevX = this.locX; 156 double prevY = this.locY; 157 double prevZ = this.locZ; 158 float prevYaw = this.yaw; 159 float prevPitch = this.pitch; 160 // CraftBukkit end 161 162 super.m_(); 163 if (this.b > 0) { 164 --this.b; 165 } 166 167 if (this.damage > 0) { 168 --this.damage; 169 } 170 171 this.lastX = this.locX; 172 this.lastY = this.locY; 173 this.lastZ = this.locZ; 174 byte b0 = 5; 175 double d0 = 0.0D; 176 177 for (int i = 0; i < b0; ++i) { 178 double d1 = this.boundingBox.b + (this.boundingBox.e - this.boundingBox.b) * (double) (i + 0) / (double) b0 - 0.125D; 179 double d2 = this.boundingBox.b + (this.boundingBox.e - this.boundingBox.b) * (double) (i + 1) / (double) b0 - 0.125D; 180 AxisAlignedBB axisalignedbb = AxisAlignedBB.b(this.boundingBox.a, d1, this.boundingBox.c, this.boundingBox.d, d2, this.boundingBox.f); 181 182 if (this.world.b(axisalignedbb, Material.WATER)) { 183 d0 += 1.0D / (double) b0; 184 } 185 } 186 187 double d3; 188 double d4; 189 double d5; 190 double d6; 191 192 if (this.world.isStatic) { 193 if (this.d > 0) { 194 d3 = this.locX + (this.e - this.locX) / (double) this.d; 195 d4 = this.locY + (this.f - this.locY) / (double) this.d; 196 d5 = this.locZ + (this.g - this.locZ) / (double) this.d; 197 198 for (d6 = this.h - (double) this.yaw; d6 < -180.0D; d6 += 360.0D) { 199 ; 200 } 201 202 while (d6 >= 180.0D) { 203 d6 -= 360.0D; 204 } 205 206 this.yaw = (float) ((double) this.yaw + d6 / (double) this.d); 207 this.pitch = (float) ((double) this.pitch + (this.i - (double) this.pitch) / (double) this.d); 208 --this.d; 209 this.setPosition(d3, d4, d5); 210 this.c(this.yaw, this.pitch); 211 } else { 212 d3 = this.locX + this.motX; 213 d4 = this.locY + this.motY; 214 d5 = this.locZ + this.motZ; 215 this.setPosition(d3, d4, d5); 216 if (this.onGround) { 217 this.motX *= 0.5D; 218 this.motY *= 0.5D; 219 this.motZ *= 0.5D; 220 } 221 222 this.motX *= 0.9900000095367432D; 223 this.motY *= 0.949999988079071D; 224 this.motZ *= 0.9900000095367432D; 225 } 226 } else { 227 if (d0 < 1.0D) { 228 d3 = d0 * 2.0D - 1.0D; 229 this.motY += 0.03999999910593033D * d3; 230 } else { 231 if (this.motY < 0.0D) { 232 this.motY /= 2.0D; 233 } 234 235 this.motY += 0.007000000216066837D; 236 } 237 238 if (this.passenger != null) { 239 this.motX += this.passenger.motX * 0.2D; 240 this.motZ += this.passenger.motZ * 0.2D; 241 } 242 243 // CraftBukkit 244 d3 = this.maxSpeed; 245 if (this.motX < -d3) { 246 this.motX = -d3; 247 } 248 249 if (this.motX > d3) { 250 this.motX = d3; 251 } 252 253 if (this.motZ < -d3) { 254 this.motZ = -d3; 255 } 256 257 if (this.motZ > d3) { 258 this.motZ = d3; 259 } 260 261 if (this.onGround) { 262 this.motX *= 0.5D; 263 this.motY *= 0.5D; 264 this.motZ *= 0.5D; 265 } 266 267 this.move(this.motX, this.motY, this.motZ); 268 d4 = Math.sqrt(this.motX * this.motX + this.motZ * this.motZ); 269 if (d4 > 0.15D) { 270 d5 = Math.cos((double) this.yaw * 3.141592653589793D / 180.0D); 271 d6 = Math.sin((double) this.yaw * 3.141592653589793D / 180.0D); 272 273 for (int j = 0; (double) j < 1.0D + d4 * 60.0D; ++j) { 274 double d7 = (double) (this.random.nextFloat() * 2.0F - 1.0F); 275 double d8 = (double) (this.random.nextInt(2) * 2 - 1) * 0.7D; 276 double d9; 277 double d10; 278 279 if (this.random.nextBoolean()) { 280 d9 = this.locX - d5 * d7 * 0.8D + d6 * d8; 281 d10 = this.locZ - d6 * d7 * 0.8D - d5 * d8; 282 this.world.a("splash", d9, this.locY - 0.125D, d10, this.motX, this.motY, this.motZ); 283 } else { 284 d9 = this.locX + d5 + d6 * d7 * 0.7D; 285 d10 = this.locZ + d6 - d5 * d7 * 0.7D; 286 this.world.a("splash", d9, this.locY - 0.125D, d10, this.motX, this.motY, this.motZ); 287 } 288 } 289 } 290 291 if (this.positionChanged && d4 > 0.15D) { 292 if (!this.world.isStatic) { 293 294 if (UberbukkitConfig.getInstance().getBoolean("mechanics.boat.break_boat_on_collision", true)) { 295 this.die(); 296 297 // uberbukkit - drop boat on damage, not planks & sticks 298 if (!UberbukkitConfig.getInstance().getBoolean("mechanics.boats.drop_boat_not_wood", false)) { 299 int k; 300 301 for (k = 0; k < 3; ++k) { 302 this.a(Block.WOOD.id, 1, 0.0F); 303 } 304 305 for (k = 0; k < 2; ++k) { 306 this.a(Item.STICK.id, 1, 0.0F); 307 } 308 } else { 309 this.a(Item.BOAT.id, 1, 0.0F); 310 } 311 } 312 313 314 } 315 } else { 316 this.motX *= 0.9900000095367432D; 317 this.motY *= 0.949999988079071D; 318 this.motZ *= 0.9900000095367432D; 319 } 320 321 this.pitch = 0.0F; 322 d5 = (double) this.yaw; 323 d6 = this.lastX - this.locX; 324 double d11 = this.lastZ - this.locZ; 325 326 if (d6 * d6 + d11 * d11 > 0.0010D) { 327 d5 = (double) ((float) (Math.atan2(d11, d6) * 180.0D / 3.141592653589793D)); 328 } 329 330 double d12; 331 332 for (d12 = d5 - (double) this.yaw; d12 >= 180.0D; d12 -= 360.0D) { 333 ; 334 } 335 336 while (d12 < -180.0D) { 337 d12 += 360.0D; 338 } 339 340 if (d12 > 20.0D) { 341 d12 = 20.0D; 342 } 343 344 if (d12 < -20.0D) { 345 d12 = -20.0D; 346 } 347 348 this.yaw = (float) ((double) this.yaw + d12); 349 this.c(this.yaw, this.pitch); 350 351 // CraftBukkit start 352 org.bukkit.Server server = this.world.getServer(); 353 org.bukkit.World bworld = this.world.getWorld(); 354 355 Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch); 356 Location to = new Location(bworld, this.locX, this.locY, this.locZ, this.yaw, this.pitch); 357 Vehicle vehicle = (Vehicle) this.getBukkitEntity(); 358 359 server.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle)); 360 361 if (!from.equals(to)) { 362 VehicleMoveEvent event = new VehicleMoveEvent(vehicle, from, to); 363 server.getPluginManager().callEvent(event); 364 } 365 // CraftBukkit end 366 367 List list = this.world.b((Entity) this, this.boundingBox.b(0.20000000298023224D, 0.0D, 0.20000000298023224D)); 368 int l; 369 370 if (list != null && list.size() > 0) { 371 for (l = 0; l < list.size(); ++l) { 372 Entity entity = (Entity) list.get(l); 373 374 if (entity != this.passenger && entity.d_() && entity instanceof EntityBoat) { 375 entity.collide(this); 376 } 377 } 378 } 379 380 for (l = 0; l < 4; ++l) { 381 int i1 = MathHelper.floor(this.locX + ((double) (l % 2) - 0.5D) * 0.8D); 382 int j1 = MathHelper.floor(this.locY); 383 int k1 = MathHelper.floor(this.locZ + ((double) (l / 2) - 0.5D) * 0.8D); 384 385 if (this.world.getTypeId(i1, j1, k1) == Block.SNOW.id) { 386 this.world.setTypeId(i1, j1, k1, 0); 387 } 388 } 389 390 if (this.passenger != null && this.passenger.dead) { 391 this.passenger.vehicle = null; // CraftBukkit 392 this.passenger = null; 393 } 394 } 395 } 396 397 public void f() { 398 if (this.passenger != null) { 399 double d0 = Math.cos((double) this.yaw * 3.141592653589793D / 180.0D) * 0.4D; 400 double d1 = Math.sin((double) this.yaw * 3.141592653589793D / 180.0D) * 0.4D; 401 402 this.passenger.setPosition(this.locX + d0, this.locY + this.m() + this.passenger.I(), this.locZ + d1); 403 } 404 } 405 406 protected void b(NBTTagCompound nbttagcompound) { 407 } 408 409 protected void a(NBTTagCompound nbttagcompound) { 410 } 411 412 public boolean a(EntityHuman entityhuman) { 413 if (this.passenger != null && this.passenger instanceof EntityHuman && this.passenger != entityhuman) { 414 return true; 415 } else { 416 if (!this.world.isStatic) { 417 // CraftBukkit start 418 VehicleEnterEvent event = new VehicleEnterEvent((Vehicle) this.getBukkitEntity(), entityhuman.getBukkitEntity()); 419 this.world.getServer().getPluginManager().callEvent(event); 420 421 if (event.isCancelled()) { 422 return true; 423 } 424 // CraftBukkit end 425 426 entityhuman.mount(this); 427 } 428 429 return true; 430 } 431 } 432}