From 9c1471d2bf9e1de5337e8adf88d49312412a6c05 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Mon, 12 Aug 2024 11:58:47 -0700 Subject: [PATCH 1/2] Move last stand handler into existing mixin --- .../universaltweaks/UniversalTweaks.java | 2 -- .../mods/openblocks/UTOpenBlocksEvents.java | 30 ------------------ .../mods/openblocks/mixin/UTConfigMixin.java | 21 ------------- .../UTLastStandEnchantmentsHandlerMixin.java | 31 +++++++++++++++++-- .../resources/mixins.mods.openblocks.json | 2 +- 5 files changed, 30 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/openblocks/UTOpenBlocksEvents.java delete mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTConfigMixin.java diff --git a/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java b/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java index c506ee68..da3cbe60 100644 --- a/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java @@ -28,7 +28,6 @@ import mod.acgaming.universaltweaks.mods.elenaidodge2.UTED2Burning; import mod.acgaming.universaltweaks.mods.elenaidodge2.UTED2Sprinting; import mod.acgaming.universaltweaks.mods.mekanism.UTMekanismFixes; -import mod.acgaming.universaltweaks.mods.openblocks.UTOpenBlocksEvents; import mod.acgaming.universaltweaks.mods.projectred.UTProjectRedWorldEvents; import mod.acgaming.universaltweaks.mods.simplyjetpacks.UTSimplyJetpacksEvents; import mod.acgaming.universaltweaks.mods.simplyjetpacks.network.message.MessageClientStatesReset; @@ -156,7 +155,6 @@ public void init(FMLInitializationEvent event) if (Loader.isModLoaded("elenaidodge2") && UTConfigMods.ELENAI_DODGE_2.utED2ExtinguishingDodgeChance > 0) MinecraftForge.EVENT_BUS.register(new UTED2Burning()); if (Loader.isModLoaded("elenaidodge2") && UTConfigMods.ELENAI_DODGE_2.utED2SprintingFeatherConsumption > 0) MinecraftForge.EVENT_BUS.register(new UTED2Sprinting()); if (Loader.isModLoaded("mekanism") && UTConfigMods.MEKANISM.utDuplicationFixesToggle) UTMekanismFixes.fixBinRecipes(); - if (Loader.isModLoaded("openblocks") && UTConfigMods.OPEN_BLOCKS.utLastStandFixToggle) MinecraftForge.EVENT_BUS.register(new UTOpenBlocksEvents()); if (Loader.isModLoaded("projectred-exploration") && UTConfigMods.PROJECTRED.utDuplicationFixesToggle) MinecraftForge.EVENT_BUS.register(new UTProjectRedWorldEvents()); // Unregister reason: disable beta warning. if (Loader.isModLoaded("railcraft") && UTConfigMods.RAILCRAFT.utNoBetaWarningToggle && UTReflectionUtil.isClassLoaded("mods.railcraft.common.core.BetaMessageTickHandler")) diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/UTOpenBlocksEvents.java b/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/UTOpenBlocksEvents.java deleted file mode 100644 index b71a60d0..00000000 --- a/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/UTOpenBlocksEvents.java +++ /dev/null @@ -1,30 +0,0 @@ -package mod.acgaming.universaltweaks.mods.openblocks; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.event.entity.living.LivingDamageEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - -import openblocks.enchantments.LastStandEnchantmentsHandler; - -public class UTOpenBlocksEvents -{ - public static LastStandEnchantmentsHandler lastStandHandler; - - /** - * Last Stand in 1.12 uses LivingHurtEvent, which is the pre-mitigation damage (before armor, potions, etc). - * It should use LivingDamageEvent, which is the post-mitigation damage. - * This was actually explicitly fixed in older versions (1.10) but once again uses the wrong event in 1.12. - */ - @SubscribeEvent - public void handleLastStand(LivingDamageEvent event) - { - // This is a double check, to avoid extra allocations. - if (event.getEntityLiving() instanceof EntityPlayer) - { - WrappedLivingHurtEvent eventIn = new WrappedLivingHurtEvent(event.getEntityLiving(), event.getSource(), event.getAmount()); - lastStandHandler.onHurt(eventIn); - event.setAmount(eventIn.getAmount()); - event.setCanceled(eventIn.isCanceled()); - } - } -} diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTConfigMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTConfigMixin.java deleted file mode 100644 index 02fe1f16..00000000 --- a/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTConfigMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package mod.acgaming.universaltweaks.mods.openblocks.mixin; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import mod.acgaming.universaltweaks.mods.openblocks.UTOpenBlocksEvents; -import openblocks.Config; -import openblocks.enchantments.LastStandEnchantmentsHandler; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -// Courtesy of jchung01 -@Mixin(value = Config.class, remap = false) -public class UTConfigMixin -{ - @WrapOperation(method = "register", at = @At(value = "NEW", target = "()Lopenblocks/enchantments/LastStandEnchantmentsHandler;")) - private static LastStandEnchantmentsHandler utCaptureLastStandHandler(Operation original) - { - UTOpenBlocksEvents.lastStandHandler = original.call(); - return UTOpenBlocksEvents.lastStandHandler; - } -} diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java index 09e43c7f..6a26548d 100644 --- a/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java @@ -1,20 +1,28 @@ package mod.acgaming.universaltweaks.mods.openblocks.mixin; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.event.entity.living.LivingDamageEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import mod.acgaming.universaltweaks.mods.openblocks.WrappedLivingHurtEvent; import openblocks.enchantments.LastStandEnchantmentsHandler; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; // Courtesy of jchung01 @Mixin(value = LastStandEnchantmentsHandler.class, remap = false) -public class UTLastStandEnchantmentsHandlerMixin +public abstract class UTLastStandEnchantmentsHandlerMixin { + @Shadow + public abstract void onHurt(LivingHurtEvent e); + /** - * Repurpose onHurt as a passthrough method for {@link mod.acgaming.universaltweaks.mods.openblocks.UTOpenBlocksEvents#handleLastStand} + * Repurpose onHurt as a passthrough method for {@link this#ut$fixLastStand} * instead of an event subscriber. * Uses a wrapper for maximum compatibilty with other mods (e.g. DimHopper Tweaks) that may mixin into this method's logic. * @@ -28,4 +36,23 @@ private void utCheckEvent(LivingHurtEvent event, CallbackInfo ci) ci.cancel(); } } + + /** + * Last Stand in 1.12 uses LivingHurtEvent, which is the pre-mitigation damage (before armor, potions, etc). + * It should use LivingDamageEvent, which is the post-mitigation damage. + * This was actually explicitly fixed in older versions (1.10) but once again uses the wrong event in 1.12. + */ + @Unique + @SubscribeEvent + public void ut$fixLastStand(LivingDamageEvent event) + { + // This is a double check, to avoid extra allocations. + if (event.getEntityLiving() instanceof EntityPlayer) + { + WrappedLivingHurtEvent eventIn = new WrappedLivingHurtEvent(event.getEntityLiving(), event.getSource(), event.getAmount()); + this.onHurt(eventIn); + event.setAmount(eventIn.getAmount()); + event.setCanceled(eventIn.isCanceled()); + } + } } diff --git a/src/main/resources/mixins.mods.openblocks.json b/src/main/resources/mixins.mods.openblocks.json index 30814967..5dce103a 100644 --- a/src/main/resources/mixins.mods.openblocks.json +++ b/src/main/resources/mixins.mods.openblocks.json @@ -3,5 +3,5 @@ "refmap": "universaltweaks.refmap.json", "minVersion": "0.8", "compatibilityLevel": "JAVA_8", - "mixins": ["UTConfigMixin", "UTLastStandEnchantmentsHandlerMixin"] + "mixins": ["UTLastStandEnchantmentsHandlerMixin"] } \ No newline at end of file From 1d4e9afe6764a0b591ec7c07d9591b73e57463d8 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Mon, 12 Aug 2024 12:05:28 -0700 Subject: [PATCH 2/2] Guarantee last stand mixin applies later --- .../openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java index 6a26548d..4d929c9c 100644 --- a/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; // Courtesy of jchung01 -@Mixin(value = LastStandEnchantmentsHandler.class, remap = false) +@Mixin(value = LastStandEnchantmentsHandler.class, remap = false, priority = 1010) public abstract class UTLastStandEnchantmentsHandlerMixin { @Shadow