Feat: Add NoJumpDelay module

- Add a cross-version Player wrapper that clears the client jump cooldown:
  jumpTicks on 1.8.9 and noJumpDelay on 26.2
- Resolve the player field and cooldown field through MappingResolver so
  vanilla, Forge and MCP runtimes all work
- Dispatch the new capability through WrapperProvider, WrapperRegistry and
  MinecraftFactory, and create it during OrangeX startup
- Clear the cooldown in EventTickPre so the next jump can start on the
  first landing tick while the jump key is held
- Register the module and add a setInt helper to ReflectionSupport
This commit is contained in:
xiaozhou233 committed 2026-11-10 21:54:17 +08:00
1 parent 8f314e1f5c
commit 9fa0176bd2
12 files changed
+289

No files matched your search

@@ -14,6 +14,7 @@ import cn.xiaozhou233.orangex.runtime.RuntimeDetector;
import cn.xiaozhou233.orangex.runtime.RuntimeInfo;
import cn.xiaozhou233.orangex.wrapper.MinecraftFactory;
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
import lombok.Getter;
import org.greenrobot.eventbus.EventBus;
@@ -46,6 +47,8 @@ public class OrangeX {
private Minecraft minecraft;
@Getter
private WorldView worldView;
@Getter
private Player player;
public OrangeX() {
System.out.println("OrangeX <init> start!");
@@ -74,6 +77,16 @@ public class OrangeX {
throwable.printStackTrace();
}
try {
this.player = MinecraftFactory.createPlayer(
runtimeInfo, MappingManager.getResolver(), minecraft);
} catch (Throwable throwable) {
// Player-dependent modules stay inactive when this fails.
System.err.println("[OrangeX] Player wrapper unavailable: "
+ throwable.getMessage());
throwable.printStackTrace();
}
render2DManager = new Render2DManager(
runtimeInfo, MappingManager.getResolver(), minecraft.getMinecraft());
System.out.println("[OrangeX] Font backend: " + render2DManager.getBackendName());
@@ -2,6 +2,7 @@ package cn.xiaozhou233.orangex.modules;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.event.impl.EventKey;
import cn.xiaozhou233.orangex.modules.impl.movement.NoJumpDelay;
import cn.xiaozhou233.orangex.modules.impl.render.ClickGUI;
import cn.xiaozhou233.orangex.modules.impl.render.ESP;
import cn.xiaozhou233.orangex.modules.impl.render.HUD;
@@ -28,6 +29,7 @@ public class ModuleManager {
register(new HUD());
register(new ClickGUI());
register(new ESP());
register(new NoJumpDelay());
}
public void register(Module module) {
@@ -0,0 +1,43 @@
package cn.xiaozhou233.orangex.modules.impl.movement;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.event.impl.EventTickPre;
import cn.xiaozhou233.orangex.modules.Module;
import cn.xiaozhou233.orangex.modules.ModuleCategory;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import org.greenrobot.eventbus.Subscribe;
/**
* Removes the client-side jump cooldown.
*
* <p>Vanilla keeps a short timer after every jump before the next one can
* start. Clearing it before the player tick lets holding the jump key trigger
* a new jump as soon as the player touches the ground again.</p>
*/
public class NoJumpDelay extends Module {
private boolean warned;
public NoJumpDelay() {
super("NoJumpDelay", ModuleCategory.MOVEMENT);
}
@Subscribe
public void onTickPre(EventTickPre event) {
Player player = OrangeX.getInstance().getPlayer();
if (player == null) {
return;
}
try {
player.clearJumpDelay();
} catch (Throwable throwable) {
// Do not retry a broken reflection lookup on every single tick.
if (!warned) {
warned = true;
System.err.println("[NoJumpDelay] Failed to clear jump delay: "
+ throwable.getMessage());
}
}
}
}
@@ -3,6 +3,7 @@ package cn.xiaozhou233.orangex.wrapper;
import cn.xiaozhou233.orangex.mapping.MappingResolver;
import cn.xiaozhou233.orangex.runtime.RuntimeInfo;
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
import cn.xiaozhou233.orangex.wrapper.internal.WrapperRegistry;
@@ -31,6 +32,17 @@ public final class MinecraftFactory {
new WrapperContext(runtimeInfo, mappingResolver), minecraft);
}
/**
* Creates the local-player view that goes with an already created
* {@link Minecraft} wrapper.
*/
public static Player createPlayer(RuntimeInfo runtimeInfo,
MappingResolver mappingResolver,
Minecraft minecraft) {
return WrapperRegistry.createPlayer(
new WrapperContext(runtimeInfo, mappingResolver), minecraft);
}
private MinecraftFactory() {
}
}
@@ -0,0 +1,23 @@
package cn.xiaozhou233.orangex.wrapper.api;
/**
* Cross-version view of the local player.
*
* <p>Only capabilities that need version-specific reflection live here. The
* implementation reads the current player from the client on every call, so a
* wrapper instance survives world changes and reconnects.</p>
*/
public interface Player {
/**
* Clears the client-side jump cooldown.
*
* <p>Vanilla only starts a new jump when the local jump timer has run out,
* which is why holding the jump key produces a fixed jump interval. Zeroing
* the timer every tick removes that interval; the server still receives
* normal jump packets, so this is a client-side timing change only.</p>
*
* <p>Does nothing while no world/player is loaded.</p>
*/
void clearJumpDelay();
}
@@ -120,6 +120,15 @@ public final class ReflectionSupport {
}
}
public static void setInt(Field field, Object target, int value) {
try {
field.setInt(target, value);
} catch (IllegalAccessException e) {
throw new IllegalStateException(
"Cannot write field '" + field.getName() + "'", e);
}
}
public static boolean getBoolean(Field field, Object target) {
try {
return field.getBoolean(target);
@@ -1,6 +1,7 @@
package cn.xiaozhou233.orangex.wrapper.internal;
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
/**
@@ -24,4 +25,9 @@ public interface WrapperProvider {
* Creates the world/camera view backed by the given client instance.
*/
WorldView createWorld(WrapperContext context, Minecraft minecraft);
/**
* Creates the local-player view backed by the given client instance.
*/
Player createPlayer(WrapperContext context, Minecraft minecraft);
}
@@ -2,6 +2,7 @@ package cn.xiaozhou233.orangex.wrapper.internal;
import cn.xiaozhou233.orangex.runtime.version.MinecraftVersion;
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
import cn.xiaozhou233.orangex.wrapper.internal.v1_8_9.V1_8_9WrapperProvider;
import cn.xiaozhou233.orangex.wrapper.internal.v26_2.V26_2WrapperProvider;
@@ -53,6 +54,10 @@ public final class WrapperRegistry {
return provider(context).createWorld(context, minecraft);
}
public static Player createPlayer(WrapperContext context, Minecraft minecraft) {
return provider(context).createPlayer(context, minecraft);
}
private static WrapperProvider provider(WrapperContext context) {
MinecraftVersion version = context.getRuntimeInfo().getMinecraftVersion();
WrapperProvider provider = PROVIDERS.get(version);
@@ -0,0 +1,82 @@
package cn.xiaozhou233.orangex.wrapper.internal.v1_8_9;
import cn.xiaozhou233.orangex.mapping.MappingClass;
import cn.xiaozhou233.orangex.mapping.MappingField;
import cn.xiaozhou233.orangex.mapping.MappingResolver;
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import cn.xiaozhou233.orangex.wrapper.internal.ReflectionSupport;
import java.lang.reflect.Field;
/**
* 1.8.9 implementation of {@link Player}.
*
* <p>The jump cooldown is {@code EntityLivingBase#jumpTicks}: vanilla sets it
* to 10 after a jump and only allows the next jump once it reaches 0. Setting
* it to 0 every tick removes the cooldown.</p>
*/
public final class V1_8_9Player implements Player {
private static final String MINECRAFT = "net/minecraft/client/Minecraft";
private static final String ENTITY_LIVING = "net/minecraft/entity/EntityLivingBase";
private static final String PLAYER_FIELD = "thePlayer";
private static final String JUMP_DELAY_FIELD = "jumpTicks";
private final Object minecraft;
private final Field playerField;
private final String jumpDelayFieldName;
private Field jumpDelayField;
public V1_8_9Player(MappingResolver resolver, Minecraft minecraft) {
this.minecraft = minecraft.getMinecraft();
MappingClass minecraftMapping = resolver.mapClass(MINECRAFT);
this.playerField = resolveField(
minecraftMapping, PLAYER_FIELD, this.minecraft.getClass());
this.jumpDelayFieldName = fieldName(
resolver.mapClass(ENTITY_LIVING), JUMP_DELAY_FIELD);
}
@Override
public void clearJumpDelay() {
Object localPlayer = ReflectionSupport.get(playerField, minecraft);
if (localPlayer == null) {
return;
}
// The player class is stable for the process, but the player instance
// is not, so only the field lookup is cached.
if (jumpDelayField == null) {
jumpDelayField = ReflectionSupport.requireField(
localPlayer.getClass(), jumpDelayFieldName, ENTITY_LIVING);
}
ReflectionSupport.setInt(jumpDelayField, localPlayer, 0);
}
private static Field resolveField(MappingClass owner,
String name,
Class<?> runtimeOwner) {
MappingField mapping = owner.getField(name);
if (mapping == null) {
throw new IllegalStateException(
"No mapping for field '" + name + "' on "
+ owner.getSourceName());
}
return ReflectionSupport.requireField(
runtimeOwner, mapping.getTargetName(), owner.getSourceName());
}
private static String fieldName(MappingClass owner, String name) {
MappingField mapping = owner.getField(name);
if (mapping == null) {
throw new IllegalStateException(
"No mapping for field '" + name + "' on "
+ owner.getSourceName());
}
return mapping.getTargetName();
}
}
@@ -1,6 +1,7 @@
package cn.xiaozhou233.orangex.wrapper.internal.v1_8_9;
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
import cn.xiaozhou233.orangex.wrapper.internal.WrapperProvider;
@@ -21,4 +22,9 @@ public final class V1_8_9WrapperProvider implements WrapperProvider {
public WorldView createWorld(WrapperContext context, Minecraft minecraft) {
return new V1_8_9WorldView(context.getMappingResolver(), minecraft);
}
@Override
public Player createPlayer(WrapperContext context, Minecraft minecraft) {
return new V1_8_9Player(context.getMappingResolver(), minecraft);
}
}
@@ -0,0 +1,82 @@
package cn.xiaozhou233.orangex.wrapper.internal.v26_2;
import cn.xiaozhou233.orangex.mapping.MappingClass;
import cn.xiaozhou233.orangex.mapping.MappingField;
import cn.xiaozhou233.orangex.mapping.MappingResolver;
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import cn.xiaozhou233.orangex.wrapper.internal.ReflectionSupport;
import java.lang.reflect.Field;
/**
* 26.2 implementation of {@link Player}.
*
* <p>Modern clients replaced the 1.8 {@code jumpTicks} counter with
* {@code LivingEntity#noJumpDelay}, which is decremented once per tick and
* blocks a new jump while positive. Zeroing it every tick removes the delay.</p>
*/
public final class V26_2Player implements Player {
private static final String MINECRAFT = "net/minecraft/client/Minecraft";
private static final String ENTITY_LIVING = "net/minecraft/world/entity/LivingEntity";
private static final String PLAYER_FIELD = "player";
private static final String JUMP_DELAY_FIELD = "noJumpDelay";
private final Object minecraft;
private final Field playerField;
private final String jumpDelayFieldName;
private Field jumpDelayField;
public V26_2Player(MappingResolver resolver, Minecraft minecraft) {
this.minecraft = minecraft.getMinecraft();
MappingClass minecraftMapping = resolver.mapClass(MINECRAFT);
this.playerField = resolveField(
minecraftMapping, PLAYER_FIELD, this.minecraft.getClass());
this.jumpDelayFieldName = fieldName(
resolver.mapClass(ENTITY_LIVING), JUMP_DELAY_FIELD);
}
@Override
public void clearJumpDelay() {
Object localPlayer = ReflectionSupport.get(playerField, minecraft);
if (localPlayer == null) {
return;
}
// The player class is stable for the process, but the player instance
// is not, so only the field lookup is cached.
if (jumpDelayField == null) {
jumpDelayField = ReflectionSupport.requireField(
localPlayer.getClass(), jumpDelayFieldName, ENTITY_LIVING);
}
ReflectionSupport.setInt(jumpDelayField, localPlayer, 0);
}
private static Field resolveField(MappingClass owner,
String name,
Class<?> runtimeOwner) {
MappingField mapping = owner.getField(name);
if (mapping == null) {
throw new IllegalStateException(
"No mapping for field '" + name + "' on "
+ owner.getSourceName());
}
return ReflectionSupport.requireField(
runtimeOwner, mapping.getTargetName(), owner.getSourceName());
}
private static String fieldName(MappingClass owner, String name) {
MappingField mapping = owner.getField(name);
if (mapping == null) {
throw new IllegalStateException(
"No mapping for field '" + name + "' on "
+ owner.getSourceName());
}
return mapping.getTargetName();
}
}
@@ -1,6 +1,7 @@
package cn.xiaozhou233.orangex.wrapper.internal.v26_2;
import cn.xiaozhou233.orangex.wrapper.api.Minecraft;
import cn.xiaozhou233.orangex.wrapper.api.Player;
import cn.xiaozhou233.orangex.wrapper.api.WorldView;
import cn.xiaozhou233.orangex.wrapper.internal.WrapperContext;
import cn.xiaozhou233.orangex.wrapper.internal.WrapperProvider;
@@ -18,4 +19,9 @@ public final class V26_2WrapperProvider implements WrapperProvider {
public WorldView createWorld(WrapperContext context, Minecraft minecraft) {
return new V26_2WorldView(minecraft);
}
@Override
public Player createPlayer(WrapperContext context, Minecraft minecraft) {
return new V26_2Player(context.getMappingResolver(), minecraft);
}
}