hassansyyid

EntityScorpion

Jul 5th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.61 KB | None | 0 0
  1. package halocraft.entities;
  2.  
  3. import halocraft.Main;
  4.  
  5. import java.util.List;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.client.model.ModelBase;
  10. import net.minecraft.entity.Entity;
  11. import net.minecraft.entity.EntityLivingBase;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.init.Blocks;
  14. import net.minecraft.init.Items;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.nbt.NBTTagCompound;
  17. import net.minecraft.util.AxisAlignedBB;
  18. import net.minecraft.util.BlockPos;
  19. import net.minecraft.util.DamageSource;
  20. import net.minecraft.util.EntityDamageSourceIndirect;
  21. import net.minecraft.util.EnumParticleTypes;
  22. import net.minecraft.util.MathHelper;
  23. import net.minecraft.world.World;
  24. import net.minecraftforge.fml.relauncher.Side;
  25. import net.minecraftforge.fml.relauncher.SideOnly;
  26.  
  27. public class EntityScorpion extends Entity
  28. {
  29.     private boolean isBoatEmpty;
  30.     private double speedMultiplier;
  31.     private int boatPosRotationIncrements;
  32.     private double boatX;
  33.     private double boatY;
  34.     private double boatZ;
  35.     private double boatYaw;
  36.     private double boatPitch;
  37.     @SideOnly(Side.CLIENT)
  38.     private double velocityX;
  39.     @SideOnly(Side.CLIENT)
  40.     private double velocityY;
  41.     @SideOnly(Side.CLIENT)
  42.     private double velocityZ;
  43.  
  44.     public EntityScorpion(World worldIn)
  45.     {
  46.         super(worldIn);
  47.         this.isBoatEmpty = true;
  48.         this.speedMultiplier = 0.07D;
  49.         this.preventEntitySpawning = true;
  50.         this.renderDistanceWeight = 12.0D;
  51.         this.setSize(9.5F, 6.25F);
  52.     }
  53.  
  54.     protected boolean canTriggerWalking()
  55.     {
  56.         return false;
  57.     }
  58.  
  59.     protected void entityInit()
  60.     {
  61.         this.dataWatcher.addObject(17, new Integer(0));
  62.         this.dataWatcher.addObject(18, new Integer(1));
  63.         this.dataWatcher.addObject(19, new Float(0.0F));
  64.     }
  65.  
  66.     public AxisAlignedBB getCollisionBox(Entity entityIn)
  67.     {
  68.         return entityIn.getEntityBoundingBox();
  69.     }
  70.  
  71.     public AxisAlignedBB getBoundingBox()
  72.     {
  73.         return this.getEntityBoundingBox();
  74.     }
  75.  
  76.     public boolean canBePushed()
  77.     {
  78.         return false;
  79.     }
  80.  
  81.     public EntityScorpion(World worldIn, double p_i1705_2_, double p_i1705_4_, double p_i1705_6_)
  82.     {
  83.         this(worldIn);
  84.         this.setPosition(p_i1705_2_, p_i1705_4_, p_i1705_6_);
  85.         this.motionX = 0.0D;
  86.         this.motionY = 0.0D;
  87.         this.motionZ = 0.0D;
  88.         this.prevPosX = p_i1705_2_;
  89.         this.prevPosY = p_i1705_4_;
  90.         this.prevPosZ = p_i1705_6_;
  91.     }
  92.  
  93.     public double getMountedYOffset()
  94.     {
  95.         return (double)this.height * 0.0D + 2D;
  96.     }
  97.  
  98.     public boolean attackEntityFrom(DamageSource source, float amount)
  99.     {
  100.         if (this.isEntityInvulnerable(source))
  101.         {
  102.             return false;
  103.         }
  104.         else if (!this.worldObj.isRemote && !this.isDead)
  105.         {
  106.             if (this.riddenByEntity != null && this.riddenByEntity == source.getEntity() && source instanceof EntityDamageSourceIndirect)
  107.             {
  108.                 return false;
  109.             }
  110.             else
  111.             {
  112.                 this.setForwardDirection(-this.getForwardDirection());
  113.                 this.setTimeSinceHit(10);
  114.                 this.setDamageTaken(this.getDamageTaken() + amount * 10.0F);
  115.                 this.setBeenAttacked();
  116.                 boolean flag = source.getEntity() instanceof EntityPlayer && ((EntityPlayer)source.getEntity()).capabilities.isCreativeMode;
  117.  
  118.                 if (this.getDamageTaken() > 1000000.0F)
  119.                 {
  120.                     if (this.riddenByEntity != null)
  121.                     {
  122.                         this.riddenByEntity.mountEntity(this);
  123.                     }
  124.  
  125.                     if (!flag)
  126.                     {
  127.                         this.dropItemWithOffset(halocraft.Main.itemScorpion, 1, 0.0F);
  128.                     }
  129.  
  130.                     this.setDead();
  131.                 }
  132.  
  133.                 return true;
  134.             }
  135.         }
  136.         else
  137.         {
  138.             return true;
  139.         }
  140.     }
  141.  
  142.     @SideOnly(Side.CLIENT)
  143.     public void performHurtAnimation()
  144.     {
  145.         this.setForwardDirection(-this.getForwardDirection());
  146.         this.setTimeSinceHit(10);
  147.         this.setDamageTaken(this.getDamageTaken() * 11.0F);
  148.     }
  149.  
  150.     public boolean canBeCollidedWith()
  151.     {
  152.         return true;
  153.     }
  154.    
  155.     public World getWorldObj(){
  156.         return this.worldObj;
  157.     }
  158.    
  159.     @SideOnly(Side.CLIENT)
  160.     public void func_180426_a(double p_180426_1_, double p_180426_3_, double p_180426_5_, float p_180426_7_, float p_180426_8_, int p_180426_9_, boolean p_180426_10_)
  161.     {
  162.         if (p_180426_10_ && this.riddenByEntity != null)
  163.         {
  164.             this.prevPosX = this.posX = p_180426_1_;
  165.             this.prevPosY = this.posY = p_180426_3_;
  166.             this.prevPosZ = this.posZ = p_180426_5_;
  167.             this.rotationYaw = p_180426_7_;
  168.             this.rotationPitch = p_180426_8_;
  169.             this.boatPosRotationIncrements = 0;
  170.             this.setPosition(p_180426_1_, p_180426_3_, p_180426_5_);
  171.             this.motionX = this.velocityX = 0.0D;
  172.             this.motionY = this.velocityY = 0.0D;
  173.             this.motionZ = this.velocityZ = 0.0D;
  174.         }
  175.         else
  176.         {
  177.             if (this.isBoatEmpty)
  178.             {
  179.                 this.boatPosRotationIncrements = p_180426_9_ + 5;
  180.             }
  181.             else
  182.             {
  183.                 double d3 = p_180426_1_ - this.posX;
  184.                 double d4 = p_180426_3_ - this.posY;
  185.                 double d5 = p_180426_5_ - this.posZ;
  186.                 double d6 = d3 * d3 + d4 * d4 + d5 * d5;
  187.  
  188.                 if (d6 <= 1.0D)
  189.                 {
  190.                     return;
  191.                 }
  192.  
  193.                 this.boatPosRotationIncrements = 3;
  194.             }
  195.  
  196.             this.boatX = p_180426_1_;
  197.             this.boatY = p_180426_3_;
  198.             this.boatZ = p_180426_5_;
  199.             this.boatYaw = (double)p_180426_7_;
  200.             this.boatPitch = (double)p_180426_8_;
  201.             this.motionX = this.velocityX;
  202.             this.motionY = this.velocityY;
  203.             this.motionZ = this.velocityZ;
  204.         }
  205.     }
  206.  
  207.     @SideOnly(Side.CLIENT)
  208.     public void setVelocity(double x, double y, double z)
  209.     {
  210.         this.velocityX = this.motionX = x;
  211.         this.velocityY = this.motionY = y;
  212.         this.velocityZ = this.motionZ = z;
  213.     }
  214.  
  215.     public void onUpdate()
  216.     {
  217.         super.onUpdate();
  218.  
  219.         if (this.getTimeSinceHit() > 0)
  220.         {
  221.             this.setTimeSinceHit(this.getTimeSinceHit() - 1);
  222.         }
  223.  
  224.         if (this.getDamageTaken() > 0.0F)
  225.         {
  226.             this.setDamageTaken(this.getDamageTaken() - 1.0F);
  227.         }
  228.  
  229.         this.prevPosX = this.posX;
  230.         this.prevPosY = this.posY;
  231.         this.prevPosZ = this.posZ;
  232.         byte b0 = 5;
  233.         double d0 = 0.0D;
  234.  
  235.         for (int i = 0; i < b0; ++i)
  236.         {
  237.             double d1 = this.getEntityBoundingBox().minY + (this.getEntityBoundingBox().maxY - this.getEntityBoundingBox().minY) * (double)(i + 0) / (double)b0 - 0.125D;
  238.             double d3 = this.getEntityBoundingBox().minY + (this.getEntityBoundingBox().maxY - this.getEntityBoundingBox().minY) * (double)(i + 1) / (double)b0 - 0.125D;
  239.             AxisAlignedBB axisalignedbb = new AxisAlignedBB(this.getEntityBoundingBox().minX, d1, this.getEntityBoundingBox().minZ, this.getEntityBoundingBox().maxX, d3, this.getEntityBoundingBox().maxZ);
  240.         }
  241.  
  242.         double d9 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  243.         double d2;
  244.         double d4;
  245.         int j;
  246.  
  247.         if (d9 > 0.2975D)
  248.         {
  249.             d2 = Math.cos((double)this.rotationYaw * Math.PI / 180.0D);
  250.             d4 = Math.sin((double)this.rotationYaw * Math.PI / 180.0D);
  251.  
  252.             for (j = 0; (double)j < 1.0D + d9 * 60.0D; ++j)
  253.             {
  254.                 double d5 = (double)(this.rand.nextFloat() * 2.0F - 1.0F);
  255.                 double d6 = (double)(this.rand.nextInt(2) * 2 - 1) * 0.7D;
  256.                 double d7;
  257.                 double d8;
  258.             }
  259.         }
  260.  
  261.         double d10;
  262.         double d11;
  263.  
  264.         if (this.worldObj.isRemote && this.isBoatEmpty)
  265.         {
  266.             if (this.boatPosRotationIncrements > 0)
  267.             {
  268.                 d2 = this.posX + (this.boatX - this.posX) / (double)this.boatPosRotationIncrements;
  269.                 d4 = this.posY + (this.boatY - this.posY) / (double)this.boatPosRotationIncrements;
  270.                 d10 = this.posZ + (this.boatZ - this.posZ) / (double)this.boatPosRotationIncrements;
  271.                 d11 = MathHelper.wrapAngleTo180_double(this.boatYaw - (double)this.rotationYaw);
  272.                 this.rotationYaw = (float)((double)this.rotationYaw + d11 / (double)this.boatPosRotationIncrements);
  273.                 this.rotationPitch = (float)((double)this.rotationPitch + (this.boatPitch - (double)this.rotationPitch) / (double)this.boatPosRotationIncrements);
  274.                 --this.boatPosRotationIncrements;
  275.                 this.setPosition(d2, d4, d10);
  276.                 this.setRotation(this.rotationYaw, this.rotationPitch);
  277.             }
  278.             else
  279.             {
  280.                 d2 = this.posX + this.motionX;
  281.                 d4 = this.posY + this.motionY;
  282.                 d10 = this.posZ + this.motionZ;
  283.                 this.setPosition(d2, d4, d10);
  284.                 this.motionX *= 0.9900000095367432D;
  285.                 this.motionY *= 0.949999988079071D;
  286.                 this.motionZ *= 0.9900000095367432D;
  287.             }
  288.         }
  289.         else
  290.         {
  291.             if (d0 < 1.0D)
  292.             {
  293.                 d2 = d0 * 2.0D - 1.0D;
  294.                 this.motionY += 0.03999999910593033D * d2;
  295.             }
  296.             else
  297.             {
  298.                 if (this.motionY < 0.0D)
  299.                 {
  300.                     this.motionY /= 2.0D;
  301.                 }
  302.  
  303.                 this.motionY += 0.007000000216066837D;
  304.             }
  305.  
  306.             if (this.riddenByEntity instanceof EntityLivingBase)
  307.             {
  308.                 EntityLivingBase entitylivingbase = (EntityLivingBase)this.riddenByEntity;
  309.                 float f = this.riddenByEntity.rotationYaw + -entitylivingbase.moveStrafing * 90.0F;
  310.                 this.motionX += -Math.sin((double)(f * (float)Math.PI / 180.0F)) * this.speedMultiplier * (double)entitylivingbase.moveForward * 0.05000000074505806D;
  311.                 this.motionZ += Math.cos((double)(f * (float)Math.PI / 180.0F)) * this.speedMultiplier * (double)entitylivingbase.moveForward * 0.05000000074505806D;
  312.             }
  313.  
  314.             d2 = Math.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  315.  
  316.             if (d2 > 0.35D)
  317.             {
  318.                 d4 = 0.35D / d2;
  319.                 this.motionX *= d4;
  320.                 this.motionZ *= d4;
  321.                 d2 = 0.35D;
  322.             }
  323.  
  324.             if (d2 > d9 && this.speedMultiplier < 0.35D)
  325.             {
  326.                 this.speedMultiplier += (0.35D - this.speedMultiplier) / 35.0D;
  327.  
  328.                 if (this.speedMultiplier > 0.35D)
  329.                 {
  330.                     this.speedMultiplier = 0.35D;
  331.                 }
  332.             }
  333.             else
  334.             {
  335.                 this.speedMultiplier -= (this.speedMultiplier - 0.07D) / 35.0D;
  336.  
  337.                 if (this.speedMultiplier < 0.07D)
  338.                 {
  339.                     this.speedMultiplier = 0.07D;
  340.                 }
  341.             }
  342.  
  343.             int l;
  344.  
  345.             for (l = 0; l < 4; ++l)
  346.             {
  347.                 int i1 = MathHelper.floor_double(this.posX + ((double)(l % 2) - 0.5D) * 0.8D);
  348.                 j = MathHelper.floor_double(this.posZ + ((double)(l / 2) - 0.5D) * 0.8D);
  349.  
  350.                 for (int j1 = 0; j1 < 2; ++j1)
  351.                 {
  352.                     int k = MathHelper.floor_double(this.posY) + j1;
  353.                     BlockPos blockpos = new BlockPos(i1, k, j);
  354.                     Block block = this.worldObj.getBlockState(blockpos).getBlock();
  355.  
  356.                     if (block == Blocks.snow_layer)
  357.                     {
  358.                         this.worldObj.setBlockToAir(blockpos);
  359.                         this.isCollidedHorizontally = false;
  360.                     }
  361.                     else if (block == Blocks.waterlily)
  362.                     {
  363.                         this.worldObj.destroyBlock(blockpos, true);
  364.                         this.isCollidedHorizontally = false;
  365.                     }
  366.                 }
  367.             }
  368.  
  369.             this.moveEntity(this.motionX, this.motionY, this.motionZ);
  370.  
  371.            // if (this.isCollidedHorizontally && d9 > 0.2D)
  372.            // {
  373.                // if (!this.worldObj.isRemote && !this.isDead)
  374.                // {
  375.                 //    this.setDead();
  376.                 //    for (l = 0; l < 2; ++l)
  377.                 //    {
  378.                 //        this.dropItemWithOffset(halocraft.Main.HaloIngot, 2, 0.0F);
  379.                 //    }
  380.               //  }
  381.           //  }
  382.         //    else
  383.         //    {
  384.                 this.motionX *= 0.9900000095367432D;
  385.                 this.motionY *= 0.949999988079071D;
  386.                 this.motionZ *= 0.9900000095367432D;
  387.             //}
  388.  
  389.             this.rotationPitch = 0.0F;
  390.             d4 = (double)this.rotationYaw;
  391.             d10 = this.prevPosX - this.posX;
  392.             d11 = this.prevPosZ - this.posZ;
  393.  
  394.             if (d10 * d10 + d11 * d11 > 0.001D)
  395.             {
  396.                 d4 = (double)((float)(Math.atan2(d11, d10) * 180.0D / Math.PI));
  397.             }
  398.  
  399.             double d12 = MathHelper.wrapAngleTo180_double(d4 - (double)this.rotationYaw);
  400.  
  401.             if (d12 > 20.0D)
  402.             {
  403.                 d12 = 20.0D;
  404.             }
  405.  
  406.             if (d12 < -20.0D)
  407.             {
  408.                 d12 = -20.0D;
  409.             }
  410.  
  411.             this.rotationYaw = (float)((double)this.rotationYaw + d12);
  412.             this.setRotation(this.rotationYaw, this.rotationPitch);
  413.  
  414.             if (!this.worldObj.isRemote)
  415.             {
  416.                 List list = this.worldObj.getEntitiesWithinAABBExcludingEntity(this, this.getEntityBoundingBox().expand(0.20000000298023224D, 0.0D, 0.20000000298023224D));
  417.  
  418.                 if (list != null && !list.isEmpty())
  419.                 {
  420.                     for (int k1 = 0; k1 < list.size(); ++k1)
  421.                     {
  422.                         Entity entity = (Entity)list.get(k1);
  423.  
  424.                         if (entity != this.riddenByEntity && entity.canBePushed() && entity instanceof EntityScorpion)
  425.                         {
  426.                             entity.applyEntityCollision(this);
  427.                         }
  428.                     }
  429.                 }
  430.  
  431.                 if (this.riddenByEntity != null && this.riddenByEntity.isDead)
  432.                 {
  433.                     this.riddenByEntity = null;
  434.                 }
  435.             }
  436.         }
  437.     }
  438.  
  439.     public void updateRiderPosition()
  440.     {
  441.         if (this.riddenByEntity != null)
  442.         {
  443.             double d0 = Math.cos((double)this.rotationYaw * Math.PI / 180.0D) * 0.4D;
  444.             double d1 = Math.sin((double)this.rotationYaw * Math.PI / 180.0D) * 0.4D;
  445.             this.riddenByEntity.setPosition(this.posX + d0, this.posY + this.getMountedYOffset() + this.riddenByEntity.getYOffset(), this.posZ + d1);
  446.         }
  447.     }
  448.  
  449.     protected void writeEntityToNBT(NBTTagCompound tagCompound) {}
  450.  
  451.     protected void readEntityFromNBT(NBTTagCompound tagCompund) {}
  452.  
  453.     public boolean interactFirst(EntityPlayer playerIn)
  454.     {
  455.         if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer && this.riddenByEntity != playerIn)
  456.         {
  457.             return true;
  458.         }
  459.         else
  460.         {
  461.             if (!this.worldObj.isRemote)
  462.             {
  463.                 playerIn.mountEntity(this);
  464.             }
  465.  
  466.             return true;
  467.         }
  468.     }
  469.  
  470.     protected void func_180433_a(double p_180433_1_, boolean p_180433_3_, Block p_180433_4_, BlockPos p_180433_5_)
  471.     {
  472.         if (p_180433_3_)
  473.         {
  474.             if (this.fallDistance > 3.0F)
  475.             {
  476.                 this.fall(this.fallDistance, 1.0F);
  477.  
  478.                 if (!this.worldObj.isRemote && !this.isDead)
  479.                 {
  480.                     this.setDead();
  481.                     int i;
  482.  
  483.                     for (i = 0; i < 2; ++i)
  484.                     {
  485.                         this.dropItemWithOffset(halocraft.Main.HaloIngot, 2, 0.0F);
  486.                     }
  487.                 }
  488.  
  489.                 this.fallDistance = 0.0F;
  490.             }
  491.         }
  492.         else if (this.worldObj.getBlockState((new BlockPos(this)).down()).getBlock().getMaterial() != Material.water && p_180433_1_ < 0.0D)
  493.         {
  494.             this.fallDistance = (float)((double)this.fallDistance - p_180433_1_);
  495.         }
  496.     }
  497.  
  498.     public void setDamageTaken(float p_70266_1_)
  499.     {
  500.         this.dataWatcher.updateObject(19, Float.valueOf(p_70266_1_));
  501.     }
  502.  
  503.     public float getDamageTaken()
  504.     {
  505.         return this.dataWatcher.getWatchableObjectFloat(19);
  506.     }
  507.  
  508.     public void setTimeSinceHit(int p_70265_1_)
  509.     {
  510.         this.dataWatcher.updateObject(17, Integer.valueOf(p_70265_1_));
  511.     }
  512.  
  513.     public int getTimeSinceHit()
  514.     {
  515.         return this.dataWatcher.getWatchableObjectInt(17);
  516.     }
  517.  
  518.     public void setForwardDirection(int p_70269_1_)
  519.     {
  520.         this.dataWatcher.updateObject(18, Integer.valueOf(p_70269_1_));
  521.     }
  522.  
  523.     public int getForwardDirection()
  524.     {
  525.         return this.dataWatcher.getWatchableObjectInt(18);
  526.     }
  527.  
  528.     @SideOnly(Side.CLIENT)
  529.     public void setIsBoatEmpty(boolean p_70270_1_)
  530.     {
  531.         this.isBoatEmpty = p_70270_1_;
  532.     }
  533. }
Advertisement
Add Comment
Please, Sign In to add comment