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

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

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

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.