Advertisement
hassansyyid

Untitled

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