Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,12 +12,16 @@ public class FovCommand {

public static void register(CommandDispatcher<FabricClientCommandSource> 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) {
Expand All @@ -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);
}
}