Jump to content

LivingAttackEvent dont effect Witches .. help pls


NoahKassem

Recommended Posts

Hello my fellow Modders
this is the event code it's working fine with every mob and attack except witches it didn't trigger when witches attacked the player .. can you help me with this problem ... this is the code 
I'm new to coding in general 

 

@SubscribeEvent(priority = EventPriority.HIGH)
    public void AttackEvent(LivingAttackEvent event) {
  
        if (!event.getEntity().getCommandSenderWorld().isClientSide) {
          
            if (!(event.getEntity() instanceof ServerPlayer player)) return;
            ItemStack ring = Utils.getFirstCurio(ModItemGod.divinering.get(), player);
            Entity attacker2 = event.getSource().getEntity();
            Entity attacker = event.getSource().getDirectEntity();

            if (ring != null && attacker instanceof SummonedZombie summonedzombie || attacker instanceof SummonedSkeleton summoneskeleton || attacker instanceof SummonedVex summonedvex || attacker instanceof Vex vex ) {
              
                ((Monster) attacker).knockback(10,2 ,10);
                attacker.kill();
                event.setCanceled(true);
            }
          
            else if (ring != null && attacker2 instanceof SummonedZombie summonedzombie || attacker2 instanceof SummonedSkeleton summoneskeleton || attacker2 instanceof SummonedVex summonedvex || attacker2 instanceof Vex vex) {
              
                ((Monster) attacker2).knockback(10,2 ,10);
                attacker2.kill();
                event.setCanceled(true);
            }
            else if (ring != null) {
                ((LivingEntity) attacker2).addEffect((new MobEffectInstance(MobEffects.BLINDNESS, 200, 2, false, false)));
                ((LivingEntity) attacker2).setHealth(((LivingEntity) attacker2).getHealth() / 2);
                ((LivingEntity) attacker2).knockback(10, 3, 10);
                event.setCanceled(true);
            }
        }
    }

 

Edited by NoahKassem
clean the code
Link to comment
Share on other sites

18 hours ago, NoahKassem said:

can you help me with this problem

Unfortunately I don't think the entity that threw the potion is propagated to the LivingAttackEvent. What you could do is subscribe to the PotionAddedEvent and check if the source entity is a witch.

  • Thanks 1
Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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