From cae8c3475956e62a090a816b03a60e46fec2a9a8 Mon Sep 17 00:00:00 2001 From: AlwaysHAK Date: Sun, 30 Mar 2025 16:16:51 +0200 Subject: [PATCH] Added Teleportation Angle Viewer (Also removed FPS counter) --- README.md | 13 +++- gradle.properties | 2 +- .../survivalfabric/SurvivalFabricClient.java | 31 +------- .../mixin/client/InGameHudMixin.java | 28 ------- .../teleportation/AngleViewHandler.java | 76 +++++++++++++++++++ .../survivalfabric.client.mixins.json | 1 - .../assets/survivalfabric/lang/en_us.json | 19 ++++- 7 files changed, 105 insertions(+), 65 deletions(-) delete mode 100644 src/client/java/wtf/hak/survivalfabric/mixin/client/InGameHudMixin.java create mode 100644 src/client/java/wtf/hak/survivalfabric/teleportation/AngleViewHandler.java diff --git a/README.md b/README.md index bfd4aa1..268201e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ This mod is FAR FROM FINISHED, and initially just created for our private Survival Server. As a challenge I'm trying to make it as user-friendly as possible. (It ain't there yet tho ;) ) -## Current feature-set +# Current feature-set + +## Server Side ### Features - Custom join message @@ -32,11 +34,14 @@ As a challenge I'm trying to make it as user-friendly as possible. (It ain't the - /spectator | Essentially server-side free-cam, you get put in spectator and are able to fly around, once you use the command again you get put back to where you were. - /slimechunk (/sc) | See if you're currently in a slimechunk -### Misc -- Updated icon +## Client Side -## Features to come +- Teleportation Angle Viewer +![Teleportation Keybindings](https://i.imgur.com/gjO1H3d.png) +# Features to come + +## Server Side - Telekinesis Other than that no more features! diff --git a/gradle.properties b/gradle.properties index d8b7053..4f61974 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.21.5+build.1 loader_version=0.16.10 # Mod Properties -mod_version=1.3.1 +mod_version=1.3.2 maven_group=wtf.hak.survivalfabric archives_base_name=survivalfabric diff --git a/src/client/java/wtf/hak/survivalfabric/SurvivalFabricClient.java b/src/client/java/wtf/hak/survivalfabric/SurvivalFabricClient.java index 7198177..226fd86 100644 --- a/src/client/java/wtf/hak/survivalfabric/SurvivalFabricClient.java +++ b/src/client/java/wtf/hak/survivalfabric/SurvivalFabricClient.java @@ -1,39 +1,12 @@ package wtf.hak.survivalfabric; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import net.minecraft.text.Text; -import org.lwjgl.glfw.GLFW; - -import java.awt.*; +import wtf.hak.survivalfabric.teleportation.AngleViewHandler; public class SurvivalFabricClient implements ClientModInitializer { - public static boolean SHOULD_SHOW_FPS = false; - - KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.survivalfabric.fps", // The translation key of the keybinding's name - InputUtil.Type.KEYSYM, // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse. - GLFW.GLFW_KEY_PERIOD, // The keycode of the key - "category.survivalfabric.utils" // The translation key of the keybinding's category. - )); - @Override public void onInitializeClient() { - ClientTickEvents.END_CLIENT_TICK.register(client -> { - while (keyBinding.wasPressed()) { - MinecraftClient mc = MinecraftClient.getInstance(); - SHOULD_SHOW_FPS = !SHOULD_SHOW_FPS; - if(SHOULD_SHOW_FPS) { - mc.player.sendMessage(Text.literal("FPS Counter is now on").withColor(Color.GREEN.getRGB()), true); - } else - mc.player.sendMessage(Text.literal("FPS Counter is now off").withColor(Color.RED.getRGB()), true); - - } - }); + AngleViewHandler.registerKeybindings(); } } \ No newline at end of file diff --git a/src/client/java/wtf/hak/survivalfabric/mixin/client/InGameHudMixin.java b/src/client/java/wtf/hak/survivalfabric/mixin/client/InGameHudMixin.java deleted file mode 100644 index 09739a7..0000000 --- a/src/client/java/wtf/hak/survivalfabric/mixin/client/InGameHudMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package wtf.hak.survivalfabric.mixin.client; - -import net.minecraft.client.MinecraftClient; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.client.render.RenderTickCounter; -import wtf.hak.survivalfabric.SurvivalFabricClient; - -import java.awt.*; - -@Mixin(InGameHud.class) -public class InGameHudMixin { - - private final int TEXT_COLOR = Color.GRAY.getRGB(); - - @Inject(method = "render", at = @At("RETURN")) - private void renderFPS(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) { - if(SurvivalFabricClient.SHOULD_SHOW_FPS) { - MinecraftClient client = MinecraftClient.getInstance(); - context.drawTextWithShadow(client.textRenderer, client.getCurrentFps() + " FPS", 5, 5, TEXT_COLOR); - } - } -} \ No newline at end of file diff --git a/src/client/java/wtf/hak/survivalfabric/teleportation/AngleViewHandler.java b/src/client/java/wtf/hak/survivalfabric/teleportation/AngleViewHandler.java new file mode 100644 index 0000000..2edcb2d --- /dev/null +++ b/src/client/java/wtf/hak/survivalfabric/teleportation/AngleViewHandler.java @@ -0,0 +1,76 @@ +package wtf.hak.survivalfabric.teleportation; + +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; +import org.lwjgl.glfw.GLFW; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class AngleViewHandler { + + private static final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); + + public static void registerKeybindings() { + for(Angle angle : Angle.values()) { + KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.survivalfabric." + angle.name().toLowerCase(), + InputUtil.Type.KEYSYM, + GLFW.GLFW_DONT_CARE, + "category.survivalfabric.tpangles" + )); + + ClientTickEvents.END_CLIENT_TICK.register(mc -> { + while (keyBinding.wasPressed()) { + ClientPlayerEntity player = mc.player; + if(player == null) return; + float oldYaw = player.getYaw(); + float oldPitch = player.getPitch(); + player.setYaw(angle.yaw); + player.setPitch(angle.pitch); + + scheduler.schedule(() -> { + if(player == null) return; + player.setPitch(-90); + scheduler.schedule(() -> { + if(player == null) return; + player.setYaw(oldYaw); + player.setPitch(oldPitch); + }, 1500, TimeUnit.MILLISECONDS); + }, 1500, TimeUnit.MILLISECONDS); + } + }); + } + } + + public enum Angle { + ANGLE0(-65.19f, -54.23f), + ANGLE1(-24.86f, -54.23f), + ANGLE2(-65.02f, -41.68f), + ANGLE3(-25.03f, -41.71f), + ANGLE4(24.81f, -54.23f), + ANGLE5(65.14f, -54.23f), + ANGLE6(24.98f, -41.68f), + ANGLE7(64.97f, -41.71f), + ANGLE8(114.81f, -54.23f), + ANGLE9(155.14f, -54.23f), + ANGLE10(114.98f, -41.68f), + ANGLE11(154.97f, -41.71f), + ANGLE12(204.81f, -54.23f), + ANGLE13(245.14f, -54.23f), + ANGLE14(204.98f, -41.68f), + ANGLE15(244.97f, -41.71f); + + public final float yaw; + public final float pitch; + + Angle(float yaw, float pitch) { + this.yaw = yaw; + this.pitch = pitch; + } + } +} diff --git a/src/client/resources/survivalfabric.client.mixins.json b/src/client/resources/survivalfabric.client.mixins.json index 4059539..c15ff45 100644 --- a/src/client/resources/survivalfabric.client.mixins.json +++ b/src/client/resources/survivalfabric.client.mixins.json @@ -3,7 +3,6 @@ "package": "wtf.hak.survivalfabric.mixin.client", "compatibilityLevel": "JAVA_21", "client": [ - "InGameHudMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/main/resources/assets/survivalfabric/lang/en_us.json b/src/main/resources/assets/survivalfabric/lang/en_us.json index db97a8d..7df7fde 100644 --- a/src/main/resources/assets/survivalfabric/lang/en_us.json +++ b/src/main/resources/assets/survivalfabric/lang/en_us.json @@ -1,4 +1,19 @@ { - "category.survivalfabric.utils": "ChirpClient", - "key.survivalfabric.fps": "Toggle FPS" + "category.survivalfabric.tpangles": "Teleportation Angles", + "key.survivalfabric.angle0": "-65.19 / -54.23", + "key.survivalfabric.angle1": "-24.86 / -54.23", + "key.survivalfabric.angle2": "-65.02 / -41.68", + "key.survivalfabric.angle3": "-25.03 / -41.71", + "key.survivalfabric.angle4": "24.81 / -54.23", + "key.survivalfabric.angle5": "65.14 / -54.23", + "key.survivalfabric.angle6": "24.98 / -41.68", + "key.survivalfabric.angle7": "64.97 / -41.71", + "key.survivalfabric.angle8": "114.81 / -54.23", + "key.survivalfabric.angle9": "155.14 / -54.23", + "key.survivalfabric.angle10": "114.98 / -41.68", + "key.survivalfabric.angle11": "154.97 / -41.71", + "key.survivalfabric.angle12": "204.81 / -54.23", + "key.survivalfabric.angle13": "245.14 / -54.23", + "key.survivalfabric.angle14": "204.98 / -41.68", + "key.survivalfabric.angle15": "244.97 / -41.71" } \ No newline at end of file