sten.wtf / STEN Vault source

In-house snapshot of sten-vault 2.3.2. GPL-3.0-or-later. Isolated from the dashboard.

src/main/java/wtf/sten/vault/mixin/KeyboardInputMixin.java

package wtf.sten.vault.mixin;

import net.minecraft.client.player.ClientInput;
import net.minecraft.client.player.KeyboardInput;
import net.minecraft.world.entity.player.Input;
import net.minecraft.world.phys.Vec2;
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;
import wtf.sten.vault.Remote;

@Mixin(KeyboardInput.class)
public abstract class KeyboardInputMixin extends ClientInput {
	@Inject(method = "tick", at = @At("TAIL"))
	private void sten$held(CallbackInfo ci) {
		Input held = Remote.heldInput();
		if (held == null) return;
		this.keyPresses = held;
		float x = held.left() == held.right() ? 0f : (held.left() ? 1f : -1f);
		float y = held.forward() == held.backward() ? 0f : (held.forward() ? 1f : -1f);
		this.moveVector = (x == 0f && y == 0f) ? Vec2.ZERO : new Vec2(x, y).normalized();
	}
}