maestro1184 Posted October 12, 2016 Posted October 12, 2016 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; } } Quote
gurujive Posted October 13, 2016 Posted October 13, 2016 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)); } } } Quote
maestro1184 Posted October 13, 2016 Author Posted October 13, 2016 I don't care about sounds or particles. It's the damage the the EntityThrowable should inflict that isn't working right. Quote
gurujive Posted October 13, 2016 Posted October 13, 2016 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); } Quote
maestro1184 Posted October 13, 2016 Author Posted October 13, 2016 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 Quote
gurujive Posted October 13, 2016 Posted October 13, 2016 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); } Quote
maestro1184 Posted October 13, 2016 Author Posted October 13, 2016 But you are still just casting an int of 20 to a float. I'm just explicitly saying 20.0F. Quote
gurujive Posted October 13, 2016 Posted October 13, 2016 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. Quote
maestro1184 Posted October 13, 2016 Author Posted October 13, 2016 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. Quote
gurujive Posted October 13, 2016 Posted October 13, 2016 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... :\ Quote
maestro1184 Posted October 13, 2016 Author Posted October 13, 2016 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 Quote
maestro1184 Posted October 13, 2016 Author Posted October 13, 2016 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. Quote
Draco18s Posted October 13, 2016 Posted October 13, 2016 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 Quote 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.
gurujive Posted October 13, 2016 Posted October 13, 2016 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 Quote
Recommended Posts
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.