fix: possibly fixed crossmod crashes caused by the armor penetration effect
@@ -13,11 +13,18 @@ public class ArmorPenetrationEffect {
private static final UUID uuid = UUID.fromString("a43e0407-f070-4e2f-8813-a5e16328f1a5");
+ /**
+ * Applies the armor reduction effect before the damage value is calculated.
+ * Note that some mods cause this to be called twice before onLivingDamage.
+ * @param event
+ * @param effectLevel
+ */
public static void onLivingHurt(LivingHurtEvent event, int effectLevel) {
Optional.of(event.getEntityLiving())
.map(LivingEntity::getAttributeManager)
.filter(manager -> manager.hasAttributeInstance(Attributes.ARMOR))
.map(manager -> manager.createInstanceIfAbsent(Attributes.ARMOR))
+ .filter(instance -> instance.getModifier(uuid) == null)
.ifPresent(instance -> instance.applyNonPersistentModifier(
new AttributeModifier(uuid, "tetra_armor_pen", effectLevel * -0.01, AttributeModifier.Operation.MULTIPLY_TOTAL)));
}
