Skip to content

Commit

Permalink
Toggle Sneak and Sprint!
Browse files Browse the repository at this point in the history
  • Loading branch information
N-slash-A committed Jul 29, 2020
1 parent 3883614 commit 811dcf5
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 18 deletions.
31 changes: 19 additions & 12 deletions src/main/java/io/github/simplycmd/quake/AntiGhost.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
package io.github.simplycmd.quake;

import org.lwjgl.glfw.GLFW;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.options.GameOptions;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_G;

public class AntiGhost implements ClientModInitializer
{
static FabricKeyBinding requestBlocks;
//static KeyBinding requestBlock;
private KeyBinding requestBlocks;

@Override
public void onInitializeClient()
{
final String category="key.categories.quake";
KeyBindingRegistry.INSTANCE.addCategory(category);
KeyBindingRegistry.INSTANCE.register(requestBlocks = FabricKeyBinding.Builder
.create(new Identifier("quake:reveal"), InputUtil.Type.KEYSYM,
GLFW_KEY_G, category)
.build());
SetupKeybinds();
}

private void SetupKeybinds() {
requestBlocks = new KeyBinding(
"key.quake.reveal",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_G,
"key.categories.quake"
);

KeyBindingHelper.registerKeyBinding(requestBlocks);

ClientTickCallback.EVENT.register(e->keyPressed());
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/simplycmd/quake/Fullbright.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Fullbright implements ClientModInitializer {
private boolean maxBrightToggled = false;
private double prevBrightness;
private boolean prevPressed;
private KeyBinding brightnessBind;
private KeyBinding fullbrightKey;


@Override
Expand All @@ -32,14 +32,14 @@ public void onInitializeClient() {
private void SetupKeybinds() {

// Create the max brightness toggle
brightnessBind = new KeyBinding(
fullbrightKey = new KeyBinding(
"key.quake.fullbright",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_B,
"key.categories.quake"
);

KeyBindingHelper.registerKeyBinding(brightnessBind);
KeyBindingHelper.registerKeyBinding(fullbrightKey);

// Callback that toggles brightness between set value and maximum
ClientTickCallback.EVENT.register(e -> {
Expand All @@ -49,7 +49,7 @@ private void SetupKeybinds() {
gameOptions = client.options;
}

if (brightnessBind.isPressed()) {
if (fullbrightKey.isPressed()) {
if (!prevPressed) {
if (!maxBrightToggled) {
prevBrightness = gameOptions.gamma;
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/io/github/simplycmd/quake/Toggle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.github.simplycmd.quake;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;
import net.minecraft.text.LiteralText;

public class Toggle implements ClientModInitializer {
private KeyBinding toggleSprint;
private KeyBinding toggleSneak;

@Override
public void onInitializeClient() {
SetupKeybinds();
}

private void SetupKeybinds() {
toggleSprint = new KeyBinding(
"key.quake.sprint",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_RIGHT_CONTROL,
"key.categories.quake"
);
toggleSneak = new KeyBinding(
"key.quake.sneak",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_RIGHT_SHIFT,
"key.categories.quake"
);

KeyBindingHelper.registerKeyBinding(toggleSprint);
KeyBindingHelper.registerKeyBinding(toggleSneak);

ClientTickCallback.EVENT.register(e->keyPressed());
}

public void keyPressed() {
MinecraftClient client = MinecraftClient.getInstance();
if (toggleSprint.wasPressed()) {
if(client.options.sprintToggled == true) {
client.player.sendMessage(new TranslatableText("msg.sprinthold"), false);
client.options.sprintToggled = false;
} else {
client.player.sendMessage(new TranslatableText("msg.sprinttoggle"), false);
client.options.sprintToggled = true;
}
}
if (toggleSneak.wasPressed()) {
if(client.options.sneakToggled == true) {
client.player.sendMessage(new TranslatableText("msg.sneakhold"), false);
client.options.sneakToggled = false;
} else {
client.player.sendMessage(new TranslatableText("msg.sneaktoggle"), false);
client.options.sneakToggled = true;
}
}
}
}
9 changes: 8 additions & 1 deletion src/main/resources/assets/quake/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,12 @@
"key.quake.reveal": "Reveal Ghost Blocks",
"msg.request": "Revealing glitched blocks (Don't spam this or else you will get kicked!)",

"key.quake.fullbright": "Toggle Fullbright"
"key.quake.fullbright": "Toggle Fullbright",

"key.quake.sprint": "Toggle Sprint",
"key.quake.sneak": "Toggle Sneak",
"msg.sprinthold": "Changed sprint mode to HOLD. (This will take effect in a few seconds)",
"msg.sprinttoggle": "Changed sprint mode to TOGGLE. (This will take effect in a few seconds)",
"msg.sneakhold": "Changed sneak mode to HOLD. (This will take effect in a few seconds)",
"msg.sneaktoggle": "Changed sneak mode to TOGGLE. (This will take effect in a few seconds)"
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"main": [
"io.github.simplycmd.quake.Quake"
],
"client": ["io.github.simplycmd.quake.AntiGhost","io.github.simplycmd.quake.Fullbright"],
"client": ["io.github.simplycmd.quake.AntiGhost","io.github.simplycmd.quake.Fullbright","io.github.simplycmd.quake.Toggle"],
"server": []
},
"mixins": [
Expand Down

0 comments on commit 811dcf5

Please sign in to comment.