Jump to content

[1.10.2] EntityThrowable not causing damage to hit entity


maestro1184

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi I have an issue with a server it solved deleting the ice and fire but my friends and me really want to use it does any of these mods are causing the issue due to incompatibility  Security craft Aquaculture Architectury Artifacts Astikorcarts Baubles BetterCaves yungs BetterStrongholds yungs BetterMineshafts yungs Bountiful Byg  Callablehorses Carry on Chococraft Citadel Clumps Collective Comforts Corailrecycler Craftable horse armor Comes alive Curios forge Decocraft Dungeonsarise  Open blocks elevator Expandability Farlanders Goblin traders Hwyla  Ice and fire Infernal expansion Jei Jump over fences Mantle  Macaws bridges Macaws doors Macaws fences Macaws furniture  Macaws fencesbyg Morpheus Mouse tweaks Mowzies mobs Obfuscate Paraglider Patchouli  Pick up notifier Random village names Spartan shields Small ships Sophisticated backpacks Spartan weaponry Storage drawers straw golem Structure gel Twilight forest  Tinkers construct Two players one horse  Valhesia core  Valhesia structures  Way stones  Vehicle mod  Wall jump Wings Wolves with armor Xptome  Xaeros minimap  Yungsapi  
    • { "type": "magic_overhaul:rune_inscribing", "base": { "item": "//base item" }, "template": { "item": "//template item" }, "output": { "count": 1, "item": "//output item" } } ^ Ok, where is your recipe JSON placed in your file structure? What's it called? And paste the actual JSON you're testing with, because it needs to be valid.
    • I'm trying to run Forge 1.12.2 on Minecraft  so I can use certain mods, but this error popped up. I've seen multiple errors but I just can't figure this one out. Unable to locate the Java runtime. Error details: 0x00000000 - system: The operation completed successfully. Filename on disk:  Path: . Exists: Directory
    • https://mclo.gs/b422RFc
    • Плагин и Приват
  • Topics

×
×
  • Create New...

Important Information

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