001 package net.minecraft.entity.item; 002 003 import cpw.mods.fml.relauncher.Side; 004 import cpw.mods.fml.relauncher.SideOnly; 005 006 import java.util.ArrayList; 007 import java.util.List; 008 import net.minecraft.block.Block; 009 import net.minecraft.block.BlockRail; 010 import net.minecraft.entity.Entity; 011 import net.minecraft.entity.EntityLiving; 012 import net.minecraft.entity.monster.EntityIronGolem; 013 import net.minecraft.entity.player.EntityPlayer; 014 import net.minecraft.inventory.IInventory; 015 import net.minecraft.item.Item; 016 import net.minecraft.item.ItemStack; 017 import net.minecraft.nbt.NBTTagCompound; 018 import net.minecraft.nbt.NBTTagList; 019 import net.minecraft.server.MinecraftServer; 020 import net.minecraft.server.gui.IUpdatePlayerListBox; 021 import net.minecraft.util.AxisAlignedBB; 022 import net.minecraft.util.DamageSource; 023 import net.minecraft.util.MathHelper; 024 import net.minecraft.util.Vec3; 025 import net.minecraft.world.World; 026 import net.minecraft.world.WorldServer; 027 028 import net.minecraftforge.common.IMinecartCollisionHandler; 029 import net.minecraftforge.common.MinecartRegistry; 030 import net.minecraftforge.common.MinecraftForge; 031 import net.minecraftforge.event.entity.minecart.*; 032 033 public class EntityMinecart extends Entity implements IInventory 034 { 035 /** Array of item stacks stored in minecart (for storage minecarts). */ 036 protected ItemStack[] cargoItems; 037 protected int fuel; 038 protected boolean field_70499_f; 039 040 /** The type of minecart, 2 for powered, 1 for storage. */ 041 public int minecartType; 042 public double pushX; 043 public double pushZ; 044 protected final IUpdatePlayerListBox field_82344_g; 045 protected boolean field_82345_h; 046 protected static final int[][][] field_70500_g = new int[][][] {{{0, 0, -1}, {0, 0, 1}}, {{ -1, 0, 0}, {1, 0, 0}}, {{ -1, -1, 0}, {1, 0, 0}}, {{ -1, 0, 0}, {1, -1, 0}}, {{0, 0, -1}, {0, -1, 1}}, {{0, -1, -1}, {0, 0, 1}}, {{0, 0, 1}, {1, 0, 0}}, {{0, 0, 1}, { -1, 0, 0}}, {{0, 0, -1}, { -1, 0, 0}}, {{0, 0, -1}, {1, 0, 0}}}; 047 048 /** appears to be the progress of the turn */ 049 protected int turnProgress; 050 protected double minecartX; 051 protected double minecartY; 052 protected double minecartZ; 053 protected double minecartYaw; 054 protected double minecartPitch; 055 @SideOnly(Side.CLIENT) 056 protected double velocityX; 057 @SideOnly(Side.CLIENT) 058 protected double velocityY; 059 @SideOnly(Side.CLIENT) 060 protected double velocityZ; 061 062 /* Forge: Minecart Compatibility Layer Integration. */ 063 public static float defaultMaxSpeedRail = 0.4f; 064 public static float defaultMaxSpeedGround = 0.4f; 065 public static float defaultMaxSpeedAirLateral = 0.4f; 066 public static float defaultMaxSpeedAirVertical = -1f; 067 public static double defaultDragRidden = 0.996999979019165D; 068 public static double defaultDragEmpty = 0.9599999785423279D; 069 public static double defaultDragAir = 0.94999998807907104D; 070 protected boolean canUseRail = true; 071 protected boolean canBePushed = true; 072 private static IMinecartCollisionHandler collisionHandler = null; 073 074 /* Instance versions of the above physics properties */ 075 protected float maxSpeedRail; 076 protected float maxSpeedGround; 077 protected float maxSpeedAirLateral; 078 protected float maxSpeedAirVertical; 079 protected double dragAir; 080 081 public EntityMinecart(World par1World) 082 { 083 super(par1World); 084 this.cargoItems = new ItemStack[36]; 085 this.fuel = 0; 086 this.field_70499_f = false; 087 this.field_82345_h = true; 088 this.preventEntitySpawning = true; 089 this.setSize(0.98F, 0.7F); 090 this.yOffset = this.height / 2.0F; 091 this.field_82344_g = par1World != null ? par1World.func_82735_a(this) : null; 092 093 maxSpeedRail = defaultMaxSpeedRail; 094 maxSpeedGround = defaultMaxSpeedGround; 095 maxSpeedAirLateral = defaultMaxSpeedAirLateral; 096 maxSpeedAirVertical = defaultMaxSpeedAirVertical; 097 dragAir = defaultDragAir; 098 } 099 100 public EntityMinecart(World world, int type) 101 { 102 this(world); 103 minecartType = type; 104 } 105 106 /** 107 * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to 108 * prevent them from trampling crops 109 */ 110 protected boolean canTriggerWalking() 111 { 112 return false; 113 } 114 115 protected void entityInit() 116 { 117 this.dataWatcher.addObject(16, new Byte((byte)0)); 118 this.dataWatcher.addObject(17, new Integer(0)); 119 this.dataWatcher.addObject(18, new Integer(1)); 120 this.dataWatcher.addObject(19, new Integer(0)); 121 } 122 123 /** 124 * Returns a boundingBox used to collide the entity with other entities and blocks. This enables the entity to be 125 * pushable on contact, like boats or minecarts. 126 */ 127 public AxisAlignedBB getCollisionBox(Entity par1Entity) 128 { 129 if (getCollisionHandler() != null) 130 { 131 return getCollisionHandler().getCollisionBox(this, par1Entity); 132 } 133 return par1Entity.canBePushed() ? par1Entity.boundingBox : null; 134 } 135 136 /** 137 * returns the bounding box for this entity 138 */ 139 public AxisAlignedBB getBoundingBox() 140 { 141 if (getCollisionHandler() != null) 142 { 143 return getCollisionHandler().getBoundingBox(this); 144 } 145 return null; 146 } 147 148 /** 149 * Returns true if this entity should push and be pushed by other entities when colliding. 150 */ 151 public boolean canBePushed() 152 { 153 return canBePushed; 154 } 155 156 public EntityMinecart(World par1World, double par2, double par4, double par6, int par8) 157 { 158 this(par1World); 159 this.setPosition(par2, par4 + (double)this.yOffset, par6); 160 this.motionX = 0.0D; 161 this.motionY = 0.0D; 162 this.motionZ = 0.0D; 163 this.prevPosX = par2; 164 this.prevPosY = par4; 165 this.prevPosZ = par6; 166 this.minecartType = par8; 167 } 168 169 /** 170 * Returns the Y offset from the entity's position for any entity riding this one. 171 */ 172 public double getMountedYOffset() 173 { 174 return (double)this.height * 0.0D - 0.30000001192092896D; 175 } 176 177 /** 178 * Called when the entity is attacked. 179 */ 180 public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) 181 { 182 if (!this.worldObj.isRemote && !this.isDead) 183 { 184 if (this.func_85032_ar()) 185 { 186 return false; 187 } 188 else 189 { 190 this.func_70494_i(-this.func_70493_k()); 191 this.func_70497_h(10); 192 this.setBeenAttacked(); 193 this.setDamage(this.getDamage() + par2 * 10); 194 195 if (par1DamageSource.getEntity() instanceof EntityPlayer && ((EntityPlayer)par1DamageSource.getEntity()).capabilities.isCreativeMode) 196 { 197 this.setDamage(100); 198 } 199 200 if (this.getDamage() > 40) 201 { 202 if (this.riddenByEntity != null) 203 { 204 this.riddenByEntity.mountEntity(this); 205 } 206 207 this.setDead(); 208 dropCartAsItem(); 209 } 210 211 return true; 212 } 213 } 214 else 215 { 216 return true; 217 } 218 } 219 220 @SideOnly(Side.CLIENT) 221 222 /** 223 * Setups the entity to do the hurt animation. Only used by packets in multiplayer. 224 */ 225 public void performHurtAnimation() 226 { 227 this.func_70494_i(-this.func_70493_k()); 228 this.func_70497_h(10); 229 this.setDamage(this.getDamage() + this.getDamage() * 10); 230 } 231 232 /** 233 * Returns true if other Entities should be prevented from moving through this Entity. 234 */ 235 public boolean canBeCollidedWith() 236 { 237 return !this.isDead; 238 } 239 240 /** 241 * Will get destroyed next tick. 242 */ 243 public void setDead() 244 { 245 if (this.field_82345_h) 246 { 247 for (int var1 = 0; var1 < this.getSizeInventory(); ++var1) 248 { 249 ItemStack var2 = this.getStackInSlot(var1); 250 251 if (var2 != null) 252 { 253 float var3 = this.rand.nextFloat() * 0.8F + 0.1F; 254 float var4 = this.rand.nextFloat() * 0.8F + 0.1F; 255 float var5 = this.rand.nextFloat() * 0.8F + 0.1F; 256 257 while (var2.stackSize > 0) 258 { 259 int var6 = this.rand.nextInt(21) + 10; 260 261 if (var6 > var2.stackSize) 262 { 263 var6 = var2.stackSize; 264 } 265 266 var2.stackSize -= var6; 267 EntityItem var7 = new EntityItem(this.worldObj, this.posX + (double)var3, this.posY + (double)var4, this.posZ + (double)var5, new ItemStack(var2.itemID, var6, var2.getItemDamage())); 268 269 if (var2.hasTagCompound()) 270 { 271 var7.func_92014_d().setTagCompound((NBTTagCompound)var2.getTagCompound().copy()); 272 } 273 274 float var8 = 0.05F; 275 var7.motionX = (double)((float)this.rand.nextGaussian() * var8); 276 var7.motionY = (double)((float)this.rand.nextGaussian() * var8 + 0.2F); 277 var7.motionZ = (double)((float)this.rand.nextGaussian() * var8); 278 this.worldObj.spawnEntityInWorld(var7); 279 } 280 } 281 } 282 } 283 284 super.setDead(); 285 286 if (this.field_82344_g != null) 287 { 288 this.field_82344_g.update(); 289 } 290 } 291 292 /** 293 * Teleports the entity to another dimension. Params: Dimension number to teleport to 294 */ 295 public void travelToDimension(int par1) 296 { 297 this.field_82345_h = false; 298 super.travelToDimension(par1); 299 } 300 301 /** 302 * Called to update the entity's position/logic. 303 */ 304 public void onUpdate() 305 { 306 if (this.field_82344_g != null) 307 { 308 this.field_82344_g.update(); 309 } 310 311 if (this.func_70496_j() > 0) 312 { 313 this.func_70497_h(this.func_70496_j() - 1); 314 } 315 316 if (this.getDamage() > 0) 317 { 318 this.setDamage(this.getDamage() - 1); 319 } 320 321 if (this.posY < -64.0D) 322 { 323 this.kill(); 324 } 325 326 if (this.isMinecartPowered() && this.rand.nextInt(4) == 0 && minecartType == 2 && getClass() == EntityMinecart.class) 327 { 328 this.worldObj.spawnParticle("largesmoke", this.posX, this.posY + 0.8D, this.posZ, 0.0D, 0.0D, 0.0D); 329 } 330 331 int var2; 332 333 if (!this.worldObj.isRemote && this.worldObj instanceof WorldServer) 334 { 335 this.worldObj.theProfiler.startSection("portal"); 336 MinecraftServer var1 = ((WorldServer)this.worldObj).getMinecraftServer(); 337 var2 = this.getMaxInPortalTime(); 338 339 if (this.inPortal) 340 { 341 if (var1.getAllowNether()) 342 { 343 if (this.ridingEntity == null && this.field_82153_h++ >= var2) 344 { 345 this.field_82153_h = var2; 346 this.timeUntilPortal = this.getPortalCooldown(); 347 byte var3; 348 349 if (this.worldObj.provider.dimensionId == -1) 350 { 351 var3 = 0; 352 } 353 else 354 { 355 var3 = -1; 356 } 357 358 this.travelToDimension(var3); 359 } 360 361 this.inPortal = false; 362 } 363 } 364 else 365 { 366 if (this.field_82153_h > 0) 367 { 368 this.field_82153_h -= 4; 369 } 370 371 if (this.field_82153_h < 0) 372 { 373 this.field_82153_h = 0; 374 } 375 } 376 377 if (this.timeUntilPortal > 0) 378 { 379 --this.timeUntilPortal; 380 } 381 382 this.worldObj.theProfiler.endSection(); 383 } 384 385 if (this.worldObj.isRemote) 386 { 387 if (this.turnProgress > 0) 388 { 389 double var46 = this.posX + (this.minecartX - this.posX) / (double)this.turnProgress; 390 double var48 = this.posY + (this.minecartY - this.posY) / (double)this.turnProgress; 391 double var5 = this.posZ + (this.minecartZ - this.posZ) / (double)this.turnProgress; 392 double var7 = MathHelper.wrapAngleTo180_double(this.minecartYaw - (double)this.rotationYaw); 393 this.rotationYaw = (float)((double)this.rotationYaw + var7 / (double)this.turnProgress); 394 this.rotationPitch = (float)((double)this.rotationPitch + (this.minecartPitch - (double)this.rotationPitch) / (double)this.turnProgress); 395 --this.turnProgress; 396 this.setPosition(var46, var48, var5); 397 this.setRotation(this.rotationYaw, this.rotationPitch); 398 } 399 else 400 { 401 this.setPosition(this.posX, this.posY, this.posZ); 402 this.setRotation(this.rotationYaw, this.rotationPitch); 403 } 404 } 405 else 406 { 407 this.prevPosX = this.posX; 408 this.prevPosY = this.posY; 409 this.prevPosZ = this.posZ; 410 this.motionY -= 0.03999999910593033D; 411 int var45 = MathHelper.floor_double(this.posX); 412 var2 = MathHelper.floor_double(this.posY); 413 int var47 = MathHelper.floor_double(this.posZ); 414 415 if (BlockRail.isRailBlockAt(this.worldObj, var45, var2 - 1, var47)) 416 { 417 --var2; 418 } 419 420 double var4 = 0.4D; 421 double var6 = 0.0078125D; 422 int var8 = this.worldObj.getBlockId(var45, var2, var47); 423 424 if (canUseRail() && BlockRail.isRailBlock(var8)) 425 { 426 this.fallDistance = 0.0F; 427 Vec3 var9 = this.func_70489_a(this.posX, this.posY, this.posZ); 428 int var10 = ((BlockRail)Block.blocksList[var8]).getBasicRailMetadata(worldObj, this, var45, var2, var47); 429 this.posY = (double)var2; 430 boolean var11 = false; 431 boolean var12 = false; 432 433 if (var8 == Block.railPowered.blockID) 434 { 435 var11 = (worldObj.getBlockMetadata(var45, var2, var47) & 8) != 0; 436 var12 = !var11; 437 } 438 439 if (((BlockRail)Block.blocksList[var8]).isPowered()) 440 { 441 var10 &= 7; 442 } 443 444 if (var10 >= 2 && var10 <= 5) 445 { 446 this.posY = (double)(var2 + 1); 447 } 448 449 adjustSlopeVelocities(var10); 450 451 int[][] var13 = field_70500_g[var10]; 452 double var14 = (double)(var13[1][0] - var13[0][0]); 453 double var16 = (double)(var13[1][2] - var13[0][2]); 454 double var18 = Math.sqrt(var14 * var14 + var16 * var16); 455 double var20 = this.motionX * var14 + this.motionZ * var16; 456 457 if (var20 < 0.0D) 458 { 459 var14 = -var14; 460 var16 = -var16; 461 } 462 463 double var22 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); 464 this.motionX = var22 * var14 / var18; 465 this.motionZ = var22 * var16 / var18; 466 double var24; 467 double var26; 468 469 if (this.riddenByEntity != null) 470 { 471 var24 = this.riddenByEntity.motionX * this.riddenByEntity.motionX + this.riddenByEntity.motionZ * this.riddenByEntity.motionZ; 472 var26 = this.motionX * this.motionX + this.motionZ * this.motionZ; 473 474 if (var24 > 1.0E-4D && var26 < 0.01D) 475 { 476 this.motionX += this.riddenByEntity.motionX * 0.1D; 477 this.motionZ += this.riddenByEntity.motionZ * 0.1D; 478 var12 = false; 479 } 480 } 481 482 if (var12 && shouldDoRailFunctions()) 483 { 484 var24 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); 485 486 if (var24 < 0.03D) 487 { 488 this.motionX *= 0.0D; 489 this.motionY *= 0.0D; 490 this.motionZ *= 0.0D; 491 } 492 else 493 { 494 this.motionX *= 0.5D; 495 this.motionY *= 0.0D; 496 this.motionZ *= 0.5D; 497 } 498 } 499 500 var24 = 0.0D; 501 var26 = (double)var45 + 0.5D + (double)var13[0][0] * 0.5D; 502 double var28 = (double)var47 + 0.5D + (double)var13[0][2] * 0.5D; 503 double var30 = (double)var45 + 0.5D + (double)var13[1][0] * 0.5D; 504 double var32 = (double)var47 + 0.5D + (double)var13[1][2] * 0.5D; 505 var14 = var30 - var26; 506 var16 = var32 - var28; 507 double var34; 508 double var36; 509 510 if (var14 == 0.0D) 511 { 512 this.posX = (double)var45 + 0.5D; 513 var24 = this.posZ - (double)var47; 514 } 515 else if (var16 == 0.0D) 516 { 517 this.posZ = (double)var47 + 0.5D; 518 var24 = this.posX - (double)var45; 519 } 520 else 521 { 522 var34 = this.posX - var26; 523 var36 = this.posZ - var28; 524 var24 = (var34 * var14 + var36 * var16) * 2.0D; 525 } 526 527 this.posX = var26 + var14 * var24; 528 this.posZ = var28 + var16 * var24; 529 this.setPosition(this.posX, this.posY + (double)this.yOffset, this.posZ); 530 531 moveMinecartOnRail(var45, var2, var47); 532 533 if (var13[0][1] != 0 && MathHelper.floor_double(this.posX) - var45 == var13[0][0] && MathHelper.floor_double(this.posZ) - var47 == var13[0][2]) 534 { 535 this.setPosition(this.posX, this.posY + (double)var13[0][1], this.posZ); 536 } 537 else if (var13[1][1] != 0 && MathHelper.floor_double(this.posX) - var45 == var13[1][0] && MathHelper.floor_double(this.posZ) - var47 == var13[1][2]) 538 { 539 this.setPosition(this.posX, this.posY + (double)var13[1][1], this.posZ); 540 } 541 542 applyDragAndPushForces(); 543 544 Vec3 var54 = this.func_70489_a(this.posX, this.posY, this.posZ); 545 546 if (var54 != null && var9 != null) 547 { 548 double var39 = (var9.yCoord - var54.yCoord) * 0.05D; 549 var22 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); 550 551 if (var22 > 0.0D) 552 { 553 this.motionX = this.motionX / var22 * (var22 + var39); 554 this.motionZ = this.motionZ / var22 * (var22 + var39); 555 } 556 557 this.setPosition(this.posX, var54.yCoord, this.posZ); 558 } 559 560 int var53 = MathHelper.floor_double(this.posX); 561 int var55 = MathHelper.floor_double(this.posZ); 562 563 if (var53 != var45 || var55 != var47) 564 { 565 var22 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); 566 this.motionX = var22 * (double)(var53 - var45); 567 this.motionZ = var22 * (double)(var55 - var47); 568 } 569 570 double var41; 571 572 updatePushForces(); 573 574 if(shouldDoRailFunctions()) 575 { 576 ((BlockRail)Block.blocksList[var8]).onMinecartPass(worldObj, this, var45, var2, var47); 577 } 578 579 if (var11 && shouldDoRailFunctions()) 580 { 581 var41 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ); 582 583 if (var41 > 0.01D) 584 { 585 double var43 = 0.06D; 586 this.motionX += this.motionX / var41 * var43; 587 this.motionZ += this.motionZ / var41 * var43; 588 } 589 else if (var10 == 1) 590 { 591 if (this.worldObj.isBlockNormalCube(var45 - 1, var2, var47)) 592 { 593 this.motionX = 0.02D; 594 } 595 else if (this.worldObj.isBlockNormalCube(var45 + 1, var2, var47)) 596 { 597 this.motionX = -0.02D; 598 } 599 } 600 else if (var10 == 0) 601 { 602 if (this.worldObj.isBlockNormalCube(var45, var2, var47 - 1)) 603 { 604 this.motionZ = 0.02D; 605 } 606 else if (this.worldObj.isBlockNormalCube(var45, var2, var47 + 1)) 607 { 608 this.motionZ = -0.02D; 609 } 610 } 611 } 612 } 613 else 614 { 615 moveMinecartOffRail(var45, var2, var47); 616 } 617 618 this.doBlockCollisions(); 619 this.rotationPitch = 0.0F; 620 double var49 = this.prevPosX - this.posX; 621 double var50 = this.prevPosZ - this.posZ; 622 623 if (var49 * var49 + var50 * var50 > 0.001D) 624 { 625 this.rotationYaw = (float)(Math.atan2(var50, var49) * 180.0D / Math.PI); 626 627 if (this.field_70499_f) 628 { 629 this.rotationYaw += 180.0F; 630 } 631 } 632 633 double var51 = (double)MathHelper.wrapAngleTo180_float(this.rotationYaw - this.prevRotationYaw); 634 635 if (var51 < -170.0D || var51 >= 170.0D) 636 { 637 this.rotationYaw += 180.0F; 638 this.field_70499_f = !this.field_70499_f; 639 } 640 641 this.setRotation(this.rotationYaw, this.rotationPitch); 642 643 AxisAlignedBB box = null; 644 if (getCollisionHandler() != null) 645 { 646 box = getCollisionHandler().getMinecartCollisionBox(this); 647 } 648 else 649 { 650 box = boundingBox.expand(0.2D, 0.0D, 0.2D); 651 } 652 653 List var15 = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, box); 654 655 if (var15 != null && !var15.isEmpty()) 656 { 657 for (int var52 = 0; var52 < var15.size(); ++var52) 658 { 659 Entity var17 = (Entity)var15.get(var52); 660 661 if (var17 != this.riddenByEntity && var17.canBePushed() && var17 instanceof EntityMinecart) 662 { 663 var17.applyEntityCollision(this); 664 } 665 } 666 } 667 668 if (this.riddenByEntity != null && this.riddenByEntity.isDead) 669 { 670 if (this.riddenByEntity.ridingEntity == this) 671 { 672 this.riddenByEntity.ridingEntity = null; 673 } 674 675 this.riddenByEntity = null; 676 } 677 678 updateFuel(); 679 MinecraftForge.EVENT_BUS.post(new MinecartUpdateEvent(this, var45, var2, var47)); 680 } 681 } 682 683 @SideOnly(Side.CLIENT) 684 public Vec3 func_70495_a(double par1, double par3, double par5, double par7) 685 { 686 int var9 = MathHelper.floor_double(par1); 687 int var10 = MathHelper.floor_double(par3); 688 int var11 = MathHelper.floor_double(par5); 689 690 if (BlockRail.isRailBlockAt(this.worldObj, var9, var10 - 1, var11)) 691 { 692 --var10; 693 } 694 695 int var12 = this.worldObj.getBlockId(var9, var10, var11); 696 697 if (!BlockRail.isRailBlock(var12)) 698 { 699 return null; 700 } 701 else 702 { 703 int var13 = ((BlockRail)Block.blocksList[var12]).getBasicRailMetadata(worldObj, this, var9, var10, var11); 704 705 par3 = (double)var10; 706 707 if (var13 >= 2 && var13 <= 5) 708 { 709 par3 = (double)(var10 + 1); 710 } 711 712 int[][] var14 = field_70500_g[var13]; 713 double var15 = (double)(var14[1][0] - var14[0][0]); 714 double var17 = (double)(var14[1][2] - var14[0][2]); 715 double var19 = Math.sqrt(var15 * var15 + var17 * var17); 716 var15 /= var19; 717 var17 /= var19; 718 par1 += var15 * par7; 719 par5 += var17 * par7; 720 721 if (var14[0][1] != 0 && MathHelper.floor_double(par1) - var9 == var14[0][0] && MathHelper.floor_double(par5) - var11 == var14[0][2]) 722 { 723 par3 += (double)var14[0][1]; 724 } 725 else if (var14[1][1] != 0 && MathHelper.floor_double(par1) - var9 == var14[1][0] && MathHelper.floor_double(par5) - var11 == var14[1][2]) 726 { 727 par3 += (double)var14[1][1]; 728 } 729 730 return this.func_70489_a(par1, par3, par5); 731 } 732 } 733 734 public Vec3 func_70489_a(double par1, double par3, double par5) 735 { 736 int var7 = MathHelper.floor_double(par1); 737 int var8 = MathHelper.floor_double(par3); 738 int var9 = MathHelper.floor_double(par5); 739 740 if (BlockRail.isRailBlockAt(this.worldObj, var7, var8 - 1, var9)) 741 { 742 --var8; 743 } 744 745 int var10 = this.worldObj.getBlockId(var7, var8, var9); 746 747 if (BlockRail.isRailBlock(var10)) 748 { 749 int var11 = ((BlockRail)Block.blocksList[var10]).getBasicRailMetadata(worldObj, this, var7, var8, var9); 750 par3 = (double)var8; 751 752 if (var11 >= 2 && var11 <= 5) 753 { 754 par3 = (double)(var8 + 1); 755 } 756 757 int[][] var12 = field_70500_g[var11]; 758 double var13 = 0.0D; 759 double var15 = (double)var7 + 0.5D + (double)var12[0][0] * 0.5D; 760 double var17 = (double)var8 + 0.5D + (double)var12[0][1] * 0.5D; 761 double var19 = (double)var9 + 0.5D + (double)var12[0][2] * 0.5D; 762 double var21 = (double)var7 + 0.5D + (double)var12[1][0] * 0.5D; 763 double var23 = (double)var8 + 0.5D + (double)var12[1][1] * 0.5D; 764 double var25 = (double)var9 + 0.5D + (double)var12[1][2] * 0.5D; 765 double var27 = var21 - var15; 766 double var29 = (var23 - var17) * 2.0D; 767 double var31 = var25 - var19; 768 769 if (var27 == 0.0D) 770 { 771 par1 = (double)var7 + 0.5D; 772 var13 = par5 - (double)var9; 773 } 774 else if (var31 == 0.0D) 775 { 776 par5 = (double)var9 + 0.5D; 777 var13 = par1 - (double)var7; 778 } 779 else 780 { 781 double var33 = par1 - var15; 782 double var35 = par5 - var19; 783 var13 = (var33 * var27 + var35 * var31) * 2.0D; 784 } 785 786 par1 = var15 + var27 * var13; 787 par3 = var17 + var29 * var13; 788 par5 = var19 + var31 * var13; 789 790 if (var29 < 0.0D) 791 { 792 ++par3; 793 } 794 795 if (var29 > 0.0D) 796 { 797 par3 += 0.5D; 798 } 799 800 return this.worldObj.getWorldVec3Pool().getVecFromPool(par1, par3, par5); 801 } 802 else 803 { 804 return null; 805 } 806 } 807 808 /** 809 * (abstract) Protected helper method to write subclass entity data to NBT. 810 */ 811 protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) 812 { 813 par1NBTTagCompound.setInteger("Type", this.minecartType); 814 815 if (isPoweredCart()) 816 { 817 par1NBTTagCompound.setDouble("PushX", this.pushX); 818 par1NBTTagCompound.setDouble("PushZ", this.pushZ); 819 par1NBTTagCompound.setInteger("Fuel", this.fuel); 820 } 821 822 if (getSizeInventory() > 0) 823 { 824 NBTTagList var2 = new NBTTagList(); 825 826 for (int var3 = 0; var3 < this.cargoItems.length; ++var3) 827 { 828 if (this.cargoItems[var3] != null) 829 { 830 NBTTagCompound var4 = new NBTTagCompound(); 831 var4.setByte("Slot", (byte)var3); 832 this.cargoItems[var3].writeToNBT(var4); 833 var2.appendTag(var4); 834 } 835 } 836 837 par1NBTTagCompound.setTag("Items", var2); 838 } 839 } 840 841 /** 842 * (abstract) Protected helper method to read subclass entity data from NBT. 843 */ 844 protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) 845 { 846 this.minecartType = par1NBTTagCompound.getInteger("Type"); 847 848 if (isPoweredCart()) 849 { 850 this.pushX = par1NBTTagCompound.getDouble("PushX"); 851 this.pushZ = par1NBTTagCompound.getDouble("PushZ"); 852 try 853 { 854 this.fuel = par1NBTTagCompound.getInteger("Fuel"); 855 } 856 catch (ClassCastException e) 857 { 858 this.fuel = par1NBTTagCompound.getShort("Fuel"); 859 } 860 } 861 862 if (getSizeInventory() > 0) 863 { 864 NBTTagList var2 = par1NBTTagCompound.getTagList("Items"); 865 this.cargoItems = new ItemStack[this.getSizeInventory()]; 866 867 for (int var3 = 0; var3 < var2.tagCount(); ++var3) 868 { 869 NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3); 870 int var5 = var4.getByte("Slot") & 255; 871 872 if (var5 >= 0 && var5 < this.cargoItems.length) 873 { 874 this.cargoItems[var5] = ItemStack.loadItemStackFromNBT(var4); 875 } 876 } 877 } 878 } 879 880 @SideOnly(Side.CLIENT) 881 public float getShadowSize() 882 { 883 return 0.0F; 884 } 885 886 /** 887 * Applies a velocity to each of the entities pushing them away from each other. Args: entity 888 */ 889 public void applyEntityCollision(Entity par1Entity) 890 { 891 MinecraftForge.EVENT_BUS.post(new MinecartCollisionEvent(this, par1Entity)); 892 if (getCollisionHandler() != null) 893 { 894 getCollisionHandler().onEntityCollision(this, par1Entity); 895 return; 896 } 897 if (!this.worldObj.isRemote) 898 { 899 if (par1Entity != this.riddenByEntity) 900 { 901 if (par1Entity instanceof EntityLiving && !(par1Entity instanceof EntityPlayer) && !(par1Entity instanceof EntityIronGolem) && canBeRidden() && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.01D && this.riddenByEntity == null && par1Entity.ridingEntity == null) 902 { 903 par1Entity.mountEntity(this); 904 } 905 906 double var2 = par1Entity.posX - this.posX; 907 double var4 = par1Entity.posZ - this.posZ; 908 double var6 = var2 * var2 + var4 * var4; 909 910 if (var6 >= 9.999999747378752E-5D) 911 { 912 var6 = (double)MathHelper.sqrt_double(var6); 913 var2 /= var6; 914 var4 /= var6; 915 double var8 = 1.0D / var6; 916 917 if (var8 > 1.0D) 918 { 919 var8 = 1.0D; 920 } 921 922 var2 *= var8; 923 var4 *= var8; 924 var2 *= 0.10000000149011612D; 925 var4 *= 0.10000000149011612D; 926 var2 *= (double)(1.0F - this.entityCollisionReduction); 927 var4 *= (double)(1.0F - this.entityCollisionReduction); 928 var2 *= 0.5D; 929 var4 *= 0.5D; 930 931 if (par1Entity instanceof EntityMinecart) 932 { 933 double var10 = par1Entity.posX - this.posX; 934 double var12 = par1Entity.posZ - this.posZ; 935 Vec3 var14 = this.worldObj.getWorldVec3Pool().getVecFromPool(var10, 0.0D, var12).normalize(); 936 Vec3 var15 = this.worldObj.getWorldVec3Pool().getVecFromPool((double)MathHelper.cos(this.rotationYaw * (float)Math.PI / 180.0F), 0.0D, (double)MathHelper.sin(this.rotationYaw * (float)Math.PI / 180.0F)).normalize(); 937 double var16 = Math.abs(var14.dotProduct(var15)); 938 939 if (var16 < 0.800000011920929D) 940 { 941 return; 942 } 943 944 double var18 = par1Entity.motionX + this.motionX; 945 double var20 = par1Entity.motionZ + this.motionZ; 946 947 if (((EntityMinecart)par1Entity).isPoweredCart() && !isPoweredCart()) 948 { 949 this.motionX *= 0.20000000298023224D; 950 this.motionZ *= 0.20000000298023224D; 951 this.addVelocity(par1Entity.motionX - var2, 0.0D, par1Entity.motionZ - var4); 952 par1Entity.motionX *= 0.949999988079071D; 953 par1Entity.motionZ *= 0.949999988079071D; 954 } 955 else if (!((EntityMinecart)par1Entity).isPoweredCart() && isPoweredCart()) 956 { 957 par1Entity.motionX *= 0.20000000298023224D; 958 par1Entity.motionZ *= 0.20000000298023224D; 959 par1Entity.addVelocity(this.motionX + var2, 0.0D, this.motionZ + var4); 960 this.motionX *= 0.949999988079071D; 961 this.motionZ *= 0.949999988079071D; 962 } 963 else 964 { 965 var18 /= 2.0D; 966 var20 /= 2.0D; 967 this.motionX *= 0.20000000298023224D; 968 this.motionZ *= 0.20000000298023224D; 969 this.addVelocity(var18 - var2, 0.0D, var20 - var4); 970 par1Entity.motionX *= 0.20000000298023224D; 971 par1Entity.motionZ *= 0.20000000298023224D; 972 par1Entity.addVelocity(var18 + var2, 0.0D, var20 + var4); 973 } 974 } 975 else 976 { 977 this.addVelocity(-var2, 0.0D, -var4); 978 par1Entity.addVelocity(var2 / 4.0D, 0.0D, var4 / 4.0D); 979 } 980 } 981 } 982 } 983 } 984 985 /** 986 * Returns the number of slots in the inventory. 987 */ 988 public int getSizeInventory() 989 { 990 return (minecartType == 1 && getClass() == EntityMinecart.class ? 27 : 0); 991 } 992 993 /** 994 * Returns the stack in slot i 995 */ 996 public ItemStack getStackInSlot(int par1) 997 { 998 return this.cargoItems[par1]; 999 } 1000 1001 /** 1002 * Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a 1003 * new stack. 1004 */ 1005 public ItemStack decrStackSize(int par1, int par2) 1006 { 1007 if (this.cargoItems[par1] != null) 1008 { 1009 ItemStack var3; 1010 1011 if (this.cargoItems[par1].stackSize <= par2) 1012 { 1013 var3 = this.cargoItems[par1]; 1014 this.cargoItems[par1] = null; 1015 return var3; 1016 } 1017 else 1018 { 1019 var3 = this.cargoItems[par1].splitStack(par2); 1020 1021 if (this.cargoItems[par1].stackSize == 0) 1022 { 1023 this.cargoItems[par1] = null; 1024 } 1025 1026 return var3; 1027 } 1028 } 1029 else 1030 { 1031 return null; 1032 } 1033 } 1034 1035 /** 1036 * When some containers are closed they call this on each slot, then drop whatever it returns as an EntityItem - 1037 * like when you close a workbench GUI. 1038 */ 1039 public ItemStack getStackInSlotOnClosing(int par1) 1040 { 1041 if (this.cargoItems[par1] != null) 1042 { 1043 ItemStack var2 = this.cargoItems[par1]; 1044 this.cargoItems[par1] = null; 1045 return var2; 1046 } 1047 else 1048 { 1049 return null; 1050 } 1051 } 1052 1053 /** 1054 * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). 1055 */ 1056 public void setInventorySlotContents(int par1, ItemStack par2ItemStack) 1057 { 1058 this.cargoItems[par1] = par2ItemStack; 1059 1060 if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) 1061 { 1062 par2ItemStack.stackSize = this.getInventoryStackLimit(); 1063 } 1064 } 1065 1066 /** 1067 * Returns the name of the inventory. 1068 */ 1069 public String getInvName() 1070 { 1071 return "container.minecart"; 1072 } 1073 1074 /** 1075 * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't 1076 * this more of a set than a get?* 1077 */ 1078 public int getInventoryStackLimit() 1079 { 1080 return 64; 1081 } 1082 1083 /** 1084 * Called when an the contents of an Inventory change, usually 1085 */ 1086 public void onInventoryChanged() {} 1087 1088 /** 1089 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. 1090 */ 1091 public boolean interact(EntityPlayer par1EntityPlayer) 1092 { 1093 if (MinecraftForge.EVENT_BUS.post(new MinecartInteractEvent(this, par1EntityPlayer))) 1094 { 1095 return true; 1096 } 1097 1098 if (canBeRidden()) 1099 { 1100 if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != par1EntityPlayer) 1101 { 1102 return true; 1103 } 1104 1105 if (!this.worldObj.isRemote) 1106 { 1107 par1EntityPlayer.mountEntity(this); 1108 } 1109 } 1110 else if (getSizeInventory() > 0) 1111 { 1112 if (!this.worldObj.isRemote) 1113 { 1114 par1EntityPlayer.displayGUIChest(this); 1115 } 1116 } 1117 else if (this.minecartType == 2 && getClass() == EntityMinecart.class) 1118 { 1119 ItemStack var2 = par1EntityPlayer.inventory.getCurrentItem(); 1120 1121 if (var2 != null && var2.itemID == Item.coal.shiftedIndex) 1122 { 1123 if (--var2.stackSize == 0) 1124 { 1125 par1EntityPlayer.inventory.setInventorySlotContents(par1EntityPlayer.inventory.currentItem, (ItemStack)null); 1126 } 1127 1128 this.fuel += 3600; 1129 } 1130 1131 this.pushX = this.posX - par1EntityPlayer.posX; 1132 this.pushZ = this.posZ - par1EntityPlayer.posZ; 1133 } 1134 1135 return true; 1136 } 1137 1138 @SideOnly(Side.CLIENT) 1139 1140 /** 1141 * Sets the position and rotation. Only difference from the other one is no bounding on the rotation. Args: posX, 1142 * posY, posZ, yaw, pitch 1143 */ 1144 public void setPositionAndRotation2(double par1, double par3, double par5, float par7, float par8, int par9) 1145 { 1146 this.minecartX = par1; 1147 this.minecartY = par3; 1148 this.minecartZ = par5; 1149 this.minecartYaw = (double)par7; 1150 this.minecartPitch = (double)par8; 1151 this.turnProgress = par9 + 2; 1152 this.motionX = this.velocityX; 1153 this.motionY = this.velocityY; 1154 this.motionZ = this.velocityZ; 1155 } 1156 1157 @SideOnly(Side.CLIENT) 1158 1159 /** 1160 * Sets the velocity to the args. Args: x, y, z 1161 */ 1162 public void setVelocity(double par1, double par3, double par5) 1163 { 1164 this.velocityX = this.motionX = par1; 1165 this.velocityY = this.motionY = par3; 1166 this.velocityZ = this.motionZ = par5; 1167 } 1168 1169 /** 1170 * Do not make give this method the name canInteractWith because it clashes with Container 1171 */ 1172 public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) 1173 { 1174 return this.isDead ? false : par1EntityPlayer.getDistanceSqToEntity(this) <= 64.0D; 1175 } 1176 1177 /** 1178 * Is this minecart powered (Fuel > 0) 1179 */ 1180 public boolean isMinecartPowered() 1181 { 1182 return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0; 1183 } 1184 1185 /** 1186 * Set if this minecart is powered (Fuel > 0) 1187 */ 1188 protected void setMinecartPowered(boolean par1) 1189 { 1190 if (par1) 1191 { 1192 this.dataWatcher.updateObject(16, Byte.valueOf((byte)(this.dataWatcher.getWatchableObjectByte(16) | 1))); 1193 } 1194 else 1195 { 1196 this.dataWatcher.updateObject(16, Byte.valueOf((byte)(this.dataWatcher.getWatchableObjectByte(16) & -2))); 1197 } 1198 } 1199 1200 public void openChest() {} 1201 1202 public void closeChest() {} 1203 1204 /** 1205 * Sets the current amount of damage the minecart has taken. Decreases over time. The cart breaks when this is over 1206 * 40. 1207 */ 1208 public void setDamage(int par1) 1209 { 1210 this.dataWatcher.updateObject(19, Integer.valueOf(par1)); 1211 } 1212 1213 /** 1214 * Gets the current amount of damage the minecart has taken. Decreases over time. The cart breaks when this is over 1215 * 40. 1216 */ 1217 public int getDamage() 1218 { 1219 return this.dataWatcher.getWatchableObjectInt(19); 1220 } 1221 1222 public void func_70497_h(int par1) 1223 { 1224 this.dataWatcher.updateObject(17, Integer.valueOf(par1)); 1225 } 1226 1227 public int func_70496_j() 1228 { 1229 return this.dataWatcher.getWatchableObjectInt(17); 1230 } 1231 1232 public void func_70494_i(int par1) 1233 { 1234 this.dataWatcher.updateObject(18, Integer.valueOf(par1)); 1235 } 1236 1237 public int func_70493_k() 1238 { 1239 return this.dataWatcher.getWatchableObjectInt(18); 1240 } 1241 1242 /** 1243 * Drops the cart as a item. The exact item dropped is defined by getItemDropped(). 1244 */ 1245 public void dropCartAsItem() 1246 { 1247 for(ItemStack item : getItemsDropped()) 1248 { 1249 entityDropItem(item, 0); 1250 } 1251 } 1252 1253 /** 1254 * Override this to define which items your cart drops when broken. 1255 * This does not include items contained in the inventory, 1256 * that is handled elsewhere. 1257 * @return A list of items dropped. 1258 */ 1259 public List<ItemStack> getItemsDropped() 1260 { 1261 List<ItemStack> items = new ArrayList<ItemStack>(); 1262 items.add(new ItemStack(Item.minecartEmpty)); 1263 1264 switch(minecartType) 1265 { 1266 case 1: 1267 items.add(new ItemStack(Block.chest)); 1268 break; 1269 case 2: 1270 items.add(new ItemStack(Block.stoneOvenIdle)); 1271 break; 1272 } 1273 return items; 1274 } 1275 1276 /** 1277 * This function returns an ItemStack that represents this cart. 1278 * This should be an ItemStack that can be used by the player to place the cart. 1279 * This is the item that was registered with the cart via the registerMinecart function, 1280 * but is not necessary the item the cart drops when destroyed. 1281 * @return An ItemStack that can be used to place the cart. 1282 */ 1283 public ItemStack getCartItem() 1284 { 1285 return MinecartRegistry.getItemForCart(this); 1286 } 1287 1288 /** 1289 * Returns true if this cart is self propelled. 1290 * @return True if powered. 1291 */ 1292 public boolean isPoweredCart() 1293 { 1294 return minecartType == 2 && getClass() == EntityMinecart.class; 1295 } 1296 1297 /** 1298 * Returns true if this cart is a storage cart 1299 * Some carts may have inventories but not be storage carts 1300 * and some carts without inventories may be storage carts. 1301 * @return True if this cart should be classified as a storage cart. 1302 */ 1303 public boolean isStorageCart() 1304 { 1305 return minecartType == 1 && getClass() == EntityMinecart.class; 1306 } 1307 1308 /** 1309 * Returns true if this cart can be ridden by an Entity. 1310 * @return True if this cart can be ridden. 1311 */ 1312 public boolean canBeRidden() 1313 { 1314 if(minecartType == 0 && getClass() == EntityMinecart.class) 1315 { 1316 return true; 1317 } 1318 return false; 1319 } 1320 1321 /** 1322 * Returns true if this cart can currently use rails. 1323 * This function is mainly used to gracefully detach a minecart from a rail. 1324 * @return True if the minecart can use rails. 1325 */ 1326 public boolean canUseRail() 1327 { 1328 return canUseRail; 1329 } 1330 1331 /** 1332 * Set whether the minecart can use rails. 1333 * This function is mainly used to gracefully detach a minecart from a rail. 1334 * @param use Whether the minecart can currently use rails. 1335 */ 1336 public void setCanUseRail(boolean use) 1337 { 1338 canUseRail = use; 1339 } 1340 1341 /** 1342 * Return false if this cart should not call IRail.onMinecartPass() and should ignore Powered Rails. 1343 * @return True if this cart should call IRail.onMinecartPass(). 1344 */ 1345 public boolean shouldDoRailFunctions() 1346 { 1347 return true; 1348 } 1349 1350 /** 1351 * Simply returns the minecartType variable. 1352 * @return minecartType 1353 */ 1354 public int getMinecartType() 1355 { 1356 return minecartType; 1357 } 1358 1359 /** 1360 * Gets the current global Minecart Collision handler if none 1361 * is registered, returns null 1362 * @return The collision handler or null 1363 */ 1364 public static IMinecartCollisionHandler getCollisionHandler() 1365 { 1366 return collisionHandler; 1367 } 1368 1369 /** 1370 * Sets the global Minecart Collision handler, overwrites any 1371 * that is currently set. 1372 * @param handler The new handler 1373 */ 1374 public static void setCollisionHandler(IMinecartCollisionHandler handler) 1375 { 1376 collisionHandler = handler; 1377 } 1378 1379 /** 1380 * Carts should return their drag factor here 1381 * @return The drag rate. 1382 */ 1383 protected double getDrag() 1384 { 1385 return riddenByEntity != null ? defaultDragRidden : defaultDragEmpty; 1386 } 1387 1388 /** 1389 * Moved to allow overrides. 1390 * This code applies drag and updates push forces. 1391 */ 1392 protected void applyDragAndPushForces() 1393 { 1394 if(isPoweredCart()) 1395 { 1396 double d27 = MathHelper.sqrt_double(pushX * pushX + pushZ * pushZ); 1397 if(d27 > 0.01D) 1398 { 1399 pushX /= d27; 1400 pushZ /= d27; 1401 double d29 = 0.04; 1402 motionX *= 0.8D; 1403 motionY *= 0.0D; 1404 motionZ *= 0.8D; 1405 motionX += pushX * d29; 1406 motionZ += pushZ * d29; 1407 } 1408 else 1409 { 1410 motionX *= 0.9D; 1411 motionY *= 0.0D; 1412 motionZ *= 0.9D; 1413 } 1414 } 1415 motionX *= getDrag(); 1416 motionY *= 0.0D; 1417 motionZ *= getDrag(); 1418 } 1419 1420 /** 1421 * Moved to allow overrides. 1422 * This code updates push forces. 1423 */ 1424 protected void updatePushForces() 1425 { 1426 if(isPoweredCart()) 1427 { 1428 double push = MathHelper.sqrt_double(pushX * pushX + pushZ * pushZ); 1429 if(push > 0.01D && motionX * motionX + motionZ * motionZ > 0.001D) 1430 { 1431 pushX /= push; 1432 pushZ /= push; 1433 if(pushX * motionX + pushZ * motionZ < 0.0D) 1434 { 1435 pushX = 0.0D; 1436 pushZ = 0.0D; 1437 } 1438 else 1439 { 1440 pushX = motionX; 1441 pushZ = motionZ; 1442 } 1443 } 1444 } 1445 } 1446 1447 /** 1448 * Moved to allow overrides. 1449 * This code handles minecart movement and speed capping when on a rail. 1450 */ 1451 protected void moveMinecartOnRail(int i, int j, int k) 1452 { 1453 int id = worldObj.getBlockId(i, j, k); 1454 if (!BlockRail.isRailBlock(id)) 1455 { 1456 return; 1457 } 1458 float railMaxSpeed = ((BlockRail)Block.blocksList[id]).getRailMaxSpeed(worldObj, this, i, j, k); 1459 1460 double maxSpeed = Math.min(railMaxSpeed, getMaxSpeedRail()); 1461 double mX = motionX; 1462 double mZ = motionZ; 1463 if(riddenByEntity != null) 1464 { 1465 mX *= 0.75D; 1466 mZ *= 0.75D; 1467 } 1468 if(mX < -maxSpeed) mX = -maxSpeed; 1469 if(mX > maxSpeed) mX = maxSpeed; 1470 if(mZ < -maxSpeed) mZ = -maxSpeed; 1471 if(mZ > maxSpeed) mZ = maxSpeed; 1472 moveEntity(mX, 0.0D, mZ); 1473 } 1474 1475 /** 1476 * Moved to allow overrides. 1477 * This code handles minecart movement and speed capping when not on a rail. 1478 */ 1479 protected void moveMinecartOffRail(int i, int j, int k) 1480 { 1481 double d2 = getMaxSpeedGround(); 1482 if(!onGround) 1483 { 1484 d2 = getMaxSpeedAirLateral(); 1485 } 1486 if(motionX < -d2) motionX = -d2; 1487 if(motionX > d2) motionX = d2; 1488 if(motionZ < -d2) motionZ = -d2; 1489 if(motionZ > d2) motionZ = d2; 1490 double moveY = motionY; 1491 if(getMaxSpeedAirVertical() > 0 && motionY > getMaxSpeedAirVertical()) 1492 { 1493 moveY = getMaxSpeedAirVertical(); 1494 if(Math.abs(motionX) < 0.3f && Math.abs(motionZ) < 0.3f) 1495 { 1496 moveY = 0.15f; 1497 motionY = moveY; 1498 } 1499 } 1500 if(onGround) 1501 { 1502 motionX *= 0.5D; 1503 motionY *= 0.5D; 1504 motionZ *= 0.5D; 1505 } 1506 moveEntity(motionX, moveY, motionZ); 1507 if(!onGround) 1508 { 1509 motionX *= getDragAir(); 1510 motionY *= getDragAir(); 1511 motionZ *= getDragAir(); 1512 } 1513 } 1514 1515 /** 1516 * Moved to allow overrides. 1517 * This code applies fuel consumption. 1518 */ 1519 protected void updateFuel() 1520 { 1521 if (fuel > 0) fuel--; 1522 if (fuel <= 0) pushX = pushZ = 0.0D; 1523 setMinecartPowered(fuel > 0); 1524 } 1525 1526 /** 1527 * Moved to allow overrides, This code handle slopes affecting velocity. 1528 * @param metadata The blocks position metadata 1529 */ 1530 protected void adjustSlopeVelocities(int metadata) 1531 { 1532 double acceleration = 0.0078125D; 1533 if (metadata == 2) 1534 { 1535 motionX -= acceleration; 1536 } 1537 else if (metadata == 3) 1538 { 1539 motionX += acceleration; 1540 } 1541 else if (metadata == 4) 1542 { 1543 motionZ += acceleration; 1544 } 1545 else if (metadata == 5) 1546 { 1547 motionZ -= acceleration; 1548 } 1549 } 1550 1551 /** 1552 * Getters/setters for physics variables 1553 */ 1554 1555 /** 1556 * Returns the carts max speed. 1557 * Carts going faster than 1.1 cause issues with chunk loading. 1558 * Carts cant traverse slopes or corners at greater than 0.5 - 0.6. 1559 * This value is compared with the rails max speed to determine 1560 * the carts current max speed. A normal rails max speed is 0.4. 1561 * @return Carts max speed. 1562 */ 1563 public float getMaxSpeedRail() 1564 { 1565 return maxSpeedRail; 1566 } 1567 1568 public void setMaxSpeedRail(float value) 1569 { 1570 maxSpeedRail = value; 1571 } 1572 1573 public float getMaxSpeedGround() 1574 { 1575 return maxSpeedGround; 1576 } 1577 1578 public void setMaxSpeedGround(float value) 1579 { 1580 maxSpeedGround = value; 1581 } 1582 1583 public float getMaxSpeedAirLateral() 1584 { 1585 return maxSpeedAirLateral; 1586 } 1587 1588 public void setMaxSpeedAirLateral(float value) 1589 { 1590 maxSpeedAirLateral = value; 1591 } 1592 1593 public float getMaxSpeedAirVertical() 1594 { 1595 return maxSpeedAirVertical; 1596 } 1597 1598 public void setMaxSpeedAirVertical(float value) 1599 { 1600 maxSpeedAirVertical = value; 1601 } 1602 1603 public double getDragAir() 1604 { 1605 return dragAir; 1606 } 1607 1608 public void setDragAir(double value) 1609 { 1610 dragAir = value; 1611 } 1612 }