Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;
    }
}

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));
        }
    }
}

  • Author

I don't care about sounds or particles. It's the damage the the EntityThrowable should inflict that isn't working right.

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);
        }

  • 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

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);
        }

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.

  • 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.

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... :\

  • 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

  • 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.

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.