Move energy sword sweep patch to mixin
This commit is contained in:
parent
b6ae90e743
commit
c9fa920a82
@ -0,0 +1,24 @@
|
||||
package ru.dbotthepony.mc.otm.mixin;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
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.CallbackInfoReturnable;
|
||||
import ru.dbotthepony.mc.otm.item.weapon.EnergySwordItem;
|
||||
|
||||
@Mixin(EnchantmentHelper.class)
|
||||
public class EnchantmentHelperMixin {
|
||||
@Inject(
|
||||
method = "getSweepingDamageRatio(Lnet/minecraft/world/entity/LivingEntity;)F",
|
||||
at = @At("HEAD"),
|
||||
cancellable = true)
|
||||
private static void getSweepingDamageRatio(LivingEntity p_44822_, CallbackInfoReturnable<Float> info) {
|
||||
var result = EnergySwordItem.getSweepingDamageRatioHook(p_44822_);
|
||||
|
||||
if (result != null) {
|
||||
info.setReturnValue(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -247,10 +247,6 @@ class EnergySwordItem : Item(Properties().stacksTo(1).rarity(Rarity.RARE)), Vani
|
||||
builder.pop()
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called from [net.minecraft.world.item.enchantment.EnchantmentHelper.getSweepingDamageRatio]
|
||||
* by coremod patch
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getSweepingDamageRatioHook(ply: LivingEntity): Float? {
|
||||
if (ply.mainHandItem.item is EnergySwordItem && ply.mainHandItem.matteryEnergy?.extractEnergyExact(ENERGY_PER_SWING, true) == true) {
|
||||
|
@ -862,80 +862,6 @@ function initializeCoreMod() {
|
||||
}
|
||||
}
|
||||
|
||||
return node
|
||||
}
|
||||
},
|
||||
|
||||
'EnchantmentHelper#getSweepingDamageRatio patch for energy sword': {
|
||||
'target': {
|
||||
'type': 'METHOD',
|
||||
'class': 'net.minecraft.world.item.enchantment.EnchantmentHelper',
|
||||
'methodName': ASMAPI.mapMethod('m_44821_'), // getSweepingDamageRatio
|
||||
'methodDesc': '(Lnet/minecraft/world/entity/LivingEntity;)F'
|
||||
},
|
||||
|
||||
'transformer': function(node) {
|
||||
// 0: getstatic #237 // Field net/minecraft/world/item/enchantment/Enchantments.SWEEPING_EDGE:Lnet/minecraft/world/item/enchantment/Enchantment;
|
||||
// 3: aload_0
|
||||
// 4: invokestatic #243 // Method getEnchantmentLevel:(Lnet/minecraft/world/item/enchantment/Enchantment;Lnet/minecraft/world/entity/LivingEntity;)I
|
||||
// 7: istore_1
|
||||
// 8: iload_1
|
||||
// 9: ifle 19
|
||||
// 12: iload_1
|
||||
// 13: invokestatic #246 // Method net/minecraft/world/item/enchantment/SweepingEdgeEnchantment.getSweepingDamageRatio:(I)F
|
||||
// 16: goto 20
|
||||
// 19: fconst_0
|
||||
// 20: freturn
|
||||
|
||||
var instructions = node.instructions
|
||||
|
||||
var last = new VarInsnNode(opcodesRemapped.aload, 0)
|
||||
instructions.insert(last) // load player onto stack
|
||||
|
||||
var next = new MethodInsnNode(
|
||||
opcodesRemapped.invokestatic,
|
||||
'ru/dbotthepony/mc/otm/item/weapon/EnergySwordItem',
|
||||
'getSweepingDamageRatioHook',
|
||||
'(Lnet/minecraft/world/entity/LivingEntity;)Ljava/lang/Float;',
|
||||
false
|
||||
) // call hook
|
||||
|
||||
instructions.insert(last, next)
|
||||
last = next
|
||||
|
||||
var label = new Label()
|
||||
var labelNode = new LabelNode(label)
|
||||
|
||||
// add label to jump to if our hook returns null
|
||||
instructions.insert(last, labelNode)
|
||||
|
||||
// duplicate our value, so `ifnull` can safely pop it from stack
|
||||
next = new InsnNode(opcodesRemapped.dup)
|
||||
instructions.insert(last, next)
|
||||
last = next
|
||||
|
||||
// jump to original code if we returned null
|
||||
next = new JumpInsnNode(opcodesRemapped.ifnull, labelNode)
|
||||
instructions.insert(last, next)
|
||||
last = next
|
||||
|
||||
// unbox float
|
||||
next = new MethodInsnNode(
|
||||
opcodesRemapped.invokevirtual,
|
||||
'java/lang/Float',
|
||||
'floatValue',
|
||||
'()F',
|
||||
false
|
||||
)
|
||||
|
||||
instructions.insert(last, next)
|
||||
last = next
|
||||
|
||||
// return float
|
||||
next = new InsnNode(opcodesRemapped.freturn)
|
||||
instructions.insert(last, next)
|
||||
last = next
|
||||
|
||||
return node
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
"minVersion": "0.8",
|
||||
"refmap": "overdrive_that_matters.refmap.json",
|
||||
"mixins": [
|
||||
"EnchantmentHelperMixin",
|
||||
"MixinPatchProjectileFinder",
|
||||
"MixinLivingEntity",
|
||||
"MixinAnvilBlock",
|
||||
|
Loading…
Reference in New Issue
Block a user