diff --git a/src/main/java/net/earthcomputer/clientcommands/command/FovCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/FovCommand.java index 7de47df37..2b307fd3d 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/FovCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/FovCommand.java @@ -1,6 +1,6 @@ package net.earthcomputer.clientcommands.command; -import com.mojang.brigadier.Command; +import com.mojang.blaze3d.platform.Window; import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.network.chat.Component; @@ -12,12 +12,16 @@ public class FovCommand { public static void register(CommandDispatcher dispatcher) { dispatcher.register(literal("cfov") - .then(argument("fov", integer(0, 360)) - .executes(ctx -> setFov(ctx.getSource(), getInteger(ctx, "fov")))) + .then(literal("vertical") + .then(argument("fov", integer(0, 360)) + .executes(ctx -> setFov(ctx.getSource(), getInteger(ctx, "fov"))))) .then(literal("normal") .executes(ctx -> setFov(ctx.getSource(), 70))) .then(literal("quakePro") - .executes(ctx -> setFov(ctx.getSource(), 110)))); + .executes(ctx -> setFov(ctx.getSource(), 110))) + .then(literal("horizontal") + .then(argument("fov", integer(0, 360)) + .executes(ctx -> setHorizontalFov(ctx.getSource(), getInteger(ctx, "fov")))))); } private static int setFov(FabricClientCommandSource source, int fov) { @@ -26,7 +30,17 @@ private static int setFov(FabricClientCommandSource source, int fov) { Component feedback = Component.translatable("commands.cfov.success", fov); source.sendFeedback(feedback); - return Command.SINGLE_SUCCESS; + return fov; } + private static int setHorizontalFov(FabricClientCommandSource source, int fov) { + Window window = source.getClient().getWindow(); + + double fovRad = Math.toRadians(fov); + double aspectRatio = (double) window.getGuiScaledWidth() / window.getGuiScaledHeight(); + double verticalFovRad = 2 * Math.atan(Math.tan(fovRad / 2) / aspectRatio); + int verticalFov = (int) Math.round(Math.toDegrees(verticalFovRad)); + + return setFov(source, verticalFov); + } }