SHARE
TWEET

EntityBullet.java

Camellias_ Jul 7th, 2017 34 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     /** 1 if the player can pick up the arrow */
  59.     public EntityBullet.PickupStatus pickupStatus;
  60.     /** Seems to be some sort of timer for animating an arrow. */
  61.     public int arrowShake;
  62.     /** The owner of this arrow. */
  63.     public Entity shootingEntity;
  64.     private int ticksInGround;
  65.     private int ticksInAir;
  66.     private double damage;
  67.     /** The amount of knockback an arrow applies when it hits a mob. */
  68.     private int knockbackStrength;
  69.  
  70.     public EntityBullet(World worldIn)
  71.     {
  72.         super(worldIn);
  73.         this.xTile = -1;
  74.         this.yTile = -1;
  75.         this.zTile = -1;
  76.         this.pickupStatus = EntityBullet.PickupStatus.DISALLOWED;
  77.         this.damage = 2.0D;
  78.         this.setSize(0.5F, 0.5F);
  79.     }
  80.  
  81.     public EntityBullet(World worldIn, double x, double y, double z)
  82.     {
  83.         this(worldIn);
  84.         this.setPosition(x, y, z);
  85.     }
  86.  
  87.     public EntityBullet(World worldIn, EntityLivingBase shooter)
  88.     {
  89.         this(worldIn, shooter.posX, shooter.posY + (double)shooter.getEyeHeight() - 0.10000000149011612D, shooter.posZ);
  90.         this.shootingEntity = shooter;
  91.  
  92.         if (shooter instanceof EntityPlayer)
  93.         {
  94.             this.pickupStatus = EntityBullet.PickupStatus.ALLOWED;
  95.         }
  96.     }
  97.  
  98.     /**
  99.      * Checks if the entity is in range to render.
  100.      */
  101.     @SideOnly(Side.CLIENT)
  102.     public boolean isInRangeToRenderDist(double distance)
  103.     {
  104.         double d0 = this.getEntityBoundingBox().getAverageEdgeLength() * 10.0D;
  105.  
  106.         if (Double.isNaN(d0))
  107.         {
  108.             d0 = 1.0D;
  109.         }
  110.  
  111.         d0 = d0 * 64.0D * getRenderDistanceWeight();
  112.         return distance < d0 * d0;
  113.     }
  114.  
  115.     protected void entityInit()
  116.     {
  117.         this.dataManager.register(CRITICAL, Byte.valueOf((byte)0));
  118.     }
  119.  
  120.     public void setAim(Entity shooter, float pitch, float yaw, float p_184547_4_, float velocity, float inaccuracy)
  121.     {
  122.         float f = -MathHelper.sin(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
  123.         float f1 = -MathHelper.sin(pitch * 0.017453292F);
  124.         float f2 = MathHelper.cos(yaw * 0.017453292F) * MathHelper.cos(pitch * 0.017453292F);
  125.         this.setThrowableHeading((double)f, (double)f1, (double)f2, velocity, inaccuracy);
  126.         this.motionX += shooter.motionX;
  127.         this.motionZ += shooter.motionZ;
  128.  
  129.         if (!shooter.onGround)
  130.         {
  131.             this.motionY += shooter.motionY;
  132.         }
  133.     }
  134.  
  135.     /**
  136.      * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction.
  137.      */
  138.     public void setThrowableHeading(double x, double y, double z, float velocity, float inaccuracy)
  139.     {
  140.         float f = MathHelper.sqrt(x * x + y * y + z * z);
  141.         x = x / (double)f;
  142.         y = y / (double)f;
  143.         z = z / (double)f;
  144.         x = x + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  145.         y = y + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  146.         z = z + this.rand.nextGaussian() * 0.007499999832361937D * (double)inaccuracy;
  147.         x = x * (double)velocity;
  148.         y = y * (double)velocity;
  149.         z = z * (double)velocity;
  150.         this.motionX = x;
  151.         this.motionY = y;
  152.         this.motionZ = z;
  153.         float f1 = MathHelper.sqrt(x * x + z * z);
  154.         this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
  155.         this.rotationPitch = (float)(MathHelper.atan2(y, (double)f1) * (180D / Math.PI));
  156.         this.prevRotationYaw = this.rotationYaw;
  157.         this.prevRotationPitch = this.rotationPitch;
  158.         this.ticksInGround = 0;
  159.     }
  160.  
  161.     /**
  162.      * Set the position and rotation values directly without any clamping.
  163.      */
  164.     @SideOnly(Side.CLIENT)
  165.     public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int posRotationIncrements, boolean teleport)
  166.     {
  167.         this.setPosition(x, y, z);
  168.         this.setRotation(yaw, pitch);
  169.     }
  170.  
  171.     /**
  172.      * Updates the velocity of the entity to a new value.
  173.      */
  174.     @SideOnly(Side.CLIENT)
  175.     public void setVelocity(double x, double y, double z)
  176.     {
  177.         this.motionX = x;
  178.         this.motionY = y;
  179.         this.motionZ = z;
  180.  
  181.         if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  182.         {
  183.             float f = MathHelper.sqrt(x * x + z * z);
  184.             this.rotationPitch = (float)(MathHelper.atan2(y, (double)f) * (180D / Math.PI));
  185.             this.rotationYaw = (float)(MathHelper.atan2(x, z) * (180D / Math.PI));
  186.             this.prevRotationPitch = this.rotationPitch;
  187.             this.prevRotationYaw = this.rotationYaw;
  188.             this.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
  189.             this.ticksInGround = 0;
  190.         }
  191.     }
  192.  
  193.     /**
  194.      * Called to update the entity's position/logic.
  195.      */
  196.     public void onUpdate()
  197.     {
  198.         super.onUpdate();
  199.  
  200.         if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F)
  201.         {
  202.             float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  203.             this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
  204.             this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f) * (180D / Math.PI));
  205.             this.prevRotationYaw = this.rotationYaw;
  206.             this.prevRotationPitch = this.rotationPitch;
  207.         }
  208.  
  209.         BlockPos blockpos = new BlockPos(this.xTile, this.yTile, this.zTile);
  210.         IBlockState iblockstate = this.world.getBlockState(blockpos);
  211.         Block block = iblockstate.getBlock();
  212.  
  213.         if (iblockstate.getMaterial() != Material.AIR)
  214.         {
  215.             AxisAlignedBB axisalignedbb = iblockstate.getCollisionBoundingBox(this.world, blockpos);
  216.  
  217.             if (axisalignedbb != Block.NULL_AABB && axisalignedbb.offset(blockpos).isVecInside(new Vec3d(this.posX, this.posY, this.posZ)))
  218.             {
  219.                 this.inGround = true;
  220.             }
  221.         }
  222.  
  223.         if (this.arrowShake > 0)
  224.         {
  225.             --this.arrowShake;
  226.         }
  227.  
  228.         if (this.inGround)
  229.         {
  230.             int j = block.getMetaFromState(iblockstate);
  231.  
  232.             if ((block != this.inTile || j != this.inData) && !this.world.collidesWithAnyBlock(this.getEntityBoundingBox().expandXyz(0.05D)))
  233.             {
  234.                 this.inGround = false;
  235.                 this.motionX *= (double)(this.rand.nextFloat() * 0.2F);
  236.                 this.motionY *= (double)(this.rand.nextFloat() * 0.2F);
  237.                 this.motionZ *= (double)(this.rand.nextFloat() * 0.2F);
  238.                 this.ticksInGround = 0;
  239.                 this.ticksInAir = 0;
  240.             }
  241.             else
  242.             {
  243.                 ++this.ticksInGround;
  244.  
  245.                 if (this.ticksInGround >= 1200)
  246.                 {
  247.                     this.setDead();
  248.                 }
  249.             }
  250.  
  251.             ++this.timeInGround;
  252.         }
  253.         else
  254.         {
  255.             this.timeInGround = 0;
  256.             ++this.ticksInAir;
  257.             Vec3d vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
  258.             Vec3d vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  259.             RayTraceResult raytraceresult = this.world.rayTraceBlocks(vec3d1, vec3d, false, true, false);
  260.             vec3d1 = new Vec3d(this.posX, this.posY, this.posZ);
  261.             vec3d = new Vec3d(this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
  262.  
  263.             if (raytraceresult != null)
  264.             {
  265.                 vec3d = new Vec3d(raytraceresult.hitVec.xCoord, raytraceresult.hitVec.yCoord, raytraceresult.hitVec.zCoord);
  266.             }
  267.  
  268.             Entity entity = this.findEntityOnPath(vec3d1, vec3d);
  269.  
  270.             if (entity != null)
  271.             {
  272.                 raytraceresult = new RayTraceResult(entity);
  273.             }
  274.  
  275.             if (raytraceresult != null && raytraceresult.entityHit instanceof EntityPlayer)
  276.             {
  277.                 EntityPlayer entityplayer = (EntityPlayer)raytraceresult.entityHit;
  278.  
  279.                 if (this.shootingEntity instanceof EntityPlayer && !((EntityPlayer)this.shootingEntity).canAttackPlayer(entityplayer))
  280.                 {
  281.                     raytraceresult = null;
  282.                 }
  283.             }
  284.  
  285.             if (raytraceresult != null)
  286.             {
  287.                 this.onHit(raytraceresult);
  288.             }
  289.  
  290.             if (this.getIsCritical())
  291.             {
  292.                 for (int k = 0; k < 4; ++k)
  293.                 {
  294.                     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]);
  295.                 }
  296.             }
  297.  
  298.             this.posX += this.motionX;
  299.             this.posY += this.motionY;
  300.             this.posZ += this.motionZ;
  301.             float f4 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  302.             this.rotationYaw = (float)(MathHelper.atan2(this.motionX, this.motionZ) * (180D / Math.PI));
  303.  
  304.             for (this.rotationPitch = (float)(MathHelper.atan2(this.motionY, (double)f4) * (180D / Math.PI)); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
  305.             {
  306.                 ;
  307.             }
  308.  
  309.             while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
  310.             {
  311.                 this.prevRotationPitch += 360.0F;
  312.             }
  313.  
  314.             while (this.rotationYaw - this.prevRotationYaw < -180.0F)
  315.             {
  316.                 this.prevRotationYaw -= 360.0F;
  317.             }
  318.  
  319.             while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
  320.             {
  321.                 this.prevRotationYaw += 360.0F;
  322.             }
  323.  
  324.             this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
  325.             this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
  326.             float f1 = 0.99F;
  327.             float f2 = 0.05F;
  328.  
  329.             if (this.isInWater())
  330.             {
  331.                 for (int i = 0; i < 4; ++i)
  332.                 {
  333.                     float f3 = 0.25F;
  334.                     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]);
  335.                 }
  336.  
  337.                 f1 = 0.6F;
  338.             }
  339.  
  340.             if (this.isWet())
  341.             {
  342.                 this.extinguish();
  343.             }
  344.  
  345.             this.motionX *= (double)f1;
  346.             this.motionY *= (double)f1;
  347.             this.motionZ *= (double)f1;
  348.  
  349.             if (!this.hasNoGravity())
  350.             {
  351.                 this.motionY -= 0.00000005074505806D;
  352.             }
  353.  
  354.             this.setPosition(this.posX, this.posY, this.posZ);
  355.             this.doBlockCollisions();
  356.         }
  357.     }
  358.  
  359.     /**
  360.      * Called when the arrow hits a block or an entity
  361.      */
  362.     protected void onHit(RayTraceResult raytraceResultIn)
  363.     {
  364.         Entity entity = raytraceResultIn.entityHit;
  365.  
  366.         if (entity != null)
  367.         {
  368.             float f = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  369.             int i = MathHelper.ceil((double)f * this.damage);
  370.  
  371.             if (this.getIsCritical())
  372.             {
  373.                 i += this.rand.nextInt(i / 2 + 2);
  374.             }
  375.  
  376.             DamageSource damagesource;
  377.  
  378.             if (this.shootingEntity == null)
  379.             {
  380.                 damagesource = DamageSource.causeThrownDamage(this, this);
  381.             }
  382.             else
  383.             {
  384.                 damagesource = DamageSource.causeThrownDamage(this, this.shootingEntity);
  385.             }
  386.  
  387.             if (this.isBurning() && !(entity instanceof EntityEnderman))
  388.             {
  389.                 entity.setFire(5);
  390.             }
  391.  
  392.             if (entity.attackEntityFrom(damagesource, (float)i))
  393.             {
  394.                 if (entity instanceof EntityLivingBase)
  395.                 {
  396.                     EntityLivingBase entitylivingbase = (EntityLivingBase)entity;
  397.  
  398.                     if (!this.world.isRemote)
  399.                     {
  400.                         entitylivingbase.setArrowCountInEntity(entitylivingbase.getArrowCountInEntity() + 1);
  401.                     }
  402.  
  403.                     if (this.knockbackStrength > 0)
  404.                     {
  405.                         float f1 = MathHelper.sqrt(this.motionX * this.motionX + this.motionZ * this.motionZ);
  406.  
  407.                         if (f1 > 0.0F)
  408.                         {
  409.                             entitylivingbase.addVelocity(this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1, 0.1D, this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f1);
  410.                         }
  411.                     }
  412.  
  413.                     if (this.shootingEntity instanceof EntityLivingBase)
  414.                     {
  415.                         EnchantmentHelper.applyThornEnchantments(entitylivingbase, this.shootingEntity);
  416.                         EnchantmentHelper.applyArthropodEnchantments((EntityLivingBase)this.shootingEntity, entitylivingbase);
  417.                     }
  418.  
  419.                     this.arrowHit(entitylivingbase);
  420.  
  421.                     if (this.shootingEntity != null && entitylivingbase != this.shootingEntity && entitylivingbase instanceof EntityPlayer && this.shootingEntity instanceof EntityPlayerMP)
  422.                     {
  423.                         ((EntityPlayerMP)this.shootingEntity).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
  424.                     }
  425.                 }
  426.  
  427.                 this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  428.  
  429.                 if (!(entity instanceof EntityEnderman))
  430.                 {
  431.                     this.setDead();
  432.                 }
  433.             }
  434.             else
  435.             {
  436.                 this.motionX *= -0.10000000149011612D;
  437.                 this.motionY *= -0.10000000149011612D;
  438.                 this.motionZ *= -0.10000000149011612D;
  439.                 this.rotationYaw += 180.0F;
  440.                 this.prevRotationYaw += 180.0F;
  441.                 this.ticksInAir = 0;
  442.  
  443.                 if (!this.world.isRemote && this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ < 0.0010000000474974513D)
  444.                 {
  445.                     if (this.pickupStatus == EntityBullet.PickupStatus.ALLOWED)
  446.                     {
  447.                         this.entityDropItem(this.getArrowStack(), 0.1F);
  448.                     }
  449.  
  450.                     this.setDead();
  451.                 }
  452.             }
  453.         }
  454.         else
  455.         {
  456.             BlockPos blockpos = raytraceResultIn.getBlockPos();
  457.             this.xTile = blockpos.getX();
  458.             this.yTile = blockpos.getY();
  459.             this.zTile = blockpos.getZ();
  460.             IBlockState iblockstate = this.world.getBlockState(blockpos);
  461.             this.inTile = iblockstate.getBlock();
  462.             this.inData = this.inTile.getMetaFromState(iblockstate);
  463.             this.motionX = (double)((float)(raytraceResultIn.hitVec.xCoord - this.posX));
  464.             this.motionY = (double)((float)(raytraceResultIn.hitVec.yCoord - this.posY));
  465.             this.motionZ = (double)((float)(raytraceResultIn.hitVec.zCoord - this.posZ));
  466.             float f2 = MathHelper.sqrt(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
  467.             this.posX -= this.motionX / (double)f2 * 0.05000000074505806D;
  468.             this.posY -= this.motionY / (double)f2 * 0.05000000074505806D;
  469.             this.posZ -= this.motionZ / (double)f2 * 0.05000000074505806D;
  470.             this.playSound(SoundEvents.ENTITY_ARROW_HIT, 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
  471.             this.inGround = true;
  472.             this.arrowShake = 7;
  473.             this.setIsCritical(false);
  474.  
  475.             if (iblockstate.getMaterial() != Material.AIR)
  476.             {
  477.                 this.inTile.onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
  478.             }
  479.         }
  480.     }
  481.  
  482.     /**
  483.      * Tries to move the entity towards the specified location.
  484.      */
  485.     public void move(MoverType type, double x, double y, double z)
  486.     {
  487.         super.move(type, x, y, z);
  488.  
  489.         if (this.inGround)
  490.         {
  491.             this.xTile = MathHelper.floor(this.posX);
  492.             this.yTile = MathHelper.floor(this.posY);
  493.             this.zTile = MathHelper.floor(this.posZ);
  494.         }
  495.     }
  496.  
  497.     protected void arrowHit(EntityLivingBase living)
  498.     {
  499.     }
  500.  
  501.     @Nullable
  502.     protected Entity findEntityOnPath(Vec3d start, Vec3d end)
  503.     {
  504.         Entity entity = null;
  505.         List<Entity> list = this.world.getEntitiesInAABBexcluding(this, this.getEntityBoundingBox().addCoord(this.motionX, this.motionY, this.motionZ).expandXyz(1.0D), ARROW_TARGETS);
  506.         double d0 = 0.0D;
  507.  
  508.         for (int i = 0; i < list.size(); ++i)
  509.         {
  510.             Entity entity1 = (Entity)list.get(i);
  511.  
  512.             if (entity1 != this.shootingEntity || this.ticksInAir >= 5)
  513.             {
  514.                 AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expandXyz(0.30000001192092896D);
  515.                 RayTraceResult raytraceresult = axisalignedbb.calculateIntercept(start, end);
  516.  
  517.                 if (raytraceresult != null)
  518.                 {
  519.                     double d1 = start.squareDistanceTo(raytraceresult.hitVec);
  520.  
  521.                     if (d1 < d0 || d0 == 0.0D)
  522.                     {
  523.                         entity = entity1;
  524.                         d0 = d1;
  525.                     }
  526.                 }
  527.             }
  528.         }
  529.  
  530.         return entity;
  531.     }
  532.  
  533.     public static void registerFixesArrow(DataFixer fixer, String name)
  534.     {
  535.     }
  536.  
  537.     public static void registerFixesArrow(DataFixer fixer)
  538.     {
  539.         registerFixesArrow(fixer, "Arrow");
  540.     }
  541.  
  542.     /**
  543.      * (abstract) Protected helper method to write subclass entity data to NBT.
  544.      */
  545.     public void writeEntityToNBT(NBTTagCompound compound)
  546.     {
  547.         compound.setInteger("xTile", this.xTile);
  548.         compound.setInteger("yTile", this.yTile);
  549.         compound.setInteger("zTile", this.zTile);
  550.         compound.setShort("life", (short)this.ticksInGround);
  551.         ResourceLocation resourcelocation = (ResourceLocation)Block.REGISTRY.getNameForObject(this.inTile);
  552.         compound.setString("inTile", resourcelocation == null ? "" : resourcelocation.toString());
  553.         compound.setByte("inData", (byte)this.inData);
  554.         compound.setByte("shake", (byte)this.arrowShake);
  555.         compound.setByte("inGround", (byte)(this.inGround ? 1 : 0));
  556.         compound.setByte("pickup", (byte)this.pickupStatus.ordinal());
  557.         compound.setDouble("damage", this.damage);
  558.         compound.setBoolean("crit", this.getIsCritical());
  559.     }
  560.  
  561.     /**
  562.      * (abstract) Protected helper method to read subclass entity data from NBT.
  563.      */
  564.     public void readEntityFromNBT(NBTTagCompound compound)
  565.     {
  566.         this.xTile = compound.getInteger("xTile");
  567.         this.yTile = compound.getInteger("yTile");
  568.         this.zTile = compound.getInteger("zTile");
  569.         this.ticksInGround = compound.getShort("life");
  570.  
  571.         if (compound.hasKey("inTile", 8))
  572.         {
  573.             this.inTile = Block.getBlockFromName(compound.getString("inTile"));
  574.         }
  575.         else
  576.         {
  577.             this.inTile = Block.getBlockById(compound.getByte("inTile") & 255);
  578.         }
  579.  
  580.         this.inData = compound.getByte("inData") & 255;
  581.         this.arrowShake = compound.getByte("shake") & 255;
  582.         this.inGround = compound.getByte("inGround") == 1;
  583.  
  584.         if (compound.hasKey("damage", 99))
  585.         {
  586.             this.damage = compound.getDouble("damage");
  587.         }
  588.  
  589.         if (compound.hasKey("pickup", 99))
  590.         {
  591.             this.pickupStatus = EntityBullet.PickupStatus.getByOrdinal(compound.getByte("pickup"));
  592.         }
  593.         else if (compound.hasKey("player", 99))
  594.         {
  595.             this.pickupStatus = compound.getBoolean("player") ? EntityBullet.PickupStatus.ALLOWED : EntityBullet.PickupStatus.DISALLOWED;
  596.         }
  597.  
  598.         this.setIsCritical(compound.getBoolean("crit"));
  599.     }
  600.  
  601.     /**
  602.      * Called by a player entity when they collide with an entity
  603.      */
  604.     public void onCollideWithPlayer(EntityPlayer entityIn)
  605.     {
  606.         if (!this.world.isRemote && this.inGround && this.arrowShake <= 0)
  607.         {
  608.             boolean flag = this.pickupStatus == EntityBullet.PickupStatus.ALLOWED || this.pickupStatus == EntityBullet.PickupStatus.CREATIVE_ONLY && entityIn.capabilities.isCreativeMode;
  609.  
  610.             if (this.pickupStatus == EntityBullet.PickupStatus.ALLOWED && !entityIn.inventory.addItemStackToInventory(this.getArrowStack()))
  611.             {
  612.                 flag = false;
  613.             }
  614.  
  615.             if (flag)
  616.             {
  617.                 entityIn.onItemPickup(this, 1);
  618.                 this.setDead();
  619.             }
  620.         }
  621.     }
  622.  
  623.     protected abstract ItemStack getArrowStack();
  624.  
  625.     /**
  626.      * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
  627.      * prevent them from trampling crops
  628.      */
  629.     protected boolean canTriggerWalking()
  630.     {
  631.         return false;
  632.     }
  633.  
  634.     public void setDamage(double damageIn)
  635.     {
  636.         this.damage = damageIn;
  637.     }
  638.  
  639.     public double getDamage()
  640.     {
  641.         return this.damage;
  642.     }
  643.  
  644.     /**
  645.      * Sets the amount of knockback the arrow applies when it hits a mob.
  646.      */
  647.     public void setKnockbackStrength(int knockbackStrengthIn)
  648.     {
  649.         this.knockbackStrength = knockbackStrengthIn;
  650.     }
  651.  
  652.     /**
  653.      * Returns true if it's possible to attack this entity with an item.
  654.      */
  655.     public boolean canBeAttackedWithItem()
  656.     {
  657.         return false;
  658.     }
  659.  
  660.     public float getEyeHeight()
  661.     {
  662.         return 0.0F;
  663.     }
  664.  
  665.     /**
  666.      * Whether the arrow has a stream of critical hit particles flying behind it.
  667.      */
  668.     public void setIsCritical(boolean critical)
  669.     {
  670.         byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
  671.  
  672.         if (critical)
  673.         {
  674.             this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 | 1)));
  675.         }
  676.         else
  677.         {
  678.             this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 & -2)));
  679.         }
  680.     }
  681.  
  682.     /**
  683.      * Whether the arrow has a stream of critical hit particles flying behind it.
  684.      */
  685.     public boolean getIsCritical()
  686.     {
  687.         byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
  688.         return (b0 & 1) != 0;
  689.     }
  690.  
  691.     public void setEnchantmentEffectsFromEntity(EntityLivingBase p_190547_1_, float p_190547_2_)
  692.     {
  693.         int i = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.POWER, p_190547_1_);
  694.         int j = EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.PUNCH, p_190547_1_);
  695.         this.setDamage((double)(p_190547_2_ * 2.0F) + this.rand.nextGaussian() * 0.25D + (double)((float)this.world.getDifficulty().getDifficultyId() * 0.11F));
  696.  
  697.         if (i > 0)
  698.         {
  699.             this.setDamage(this.getDamage() + (double)i * 0.5D + 0.5D);
  700.         }
  701.  
  702.         if (j > 0)
  703.         {
  704.             this.setKnockbackStrength(j);
  705.         }
  706.  
  707.         if (EnchantmentHelper.getMaxEnchantmentLevel(Enchantments.FLAME, p_190547_1_) > 0)
  708.         {
  709.             this.setFire(100);
  710.         }
  711.     }
  712.  
  713.     public static enum PickupStatus
  714.     {
  715.         DISALLOWED,
  716.         ALLOWED,
  717.         CREATIVE_ONLY;
  718.  
  719.         public static EntityBullet.PickupStatus getByOrdinal(int ordinal)
  720.         {
  721.             if (ordinal < 0 || ordinal > values().length)
  722.             {
  723.                 ordinal = 0;
  724.             }
  725.  
  726.             return values()[ordinal];
  727.         }
  728.         protected float getGravityVelocity()
  729.         {
  730.             return 0.005F;
  731.         }
  732.     }
  733. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top