Mob are not immune of Custom Arrow

Started by Ro... on

Topic category: Help with Minecraft modding (Java Edition)

Active 1 month ago
Joined Mar 2020
Points:
1182

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
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.

Active 4 years ago
Joined Sep 2019
Points:
986

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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
        }
    }

 

Active 1 month ago
Joined Mar 2020
Points:
1182

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
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?

Active 4 years ago
Joined Sep 2019
Points:
986

User statistics:

  • Modifications: 1
  • Forum topics: 14
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 507
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

Active 3 months ago
Joined Dec 2018
Points:
982

User statistics:

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

Riku, did you ever solve this problem?

Active 1 month ago
Joined Mar 2020
Points:
1182

User statistics:

  • Modifications: 6
  • Forum topics: 71
  • Wiki pages: 0
  • MCreator plugins: 0
  • Comments: 270
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.