Jump to content

Issue multiple shotgun bullets not damaging multiple times


Recommended Posts

Posted (edited)

Hey there!

For my mod I've created a shotgun. This shotgun is spawning multiple bullets (15) flying in the direction the player is facing. Now if these 15 bullets hit one entity it only damages the entity one time not 15 times. But if the bullets hit two entities they damage each entity one time.

 

I am sorry if I mix things up here, I am not experienced in Minecraft modding or in Java.

 

 

Code of the spawning: Full Class

 

Spoiler

private void shoot(World world, EntityPlayer player, ItemStack itemStack)
{
    if(!world.isRemote)
    {
        for (int i =0; i < 16; i++)
        {
            itemStack.damageItem(1, player);
            EntityShot entityShot = new EntityShot(world, player);
            entityShot.readFromNBT(itemStack.getTagCompound());
            entityShot.setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0.0F, 2.5F, 8.0F);
            world.spawnEntity(entityShot);
        }
    }
}

Damaging Code: Full Class

Spoiler

protected void onImpact(RayTraceResult result)
{
    if (result.entityHit != null)
    {
        int i = 0;
        if (this.getDataManager().get(SHOTTYPE).equals("Salt"))
        {
            if (result.entityHit.equals(shooter))
            {
                i = 0;
            }
            else if (result.entityHit instanceof EntityLivingBase)
            {
                i = 1;
            }
        }
        else if (this.getDataManager().get(SHOTTYPE).equals("Iron"))
        {
            if (result.entityHit.equals(shooter))
            {
                i = 0;
            }
            else if (result.entityHit instanceof EntityLivingBase)
            {
                i = 2;
            }
        }
        else if (this.getDataManager().get(SHOTTYPE).equals("Ash"))
        {
            if (result.entityHit.equals(shooter))
            {
                i = 0;
            }
        }
        else if (this.getDataManager().get(SHOTTYPE).equals("Blaze"))
        {
            if (result.entityHit.equals(shooter))
            {
                i = 0;
            }
            else if (result.entityHit instanceof EntityLivingBase)
            {
                i = 1;
                result.entityHit.setFire(4);
            }
        }

        if (result.entityHit != shooter)
        {
            result.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.getThrower()), (float) i);
        }
    }

    if (!this.world.isRemote && result.entityHit != shooter)
    {
        if (this.getDataManager().get(SHOTTYPE).equals("Blaze"))
        {
            this.world.spawnParticle(EnumParticleTypes.FLAME, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
        }
        else
        {
            this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
        }
        this.ticksInWorld = 0;
        this.setDead();

    }
}

 

Edited by mylimo
Posted

This is because entities have a hurt resistance time: when they are flashing red they cannot take additional damage.

You need to reset the hurt resistance time yourself to 0 when your shotgun bullets impact, allowing all of them to deal full damage.

 

I did this once back in 1.7:

https://github.com/Draco18s/Artifacts/blob/master/main/java/com/draco18s/artifacts/entity/EntitySpecialArrow.java#L184

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

×   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



×
×
  • Create New...

Important Information

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