Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 15th, 2012  |  syntax: Java  |  size: 9.20 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package net.minecraft.src;
  2.  
  3. import java.util.List;
  4. import java.util.Random;
  5.  
  6. public class EntityTPHFlamethrower extends EntityFireball
  7. {
  8.     private int xTile;
  9.     private int yTile;
  10.     private int zTile;
  11.     private int inTile;
  12.     private boolean inGround;
  13.     private int ticksAlive;
  14.     private int ticksInAir;
  15.     public float moveSpeed;
  16.     public double destX;
  17.     public double destZ;
  18.  
  19.     public EntityTPHFlamethrower(World par1World, EntityLiving shooter, EntityLiving target)
  20.     {
  21.         super(par1World);
  22.         xTile = -1;
  23.         yTile = -1;
  24.         zTile = -1;
  25.         inTile = 0;
  26.         inGround = false;
  27.         ticksInAir = 0;
  28.         destX = target.posX;
  29.         destZ = target.posZ;
  30.         moveSpeed = 1.0F;
  31.         shootingEntity = shooter;
  32.         setSize(1.0F, 1.0F);
  33.     }
  34.  
  35.     protected void entityInit()
  36.     {
  37.     }
  38.  
  39.     /**
  40.      * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
  41.      * length * 64 * renderDistanceWeight Args: distance
  42.      */
  43.     public boolean isInRangeToRenderDist(double par1)
  44.     {
  45.         double d = boundingBox.getAverageEdgeLength() * 4D;
  46.         d *= 64D;
  47.         return par1 < d * d;
  48.     }
  49.  
  50.     /**
  51.      * Called to update the entity's position/logic.
  52.      */
  53.     public void onUpdate()
  54.     {
  55.         if (something((int)posX, (int)posY, (int)posZ))
  56.         {
  57.                 if (something((int)posX, (int)posY + 1, (int)posZ))
  58.                 {
  59.                     setDead();
  60.                     return;
  61.                 } else posY += 1;
  62.         } else if (!something((int)posX, (int)posY - 1, (int)posZ)) {
  63.                 if (!something((int)posX, (int)posY - 2, (int)posZ)){
  64.                         setDead();
  65.                         return;
  66.                 } else posY -= 1;
  67.         }
  68.  
  69.         worldObj.setBlockWithNotify((int) posX, (int) posY, (int) posZ, Block.fire.blockID);
  70.         super.onUpdate();
  71.         setFire(1);
  72.        
  73.         //if (inGround)
  74.         //{
  75.             //int i = worldObj.getBlockId(xTile, yTile, zTile);
  76.  
  77.             //if (i != inTile)
  78.             //{
  79.             //    inGround = false;
  80.             //    motionX *= rand.nextFloat() * 0.2F;
  81.             //    motionY *= rand.nextFloat() * 0.2F;
  82.             //    motionZ *= rand.nextFloat() * 0.2F;
  83.             //    ticksAlive = 0;
  84.             //    ticksInAir = 0;
  85.             //}
  86.             //else
  87.             //{
  88.                 ticksAlive++;
  89.  
  90.                 if (ticksAlive >= 100)
  91.                 {
  92.                     setDead();
  93.                     worldObj.newExplosion(null, posX, posY, posZ, 1.0F, true);
  94.                 }
  95.  
  96.                 //return;
  97.             //}
  98.         //}
  99.         //else
  100.         //{
  101.             ticksInAir++;
  102.         //}
  103.                
  104.         Vec3D vec3d = Vec3D.createVector(posX, posY, posZ);
  105.         Vec3D vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
  106.         MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
  107.         vec3d = Vec3D.createVector(posX, posY, posZ);
  108.         vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
  109.  
  110.         if (movingobjectposition != null)
  111.         {
  112.             vec3d1 = Vec3D.createVector(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  113.         }
  114.  
  115.         Entity entity = null;
  116.         List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
  117.         double d = 0.0D;
  118.  
  119.         for (int j = 0; j < list.size(); j++)
  120.         {
  121.             Entity entity1 = (Entity)list.get(j);
  122.  
  123.             if (!entity1.canBeCollidedWith() || entity1.isEntityEqual(shootingEntity) && ticksInAir < 25)
  124.             {
  125.                 continue;
  126.             }
  127.  
  128.             float f2 = 0.3F;
  129.             AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f2, f2, f2);
  130.             MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3d, vec3d1);
  131.  
  132.             if (movingobjectposition1 == null)
  133.             {
  134.                 continue;
  135.             }
  136.  
  137.             double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
  138.  
  139.             if (d1 < d || d == 0.0D)
  140.             {
  141.                 entity = entity1;
  142.                 d = d1;
  143.             }
  144.         }
  145.  
  146.         if (entity != null)
  147.         {
  148.             movingobjectposition = new MovingObjectPosition(entity);
  149.         }
  150.  
  151.         if (movingobjectposition != null)
  152.         {
  153.             func_40071_a(movingobjectposition);
  154.         }
  155.  
  156.         posX += motionX;
  157.         posY += motionY;
  158.         posZ += motionZ;
  159.         float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  160.         //rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / Math.PI);
  161.  
  162.         //for (rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / Math.PI); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { }
  163.  
  164.         //for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { }
  165.  
  166.         //for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { }
  167.  
  168.         //for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { }
  169.  
  170.         //rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
  171.         //rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
  172.         float f1 = 0.95F;
  173.  
  174.         if (isInWater())
  175.         {
  176.             for (int k = 0; k < 4; k++)
  177.             {
  178.                 float f3 = 0.25F;
  179.                 worldObj.spawnParticle("bubble", posX - motionX * (double)f3, posY - motionY * (double)f3, posZ - motionZ * (double)f3, motionX, motionY, motionZ);
  180.             }
  181.  
  182.             f1 = 0.8F;
  183.         }
  184.  
  185.         //motionX += accelerationX;
  186.         //motionY += accelerationY;
  187.         //motionZ += accelerationZ;
  188.         //motionX *= f1;
  189.         //motionY *= f1;
  190.         //motionZ *= f1;
  191.  
  192.         motionX = Math.cos(Math.toRadians(rotationYaw)) * moveSpeed;
  193.         motionY = 0;
  194.         motionZ = Math.sin(Math.toRadians(rotationYaw)) * moveSpeed;
  195.         float n = (float) Math.atan2(destZ - 100, destX - 100) - rotationYaw;
  196.         rotationYaw += (n > ticksAlive) ? (float) ticksAlive : n;
  197.         //worldObj.spawnParticle("smoke", posX, posY + 0.5D, posZ, 0.0D, 0.0D, 0.0D);
  198.         setPosition(posX, posY, posZ);
  199.     }
  200.  
  201.     protected void func_40071_a(MovingObjectPosition par1MovingObjectPosition)
  202.     {
  203.         if (!worldObj.isRemote)
  204.         {
  205.             if (par1MovingObjectPosition.entityHit != null)
  206.             {
  207.                 if (!par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeFireballDamage((EntityFireball) this, shootingEntity), 4));
  208.             }
  209.  
  210.             worldObj.newExplosion(null, posX, posY, posZ, 1.0F, true);
  211.             setDead();
  212.         }
  213.     }
  214.  
  215.     /**
  216.      * (abstract) Protected helper method to write subclass entity data to NBT.
  217.      */
  218.     public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
  219.     {
  220.         par1NBTTagCompound.setShort("xTile", (short)xTile);
  221.         par1NBTTagCompound.setShort("yTile", (short)yTile);
  222.         par1NBTTagCompound.setShort("zTile", (short)zTile);
  223.         par1NBTTagCompound.setByte("inTile", (byte)inTile);
  224.         par1NBTTagCompound.setByte("inGround", (byte)(inGround ? 1 : 0));
  225.     }
  226.  
  227.     /**
  228.      * (abstract) Protected helper method to read subclass entity data from NBT.
  229.      */
  230.     public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
  231.     {
  232.         xTile = par1NBTTagCompound.getShort("xTile");
  233.         yTile = par1NBTTagCompound.getShort("yTile");
  234.         zTile = par1NBTTagCompound.getShort("zTile");
  235.         inTile = par1NBTTagCompound.getByte("inTile") & 0xff;
  236.         inGround = par1NBTTagCompound.getByte("inGround") == 1;
  237.     }
  238.  
  239.     /**
  240.      * Returns true if other Entities should be prevented from moving through this Entity.
  241.      */
  242.     public boolean canBeCollidedWith()
  243.     {
  244.         return true;
  245.     }
  246.  
  247.     public float getCollisionBorderSize()
  248.     {
  249.         return 1.0F;
  250.     }
  251.    
  252.     public boolean attackEntityFrom(DamageSource par1DamageSource, int par2)
  253.     {
  254.         setBeenAttacked();
  255.         if (par1DamageSource.getEntity() != null)
  256.                 return true;
  257.         else
  258.                 return false;
  259.     }
  260.  
  261.     public float getShadowSize()
  262.     {
  263.         return 0.0F;
  264.     }
  265.  
  266.     /**
  267.      * Gets how bright this entity is.
  268.      */
  269.     public float getBrightness(float par1)
  270.     {
  271.         return 1.0F;
  272.     }
  273.  
  274.     public int getBrightnessForRender(float par1)
  275.     {
  276.         return 0xf000f0;
  277.     }
  278.    
  279.     /**
  280.      * @param Radius
  281.      * @param OriginX
  282.      * @param OriginY
  283.      * @param Angle
  284.      * @return Point on circumference of circle at that angle
  285.      */
  286.     public double[] GetCircumferencePoints(double Radius, double OriginX, double OriginY, double Angle)
  287.     {
  288.         double X = OriginX+Radius*Math.sin(Angle*Math.PI/180);
  289.         double Y = OriginY+Radius*-Math.cos(Angle*Math.PI/180);
  290.         return new double[] {X, Y};
  291.     }
  292.    
  293.     public boolean something(int x, int y, int z)
  294.     {
  295.         return (worldObj.blockExists(x, y, z) && worldObj.getBlockId(x, y, z) != Block.fire.blockID);
  296.     }
  297. }