Skip to content
Open
Show file tree
Hide file tree
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
Expand Up @@ -195,6 +195,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
WeatherCommand.register(dispatcher);
WhisperEncryptedCommand.register(dispatcher);
WikiCommand.register(dispatcher);
WindowSizeCommand.register(dispatcher);

Calendar calendar = Calendar.getInstance();
boolean registerChatCommand = calendar.get(Calendar.MONTH) == Calendar.APRIL && calendar.get(Calendar.DAY_OF_MONTH) == 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.earthcomputer.clientcommands.command;

import com.mojang.blaze3d.opengl.GlStateManager;
import com.mojang.blaze3d.platform.Window;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import org.lwjgl.glfw.GLFW;

import static com.mojang.brigadier.arguments.IntegerArgumentType.*;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*;

public class WindowSizeCommand {
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
dispatcher.register(literal("cwindowsize")
.then(argument("width", integer(0))
.then(argument("height", integer(0))
.executes(ctx -> setWindowSize(ctx.getSource(), getInteger(ctx, "width"), getInteger(ctx, "height"))))));
}

private static int setWindowSize(FabricClientCommandSource source, int width, int height) {
Window window = source.getClient().getWindow();
long handle = window.handle();

int oldX = window.getX();
int oldY = window.getY();
int oldWidth = window.getWidth();
int oldHeight = window.getHeight();

int centerX = oldX + oldWidth / 2;
int centerY = oldY + oldHeight / 2;

GLFW.glfwSetWindowSize(handle, width, height);

int newX = centerX - width / 2;
int newY = centerY - height / 2;

GLFW.glfwSetWindowPos(handle, newX, newY);
return Command.SINGLE_SUCCESS;
}
}