KeyboardInput .java

net.minecraft.client.player.KeyboardInput (class, 41 lines): members: options, tick. imports: Input, Vec2, Options, EnvType, Environment.

net.minecraft.client.playerclass41 linesclientextends ClientInput1.2 KB

API Surface (1)

void tick()

Fields & Constants (1)

options

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

KeyboardInput.java41 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.player;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.Options;
6
import net.minecraft.world.entity.player.Input;
7
import net.minecraft.world.phys.Vec2;
8
9
@Environment(EnvType.CLIENT)
10
public class KeyboardInput extends ClientInput {
11
	private final Options options;
12
13
	public KeyboardInput(final Options options) {
14
		this.options = options;
15
	}
16
17
	private static float calculateImpulse(final boolean positive, final boolean negative) {
18
		if (positive == negative) {
19
			return 0.0F;
20
		} else {
21
			return positive ? 1.0F : -1.0F;
22
		}
23
	}
24
25
	@Override
26
	public void tick() {
27
		this.keyPresses = new Input(
28
			this.options.keyUp.isDown(),
29
			this.options.keyDown.isDown(),
30
			this.options.keyLeft.isDown(),
31
			this.options.keyRight.isDown(),
32
			this.options.keyJump.isDown(),
33
			this.options.keyShift.isDown(),
34
			this.options.keySprint.isDown()
35
		);
36
		float forwardImpulse = calculateImpulse(this.keyPresses.forward(), this.keyPresses.backward());
37
		float leftImpulse = calculateImpulse(this.keyPresses.left(), this.keyPresses.right());
38
		this.moveVector = new Vec2(leftImpulse, forwardImpulse).normalized();
39
	}
40
}
41

Decompiled Minecraft 26.3 source of KeyboardInput (net/minecraft/client/player/KeyboardInput.java) with Mojang official mappings, stored verbatim on the site.