ZornTaov

EntityTank

Mar 14th, 2011
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.72 KB | None | 0 0
  1. package net.minecraft.src;
  2. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  3. // Jad home page: http://www.kpdus.com/jad.html
  4. // Decompiler options: packimports(3) braces deadcode
  5. import java.io.PrintStream;
  6. import java.util.List;
  7. import java.util.Random;
  8.  
  9. public class EntityTank extends Entity
  10. {
  11.  
  12.     public EntityTank(World world)
  13.     {
  14.         super(world);
  15.         tankCurrentDamage = 0;
  16.         tankTimeSinceHit = 0;
  17.         tankRockDirection = 1;
  18.         preventEntitySpawning = true;
  19.         setSize(3F, 2F);
  20.         yOffset = height / 2.0F;
  21.         entityWalks = false;
  22.     }
  23.  
  24.     protected void entityInit()
  25.     {
  26.     }
  27.  
  28.     public AxisAlignedBB func_383_b_(Entity entity)
  29.     {
  30.         return entity.boundingBox;
  31.     }
  32.  
  33.     public AxisAlignedBB getBoundingBox()
  34.     {
  35.         return boundingBox;
  36.     }
  37.  
  38.     public boolean canBePushed()
  39.     {
  40.         return true;
  41.     }
  42.  
  43.     public EntityTank(World world, double d, double d1, double d2)
  44.     {
  45.         this(world);
  46.         setPosition(d, d1 + (double)yOffset, d2);
  47.         motionX = 0.0D;
  48.         motionY = 0.0D;
  49.         motionZ = 0.0D;
  50.         prevPosX = d;
  51.         prevPosY = d1;
  52.         prevPosZ = d2;
  53.     }
  54.  
  55.     public double getMountedYOffset()
  56.     {
  57.         return (double)height * 0.0D - 0.30000001192092896D;
  58.     }
  59.  
  60.     public boolean attackEntityFrom(Entity entity, int i)
  61.     {
  62.     if(riddenByEntity != null&&riddenByEntity != entity||riddenByEntity == null)
  63.         {
  64.         if(worldObj.multiplayerWorld || isDead)
  65.         {
  66.         return true;
  67.         }
  68.         tankRockDirection = -tankRockDirection;
  69.         tankTimeSinceHit = 10;
  70.         tankCurrentDamage += i * 10;
  71.         setBeenAttacked();
  72.         if(tankCurrentDamage > 80)
  73.         {
  74.            
  75.         dropItemWithOffset(Block.stoneOvenIdle.blockID, 1, 0.0F);
  76.        
  77.         for(int k = 0; k < 4; k++)
  78.         {
  79.             dropItemWithOffset(Item.ingotIron.shiftedIndex, 1, 0.0F);
  80.         }
  81.  
  82.         setEntityDead();
  83.         }
  84.         return true;
  85.     }else if(riddenByEntity != null&&riddenByEntity == entity)
  86.     {
  87.         if(tankCanShoot == 1)
  88.         {
  89.         tankCanShoot = 0;
  90.         return false;
  91.         }
  92.     }
  93.     return false;
  94.     }
  95.  
  96.     public void performHurtAnimation()
  97.     {
  98.         tankRockDirection = -tankRockDirection;
  99.         tankTimeSinceHit = 10;
  100.         tankCurrentDamage += tankCurrentDamage * 10;
  101.     }
  102.  
  103.     public boolean canBeCollidedWith()
  104.     {
  105.         return !isDead;
  106.     }
  107.  
  108.     public void setPositionAndRotation2(double d, double d1, double d2, float f,
  109.             float f1, int i)
  110.     {
  111.         field_9393_e = d;
  112.         field_9392_f = d1;
  113.         field_9391_g = d2;
  114.         field_9390_h = f;
  115.         field_9389_i = f1;
  116.         field_9394_d = i + 4;
  117.         motionX = field_9388_j;
  118.         motionY = field_9387_k;
  119.         motionZ = field_9386_l;
  120.     }
  121.  
  122.     public void setVelocity(double d, double d1, double d2)
  123.     {
  124.         field_9388_j = motionX = d;
  125.         field_9387_k = motionY = d1;
  126.         field_9386_l = motionZ = d2;
  127.     }
  128.  
  129.     public void onUpdate()
  130.     {
  131.         super.onUpdate();
  132.         if(tankTimeSinceHit > 0)
  133.         {
  134.             tankTimeSinceHit--;
  135.         }
  136.         if(tankCurrentDamage > 0)
  137.         {
  138.             tankCurrentDamage--;
  139.         }
  140.         prevPosX = posX;
  141.         prevPosY = posY;
  142.         prevPosZ = posZ;
  143.         int i = 5;
  144.         double d = 0.0D;
  145.         for(int j = 0; j < i; j++)
  146.         {
  147.             double d4 = (boundingBox.minY + ((boundingBox.maxY - boundingBox.minY) * (double)(j + 0)) / (double)i) - 0.125D;
  148.             double d8 = (boundingBox.minY + ((boundingBox.maxY - boundingBox.minY) * (double)(j + 1)) / (double)i) - 0.125D;
  149.             AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBoxFromPool(boundingBox.minX, d4, boundingBox.minZ, boundingBox.maxX, d8, boundingBox.maxZ);
  150.             if(worldObj.isAABBInMaterial(axisalignedbb, Material.water))
  151.             {
  152.                 d += 1.0D / (double)i;
  153.             }
  154.         }
  155.  
  156.         if(worldObj.multiplayerWorld)
  157.         {
  158.             if(field_9394_d > 0)
  159.             {
  160.                 double d1 = posX + (field_9393_e - posX) / (double)field_9394_d;
  161.                 double d5 = posY + (field_9392_f - posY) / (double)field_9394_d;
  162.                 double d9 = posZ + (field_9391_g - posZ) / (double)field_9394_d;
  163.                 double d12;
  164.                 for(d12 = field_9390_h - (double)rotationYaw; d12 < -180D; d12 += 360D) { }
  165.                 for(; d12 >= 180D; d12 -= 360D) { }
  166.                 rotationYaw += d12 / (double)field_9394_d;
  167.                 rotationPitch += (field_9389_i - (double)rotationPitch) / (double)field_9394_d;
  168.                 field_9394_d--;
  169.                 setPosition(d1, d5, d9);
  170.                 setRotation(rotationYaw, rotationPitch);
  171.             } else
  172.             {
  173.                 double d2 = posX + motionX;
  174.                 double d6 = posY + motionY;
  175.                 double d10 = posZ + motionZ;
  176.                 setPosition(d2, d6, d10);
  177.                
  178.                 motionX *= 0.99000000953674316D;
  179.                 motionY *= 0.94999998807907104D;
  180.                 motionZ *= 0.99000000953674316D;
  181.             }
  182.             return;
  183.         }
  184.         double d3 = d * 2D - 1.0D;
  185.         motionY += 0.039999999105930328D * d3;
  186.         if(riddenByEntity != null)
  187.         {
  188.         stepHeight = riddenByEntity.stepHeight + 1F;
  189.             motionX += riddenByEntity.motionX;// * 0.40000000000000001D;
  190.             motionZ += riddenByEntity.motionZ;// * 0.40000000000000001D;
  191.         }else
  192.     {
  193.         stepHeight = 0;
  194.         motionX = 0;// * 0.40000000000000001D;
  195.             motionZ = 0;// * 0.40000000000000001D;
  196.     }
  197.         double d7 = 0.40000000000000002D;
  198.         if(motionX < -d7)
  199.         {
  200.             motionX = -d7;
  201.         }
  202.         if(motionX > d7)
  203.         {
  204.             motionX = d7;
  205.         }
  206.         if(motionZ < -d7)
  207.         {
  208.             motionZ = -d7;
  209.         }
  210.         if(motionZ > d7)
  211.         {
  212.             motionZ = d7;
  213.         }
  214.        
  215.         moveEntity(motionX, motionY, motionZ);
  216.         tankSpeed = Math.sqrt(motionX * motionX + motionZ * motionZ);
  217.     //System.out.println((new StringBuilder("tankspeed ")).append(tankSpeed).append(" motionX ").append(motionX).append(" motionZ ").append(motionZ).toString());
  218.     boolean flag = handleWaterMovement();
  219.         boolean flag1 = handleLavaMovement();
  220.    
  221.         if(isCollidedHorizontally)
  222.         {
  223.         if(flag)
  224.             {
  225.                 motionY += 0.1D;
  226.             } else
  227.             if(flag1)
  228.             {
  229.                 motionY += 0.1D;
  230.             }
  231.         //if(onGround)
  232.         //{
  233.         //  motionY = 0.40999998688697815D;
  234.         //}
  235.         } else
  236.         {
  237.             motionX *= 0.90000000953674316D;
  238.             motionY *= 0.94999998807907104D;
  239.             motionZ *= 0.90000000953674316D;
  240.         }
  241.         rotationPitch = 0.0F;
  242.         double d14 = rotationYaw;
  243.         double d16 = prevPosX - posX;
  244.         double d17 = prevPosZ - posZ;
  245.         if(d16 * d16 + d17 * d17 > 0.001D)
  246.         {
  247.             d14 = (float)((Math.atan2(d17, d16) * 180D) / 3.1415926535897931D);
  248.         }
  249.         double d19;
  250.         for(d19 = d14 - (double)rotationYaw; d19 >= 180D; d19 -= 360D) { }
  251.         for(; d19 < -180D; d19 += 360D) { }
  252.         if(d19 > 20D)
  253.         {
  254.             d19 = 20D;
  255.         }
  256.         if(d19 < -20D)
  257.         {
  258.             d19 = -20D;
  259.         }
  260.         rotationYaw += d19;
  261.         setRotation(rotationYaw, rotationPitch);
  262.         List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));// collision detection
  263.         if(list != null && list.size() > 0)
  264.         {
  265.             for(int j1 = 0; j1 < list.size(); j1++)
  266.             {
  267.                 Entity entity = (Entity)list.get(j1);
  268.                 if(entity != riddenByEntity && entity.canBePushed() && (entity instanceof EntityTank))
  269.                 {
  270.                     entity.applyEntityCollision(this);
  271.                 }
  272.             }
  273.  
  274.         }
  275.         if(riddenByEntity != null && riddenByEntity.isDead)//kill code
  276.         {
  277.             riddenByEntity = null;
  278.         }
  279.     wheelRotation -= tankSpeed*Math.PI;
  280.    
  281.     if(tankCanShoot == 40)
  282.     {
  283.         System.out.println("ANGLE "+currentModel.muzzleAngle.angleX+", "+
  284.                         currentModel.muzzleAngle.angleY+", "+
  285.                     currentModel.muzzleAngle.angleZ+" POS "+
  286.                     currentModel.muzzlePos.xCoord+", "+
  287.                     currentModel.muzzlePos.yCoord+", "+
  288.                     currentModel.muzzlePos.zCoord);
  289.         double muzzPosX = (currentModel.muzzlePos.xCoord * 0.125F) + posX;
  290.         double muzzPosY = (currentModel.muzzlePos.yCoord * 0.125F) + posY;
  291.         double muzzPosZ = (currentModel.muzzlePos.zCoord * 0.125F) + posZ;
  292.         float muzzAngleX = currentModel.muzzleAngle.angleX + rotationYaw;
  293.         float muzzAngleY = currentModel.muzzleAngle.angleY + rotationPitch;
  294.         System.out.println("Shooting");
  295.         System.out.println("Angle "+muzzAngleX+", "+muzzAngleY);
  296.         System.out.println("POS "+muzzPosX+", "+muzzPosY+", "+muzzPosZ);       
  297.        
  298.             EntityArrow entityarrow = new EntityArrow(worldObj);
  299.             //entityarrow.setLocationAndAngles(muzzPosX, muzzPosY, muzzPosZ, muzzAngleX, muzzAngleY);
  300.         entityarrow.setPosition(muzzPosX, muzzPosY, muzzPosZ);
  301.         entityarrow.setArrowHeading((-currentModel.muzzlePos.xCoord ),
  302.                         (-currentModel.muzzlePos.yCoord ),
  303.                     (currentModel.muzzlePos.zCoord ), 1, 1);
  304.             worldObj.entityJoinedWorld(entityarrow);
  305.     }
  306.     if(tankCanShoot > 1)
  307.     {
  308.         tankCanShoot--;
  309.     }
  310.     }
  311.     // THIS IS ALL TO FIGURE OUT how to angle the tank to go up and down, possibly side to side
  312.    /* public Vec3D func_515_a(double d, double d1, double d2, double d3)
  313.     {
  314.         int i = MathHelper.floor_double(d);
  315.         int j = MathHelper.floor_double(d1);
  316.         int k = MathHelper.floor_double(d2);
  317.         if(worldObj.getBlockId(i, j - 1, k) == Block.minecartTrack.blockID)
  318.         {
  319.             j--;
  320.         }
  321.         if(worldObj.getBlockId(i, j, k) == Block.minecartTrack.blockID)
  322.         {
  323.             int l = worldObj.getBlockMetadata(i, j, k);
  324.             d1 = j;
  325.             if(l >= 2 && l <= 5)
  326.             {
  327.                 d1 = j + 1;
  328.             }
  329.             int ai[][] = field_855_j[l];
  330.             double d4 = ai[1][0] - ai[0][0];
  331.             double d5 = ai[1][2] - ai[0][2];
  332.             double d6 = Math.sqrt(d4 * d4 + d5 * d5);
  333.             d4 /= d6;
  334.             d5 /= d6;
  335.             d += d4 * d3;
  336.             d2 += d5 * d3;
  337.             if(ai[0][1] != 0 && MathHelper.floor_double(d) - i == ai[0][0] && MathHelper.floor_double(d2) - k == ai[0][2])
  338.             {
  339.                 d1 += ai[0][1];
  340.             } else
  341.             if(ai[1][1] != 0 && MathHelper.floor_double(d) - i == ai[1][0] && MathHelper.floor_double(d2) - k == ai[1][2])
  342.             {
  343.                 d1 += ai[1][1];
  344.             }
  345.             return func_514_g(d, d1, d2);
  346.         } else
  347.         {
  348.             return null;
  349.         }
  350.     }
  351.  
  352.     public Vec3D func_514_g(double d, double d1, double d2)
  353.     {
  354.         int i = MathHelper.floor_double(d);
  355.         int j = MathHelper.floor_double(d1);
  356.         int k = MathHelper.floor_double(d2);
  357.         if(worldObj.getBlockId(i, j - 1, k) == Block.minecartTrack.blockID)
  358.         {
  359.             j--;
  360.         }
  361.         if(worldObj.getBlockId(i, j, k) == Block.minecartTrack.blockID)
  362.         {
  363.             int l = worldObj.getBlockMetadata(i, j, k);
  364.             d1 = j;
  365.             if(l >= 2 && l <= 5)
  366.             {
  367.                 d1 = j + 1;
  368.             }
  369.             int ai[][] = field_855_j[l];
  370.             double d3 = 0.0D;
  371.             double d4 = (double)i + 0.5D + (double)ai[0][0] * 0.5D;
  372.             double d5 = (double)j + 0.5D + (double)ai[0][1] * 0.5D;
  373.             double d6 = (double)k + 0.5D + (double)ai[0][2] * 0.5D;
  374.             double d7 = (double)i + 0.5D + (double)ai[1][0] * 0.5D;
  375.             double d8 = (double)j + 0.5D + (double)ai[1][1] * 0.5D;
  376.             double d9 = (double)k + 0.5D + (double)ai[1][2] * 0.5D;
  377.             double d10 = d7 - d4;
  378.             double d11 = (d8 - d5) * 2D;
  379.             double d12 = d9 - d6;
  380.             if(d10 == 0.0D)
  381.             {
  382.                 d = (double)i + 0.5D;
  383.                 d3 = d2 - (double)k;
  384.             } else
  385.             if(d12 == 0.0D)
  386.             {
  387.                 d2 = (double)k + 0.5D;
  388.                 d3 = d - (double)i;
  389.             } else
  390.             {
  391.                 double d13 = d - d4;
  392.                 double d14 = d2 - d6;
  393.                 double d15 = (d13 * d10 + d14 * d12) * 2D;
  394.                 d3 = d15;
  395.             }
  396.             d = d4 + d10 * d3;
  397.             d1 = d5 + d11 * d3;
  398.             d2 = d6 + d12 * d3;
  399.             if(d11 < 0.0D)
  400.             {
  401.                 d1++;
  402.             }
  403.             if(d11 > 0.0D)
  404.             {
  405.                 d1 += 0.5D;
  406.             }
  407.             return Vec3D.createVector(d, d1, d2);
  408.         } else
  409.         {
  410.             return null;
  411.         }
  412.     }*/
  413.    
  414.     public void updateRiderPosition()
  415.     {
  416.         if(riddenByEntity == null)
  417.         {
  418.             return;
  419.         } else
  420.         {
  421.             double d = Math.cos(((double)rotationYaw * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
  422.             double d1 = Math.sin(((double)rotationYaw * 3.1415926535897931D) / 180D) * 0.40000000000000002D;
  423.             riddenByEntity.setPosition(posX + d, posY + getMountedYOffset() + riddenByEntity.getYOffset(), posZ + d1);
  424.             return;
  425.         }
  426.     }
  427.  
  428.     protected void writeEntityToNBT(NBTTagCompound nbttagcompound)
  429.     {
  430.     }
  431.  
  432.     protected void readEntityFromNBT(NBTTagCompound nbttagcompound)
  433.     {
  434.     }
  435.  
  436.     public float getShadowSize()
  437.     {
  438.         return 1.0F;
  439.     }
  440.  
  441.     public boolean interact(EntityPlayer entityplayer)
  442.     {
  443.         if(riddenByEntity != null && (riddenByEntity instanceof EntityPlayer) && riddenByEntity != entityplayer)
  444.         {
  445.             return true;
  446.         }
  447.         if(!worldObj.multiplayerWorld)
  448.         {
  449.             entityplayer.mountEntity(this);
  450.         }
  451.         return true;
  452.     }
  453.    
  454.      private static final int field_855_j[][][] = {
  455.         {
  456.             {
  457.                 0, 0, -1
  458.             }, {
  459.                 0, 0, 1
  460.             }
  461.         }, {
  462.             {
  463.                 -1, 0, 0
  464.             }, {
  465.                 1, 0, 0
  466.             }
  467.         }, {
  468.             {
  469.                 -1, -1, 0
  470.             }, {
  471.                 1, 0, 0
  472.             }
  473.         }, {
  474.             {
  475.                 -1, 0, 0
  476.             }, {
  477.                 1, -1, 0
  478.             }
  479.         }, {
  480.             {
  481.                 0, 0, -1
  482.             }, {
  483.                 0, -1, 1
  484.             }
  485.         }, {
  486.             {
  487.                 0, -1, -1
  488.             }, {
  489.                 0, 0, 1
  490.             }
  491.         }, {
  492.             {
  493.                 0, 0, 1
  494.             }, {
  495.                 1, 0, 0
  496.             }
  497.         }, {
  498.             {
  499.                 0, 0, 1
  500.             }, {
  501.                 -1, 0, 0
  502.             }
  503.         }, {
  504.             {
  505.                 0, 0, -1
  506.             }, {
  507.                 -1, 0, 0
  508.             }
  509.         }, {
  510.             {
  511.                 0, 0, -1
  512.             }, {
  513.                 1, 0, 0
  514.             }
  515.         }
  516.     };
  517.     public ModelTank currentModel;
  518.     public int tankCanShoot = 1;
  519.     public double tankSpeed;
  520.     public float wheelRotation;
  521.     public int tankCurrentDamage;
  522.     public int tankTimeSinceHit;
  523.     public int tankRockDirection;
  524.     private int field_9394_d;
  525.     private double field_9393_e;
  526.     private double field_9392_f;
  527.     private double field_9391_g;
  528.     private double field_9390_h;
  529.     private double field_9389_i;
  530.     private double field_9388_j;
  531.     private double field_9387_k;
  532.     private double field_9386_l;
  533. }
Advertisement
Add Comment
Please, Sign In to add comment