TGAM123

mooncraft_bullet

Apr 6th, 2011
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.11 KB | None | 0 0
  1. EntityBullet:
  2. package net.minecraft.src;
  3. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  4. // Jad home page: http://www.kpdus.com/jad.html
  5. // Decompiler options: packimports(3) braces deadcode
  6.  
  7. import java.util.List;
  8. import java.util.Random;
  9.  
  10. public class EntityBullet extends Entity
  11. {
  12.  
  13.     public EntityBullet(World world)
  14.     {
  15.         super(world);
  16.         xTile = -1;
  17.         yTile = -1;
  18.         zTile = -1;
  19.         inTile = 0;
  20.         inGround = false;
  21.         arrowShake = 0;
  22.         flyTime = 0;
  23.         setSize(0.5F, 0.5F);
  24.     }
  25.  
  26.     public EntityBullet(World world, double d, double d1, double d2)
  27.     {
  28.         super(world);
  29.         xTile = -1;
  30.         yTile = -1;
  31.         zTile = -1;
  32.         inTile = 0;
  33.         inGround = false;
  34.         arrowShake = 0;
  35.         flyTime = 0;
  36.         setSize(0.5F, 0.5F);
  37.         setPosition(d, d1, d2);
  38.         yOffset = 0.0F;
  39.     }
  40.  
  41.     public EntityBullet(World world, EntityLiving entityliving)
  42.     {
  43.         super(world);
  44.         xTile = -1;
  45.         yTile = -1;
  46.         zTile = -1;
  47.         inTile = 0;
  48.         inGround = false;
  49.         arrowShake = 0;
  50.         flyTime = 0;
  51.         field_682_g = entityliving;
  52.         setSize(0.5F, 0.5F);
  53.         setLocationAndAngles(entityliving.posX, entityliving.posY + (double)entityliving.getEyeHeight(), entityliving.posZ, entityliving.rotationYaw, entityliving.rotationPitch);
  54.         posX -= MathHelper.cos((rotationYaw / 180F) * 3.141593F) * 0.16F;
  55.         posY -= 0D;
  56.         posZ -= MathHelper.sin((rotationYaw / 180F) * 3.141593F) * 0.16F;
  57.         setPosition(posX, posY, posZ);
  58.         yOffset = 0.0F;
  59.         motionX = -MathHelper.sin((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
  60.         motionZ = MathHelper.cos((rotationYaw / 180F) * 3.141593F) * MathHelper.cos((rotationPitch / 180F) * 3.141593F);
  61.         motionY = -MathHelper.sin((rotationPitch / 180F) * 3.141593F);
  62.         setArrowHeading(motionX, motionY, motionZ, 5F, 5F);
  63.     }
  64.  
  65.     protected void entityInit()
  66.     {
  67.     }
  68.  
  69.     public void setArrowHeading(double d, double d1, double d2, float f,
  70.             float f1)
  71.     {
  72.         float f2 = MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2);
  73.         d /= f2;
  74.         d1 /= f2;
  75.         d2 /= f2;
  76.         d += rand.nextGaussian() * 0D * (double)f1;
  77.         d1 += rand.nextGaussian() * 0D * (double)f1;
  78.         d2 += rand.nextGaussian() * 0D * (double)f1;
  79.         d *= f;
  80.         d1 *= f;
  81.         d2 *= f;
  82.         motionX = d;
  83.         motionY = d1;
  84.         motionZ = d2;
  85.         float f3 = MathHelper.sqrt_double(d * d + d2 * d2);
  86.         prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
  87.         prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f3) * 180D) / 3.1415927410125732D);
  88.         timeTillDeath = 0;
  89.     }
  90.  
  91.     public void setVelocity(double d, double d1, double d2)
  92.     {
  93.         motionX = d;
  94.         motionY = d1;
  95.         motionZ = d2;
  96.         if(prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  97.         {
  98.             float f = MathHelper.sqrt_double(d * d + d2 * d2);
  99.             prevRotationYaw = rotationYaw = (float)((Math.atan2(d, d2) * 180D) / 3.1415927410125732D);
  100.             prevRotationPitch = rotationPitch = (float)((Math.atan2(d1, f) * 180D) / 3.1415927410125732D);
  101.         }
  102.     }
  103.  
  104.     public void onUpdate()
  105.     {
  106.         super.onUpdate();
  107.         if(prevRotationPitch == 0.0F && prevRotationYaw == 0.0F)
  108.         {
  109.             float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  110.             prevRotationYaw = rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
  111.             prevRotationPitch = rotationPitch = (float)((Math.atan2(motionY, f) * 180D) / 3.1415927410125732D);
  112.         }
  113.         if(arrowShake > 0)
  114.         {
  115.             arrowShake--;
  116.         }
  117.         if(inGround)
  118.         {
  119.             int i = worldObj.getBlockId(xTile, yTile, zTile);
  120.             if(i != inTile)
  121.             {
  122.                 inGround = false;
  123.                 motionX *= rand.nextFloat() * 0.05F;
  124.                 motionY *= rand.nextFloat() * 0.05F;
  125.                 motionZ *= rand.nextFloat() * 0.05F;
  126.                 timeTillDeath = 0;
  127.                 flyTime = 0;
  128.             } else
  129.             {
  130.                 timeTillDeath++;
  131.                 if(timeTillDeath == 1200)
  132.                 {
  133.                     setEntityDead();
  134.                 }
  135.                 return;
  136.             }
  137.         } else
  138.         {
  139.             flyTime++;
  140.         }
  141.         Vec3D vec3d = Vec3D.createVector(posX, posY, posZ);
  142.         Vec3D vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
  143.         MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
  144.         vec3d = Vec3D.createVector(posX, posY, posZ);
  145.         vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
  146.         if(movingobjectposition != null)
  147.         {
  148.             vec3d1 = Vec3D.createVector(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  149.         }
  150.         Entity entity = null;
  151.         List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
  152.         double d = 0.0D;
  153.         for(int j = 0; j < list.size(); j++)
  154.         {
  155.             Entity entity1 = (Entity)list.get(j);
  156.             if(!entity1.canBeCollidedWith() || entity1 == field_682_g && flyTime < 5)
  157.             {
  158.                 continue;
  159.             }
  160.             float f4 = 0.3F;
  161.             AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
  162.             MovingObjectPosition movingobjectposition1 = axisalignedbb.func_1169_a(vec3d, vec3d1);
  163.             if(movingobjectposition1 == null)
  164.             {
  165.                 continue;
  166.             }
  167.             double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);
  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.         if(movingobjectposition != null)
  180.         {
  181.             if(movingobjectposition.entityHit != null)
  182.             {
  183.                 if(movingobjectposition.entityHit.attackEntityFrom(field_682_g, 4))
  184.                 {
  185.                     worldObj.playSoundAtEntity(this, "random.swp", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
  186.                     setEntityDead();
  187.                 } else
  188.                 {
  189.                     motionX *= -0.10000000149011612D;
  190.                     motionY *= -0.10000000149011612D;
  191.                     motionZ *= -0.10000000149011612D;
  192.                     rotationYaw += 180F;
  193.                     prevRotationYaw += 180F;
  194.                     flyTime = 0;
  195.                 }
  196.             } else
  197.             {
  198.                 xTile = movingobjectposition.blockX;
  199.                 yTile = movingobjectposition.blockY;
  200.                 zTile = movingobjectposition.blockZ;
  201.                 inTile = worldObj.getBlockId(xTile, yTile, zTile);
  202.                 motionX = (float)(movingobjectposition.hitVec.xCoord - posX);
  203.                 motionY = (float)(movingobjectposition.hitVec.yCoord - posY);
  204.                 motionZ = (float)(movingobjectposition.hitVec.zCoord - posZ);
  205.                 float f1 = MathHelper.sqrt_double(motionX * motionX + motionY * motionY + motionZ * motionZ);
  206.                 posX -= (motionX / (double)f1) * 0.05000000074505806D;
  207.                 posY -= (motionY / (double)f1) * 0.05000000074505806D;
  208.                 posZ -= (motionZ / (double)f1) * 0.05000000074505806D;
  209.                 worldObj.playSoundAtEntity(this, "random.swp", 1.0F, 1.2F / (rand.nextFloat() * 0.2F + 0.9F));
  210.                 inGround = true;
  211.                 arrowShake = 7;
  212.             }
  213.         }
  214.         posX += motionX;
  215.         posY += motionY;
  216.         posZ += motionZ;
  217.         float f2 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
  218.         rotationYaw = (float)((Math.atan2(motionX, motionZ) * 180D) / 3.1415927410125732D);
  219.         for(rotationPitch = (float)((Math.atan2(motionY, f2) * 180D) / 3.1415927410125732D); rotationPitch - prevRotationPitch < -180F; prevRotationPitch -= 360F) { }
  220.         for(; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) { }
  221.         for(; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) { }
  222.         for(; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) { }
  223.         rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
  224.         rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
  225.         float f3 = 0.99F;
  226.         float f5 = 0.03F;
  227.         if(handleWaterMovement())
  228.         {
  229.             for(int k = 0; k < 4; k++)
  230.             {
  231.                 float f6 = 0.25F;
  232.                 worldObj.spawnParticle("bubble", posX - motionX * (double)f6, posY - motionY * (double)f6, posZ - motionZ * (double)f6, motionX, motionY, motionZ);
  233.             }
  234.  
  235.             f3 = 0.8F;
  236.         }
  237.         motionX *= f3;
  238.         motionY *= f3;
  239.         motionZ *= f3;
  240.         motionY -= f5;
  241.         setPosition(posX, posY, posZ);
  242.     }
  243.  
  244.     public void writeEntityToNBT(NBTTagCompound nbttagcompound)
  245.     {
  246.         nbttagcompound.setShort("xTile", (short)xTile);
  247.         nbttagcompound.setShort("yTile", (short)yTile);
  248.         nbttagcompound.setShort("zTile", (short)zTile);
  249.         nbttagcompound.setByte("inTile", (byte)inTile);
  250.         nbttagcompound.setByte("shake", (byte)arrowShake);
  251.         nbttagcompound.setByte("inGround", (byte)(inGround ? 1 : 0));
  252.     }
  253.  
  254.     public void readEntityFromNBT(NBTTagCompound nbttagcompound)
  255.     {
  256.         xTile = nbttagcompound.getShort("xTile");
  257.         yTile = nbttagcompound.getShort("yTile");
  258.         zTile = nbttagcompound.getShort("zTile");
  259.         inTile = nbttagcompound.getByte("inTile") & 0xff;
  260.         arrowShake = nbttagcompound.getByte("shake") & 0xff;
  261.         inGround = nbttagcompound.getByte("inGround") == 1;
  262.     }
  263.  
  264.     public void onCollideWithPlayer(EntityPlayer entityplayer)
  265.     {
  266.         if(worldObj.multiplayerWorld)
  267.         {
  268.             return;
  269.         }
  270.         if(inGround && field_682_g == entityplayer && arrowShake <= 0 && entityplayer.inventory.addItemStackToInventory(new ItemStack(Item.bullet, 1)))
  271.         {
  272.             worldObj.playSoundAtEntity(this, "random.pop", 0.2F, ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
  273.             entityplayer.onItemPickup(this, 1);
  274.             setEntityDead();
  275.         }
  276.     }
  277.  
  278.     public float getShadowSize()
  279.     {
  280.         return 0.0F;
  281.     }
  282.  
  283.     private int xTile;
  284.     private int yTile;
  285.     private int zTile;
  286.     private int inTile;
  287.     private boolean inGround;
  288.     public int arrowShake;
  289.     public EntityLiving field_682_g;
  290.     private int timeTillDeath;
  291.     private int flyTime;
  292. }
  293.  
  294. RenderBullet:
  295. package net.minecraft.src;
  296. // Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
  297. // Jad home page: http://www.kpdus.com/jad.html
  298. // Decompiler options: packimports(3) braces deadcode
  299.  
  300. import org.lwjgl.opengl.GL11;
  301.  
  302. public class RenderBullet extends Render
  303. {
  304.  
  305.     public RenderBullet()
  306.     {
  307.     }
  308.  
  309.     public void func_154_a(EntityBullet entitybullet, double d, double d1, double d2,
  310.             float f, float f1)
  311.     {
  312.         loadTexture("/item/bullets.png");
  313.         GL11.glPushMatrix();
  314.         GL11.glTranslatef((float)d, (float)d1, (float)d2);
  315.         GL11.glRotatef((entitybullet.prevRotationYaw + (entitybullet.rotationYaw - entitybullet.prevRotationYaw) * f1) - 90F, 0.0F, 1.0F, 0.0F);
  316.         GL11.glRotatef(entitybullet.prevRotationPitch + (entitybullet.rotationPitch - entitybullet.prevRotationPitch) * f1, 0.0F, 0.0F, 1.0F);
  317.         Tessellator tessellator = Tessellator.instance;
  318.         int i = 0;
  319.         float f2 = 0.0F;
  320.         float f3 = 0.5F;
  321.         float f4 = (float)(0 + i * 10) / 32F;
  322.         float f5 = (float)(5 + i * 10) / 32F;
  323.         float f6 = 0.0F;
  324.         float f7 = 0.15625F;
  325.         float f8 = (float)(5 + i * 10) / 32F;
  326.         float f9 = (float)(10 + i * 10) / 32F;
  327.         float f10 = 0.05625F;
  328.         GL11.glEnable(32826 /*GL_RESCALE_NORMAL_EXT*/);
  329.         float f11 = (float)entitybullet.arrowShake - f1;
  330.         if(f11 > 0.0F)
  331.         {
  332.             float f12 = -MathHelper.sin(f11 * 3F) * f11;
  333.             GL11.glRotatef(f12, 0.0F, 0.0F, 1.0F);
  334.         }
  335.         GL11.glRotatef(45F, 1.0F, 0.0F, 0.0F);
  336.         GL11.glScalef(f10, f10, f10);
  337.         GL11.glTranslatef(-4F, 0.0F, 0.0F);
  338.         GL11.glNormal3f(f10, 0.0F, 0.0F);
  339.         tessellator.startDrawingQuads();
  340.         tessellator.addVertexWithUV(-7D, -2D, -2D, f6, f8);
  341.         tessellator.addVertexWithUV(-7D, -2D, 2D, f7, f8);
  342.         tessellator.addVertexWithUV(-7D, 2D, 2D, f7, f9);
  343.         tessellator.addVertexWithUV(-7D, 2D, -2D, f6, f9);
  344.         tessellator.draw();
  345.         GL11.glNormal3f(-f10, 0.0F, 0.0F);
  346.         tessellator.startDrawingQuads();
  347.         tessellator.addVertexWithUV(-7D, 2D, -2D, f6, f8);
  348.         tessellator.addVertexWithUV(-7D, 2D, 2D, f7, f8);
  349.         tessellator.addVertexWithUV(-7D, -2D, 2D, f7, f9);
  350.         tessellator.addVertexWithUV(-7D, -2D, -2D, f6, f9);
  351.         tessellator.draw();
  352.         for(int j = 0; j < 4; j++)
  353.         {
  354.             GL11.glRotatef(90F, 1.0F, 0.0F, 0.0F);
  355.             GL11.glNormal3f(0.0F, 0.0F, f10);
  356.             tessellator.startDrawingQuads();
  357.             tessellator.addVertexWithUV(-8D, -2D, 0.0D, f2, f4);
  358.             tessellator.addVertexWithUV(8D, -2D, 0.0D, f3, f4);
  359.             tessellator.addVertexWithUV(8D, 2D, 0.0D, f3, f5);
  360.             tessellator.addVertexWithUV(-8D, 2D, 0.0D, f2, f5);
  361.             tessellator.draw();
  362.         }
  363.  
  364.         GL11.glDisable(32826 /*GL_RESCALE_NORMAL_EXT*/);
  365.         GL11.glPopMatrix();
  366.     }
  367.  
  368.     public void doRender(Entity entity, double d, double d1, double d2,
  369.             float f, float f1)
  370.     {
  371.         func_154_a((EntityBullet)entity, d, d1, d2, f, f1);
  372.     }
  373. }
Advertisement
Add Comment
Please, Sign In to add comment