Mob are not immune of Custom Arrow

Started by Ro... on Sat, 05/30/2020 - 23:02

Topic category: Help with modding (Java Edition)

Last seen on 01:41, 5. Aug 2021
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Mob are not immune of Custom Arrow
Sat, 05/30/2020 - 23:02

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:
  • Tracker tickets:
  • 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 01:41, 5. Aug 2021
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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:
  • Tracker tickets:
  • 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