generated from Fallen-Breath/fabric-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mc tweak
windowSizeApply
, windowSizeWidth
, `windowSizeHeigh…
…t`, `windowSizePinned`
- Loading branch information
1 parent
40fa27b
commit 0b474a0
Showing
8 changed files
with
328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/me/fallenbreath/tweakermore/impl/mc_tweaks/windowSize/WindowSizeHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* This file is part of the TweakerMore project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 Fallen_Breath and contributors | ||
* | ||
* TweakerMore is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* TweakerMore is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.fallenbreath.tweakermore.impl.mc_tweaks.windowSize; | ||
|
||
import fi.dy.masa.malilib.gui.Message; | ||
import fi.dy.masa.malilib.util.InfoUtils; | ||
import me.fallenbreath.tweakermore.TweakerMoreMod; | ||
import me.fallenbreath.tweakermore.config.TweakerMoreConfigs; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.util.Window; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
public class WindowSizeHelper | ||
{ | ||
public static void applyWindowSize() | ||
{ | ||
MinecraftClient mc = MinecraftClient.getInstance(); | ||
//#if MC >= 11500 | ||
Window window = mc.getWindow(); | ||
//#else | ||
//$$ Window window = mc.window; | ||
//#endif | ||
|
||
if (window == null) | ||
{ | ||
return; | ||
} | ||
if (window.isFullscreen()) | ||
{ | ||
InfoUtils.showGuiOrInGameMessage(Message.MessageType.WARNING, "tweakermore.impl.windowSize.full_screen_nope"); | ||
return; | ||
} | ||
|
||
applyWindowSizeImpl(window); | ||
} | ||
|
||
private static int getConfigWidth() | ||
{ | ||
return Math.max(1, TweakerMoreConfigs.WINDOW_SIZE_WIDTH.getIntegerValue()); | ||
} | ||
|
||
private static int getConfigHeight() | ||
{ | ||
return Math.max(1, TweakerMoreConfigs.WINDOW_SIZE_HEIGHT.getIntegerValue()); | ||
} | ||
|
||
private static void applyWindowSizeImpl(Window window) | ||
{ | ||
if (window.isFullscreen()) | ||
{ | ||
throw new RuntimeException("resize in full screen"); | ||
} | ||
GLFW.glfwSetWindowSize(window.getHandle(), getConfigWidth(), getConfigHeight()); | ||
} | ||
|
||
public static void onWindowSizeChanged(Window window) | ||
{ | ||
if (!TweakerMoreConfigs.WINDOW_SIZE_PINNED.getBooleanValue()) | ||
{ | ||
return; | ||
} | ||
if (window.isFullscreen()) | ||
{ | ||
return; | ||
} | ||
|
||
int windowWidth = window.getWidth(); | ||
int windowHeight = window.getHeight(); | ||
int configWidth = getConfigWidth(); | ||
int configHeight = getConfigHeight(); | ||
|
||
if (windowWidth != configWidth || windowHeight != configHeight) | ||
{ | ||
TweakerMoreMod.LOGGER.debug( | ||
"Window size was changed to ({}, {}) and is different to the configured size ({}, {}), resizing", | ||
windowWidth, windowHeight, configWidth, configHeight | ||
); | ||
applyWindowSizeImpl(window); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/windowSize/WindowMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of the TweakerMore project, licensed under the | ||
* GNU Lesser General Public License v3.0 | ||
* | ||
* Copyright (C) 2024 Fallen_Breath and contributors | ||
* | ||
* TweakerMore is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* TweakerMore is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with TweakerMore. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.windowSize; | ||
|
||
import me.fallenbreath.tweakermore.impl.mc_tweaks.windowSize.WindowSizeHelper; | ||
import net.minecraft.client.util.Window; | ||
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; | ||
|
||
@Mixin(Window.class) | ||
public abstract class WindowMixin | ||
{ | ||
@Inject(method = "onWindowSizeChanged", at = @At("TAIL")) | ||
private void onWindowSizeChanged_windowSize(CallbackInfo ci) | ||
{ | ||
WindowSizeHelper.onWindowSizeChanged((Window)(Object)this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters