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