diff --git a/build.gradle b/build.gradle index 50b5874..215d843 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/src/main/java/io/github/betterclient/snaptap/SnapTap.java b/src/main/java/io/github/betterclient/snaptap/SnapTap.java index 8e45eb0..feb4d19 100644 --- a/src/main/java/io/github/betterclient/snaptap/SnapTap.java +++ b/src/main/java/io/github/betterclient/snaptap/SnapTap.java @@ -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; @@ -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; @@ -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( @@ -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) {