Skip to content

Commit

Permalink
fixed resonarium armor functionality from absorbing health and not br…
Browse files Browse the repository at this point in the history
…eaking
  • Loading branch information
NewJumper committed Aug 5, 2024
1 parent 45bdb03 commit 420c211
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.Difficulty;
import net.minecraft.world.entity.EntityType;
Expand Down Expand Up @@ -143,11 +144,14 @@ public static void breakEvent(final BlockEvent.BreakEvent event) {

@SubscribeEvent
public static void livingDamageEvent(final LivingDamageEvent.Pre event) {
if(event.getSource().is(DamageTypeTags.BYPASSES_ARMOR)) return;

AtomicReference<Float> incoming = new AtomicReference<>(event.getOriginalDamage());
float reduction = incoming.get() / 4;
event.getEntity().getArmorSlots().forEach(stack -> {
if(stack.getItem() instanceof ArmorItem armor && armor.getMaterial().is(DDArmorMaterials.RESONARIUM.getId())) {
incoming.updateAndGet(f -> f - reduction);
stack.hurtAndBreak((int) (event.getOriginalDamage() / 1.5f), event.getEntity(), stack.getEquipmentSlot());
}
});
event.setNewDamage(incoming.get());
Expand All @@ -157,7 +161,7 @@ public static void livingDamageEvent(final LivingDamageEvent.Pre event) {
public static void armorHurtEvent(final ArmorHurtEvent event) {
event.getArmorMap().forEach((equipmentSlot, armorEntry) -> {
if(event.getArmorItemStack(equipmentSlot).getItem() instanceof ArmorItem armor && armor.getMaterial().is(DDArmorMaterials.RESONARIUM.getId())) {
armorEntry.newDamage = armorEntry.originalDamage * 4;
armorEntry.newDamage = 0;
}
});
}
Expand Down

0 comments on commit 420c211

Please sign in to comment.