Skip to content

Commit

Permalink
Merge pull request #535 from jchung01/mod-tweaks
Browse files Browse the repository at this point in the history
Simplify last stand mixin
  • Loading branch information
ACGaming authored Aug 14, 2024
2 parents ba0bdfe + 983f7c2 commit f5f8c88
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
@Mixin(value = LastStandEnchantmentsHandler.class, remap = false, priority = 1010)
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.
*
Expand All @@ -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());
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/mixins.mods.openblocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTConfigMixin", "UTLastStandEnchantmentsHandlerMixin"]
"mixins": ["UTLastStandEnchantmentsHandlerMixin"]
}

0 comments on commit f5f8c88

Please sign in to comment.