Guest User

base

a guest
Jun 19th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.10 KB | None | 0 0
  1. package com.svk.industrialGuns.entity;
  2.  
  3. import cpw.mods.fml.relauncher.Side;
  4. import cpw.mods.fml.relauncher.SideOnly;
  5.  
  6. import java.util.List;
  7.  
  8. import net.minecraft.block.Block;
  9. import net.minecraft.entity.Entity;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.IProjectile;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.init.Blocks;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.util.AxisAlignedBB;
  16. import net.minecraft.util.MathHelper;
  17. import net.minecraft.util.MovingObjectPosition;
  18. import net.minecraft.util.Vec3;
  19. import net.minecraft.world.World;
  20.  
  21. public abstract class EntityBulletBase extends Entity implements IProjectile
  22. {
  23.     private int field_145788_c = -1;
  24.     private int field_145786_d = -1;
  25.     private int field_145787_e = -1;
  26.     private Block field_145785_f;
  27.     protected boolean inGround;
  28.     public int throwableShake;
  29.     /** The entity that threw this throwable item. */
  30.     private EntityLivingBase thrower;
  31.     private String throwerName;
  32.     private int ticksInGround;
  33.     private int ticksInAir;
  34.     private static final String __OBFID = "CL_00001723";
  35.     protected boolean render;
  36.     public float addSize = 0;
  37.  
  38.     public EntityBulletBase(World p_i1776_1_)
  39.     {
  40.         super(p_i1776_1_);
  41.         this.setSize(0.25F, 0.25F);
  42.     }
  43.  
  44.     protected void entityInit() {}
  45.  
  46.     /**
  47.      * Checks if the entity is in range to render by using the past in distance and comparing it to its average edge
  48.      * length * 64 * renderDistanceWeight Args: distance
  49.      */
  50.     @SideOnly(Side.CLIENT)
  51.     public boolean isInRangeToRenderDist(double p_70112_1_)
  52.     {
  53.         if(render)
  54.         {
  55.             double d1 = this.boundingBox.getAverageEdgeLength();
  56.             d1 *= 64.0D * 256;
  57.             return p_70112_1_ < d1 * d1;
  58.         }
  59.         else
  60.         {
  61.             return false;
  62.         }
  63.     }
  64.    
  65.     public EntityBulletBase(World p_i1777_1_, EntityLivingBase p_i1777_2_)
  66.     {
  67.         super(p_i1777_1_);
  68.         this.thrower = p_i1777_2_;
  69.         this.setSize(0.25F, 0.25F);
  70.         this.setLocationAndAngles(p_i1777_2_.posX, p_i1777_2_.posY + (double)p_i1777_2_.getEyeHeight(), p_i1777_2_.posZ, p_i1777_2_.rotationYaw, p_i1777_2_.rotationPitch);
  71.         this.posX -= (double)(MathHelper.cos(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
  72.         this.posY -= 0.10000000149011612D;
  73.         this.posZ -= (double)(MathHelper.sin(this.rotationYaw / 180.0F * (float)Math.PI) * 0.16F);
  74.         this.setPosition(this.posX, this.posY, this.posZ);
  75.         this.yOffset = 0.0F;
  76.         float f = 0.4F;
  77.         this.setThrowableHeading(this.motionX, this.motionY, this.motionZ, this.func_70182_d(), 1.0F);
  78.     }
  79.  
  80.     public EntityBulletBase(World p_i1778_1_, double p_i1778_2_, double p_i1778_4_, double p_i1778_6_)
  81.     {
  82.         super(p_i1778_1_);
  83.         this.ticksInGround = 0;
  84.         this.setSize(0.25F, 0.25F);
  85.         this.setPosition(p_i1778_2_, p_i1778_4_, p_i1778_6_);
  86.         this.yOffset = 0.0F;
  87.     }
  88.  
  89.     protected float func_70182_d()
  90.     {
  91.         return 1.5F;
  92.     }
  93.  
  94.     protected float func_70183_g()
  95.     {
  96.         return 0.0F;
  97.     }
  98.  
  99.     /**
  100.      * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
  101.      */
  102.     public void setThrowableHeading(double p_70186_1_, double p_70186_3_, double p_70186_5_, float p_70186_7_, float p_70186_8_)
  103.     {
  104.         float f2 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_3_ * p_70186_3_ + p_70186_5_ * p_70186_5_);
  105.         p_70186_1_ /= (double)f2;
  106.         p_70186_3_ /= (double)f2;
  107.         p_70186_5_ /= (double)f2;
  108.         p_70186_1_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_70186_8_;
  109.         p_70186_3_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_70186_8_;
  110.         p_70186_5_ += this.rand.nextGaussian() * 0.007499999832361937D * (double)p_70186_8_;
  111.         p_70186_1_ *= (double)p_70186_7_;
  112.         p_70186_3_ *= (double)p_70186_7_;
  113.         p_70186_5_ *= (double)p_70186_7_;
  114.         this.motionX = p_70186_1_;
  115.         this.motionY = p_70186_3_;
  116.         this.motionZ = p_70186_5_;
  117.         float f3 = MathHelper.sqrt_double(p_70186_1_ * p_70186_1_ + p_70186_5_ * p_70186_5_);
  118.         this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_70186_1_, p_70186_5_) * 180.0D / Math.PI);
  119.         this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_70186_3_, (double)f3) * 180.0D / Math.PI);
  120.         this.ticksInGround = 0;
  121.     }
  122.  
  123.     /**
  124.      * Sets the velocity to the args. Args: x, y, z
  125.      */
  126.     @SideOnly(Side.CLIENT)
  127.     public void setVelocity(double p_70016_1_, double p_70016_3_, double p_70016_5_)
  128.     {
  129.         this.motionX = p_70016_1_;
  130.         this.motionY = p_70016_3_;
  131.         this.motionZ = p_70016_5_;
  132.  
  133.         if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  134.         {
  135.             float f = MathHelper.sqrt_double(p_70016_1_ * p_70016_1_ + p_70016_5_ * p_70016_5_);
  136.             this.prevRotationYaw = this.rotationYaw = (float)(Math.atan2(p_70016_1_, p_70016_5_) * 180.0D / Math.PI);
  137.             this.prevRotationPitch = this.rotationPitch = (float)(Math.atan2(p_70016_3_, (double)f) * 180.0D / Math.PI);
  138.         }
  139.     }
  140.  
  141.     /**
  142.      * Called to update the entity's position/logic.
  143.      */
  144.     public void onUpdate()
  145.     {      
  146.         if(this.posY > 255 || this.posY < 1)
  147.         {
  148.             this.setDead();
  149.         }
  150.        
  151.         this.lastTickPosX = this.posX;
  152.         this.lastTickPosY = this.posY;
  153.         this.lastTickPosZ = this.posZ;
  154.         super.onUpdate();
  155.  
  156.         if (this.throwableShake > 0)
  157.         {
  158.             --this.throwableShake;
  159.         }
  160.  
  161.         if (this.inGround)
  162.         {
  163.             if (this.worldObj.getBlock(this.field_145788_c, this.field_145786_d, this.field_145787_e) == this.field_145785_f)
  164.             {
  165.                 ++this.ticksInGround;
  166.  
  167.                 if (this.ticksInGround == 1200)
  168.                 {
  169.                     this.setDead();
  170.                 }
  171.  
  172.                 return;
  173.             }
  174.  
  175.             this.inGround = false;
  176.             this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
  177.             this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
  178.             this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
  179.             this.ticksInGround = 0;
  180.             this.ticksInAir = 0;
  181.         }
  182.         else
  183.         {
  184.             ++this.ticksInAir;
  185.         }
  186.  
  187.         Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
  188.         Vec3 vec31 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  189.         MovingObjectPosition movingobjectposition = this.worldObj.rayTraceBlocks(vec3, vec31);
  190.         vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
  191.         vec31 = Vec3.createVectorHelper(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  192.  
  193.         if (movingobjectposition != null)
  194.         {
  195.             vec31 = Vec3.createVectorHelper(movingobjectposition.hitVec.xCoord, movingobjectposition.hitVec.yCoord, movingobjectposition.hitVec.zCoord);
  196.         }
  197.  
  198.             Entity entity = null;
  199.             List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.addCoord(this.motionX, this.motionY, this.motionZ).expand(2.0D, 2.0D, 2.0D));
  200.             double d0 = 0.0D;
  201.             EntityLivingBase entitylivingbase = this.getThrower();
  202.  
  203.             for (int j = 0; j < list.size(); ++j)
  204.             {
  205.                 Entity entity1 = (Entity)list.get(j);
  206.  
  207.                 if (entity1.canBeCollidedWith() && (entity1 != entitylivingbase || this.ticksInAir >= 5))
  208.                 {
  209.                     float f = 0.3F + addSize*2;
  210.                     AxisAlignedBB axisalignedbb = entity1.boundingBox.expand((double)f, (double)f, (double)f);
  211.                     MovingObjectPosition movingobjectposition1 = axisalignedbb.calculateIntercept(vec3, vec31);
  212.  
  213.                     if (movingobjectposition1 != null)
  214.                     {
  215.                         double d1 = vec3.distanceTo(movingobjectposition1.hitVec);
  216.  
  217.                         if (d1 < d0 || d0 == 0.0D)
  218.                         {
  219.                             entity = entity1;
  220.                             d0 = d1;
  221.                         }
  222.                     }
  223.                 }
  224.             }
  225.  
  226.             if (entity != null)
  227.             {
  228.                 movingobjectposition = new MovingObjectPosition(entity);
  229.             }
  230.  
  231.         if (movingobjectposition != null)
  232.         {
  233.             if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK && this.worldObj.getBlock(movingobjectposition.blockX, movingobjectposition.blockY, movingobjectposition.blockZ) == Blocks.portal)
  234.             {
  235.                 this.setInPortal();
  236.             }
  237.             else
  238.             {
  239.                 this.onImpact(movingobjectposition);
  240.             }
  241.         }
  242.  
  243.         this.posX += this.motionX;
  244.         this.posY += this.motionY;
  245.         this.posZ += this.motionZ;
  246.         float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
  247.         this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
  248.  
  249.         for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)f1) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
  250.         {
  251.             ;
  252.         }
  253.  
  254.         while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
  255.         {
  256.             this.prevRotationPitch += 360.0F;
  257.         }
  258.  
  259.         while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  260.         {
  261.             this.prevRotationYaw -= 360.0F;
  262.         }
  263.  
  264.         while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  265.         {
  266.             this.prevRotationYaw += 360.0F;
  267.         }
  268.  
  269.         this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  270.         this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  271.         float f2 = 0.99F;
  272.         float f3 = this.getGravityVelocity();
  273.  
  274.         if (this.isInWater())
  275.         {
  276.             for (int i = 0; i < 4; ++i)
  277.             {
  278.                 float f4 = 0.25F;
  279.                 this.worldObj.spawnParticle("bubble", this.posX - this.motionX * (double)f4, this.posY - this.motionY * (double)f4, this.posZ - this.motionZ * (double)f4, this.motionX, this.motionY, this.motionZ);
  280.             }
  281.  
  282.             f2 = 0.8F;
  283.         }
  284.  
  285.         this.motionX *= (double)f2;
  286.         this.motionY *= (double)f2;
  287.         this.motionZ *= (double)f2;
  288.         this.motionY -= (double)f3;
  289.         this.setPosition(this.posX, this.posY, this.posZ);
  290.     }
  291.  
  292.     /**
  293.      * Gets the amount of gravity to apply to the thrown entity with each tick.
  294.      */
  295.     protected float getGravityVelocity()
  296.     {
  297.         return 0.03F;
  298.     }
  299.  
  300.     /**
  301.      * Called when this EntityThrowable hits a block or entity.
  302.      */
  303.     protected abstract void onImpact(MovingObjectPosition p_70184_1_);
  304.  
  305.     /**
  306.      * (abstract) Protected helper method to write subclass entity data to NBT.
  307.      */
  308.     public void writeEntityToNBT(NBTTagCompound p_70014_1_)
  309.     {
  310.         p_70014_1_.setShort("xTile", (short)this.field_145788_c);
  311.         p_70014_1_.setShort("yTile", (short)this.field_145786_d);
  312.         p_70014_1_.setShort("zTile", (short)this.field_145787_e);
  313.         p_70014_1_.setByte("inTile", (byte)Block.getIdFromBlock(this.field_145785_f));
  314.         p_70014_1_.setByte("shake", (byte)this.throwableShake);
  315.         p_70014_1_.setByte("inGround", (byte)(this.inGround ? 1 : 0));
  316.  
  317.         if ((this.throwerName == null || this.throwerName.length() == 0) && this.thrower != null && this.thrower instanceof EntityPlayer)
  318.         {
  319.             this.throwerName = this.thrower.getCommandSenderName();
  320.         }
  321.  
  322.         p_70014_1_.setString("ownerName", this.throwerName == null ? "" : this.throwerName);
  323.     }
  324.  
  325.     /**
  326.      * (abstract) Protected helper method to read subclass entity data from NBT.
  327.      */
  328.     public void readEntityFromNBT(NBTTagCompound p_70037_1_)
  329.     {
  330.         this.field_145788_c = p_70037_1_.getShort("xTile");
  331.         this.field_145786_d = p_70037_1_.getShort("yTile");
  332.         this.field_145787_e = p_70037_1_.getShort("zTile");
  333.         this.field_145785_f = Block.getBlockById(p_70037_1_.getByte("inTile") & 255);
  334.         this.throwableShake = p_70037_1_.getByte("shake") & 255;
  335.         this.inGround = p_70037_1_.getByte("inGround") == 1;
  336.         this.throwerName = p_70037_1_.getString("ownerName");
  337.  
  338.         if (this.throwerName != null && this.throwerName.length() == 0)
  339.         {
  340.             this.throwerName = null;
  341.         }
  342.     }
  343.  
  344.     @SideOnly(Side.CLIENT)
  345.     public float getShadowSize()
  346.     {
  347.         return 0.0F;
  348.     }
  349.  
  350.     public EntityLivingBase getThrower()
  351.     {
  352.         if (this.thrower == null && this.throwerName != null && this.throwerName.length() > 0)
  353.         {
  354.             this.thrower = this.worldObj.getPlayerEntityByName(this.throwerName);
  355.         }
  356.  
  357.         return this.thrower;
  358.     }
  359. }
Advertisement
Add Comment
Please, Sign In to add comment