-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #477 from jchung01/openblocks-last-stand
Fix OpenBlocks Last Stand trigger condition
- Loading branch information
Showing
11 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/mod/acgaming/universaltweaks/mods/openblocks/UTOpenBlocksEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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()); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/mod/acgaming/universaltweaks/mods/openblocks/WrappedLivingHurtEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package mod.acgaming.universaltweaks.mods.openblocks; | ||
|
||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.util.DamageSource; | ||
import net.minecraftforge.event.entity.living.LivingHurtEvent; | ||
|
||
/** | ||
* Same as LivingHurtEvent, but only fired manually by the last stand handler. | ||
* @author jchung01 | ||
*/ | ||
public class WrappedLivingHurtEvent extends LivingHurtEvent | ||
{ | ||
public WrappedLivingHurtEvent(EntityLivingBase entity, DamageSource source, float amount) | ||
{ | ||
super(entity, source, amount); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/mod/acgaming/universaltweaks/mods/openblocks/mixin/UTConfigMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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.enchantments.LastStandEnchantmentsHandler; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import openblocks.Config; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
// Courtesy of jchung01 | ||
@Mixin(value = Config.class, remap = false) | ||
public class UTConfigMixin | ||
{ | ||
// MixinBooter 8.9 (MixinExtras 0.2.1) required! | ||
@WrapOperation(method = "register", at = @At(value = "NEW", target = "()Lopenblocks/enchantments/LastStandEnchantmentsHandler;")) | ||
private static LastStandEnchantmentsHandler utCaptureLastStandHandler(Operation<LastStandEnchantmentsHandler> original) | ||
{ | ||
UTOpenBlocksEvents.lastStandHandler = original.call(); | ||
return UTOpenBlocksEvents.lastStandHandler; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...d/acgaming/universaltweaks/mods/openblocks/mixin/UTLastStandEnchantmentsHandlerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package mod.acgaming.universaltweaks.mods.openblocks.mixin; | ||
|
||
import net.minecraftforge.event.entity.living.LivingHurtEvent; | ||
import mod.acgaming.universaltweaks.mods.openblocks.WrappedLivingHurtEvent; | ||
import openblocks.enchantments.LastStandEnchantmentsHandler; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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 | ||
{ | ||
/** | ||
* Repurpose onHurt as a passthrough method for {@link mod.acgaming.universaltweaks.mods.openblocks.UTOpenBlocksEvents#handleLastStand} | ||
* 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. | ||
* | ||
* @reason Only handle player damage from LivingDamageEvent, not LivingHurtEvent | ||
*/ | ||
@Inject(method = "onHurt", at = @At(value = "HEAD"), cancellable = true) | ||
private void utCheckEvent(LivingHurtEvent event, CallbackInfo ci) | ||
{ | ||
if (!(event instanceof WrappedLivingHurtEvent)) | ||
{ | ||
ci.cancel(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"package": "mod.acgaming.universaltweaks.mods.openblocks.mixin", | ||
"refmap": "universaltweaks.refmap.json", | ||
"minVersion": "0.8", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": ["UTConfigMixin", "UTLastStandEnchantmentsHandlerMixin"] | ||
} |