Skip to content

Commit

Permalink
Fix reach calculation when player has higher/lower eye height than no…
Browse files Browse the repository at this point in the history
…rmal
  • Loading branch information
Meldexun committed Jan 28, 2022
1 parent 760c4d4 commit c646690
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/meldexun/reachfix/asm/ReachFixClassTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit c646690

Please sign in to comment.