Advertisement
Camellias_

EntityBullet.java

Jul 10th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.79 KB | None | 0 0
  1. package entities;
  2.  
  3. import com.google.common.base.Predicate;
  4. import com.google.common.base.Predicates;
  5. import java.util.List;
  6. import javax.annotation.Nullable;
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.enchantment.EnchantmentHelper;
  11. import net.minecraft.entity.Entity;
  12. import net.minecraft.entity.EntityLivingBase;
  13. import net.minecraft.entity.IProjectile;
  14. import net.minecraft.entity.MoverType;
  15. import net.minecraft.entity.monster.EntityEnderman;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.entity.player.EntityPlayerMP;
  18. import net.minecraft.init.Enchantments;
  19. import net.minecraft.init.SoundEvents;
  20. import net.minecraft.item.ItemStack;
  21. import net.minecraft.nbt.NBTTagCompound;
  22. import net.minecraft.network.datasync.DataParameter;
  23. import net.minecraft.network.datasync.DataSerializers;
  24. import net.minecraft.network.datasync.EntityDataManager;
  25. import net.minecraft.network.play.server.SPacketChangeGameState;
  26. import net.minecraft.util.DamageSource;
  27. import net.minecraft.util.EntitySelectors;
  28. import net.minecraft.util.EnumParticleTypes;
  29. import net.minecraft.util.ResourceLocation;
  30. import net.minecraft.util.datafix.DataFixer;
  31. import net.minecraft.util.math.AxisAlignedBB;
  32. import net.minecraft.util.math.BlockPos;
  33. import net.minecraft.util.math.MathHelper;
  34. import net.minecraft.util.math.RayTraceResult;
  35. import net.minecraft.util.math.Vec3d;
  36. import net.minecraft.world.World;
  37. import net.minecraftforge.fml.relauncher.Side;
  38. import net.minecraftforge.fml.relauncher.SideOnly;
  39.  
  40. public abstract class EntityBullet extends Entity implements IProjectile
  41. {
  42.     private static final Predicate<Entity> ARROW_TARGETS = Predicates.and(new Predicate[] {EntitySelectors.NOT_SPECTATING, EntitySelectors.IS_ALIVE, new Predicate<Entity>()
  43.     {
  44.         public boolean apply(@Nullable Entity p_apply_1_)
  45.         {
  46.             return p_apply_1_.canBeCollidedWith();
  47.         }
  48.     }
  49.                                                                                            });
  50.     private static final DataParameter<Byte> CRITICAL = EntityDataManager.<Byte>createKey(EntityBullet.class, DataSerializers.BYTE);
  51.     private int xTile;
  52.     private int yTile;
  53.     private int zTile;
  54.     private Block inTile;
  55.     private int inData;
  56.     protected boolean inGround;
  57.     protected int timeInGround;
  58.     public EntityBullet.PickupStatus pickupStatus;
  59.     public int arrowShake;
  60.     public Entity shootingEntity;
  61.     private int ticksInGround;
  62.     private int ticksInAir;
  63.     private double damage;
  64.     private int knockbackStrength;
  65.  
  66.     public EntityBullet(World worldIn)
  67.     {
  68.         super(worldIn);
  69.         this.xTile = -1;
  70.         this.yTile = -1;
  71.         this.zTile = -1;
  72.         this.pickupStatus = EntityBullet.PickupStatus.DISALLOWED;
  73.         this.damage = 2.0D;
  74.         this.setSize(0.5F, 0.5F);
  75.     }
  76.  
  77.     public EntityBullet(World worldIn, double x, double y, double z)
  78.     {
  79.         this(worldIn);
  80.         this.setPosition(x, y, z);
  81.     }
  82.  
  83.     public EntityBullet(World worldIn, EntityLivingBase shooter)
  84.     {
  85.         this(worldIn, shooter.posX, shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D, shooter.posZ);
  86.         this.shootingEntity = shooter;
  87.  
  88.         if (shooter instanceof EntityPlayer)
  89.         {
  90.             this.pickupStatus = EntityBullet.PickupStatus.ALLOWED;
  91.         }
  92.     }
  93.  
  94.     @SideOnly(Side.CLIENT)
  95.     public boolean isInRangeToRenderDist(double distance)
  96.     {
  97.         double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 10.0D;
  98.  
  99.         if (Double.isNaN(d0))
  100.         {
  101.             d0 = 1.0D;
  102.         }
  103.  
  104.         d0 = d0 * 64.0D * getRenderDistanceWeight();
  105.         return distance < d0 * d0;
  106.     }
  107.  
  108.     protected void entityInit()
  109.     {
  110.         this.dataManager.register(CRITICAL, Byte.valueOf((byte)0));
  111.     }
  112.  
  113.     public void setAim(Entity shooter, float pitch, float yaw, float p_184547_4_, float velocity, float inaccuracy)
  114.     {
  115.         float f = -MathHelper.sin(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
  116.         float f1 = -MathHelper.sin(pitch * 0.017453292F);
  117.         float f2 = MathHelper.cos(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
  118.         this.setThrowableHeading((double)f, (double)f1, (double)f2, velocity, inaccuracy);
  119.         this.motionX += shooter.motionX;
  120.         this.motionZ += shooter.motionZ;
  121.  
  122.         if (!shooter.onGround)
  123.         {
  124.             this.motionY += shooter.motionY;
  125.         }
  126.     }
  127.  
  128.     public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy)
  129.     {
  130.         float f = MathHelper.sqrt(x * x + y * y + z * z);
  131.         x = x / (double)f;
  132.         y = y / (double)f;
  133.         z = z / (double)f;
  134.         x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  135.         y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  136.         z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  137.         x = x * (double)velocity;
  138.         y = y * (double)velocity;
  139.         z = z * (double)velocity;
  140.         this.motionX = x;
  141.         this.motionY = y;
  142.         this.motionZ = z;
  143.         float f1 = MathHelper.sqrt(x * x + z * z);
  144.         this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
  145.         this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
  146.         this.prevRotationYaw = this.rotationYaw;
  147.         this.prevRotationPitch = this.rotationPitch;
  148.         this.ticksInGround = 0;
  149.     }
  150.  
  151.     @SideOnly(Side.CLIENT)
  152.     public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
  153.     {
  154.         this.setPosition(x, y, z);
  155.         this.setRotation(yaw, pitch);
  156.     }
  157.  
  158.     @SideOnly(Side.CLIENT)
  159.     public void setVelocity(double x, double y, double z)
  160.     {
  161.         this.motionX = x;
  162.         this.motionY = y;
  163.         this.motionZ = z;
  164.  
  165.         if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  166.         {
  167.             float f = MathHelper.sqrt(x * x + z * z);
  168.             this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
  169.             this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
  170.             this.prevRotationPitch = this.rotationPitch;
  171.             this.prevRotationYaw = this.rotationYaw;
  172.             this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
  173.             this.ticksInGround = 0;
  174.         }
  175.     }
  176.  
  177.     public void onUpdate()
  178.     {
  179.         super.onUpdate();
  180.  
  181.         if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  182.         {
  183.             float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  184.             this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
  185.             this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI));
  186.             this.prevRotationYaw = this.rotationYaw;
  187.             this.prevRotationPitch = this.rotationPitch;
  188.         }
  189.  
  190.         BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
  191.         IBlockState iblockstate = this.world.getBlockState(blockpos);
  192.         Block block = iblockstate.getBlock();
  193.  
  194.         if (iblockstate.getMaterial() != Material.AIR)
  195.         {
  196.             AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
  197.  
  198.             if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).isVecInside(new Vec3d(this.posX, this.posY, this.posZ)))
  199.             {
  200.                 this.inGround = true;
  201.             }
  202.         }
  203.  
  204.         if (this.arrowShake > 0)
  205.         {
  206.             --this.arrowShake;
  207.         }
  208.  
  209.         if (this.inGround)
  210.         {
  211.             int j = block.getMetaFromState(iblockstate);
  212.  
  213.             if ((block != this.inTile || j != this.inData) && !this.world.collidesWithAnyBlock(this.getEntityBoundingBox().expandXyz(0.05D)))
  214.             {
  215.                 this.inGround = false;
  216.                 this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
  217.                 this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
  218.                 this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
  219.                 this.ticksInGround = 0;
  220.                 this.ticksInAir = 0;
  221.             }
  222.             else
  223.             {
  224.                 ++this.ticksInGround;
  225.  
  226.                 if (this.ticksInGround >= 1200)
  227.                 {
  228.                     this.setDead();
  229.                 }
  230.             }
  231.  
  232.             ++this.timeInGround;
  233.         }
  234.         else
  235.         {
  236.             this.timeInGround = 0;
  237.             ++this.ticksInAir;
  238.             Vec3d vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
  239.             Vec3d vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  240.             RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d1, vec3d, false, true, false);
  241.             vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
  242.             vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  243.  
  244.             if (raytraceresult != null)
  245.             {
  246.                 vec3d = new Vec3d(raytraceresult.hitVec.xCoord, raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
  247.             }
  248.  
  249.             Entity entity = this.findEntityOnPath(vec3d1, vec3d);
  250.  
  251.             if (entity != null)
  252.             {
  253.                 raytraceresult = new RayTraceResult(entity);
  254.             }
  255.  
  256.             if (raytraceresult != null && raytraceresult.entityHit instanceof EntityPlayer)
  257.             {
  258.                 EntityPlayer entityplayer = (EntityPlayer)raytraceresult.entityHit;
  259.  
  260.                 if (this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
  261.                 {
  262.                     raytraceresult = null;
  263.                 }
  264.             }
  265.  
  266.             if (raytraceresult != null)
  267.             {
  268.                 this.onHit(raytraceresult);
  269.             }
  270.  
  271.             if (this.getIsCritical())
  272.             {
  273.                 for (int k = 0; k < 4; ++k)
  274.                 {
  275.                     this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX + this.motionX * (double)k / 4.0D, this.posY + this.motionY * (double)k / 4.0D, this.posZ + this.motionZ * (double)k / 4.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ, new int[0]);
  276.                 }
  277.             }
  278.  
  279.             this.posX += this.motionX;
  280.             this.posY += this.motionY;
  281.             this.posZ += this.motionZ;
  282.             float f4 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  283.             this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
  284.  
  285.             for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f4) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
  286.             {
  287.                 ;
  288.             }
  289.  
  290.             while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
  291.             {
  292.                 this.prevRotationPitch += 360.0F;
  293.             }
  294.  
  295.             while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  296.             {
  297.                 this.prevRotationYaw -= 360.0F;
  298.             }
  299.  
  300.             while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  301.             {
  302.                 this.prevRotationYaw += 360.0F;
  303.             }
  304.  
  305.             this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  306.             this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  307.             float f1 = 0.99F;
  308.             float f2 = 0.05F;
  309.  
  310.             if (this.isInWater())
  311.             {
  312.                 for (int i = 0; i < 4; ++i)
  313.                 {
  314.                     float f3 = 0.25F;
  315.                     this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ, new int[0]);
  316.                 }
  317.  
  318.                 f1 = 0.6F;
  319.             }
  320.  
  321.             if (this.isWet())
  322.             {
  323.                 this.extinguish();
  324.             }
  325.  
  326.             this.motionX *= (double)f1;
  327.             this.motionY *= (double)f1;
  328.             this.motionZ *= (double)f1;
  329.  
  330.             if (!this.hasNoGravity())
  331.             {
  332.                 this.motionY -= 0.00000005074505806D;
  333.             }
  334.  
  335.             this.setPosition(this.posX, this.posY, this.posZ);
  336.             this.doBlockCollisions();
  337.         }
  338.     }
  339.  
  340.     protected void onHit(RayTraceResult raytraceResultIn)
  341.     {
  342.         Entity entity = raytraceResultIn.entityHit;
  343.  
  344.         if (entity != null)
  345.         {
  346.             float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  347.             int i = MathHelper.ceil((double)f * this.damage);
  348.  
  349.             if (this.getIsCritical())
  350.             {
  351.                 i += this.rand.nextInt(i / 2 + 2);
  352.             }
  353.  
  354.             DamageSource damagesource;
  355.  
  356.             if (this.shootingEntity == null)
  357.             {
  358.                 damagesource = DamageSource.causeThrownDamage(this, this);
  359.             }
  360.             else
  361.             {
  362.                 damagesource = DamageSource.causeThrownDamage(this, this.shootingEntity);
  363.             }
  364.  
  365.             if (this.isBurning() && !(entity instanceof EntityEnderman))
  366.             {
  367.                 entity.setFire(5);
  368.             }
  369.  
  370.             if (entity.attackEntityFrom(damagesource, (float)i))
  371.             {
  372.                 if (entity instanceof EntityLivingBase)
  373.                 {
  374.                     EntityLivingBase entitylivingbase = (EntityLivingBase)entity;
  375.  
  376.                     if (!this.world.isRemote)
  377.                     {
  378.                         entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
  379.                     }
  380.  
  381.                     if (this.knockbackStrength > 0)
  382.                     {
  383.                         float f1 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  384.  
  385.                         if (f1 > 0.0F)
  386.                         {
  387.                             entitylivingbase.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1);
  388.                         }
  389.                     }
  390.  
  391.                     if (this.shootingEntity instanceof EntityLivingBase)
  392.                     {
  393.                         EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
  394.                         EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase)this.shootingEntity, entitylivingbase);
  395.                     }
  396.  
  397.                     this.arrowHit(entitylivingbase);
  398.  
  399.                     if (this.shootingEntity != null && entitylivingbase != this.shootingEntity && entitylivingbase instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
  400.                     {
  401.                         ((EntityPlayerMP)this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
  402.                     }
  403.                 }
  404.  
  405.                 this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  406.  
  407.                 if (!(entity instanceof EntityEnderman))
  408.                 {
  409.                     this.setDead();
  410.                 }
  411.             }
  412.             else
  413.             {
  414.                 this.motionX *= -0.10000000149011612D;
  415.                 this.motionY *= -0.10000000149011612D;
  416.                 this.motionZ *= -0.10000000149011612D;
  417.                 this.rotationYaw += 180.0F;
  418.                 this.prevRotationYaw += 180.0F;
  419.                 this.ticksInAir = 0;
  420.  
  421.                 if (!this.world.isRemote && this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ < 0.0010000000474974513D)
  422.                 {
  423.                     if (this.pickupStatus == EntityBullet.PickupStatus.ALLOWED)
  424.                     {
  425.                         this.entityDropItem(this.getBulletStack(), 0.1F);
  426.                     }
  427.  
  428.                     this.setDead();
  429.                 }
  430.             }
  431.         }
  432.         else
  433.         {
  434.             BlockPos blockpos = raytraceResultIn.getBlockPos();
  435.             this.xTile = blockpos.getX();
  436.             this.yTile = blockpos.getY();
  437.             this.zTile = blockpos.getZ();
  438.             IBlockState iblockstate = this.world.getBlockState(blockpos);
  439.             this.inTile = iblockstate.getBlock();
  440.             this.inData = this.inTile.getMetaFromState(iblockstate);
  441.             this.motionX = (double)((float)(raytraceResultIn.hitVec.xCoord - this.posX));
  442.             this.motionY = (double)((float)(raytraceResultIn.hitVec.yCoord - this.posY));
  443.             this.motionZ = (double)((float)(raytraceResultIn.hitVec.zCoord - this.posZ));
  444.             float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  445.             this.posX -= this.motionX / (double)f2 * 0.05000000074505806D;
  446.             this.posY -= this.motionY / (double)f2 * 0.05000000074505806D;
  447.             this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D;
  448.             this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  449.             this.inGround = true;
  450.             this.arrowShake = 7;
  451.             this.setIsCritical(false);
  452.  
  453.             if (iblockstate.getMaterial() != Material.AIR)
  454.             {
  455.                 this.inTile.onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
  456.             }
  457.         }
  458.     }
  459.  
  460.     public void move(MoverType type, double x, double y, double z)
  461.     {
  462.         super.move(type, x, y, z);
  463.  
  464.         if (this.inGround)
  465.         {
  466.             this.xTile = MathHelper.floor(this.posX);
  467.             this.yTile = MathHelper.floor(this.posY);
  468.             this.zTile = MathHelper.floor(this.posZ);
  469.         }
  470.     }
  471.  
  472.     protected void arrowHit(EntityLivingBase living)
  473.     {
  474.     }
  475.  
  476.     @Nullable
  477.     protected Entity findEntityOnPath(Vec3d start, Vec3d end)
  478.     {
  479.         Entity entity = null;
  480.         List<Entity> list = this.world.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expandXyz(1.0D), ARROW_TARGETS);
  481.         double d0 = 0.0D;
  482.  
  483.         for (int i = 0; i < list.size(); ++i)
  484.         {
  485.             Entity entity1 = (Entity)list.get(i);
  486.  
  487.             if (entity1 != this.shootingEntity || this.ticksInAir >= 5)
  488.             {
  489.                 AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expandXyz(0.30000001192092896D);
  490.                 RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(start, end);
  491.  
  492.                 if (raytraceresult != null)
  493.                 {
  494.                     double d1 = start.squareDistanceTo(raytraceresult.hitVec);
  495.  
  496.                     if (d1 < d0 || d0 == 0.0D)
  497.                     {
  498.                         entity = entity1;
  499.                         d0 = d1;
  500.                     }
  501.                 }
  502.             }
  503.         }
  504.  
  505.         return entity;
  506.     }
  507.  
  508.     public static void registerFixesArrow(DataFixer fixer, String name)
  509.     {
  510.     }
  511.  
  512.     public static void registerFixesArrow(DataFixer fixer)
  513.     {
  514.         registerFixesArrow(fixer, "Bullet");
  515.     }
  516.  
  517.     public void writeEntityToNBT(NBTTagCompound compound)
  518.     {
  519.         compound.setInteger("xTile", this.xTile);
  520.         compound.setInteger("yTile", this.yTile);
  521.         compound.setInteger("zTile", this.zTile);
  522.         compound.setShort("life", (short)this.ticksInGround);
  523.         ResourceLocation resourcelocation = (ResourceLocation)Block.REGISTRY.getNameForObject(this.inTile);
  524.         compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
  525.         compound.setByte("inData", (byte)this.inData);
  526.         compound.setByte("shake", (byte)this.arrowShake);
  527.         compound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
  528.         compound.setByte("pickup", (byte)this.pickupStatus.ordinal());
  529.         compound.setDouble("damage", this.damage);
  530.         compound.setBoolean("crit", this.getIsCritical());
  531.     }
  532.  
  533.     public void readEntityFromNBT(NBTTagCompound compound)
  534.     {
  535.         this.xTile = compound.getInteger("xTile");
  536.         this.yTile = compound.getInteger("yTile");
  537.         this.zTile = compound.getInteger("zTile");
  538.         this.ticksInGround = compound.getShort("life");
  539.  
  540.         if (compound.hasKey("inTile", 8))
  541.         {
  542.             this.inTile = Block.getBlockFromName(compound.getString("inTile"));
  543.         }
  544.         else
  545.         {
  546.             this.inTile = Block.getBlockById(compound.getByte("inTile") & 255);
  547.         }
  548.  
  549.         this.inData = compound.getByte("inData") & 255;
  550.         this.arrowShake = compound.getByte("shake") & 255;
  551.         this.inGround = compound.getByte("inGround") == 1;
  552.  
  553.         if (compound.hasKey("damage", 99))
  554.         {
  555.             this.damage = compound.getDouble("damage");
  556.         }
  557.  
  558.         if (compound.hasKey("pickup", 99))
  559.         {
  560.             this.pickupStatus = EntityBullet.PickupStatus.getByOrdinal(compound.getByte("pickup"));
  561.         }
  562.         else if (compound.hasKey("player", 99))
  563.         {
  564.             this.pickupStatus = compound.getBoolean("player") ? EntityBullet.PickupStatus.ALLOWED : EntityBullet.PickupStatus.DISALLOWED;
  565.         }
  566.  
  567.         this.setIsCritical(compound.getBoolean("crit"));
  568.     }
  569.  
  570.     public void onCollideWithPlayer(EntityPlayer entityIn)
  571.     {
  572.         if (!this.world.isRemote && this.inGround && this.arrowShake <= 0)
  573.         {
  574.             boolean flag = this.pickupStatus == EntityBullet.PickupStatus.ALLOWED || this.pickupStatus == EntityBullet.PickupStatus.CREATIVE_ONLY && entityIn.capabilities.isCreativeMode;
  575.  
  576.             if (this.pickupStatus == EntityBullet.PickupStatus.ALLOWED && !entityIn.inventory.addItemStackToInventory(this.getBulletStack()))
  577.             {
  578.                 flag = false;
  579.             }
  580.  
  581.             if (flag)
  582.             {
  583.                 entityIn.onItemPickup(this, 1);
  584.                 this.setDead();
  585.             }
  586.         }
  587.     }
  588.  
  589.     protected abstract ItemStack getBulletStack();
  590.  
  591.     protected boolean canTriggerWalking()
  592.     {
  593.         return false;
  594.     }
  595.  
  596.     public void setDamage(double damageIn)
  597.     {
  598.         this.damage = damageIn;
  599.     }
  600.  
  601.     public double getDamage()
  602.     {
  603.         return this.damage;
  604.     }
  605.  
  606.     public void setKnockbackStrength(int knockbackStrengthIn)
  607.     {
  608.         this.knockbackStrength = knockbackStrengthIn;
  609.     }
  610.  
  611.     public boolean canBeAttackedWithItem()
  612.     {
  613.         return false;
  614.     }
  615.  
  616.     public float getEyeHeight()
  617.     {
  618.         return 0.0F;
  619.     }
  620.  
  621.     public void setIsCritical(boolean critical)
  622.     {
  623.         byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
  624.  
  625.         if (critical)
  626.         {
  627.             this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 | 1)));
  628.         }
  629.         else
  630.         {
  631.             this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 & -2)));
  632.         }
  633.     }
  634.  
  635.     public boolean getIsCritical()
  636.     {
  637.         byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
  638.         return (b0 & 1) != 0;
  639.     }
  640.  
  641.     public void setEnchantmentEffectsFromEntity(EntityLivingBase p_190547_1_, float p_190547_2_)
  642.     {
  643.         int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, p_190547_1_);
  644.         int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, p_190547_1_);
  645.         this.setDamage((double)(p_190547_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.world.getDifficulty().getDifficultyId() * 0.11F));
  646.  
  647.         if (i > 0)
  648.         {
  649.             this.setDamage(this.getDamage() + (double)i * 0.5D + 0.5D);
  650.         }
  651.  
  652.         if (j > 0)
  653.         {
  654.             this.setKnockbackStrength(j);
  655.         }
  656.  
  657.         if (EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FLAME, p_190547_1_) > 0)
  658.         {
  659.             this.setFire(100);
  660.         }
  661.     }
  662.  
  663.     public static enum PickupStatus
  664.     {
  665.         DISALLOWED,
  666.         ALLOWED,
  667.         CREATIVE_ONLY;
  668.  
  669.         public static EntityBullet.PickupStatus getByOrdinal(int ordinal)
  670.         {
  671.             if (ordinal < 0 || ordinal > values().length)
  672.             {
  673.                 ordinal = 0;
  674.             }
  675.  
  676.             return values()[ordinal];
  677.         }
  678.         protected float getGravityVelocity()
  679.         {
  680.             return 0.005F;
  681.         }
  682.     }
  683. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement