Guest User

Untitled

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