Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 142
src/main/java/dev/kodari/cheatkeys/CheatKeysClient.java
package dev.kodari.cheatkeys;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
public final class CheatKeysClient implements ModInitializer {
private static final double FULLBRIGHT_GAMMA = 1.0;
private KeyBinding fullbrightKey;
private KeyBinding autoSprintKey;
private boolean fullbrightEnabled;
private boolean autoSprintEnabled;
private double previousGamma;
@Override
public void onInitialize() {
fullbrightKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.cheatkeys.fullbright",
InputUtil.fromTranslationKey("key.keyboard.f6").getCode(),
"key.category.cheatkeys"
));
autoSprintKey = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.cheatkeys.auto_sprint",
InputUtil.fromTranslationKey("key.keyboard.f7").getCode(),
"key.category.cheatkeys"
));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (fullbrightKey.wasPressed()) {
if (fullbrightEnabled) {
fullbrightEnabled = false;
client.options.getGamma().setValue(previousGamma);
} else {
previousGamma = client.options.getGamma().getValue();
fullbrightEnabled = true;
}
}
if (autoSprintKey.wasPressed()) {
autoSprintEnabled = !autoSprintEnabled;
if (!autoSprintEnabled && client.player != null) {
client.player.setSprinting(false);
}
}
if (fullbrightEnabled) {
client.options.getGamma().setValue(FULLBRIGHT_GAMMA);
}
if (autoSprintEnabled && client.player != null) {
boolean movingForward = client.options.forwardKey.isPressed();
boolean enoughFood = client.player.getHungerManager().getFoodLevel() > 6;
client.player.setSprinting(movingForward && enoughFood);
}
});
}
}