Skip to content

Commit

Permalink
ALLOW SERVER DISABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
BetterClient committed Sep 1, 2024
1 parent df6f640 commit 32cb8b3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" //only used so that languages work
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
}

processResources {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/io/github/betterclient/snaptap/SnapTap.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package io.github.betterclient.snaptap;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;

public class SnapTap implements ModInitializer {
public static long LEFT_STRAFE_LAST_PRESS_TIME = 0;
Expand All @@ -18,6 +22,9 @@ public class SnapTap implements ModInitializer {
public static KeyBinding KEYSTROKES_TOGGLE_BIND;
public static boolean KEYSTROKES_TOGGLED = true;

private static boolean SERVER_ALLOWS = true;
private static boolean PRE_SERVER_ALLOWS = true;

@Override
public void onInitialize() {
LEFT_STRAFE_LAST_PRESS_TIME = 0;
Expand All @@ -41,6 +48,12 @@ public void setPressed(boolean pressed) {
KEYSTROKES_TOGGLE_BIND = new KeyBinding("text.snaptap.keystrokestoggle", InputUtil.GLFW_KEY_F7, "key.categories.misc") {
@Override
public void setPressed(boolean pressed) {
if (!SERVER_ALLOWS) {
TOGGLED = false;
super.setPressed(pressed);
return;
}

if(pressed) {
KEYSTROKES_TOGGLED = !KEYSTROKES_TOGGLED;
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(
Expand All @@ -53,6 +66,16 @@ public void setPressed(boolean pressed) {
super.setPressed(pressed);
}
};

ClientPlayNetworking.registerGlobalReceiver(new CustomPayload.Id<>(Identifier.of("snaptap", "update_status")), (payload, context) -> {
PRE_SERVER_ALLOWS = TOGGLED;
TOGGLED = false;
SERVER_ALLOWS = false;
});
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
TOGGLED = PRE_SERVER_ALLOWS;
SERVER_ALLOWS = true;
});
}

public static void render(DrawContext context) {
Expand Down

0 comments on commit 32cb8b3

Please sign in to comment.