Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Best way to check if attack was blocked by shield


 Share

Recommended Posts

Hi! In my mod, "Zombination", being attacked by zombie gives a slight chance to contract a zombie virus. It happens in LivingAttackEvent handler, and, problem is, zombies may infect players even if attack was blocked by shield. Of course, I can check if attacked entity is a player, has a shield, and is crouching, but, maybe, there is a better way to make shield protect from infection?

This is how it works currently (no check for shield blocking):

 

/* Is damage source a zombie ? */
        if (event.getSource().getEntity() instanceof ZombieEntity ||
            event.getSource().getEntity() instanceof ZombieBear ||
            event.getSource().getEntity() instanceof ZolphinEntity) {

            /* Is target an enderman? */
            if(event.getEntityLiving() instanceof EndermanEntity) {
                // Heal enderman, so that zombies almost never win this fight
                event.getEntityLiving().heal(10f);
            }

            /* Is target infectable */
            if (isInfectable(event.getEntity())) {
                double d = Math.random();
                if (d <= ConfigHandler.INFECTION.infectionChance.get() || (event.getEntity().hasCustomName() && event.getEntity().getCustomName().getString().equals("Heisenberg"))) {
                    /* Is entity already infected? */
                    if(!event.getEntityLiving().hasEffect(PotionsRegistry.POTION_ZOMBIE_VIRUS.getEffect())) {
                        event.getEntityLiving().addEffect(new EffectInstance(PotionsRegistry.POTION_ZOMBIE_VIRUS, ConfigHandler.INFECTION.infectionDuration.get() * 20, (int) 0, true, (false)));
                    }
                }
            }

 

Edited by Mad Alchemist
Added some code to make problem easier to understand
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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.