Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package your.project.package; //CHANGE. VERY IMPORTANT!
- import net.minecraft.world.damagesource.DamageSource;
- import net.minecraft.tags.DamageTypeTags;
- import net.minecraft.world.entity.LivingEntity;
- import net.minecraft.world.entity.ai.attributes.Attributes;
- import net.minecraftforge.event.entity.living.LivingDamageEvent;
- import net.minecraftforge.eventbus.api.SubscribeEvent;
- import net.minecraftforge.eventbus.api.EventPriority;
- import net.minecraftforge.fml.common.Mod;
- @Mod.EventBusSubscriber(modid = "seraph")
- public class ArmorFixProcedure {
- private static final double EXTRA_ARMOR_SCALE = 100.0;
- private static final double MIN_MULT_AFTER_EXTRA = 0.20;
- @SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
- public static void onLivingDamage(LivingDamageEvent event) {
- if (!(event.getEntity() instanceof LivingEntity)) return;
- LivingEntity living = (LivingEntity) event.getEntity();
- if (living.level().isClientSide()) return;
- System.out.println("[ArmorFix] Event fired for: " + living.getName().getString() //debug. can be removed
- + " with armor=" + living.getAttributeValue(Attributes.ARMOR)); //debug. can be removed
- DamageSource source = event.getSource();
- if (source.is(DamageTypeTags.BYPASSES_ARMOR)) return;
- if (!living.getAttributes().hasAttribute(Attributes.ARMOR)) return;
- double armor = living.getAttributeValue(Attributes.ARMOR);
- if (armor <= 30.0) return;
- float current = event.getAmount();
- if (current <= 0f) return;
- double extraArmor = armor - 30.0;
- double mult = 1.0 / (1.0 + (extraArmor / EXTRA_ARMOR_SCALE));
- mult = Math.max(mult, MIN_MULT_AFTER_EXTRA);
- float adjusted = (float) (current * mult);
- if (Float.isFinite(adjusted) && adjusted >= 0f && adjusted < current) {
- event.setAmount(adjusted);
- System.out.println("[ArmorFix] armor=" + armor + " extra=" + extraArmor + " mult=" + mult + " dmg " + current + " -> " + adjusted); //debug. can be removed
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment