From c6466908ab9c0c21fd173242a52ea18868be3ea5 Mon Sep 17 00:00:00 2001 From: Meldexun <27779321+Meldexun@users.noreply.github.com> Date: Fri, 28 Jan 2022 19:42:26 +0100 Subject: [PATCH] Fix reach calculation when player has higher/lower eye height than normal --- .../reachfix/asm/ReachFixClassTransformer.java | 13 +++++++++++++ .../reachfix/asm/hook/NetHandlerPlayServerHook.java | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/meldexun/reachfix/asm/ReachFixClassTransformer.java b/src/main/java/meldexun/reachfix/asm/ReachFixClassTransformer.java index 1464077..77ac726 100644 --- a/src/main/java/meldexun/reachfix/asm/ReachFixClassTransformer.java +++ b/src/main/java/meldexun/reachfix/asm/ReachFixClassTransformer.java @@ -5,6 +5,7 @@ import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.JumpInsnNode; import org.objectweb.asm.tree.LabelNode; +import org.objectweb.asm.tree.LdcInsnNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.VarInsnNode; @@ -47,6 +48,18 @@ protected void registerTransformers() { popNode11 )); }); + this.registerMethodTransformer("pa", "a", "(Llp;)V", "net/minecraft/network/NetHandlerPlayServer", "processPlayerDigging", "(Lnet/minecraft/network/play/client/CPacketPlayerDigging;)V", methodNode -> { + AbstractInsnNode targetNode1 = ASMUtil.findFirstInsnByType(methodNode, AbstractInsnNode.LDC_INSN); + while (!((LdcInsnNode) targetNode1).cst.equals(1.5D)) { + targetNode1 = ASMUtil.findFirstInsnByType(methodNode, AbstractInsnNode.LDC_INSN, targetNode1); + } + + methodNode.instructions.insert(targetNode1, ASMUtil.listOf( + new VarInsnNode(Opcodes.ALOAD, 0), + new MethodInsnNode(Opcodes.INVOKESTATIC, "meldexun/reachfix/asm/hook/NetHandlerPlayServerHook", "getEyeHeightMinusOnePointFive", "(Lnet/minecraft/network/NetHandlerPlayServer;)D", false), + new InsnNode(Opcodes.DADD) + )); + }); this.registerMethodTransformer("bsc", "a", "(Lams;)V", "net/minecraft/client/network/NetworkPlayerInfo", "setGameType", "(Lnet/minecraft/world/GameType;)V", methodNode -> { methodNode.instructions.insert(ASMUtil.listOf( new VarInsnNode(Opcodes.ALOAD, 0), diff --git a/src/main/java/meldexun/reachfix/asm/hook/NetHandlerPlayServerHook.java b/src/main/java/meldexun/reachfix/asm/hook/NetHandlerPlayServerHook.java index 2baa1ed..d452636 100644 --- a/src/main/java/meldexun/reachfix/asm/hook/NetHandlerPlayServerHook.java +++ b/src/main/java/meldexun/reachfix/asm/hook/NetHandlerPlayServerHook.java @@ -26,4 +26,8 @@ public static boolean isEntityInRange(NetHandlerPlayServer serverHandler, Entity return distance < reach + aabbRadius + 1.0D; } + public static double getEyeHeightMinusOnePointFive(NetHandlerPlayServer serverHandler) { + return serverHandler.player.eyeHeight - 1.5D; + } + }