Mob are not immune of Custom Arrow

Started by Ro... on

Topic category: Help with modding (Java Edition)

Last seen on 12:04, 24. Apr 2024
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mob are not immune of Custom Arrow

Hi, i want to release the version 8 of my mod. this version add a boss (kinda hard to kill). this boss is immune of everything exept Melee Damage, so if u shoot an arrow, the arrow will just bounce. but if u use a custom arrow, example. my mod is a magic mod with staff and all, and one of the 12 spell is shooting Magic orb. for that. i just created a ranged weapon that shoot a thing. but when i shoot with that staff on the boss. he lose health. i need help or i wont be able to finish my mod.

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I would call…
Sun, 05/31/2020 - 00:18

I would call LivingDamageEvent. Then use event.getSource to check if the DamageSource is an instance of your custom arrow. If the damage source is because of your arrow. We can cancel it. 

Here is what it should look like (TEST THIS FOR YOURSELF, I JUST MADE THIS CODE SO THERE MAY BE ERRORS),

    public void entityDamageEvent(LivingDamageEvent event)
    {
        DamageSource source = event.getSource();
        if (source.getImmediateSource() instanceof YourCustomArrowEntity)
        {
            event.setCanceled(true);
            //DO WHATEVER ELSE YOU WANT HERE. I.e give player "magic". idk
        }
    }

 

Last seen on 12:04, 24. Apr 2024
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok thx, but in my mod there…
Mon, 06/01/2020 - 15:45

Ok thx, but in my mod there is around 48 staff that use the same projectile so it should work. and what is the instanceof. is that ID or something like that?

Last seen on 04:35, 17. Jan 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I will provide you with a…
Mon, 06/01/2020 - 15:59

I will provide you with a link about instanceof below. For your question,

but in my mod there is around 48 staff that use the same projectile so it should work

Yes if they use the same projectile it will work

https://www.javatpoint.com/downcasting-with-instanceof-operator

Last seen on 19:56, 23. Apr 2024
Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Riku, did you ever solve…
Sun, 01/30/2022 - 01:47

Riku, did you ever solve this problem?

Last seen on 12:04, 24. Apr 2024
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
nope, i didnt test it either…
Sat, 02/05/2022 - 13:11

nope, i didnt test it either, so i don't know if it works.