From 077205c9b30c5854087c98f7bb3605bbb1484d6b Mon Sep 17 00:00:00 2001 From: Infinityy <120841985+Inf1nityy@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:06:57 +0200 Subject: [PATCH] fix blast prot kb (MC-198809) --- .../misc/ProtectionEnchantmentMixin.java | 27 +++++++++++++++++++ src/main/resources/core.mixins.json | 1 + 2 files changed, 28 insertions(+) create mode 100644 src/main/java/com/nexia/core/mixin/misc/ProtectionEnchantmentMixin.java diff --git a/src/main/java/com/nexia/core/mixin/misc/ProtectionEnchantmentMixin.java b/src/main/java/com/nexia/core/mixin/misc/ProtectionEnchantmentMixin.java new file mode 100644 index 00000000..8f4fd658 --- /dev/null +++ b/src/main/java/com/nexia/core/mixin/misc/ProtectionEnchantmentMixin.java @@ -0,0 +1,27 @@ +package com.nexia.core.mixin.misc; + +import net.minecraft.util.Mth; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.enchantment.EnchantmentHelper; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.item.enchantment.ProtectionEnchantment; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; + +@Mixin(ProtectionEnchantment.class) +public class ProtectionEnchantmentMixin { + /** + * @author NotInfinityy + * @reason This fixes blast protection not reducing explosion knockback + * MC-198809 + */ + @Overwrite + public static double getExplosionKnockbackAfterDampener(LivingEntity livingEntity, double d) { + int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.BLAST_PROTECTION, livingEntity); + if (i > 0) { + d *= Mth.clamp(1.0 - (double)i * 0.15, 0.0, 1.0); + } + + return d; + } +} diff --git a/src/main/resources/core.mixins.json b/src/main/resources/core.mixins.json index fb47d280..41315e1e 100644 --- a/src/main/resources/core.mixins.json +++ b/src/main/resources/core.mixins.json @@ -45,6 +45,7 @@ "misc.ExplosionMixin", "misc.ItemCombinerMenuMixin", "misc.MinecraftServerMixin", + "misc.ProtectionEnchantmentMixin", "misc.ServerLevelMixin", "misc.commands.BanCommandMixin", "misc.commands.EmoteCommandMixin",