thingy48624

Code For Mcreator

Aug 22nd, 2025
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package your.project.package; //CHANGE. VERY IMPORTANT!
  2.  
  3. import net.minecraft.world.damagesource.DamageSource;
  4. import net.minecraft.tags.DamageTypeTags;
  5. import net.minecraft.world.entity.LivingEntity;
  6. import net.minecraft.world.entity.ai.attributes.Attributes;
  7. import net.minecraftforge.event.entity.living.LivingDamageEvent;
  8. import net.minecraftforge.eventbus.api.SubscribeEvent;
  9. import net.minecraftforge.eventbus.api.EventPriority;
  10. import net.minecraftforge.fml.common.Mod;
  11.  
  12. @Mod.EventBusSubscriber(modid = "seraph")
  13. public class ArmorFixProcedure {
  14. private static final double EXTRA_ARMOR_SCALE = 100.0;
  15. private static final double MIN_MULT_AFTER_EXTRA = 0.20;
  16.  
  17. @SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
  18. public static void onLivingDamage(LivingDamageEvent event) {
  19. if (!(event.getEntity() instanceof LivingEntity)) return;
  20. LivingEntity living = (LivingEntity) event.getEntity();
  21. if (living.level().isClientSide()) return;
  22.  
  23. System.out.println("[ArmorFix] Event fired for: " + living.getName().getString() //debug. can be removed
  24. + " with armor=" + living.getAttributeValue(Attributes.ARMOR)); //debug. can be removed
  25.  
  26. DamageSource source = event.getSource();
  27.  
  28. if (source.is(DamageTypeTags.BYPASSES_ARMOR)) return;
  29.  
  30. if (!living.getAttributes().hasAttribute(Attributes.ARMOR)) return;
  31. double armor = living.getAttributeValue(Attributes.ARMOR);
  32. if (armor <= 30.0) return;
  33.  
  34. float current = event.getAmount();
  35. if (current <= 0f) return;
  36.  
  37. double extraArmor = armor - 30.0;
  38. double mult = 1.0 / (1.0 + (extraArmor / EXTRA_ARMOR_SCALE));
  39. mult = Math.max(mult, MIN_MULT_AFTER_EXTRA);
  40.  
  41. float adjusted = (float) (current * mult);
  42. if (Float.isFinite(adjusted) && adjusted >= 0f && adjusted < current) {
  43. event.setAmount(adjusted);
  44. System.out.println("[ArmorFix] armor=" + armor + " extra=" + extraArmor + " mult=" + mult + " dmg " + current + " -> " + adjusted); //debug. can be removed
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment