Posted October 12, 20169 yr I have a class that I'm trying to upgrade from 1.8.9 to 1.10.2. It's basically just a custom EntityThrowable that is a bullet for a gun. Everything is working except that the bullet causes no damage when it hits another entity. I can't figure out why since I believe this line in the onImpact method: result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 20.0F); is correct. Does 1.10.2 handle damage differently? public class EntityBullet extends EntityThrowable { public EntityBullet(World worldIn, EntityLivingBase throwerIn) { super(worldIn, throwerIn); setHeadingFromThrower(throwerIn, throwerIn.rotationPitch, throwerIn.rotationYaw, 0.0F, 5.0F, 1.0F); } @Override protected void onImpact(RayTraceResult result) { if (this.worldObj.isRemote) { if (result.entityHit != null) { result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 20.0F); } this.setDead(); } } @Override protected float getGravityVelocity() { return 0.005F; } }
October 13, 20169 yr This is possibly the most basic entity throwable for 1.10.2 with sounds and particles, you may be able to draw some conclusions from this: public class EntityExample extends EntityThrowable { public EntityExample(World worldIn) { super(worldIn); } public EntityExample(World worldIn, EntityLivingBase throwerIn) { super(worldIn, throwerIn); } public void onUpdate() { super.onUpdate(); this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, posY + (worldObj.rand.nextFloat() / -2 - worldObj.rand.nextFloat()) / -1.3, posZ + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) / 2, 0, 0, 0, new int[] {Block.getIdFromBlock(Blocks.DIRT)}); } public float getGravityVelocity() { return 0.005F; } public EntityExample(World worldIn, double x, double y, double z) { super(worldIn, x, y, z); } protected void onImpact(RayTraceResult result) { if (result.entityHit != null) { int i = 0; if (result.entityHit instanceof EntityLivingBase) { i = 4; } result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i); worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.8F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F)); } for (int j = 0; j < 8; ++j) { this.worldObj.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[] {Block.getIdFromBlock(Blocks.DIRT)}); } if (!this.worldObj.isRemote) { this.setDead(); worldObj.playSound((EntityPlayer)null, posX, posY, posZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.NEUTRAL, 0.7F, 1.5F / (worldObj.rand.nextFloat() * 0.4F + 0.8F)); } } }
October 13, 20169 yr Author I don't care about sounds or particles. It's the damage the the EntityThrowable should inflict that isn't working right.
October 13, 20169 yr If on impact the result is entity hit get thrower return float for damage: protected void onImpact(RayTraceResult result) { if (result.entityHit != null) { int i = 0; if (result.entityHit instanceof EntityLivingBase) { i = 4; } result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i); }
October 13, 20169 yr Author Except in that code snippet, the cast of (float)i is either 0 or 4. In my code, it is this: result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 20.0F); Notice my code explicitly says 20.0F
October 13, 20169 yr Except in that code snippet, the cast of (float)i is either 0 or 4. In my code, it is this: result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 20.0F); Notice my code explicitly says 20.0F protected void onImpact(RayTraceResult result) { if (result.entityHit != null) { int i = 0; if (result.entityHit instanceof EntityLivingBase) { i = 20; } result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i); }
October 13, 20169 yr Author But you are still just casting an int of 20 to a float. I'm just explicitly saying 20.0F.
October 13, 20169 yr yeah the int of i = 20. In the case of it hitting anything that is an entity, it will deal a damage of 20. Whereas: if (result.entityHit != null) { int i = 0; if (result.entityHit instanceof EntitySlime) { i = 2; } if (result.entityHit instanceof EntityBlaze) { i = 5; } would return different damage values for different types of entities. 20.0F would be 20 f. Or f = 20; Or i = 20; i is the letter to represent that particular float.
October 13, 20169 yr Author But I don't care about the kind of entity. I always want the damage to be 20.0F and that is what my code shows.
October 13, 20169 yr But I don't care about the kind of entity. I always want the damage to be 20.0F and that is what my code shows. I apologize for not being able to demonstrate in a nicer way how the floats work... :\
October 13, 20169 yr Author The "F" isn't a variable, it is an explicit cast to a float. If I had used 20.0D, the java compiler would have recognized that value as a double. Also, this particular line of code worked fine in 1.8.9
October 13, 20169 yr Author I know java. I just hit this weird instance with an EntityThrowable not causing damage. Not sure if it is a forge bug or if something changed along the way and I missed it.
October 13, 20169 yr 20.0F would be 20 f. Or f = 20; Or i = 20; i is the letter to represent that particular float. Wrong. http://stackoverflow.com/questions/9748160/why-f-is-placed-after-float-values Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
October 13, 20169 yr 20.0F would be 20 f. Or f = 20; Or i = 20; i is the letter to represent that particular float. Wrong. http://stackoverflow.com/questions/9748160/why-f-is-placed-after-float-values thanks
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.