Posted April 23, 20223 yr 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 April 23, 20223 yr by Mad Alchemist Added some code to make problem easier to understand
April 23, 20223 yr take a look at the vanilla logic: LivingEntity#isDamageSourceBlocked and LivingEntity#isBlocking
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.