Skip to content

Commit e68e780

Browse files
committed
Port the mod to Minecraft 26.2
Closes #129
1 parent ea90ab9 commit e68e780

6 files changed

Lines changed: 73 additions & 80 deletions

File tree

gradle.properties

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ mod.modrinth.id=ETlrkaYF
1818
mod.curseforge.id=975120
1919

2020
# Dependencies
21-
dependencies.loom=1.15-SNAPSHOT
22-
dependencies.minecraft=26.1
21+
dependencies.loom=1.17-SNAPSHOT
22+
dependencies.minecraft=26.2
2323
dependencies.java=25
2424
dependencies.fabric-loader=0.17.0
25-
dependencies.forge=26.1-62.0.0
26-
dependencies.neoforge=26.1.0.1-beta
25+
dependencies.forge=26.2-65.0.0
26+
dependencies.neoforge=26.2.0.0-beta
2727
dependencies.fancymodloader=11.0.0
28-
dependencies.sodium=mc26.1-0.8.7-fabric
29-
dependencies.modmenu=18.0.0-alpha.8
30-
dependencies.cloth-config=26.1.154+fabric
31-
dependencies.yacl=3.9.1+26.1-fabric
28+
dependencies.sodium=mc26.2-0.9.0-fabric
29+
dependencies.modmenu=20.0.0-beta.1
30+
dependencies.cloth-config=26.2.155+fabric
31+
dependencies.yacl=3.9.4+26.2-fabric

src/main/java/dev/kirant/cwb/FullscreenTypes.java

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,20 @@ public boolean isSupported() {
8989

9090
@Override
9191
public void enable(Window window, Monitor monitor, VideoMode videoMode) {
92-
long handle = MinecraftWindow.getHandle(window);
93-
GLFW.glfwSetWindowAttrib(handle, GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
94-
GLFW.glfwSetWindowAttrib(handle, GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_FALSE);
95-
96-
window.x = monitor.getX();
97-
window.y = monitor.getY();
98-
window.width = monitor.getCurrentMode().getWidth();
99-
window.height = monitor.getCurrentMode().getHeight();
100-
GLFW.glfwSetWindowMonitor(handle, 0, window.x, window.y, window.width, window.height, -1);
92+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
93+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_FALSE);
94+
95+
window.x = monitor.x();
96+
window.y = monitor.y();
97+
window.width = monitor.currentMode().getWidth();
98+
window.height = monitor.currentMode().getHeight();
99+
GLFW.glfwSetWindowMonitor(window.handle(), 0, window.x, window.y, window.width, window.height, -1);
101100
}
102101

103102
@Override
104103
public void disable(Window window) {
105-
GLFW.glfwSetWindowAttrib(MinecraftWindow.getHandle(window), GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
106-
GLFW.glfwSetWindowAttrib(MinecraftWindow.getHandle(window), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
104+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
105+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
107106
}
108107
}
109108

@@ -116,16 +115,15 @@ public String getId() {
116115
//? if >=26.1 {
117116
@Override
118117
public void enable(Window window, Monitor monitor, VideoMode videoMode) {
119-
long handle = MinecraftWindow.getHandle(window);
120118
GLFW.glfwWindowHint(GLFW.GLFW_SOFT_FULLSCREEN, GLFW.GLFW_TRUE);
121-
GLFW.glfwSetWindowAttrib(handle, GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
119+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
122120

123-
window.x = monitor.getX();
124-
window.y = monitor.getY();
121+
window.x = monitor.x();
122+
window.y = monitor.y();
125123
window.width = videoMode.getWidth();
126124
window.height = videoMode.getHeight();
127125
int refreshRate = videoMode.getRefreshRate();
128-
GLFW.glfwSetWindowMonitor(handle, monitor.getMonitor(), window.x, window.y, window.width, window.height, refreshRate);
126+
GLFW.glfwSetWindowMonitor(window.handle(), monitor.monitor(), window.x, window.y, window.width, window.height, refreshRate);
129127
}
130128

131129
@Override
@@ -148,20 +146,19 @@ public boolean isSupported() {
148146

149147
@Override
150148
public void enable(Window window, Monitor monitor, VideoMode videoMode) {
151-
long handle = MinecraftWindow.getHandle(window);
152-
GLFW.glfwSetWindowAttrib(handle, GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_FALSE);
153-
154-
window.x = monitor.getX();
155-
window.y = monitor.getY();
156-
window.width = monitor.getCurrentMode().getWidth();
157-
window.height = monitor.getCurrentMode().getHeight();
158-
int refreshRate = monitor.getCurrentMode().getRefreshRate();
159-
GLFW.glfwSetWindowMonitor(handle, monitor.getMonitor(), window.x, window.y, window.width, window.height, refreshRate);
149+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_FALSE);
150+
151+
window.x = monitor.x();
152+
window.y = monitor.y();
153+
window.width = monitor.currentMode().getWidth();
154+
window.height = monitor.currentMode().getHeight();
155+
int refreshRate = monitor.currentMode().getRefreshRate();
156+
GLFW.glfwSetWindowMonitor(window.handle(), monitor.monitor(), window.x, window.y, window.width, window.height, refreshRate);
160157
}
161158

162159
@Override
163160
public void disable(Window window) {
164-
GLFW.glfwSetWindowAttrib(MinecraftWindow.getHandle(window), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
161+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
165162
}
166163
}
167164

@@ -178,17 +175,16 @@ public boolean isSupported() {
178175

179176
@Override
180177
public void enable(Window window, Monitor monitor, VideoMode videoMode) {
181-
long handle = MinecraftWindow.getHandle(window);
182-
GLFW.glfwSetWindowAttrib(handle, GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
183-
GLFW.glfwSetWindowAttrib(handle, GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_FALSE);
178+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
179+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_FALSE);
184180
MinecraftWindow.MacOS.setHasShadow(window, false);
185181
MinecraftWindow.MacOS.hideGlobalUI();
186182

187-
window.x = monitor.getX();
188-
window.y = monitor.getY();
189-
window.width = monitor.getCurrentMode().getWidth();
190-
window.height = monitor.getCurrentMode().getHeight();
191-
GLFW.glfwSetWindowMonitor(handle, 0, window.x, window.y, window.width, window.height, -1);
183+
window.x = monitor.x();
184+
window.y = monitor.y();
185+
window.width = monitor.currentMode().getWidth();
186+
window.height = monitor.currentMode().getHeight();
187+
GLFW.glfwSetWindowMonitor(window.handle(), 0, window.x, window.y, window.width, window.height, -1);
192188

193189
// GLFW ignores the GLFW_RESIZABLE flag for undecorated windows because such windows are
194190
// always meant to be non-resizable. However, there was a brief bug where it failed
@@ -204,15 +200,15 @@ public void disable(Window window) {
204200
MinecraftWindow.MacOS.registerWindowWillReturnFieldEditorStub(window);
205201
MinecraftWindow.MacOS.showGlobalUI();
206202
MinecraftWindow.MacOS.setHasShadow(window, true);
207-
GLFW.glfwSetWindowAttrib(MinecraftWindow.getHandle(window), GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
208-
GLFW.glfwSetWindowAttrib(MinecraftWindow.getHandle(window), GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
209-
GLFW.glfwSetWindowAttrib(MinecraftWindow.getHandle(window), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
203+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
204+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
205+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
210206

211207
// macOS 26.3+ (Tahoe) seems to leave a re-decorated window in a weird state
212208
// where it stops receiving keyboard and mouse inputs.
213209
// Thankfully, manually re-focusing it via `[window makeKeyAndOrderFront:nil]` helps,
214210
// which is exactly what `glfwFocusWindow` does under the hood.
215-
GLFW.glfwFocusWindow(MinecraftWindow.getHandle(window));
211+
GLFW.glfwFocusWindow(window.handle());
216212
}
217213
}
218214

@@ -249,23 +245,22 @@ public boolean isSupported() {
249245

250246
@Override
251247
public void enable(Window window, Monitor monitor, VideoMode videoMode) {
252-
long handle = MinecraftWindow.getHandle(window);
253-
GLFW.glfwSetWindowAttrib(handle, GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
254-
GLFW.glfwSetWindowAttrib(handle, GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_FALSE);
255-
256-
window.x = monitor.getX();
257-
window.y = monitor.getY();
258-
window.width = monitor.getCurrentMode().getWidth();
259-
window.height = monitor.getCurrentMode().getHeight() + 1;
260-
GLFW.glfwSetWindowMonitor(handle, 0, window.x, window.y, window.width, window.height, -1);
248+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_DECORATED, GLFW.GLFW_FALSE);
249+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_FALSE);
250+
251+
window.x = monitor.x();
252+
window.y = monitor.y();
253+
window.width = monitor.currentMode().getWidth();
254+
window.height = monitor.currentMode().getHeight() + 1;
255+
GLFW.glfwSetWindowMonitor(window.handle(), 0, window.x, window.y, window.width, window.height, -1);
261256
MinecraftWindow.Windows.pleaseStopDiscardingFuckingFramesThankYou(window);
262257
}
263258

264259
@Override
265260
public void disable(Window window) {
266261
MinecraftWindow.Windows.restoreStyle(window);
267-
GLFW.glfwSetWindowAttrib(MinecraftWindow.getHandle(window), GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
268-
GLFW.glfwSetWindowAttrib(MinecraftWindow.getHandle(window), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
262+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_DECORATED, GLFW.GLFW_TRUE);
263+
GLFW.glfwSetWindowAttrib(window.handle(), GLFW.GLFW_AUTO_ICONIFY, GLFW.GLFW_TRUE);
269264
}
270265
}
271266

src/main/java/dev/kirant/cwb/mixin/MinecraftMixin.java renamed to src/main/java/dev/kirant/cwb/mixin/GuiMixin.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
import org.spongepowered.asm.mixin.injection.Inject;
1111
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1212

13-
@Mixin(Minecraft.class)
14-
abstract class MinecraftMixin {
13+
@Mixin(/*? >=26.2 {*/net.minecraft.client.gui.Gui/*?} else {*//*Minecraft*//*?}*/.class)
14+
abstract class GuiMixin {
1515
private static boolean IS_FULLSCREEN_STATE_INITIALIZED = false;
1616

17-
@WrapOperation(method = "pauseGame", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;setScreen(Lnet/minecraft/client/gui/screens/Screen;)V", ordinal = 1), require = 0)
17+
//? if <26.2 {
18+
/*@WrapOperation(method = "pauseGame", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;setScreen(Lnet/minecraft/client/gui/screens/Screen;)V", ordinal = 1), require = 0)
1819
private void ignorePauseOnLostFocusDuringMultiplayer(Minecraft it, Screen screen, Operation<Void> setScreen) {
19-
if (it.isWindowActive() || CWB.CONFIG.getPauseOnLostFocusDuringMultiplayer()) {
20+
*///?} else {
21+
@WrapOperation(method = "setPauseScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;setScreen(Lnet/minecraft/client/gui/screens/Screen;)V", ordinal = 1), require = 0)
22+
private void ignorePauseOnLostFocusDuringMultiplayer(net.minecraft.client.gui.Gui it, Screen screen, Operation<Void> setScreen) {
23+
//?}
24+
if (Minecraft.getInstance().isWindowActive() || CWB.CONFIG.getPauseOnLostFocusDuringMultiplayer()) {
2025
setScreen.call(it, screen);
2126
}
2227
}

src/main/java/dev/kirant/cwb/mixin/WindowMixin.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
44
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
55
import com.mojang.blaze3d.platform.Monitor;
6-
import com.mojang.blaze3d.platform.ScreenManager;
6+
import com.mojang.blaze3d.platform.MonitorManager;
77
import com.mojang.blaze3d.platform.VideoMode;
88
import com.mojang.blaze3d.platform.Window;
99
import dev.kirant.cwb.*;
@@ -25,7 +25,7 @@
2525
abstract class WindowMixin implements FullscreenManager {
2626
private static @Shadow @Final Logger LOGGER;
2727

28-
private @Shadow @Final ScreenManager screenManager;
28+
private @Shadow @Final MonitorManager monitorManager;
2929

3030
private @Shadow Optional<VideoMode> preferredFullscreenVideoMode;
3131

@@ -61,8 +61,8 @@ public void setFullscreenMode(FullscreenMode fullscreenMode) {
6161
this.syncCurrentFullscreenState();
6262
}
6363

64-
@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/ScreenManager;getMonitor(J)Lcom/mojang/blaze3d/platform/Monitor;"))
65-
private Monitor patchInitialFullscreenMode(ScreenManager screenManager, long monitor, Operation<Monitor> getMonitor) {
64+
@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/platform/MonitorManager;getMonitor(J)Lcom/mojang/blaze3d/platform/Monitor;"))
65+
private Monitor patchInitialFullscreenMode(MonitorManager screenManager, long monitor, Operation<Monitor> getMonitor) {
6666
// Do not create a fullscreen window right away, as it would steal the user's focus.
6767
// We will handle the transition later.
6868
this.fullscreen = this.actuallyFullscreen = false;
@@ -126,7 +126,7 @@ private void enableFullscreen(CallbackInfo ci) {
126126
return;
127127
}
128128

129-
Monitor monitor = this.screenManager.findBestMonitor(window);
129+
Monitor monitor = this.monitorManager.findBestMonitor(window);
130130
if (monitor == null) {
131131
// We couldn't detect a monitor to attach this window to.
132132
// Let the original method deal with this problem.
@@ -191,7 +191,7 @@ private void refreshWindowSize() {
191191
Window window = (Window)(Object)this;
192192
int[] outWindowWidth = new int[1];
193193
int[] outWindowHeight = new int[1];
194-
GLFW.glfwGetWindowSize(MinecraftWindow.getHandle(window), outWindowWidth, outWindowHeight);
194+
GLFW.glfwGetWindowSize(window.handle(), outWindowWidth, outWindowHeight);
195195
window.width = outWindowWidth[0] > 0 ? outWindowWidth[0] : 1;
196196
window.height = outWindowHeight[0] > 0 ? outWindowHeight[0] : 1;
197197
}

src/main/java/dev/kirant/cwb/util/MinecraftWindow.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ public static Window getInstance() {
2424
/*return Minecraft.getInstance().window;*/
2525
}
2626

27-
public static long getHandle(Window window) {
28-
//? if >=1.21.9 {
29-
return window.handle();
30-
//?} else
31-
/*return window.getWindow();*/
32-
}
33-
3427
public static final class Windows {
3528
private static final WeakHashMap<Window, Map.Entry<Long, Long>> WINDOW_STYLES = new WeakHashMap<>();
3629

@@ -108,7 +101,7 @@ public static void pleaseStopDiscardingFuckingFramesThankYou(Window window) {
108101
}
109102

110103
public static void setStyle(Window window, long style, long exStyle) {
111-
long hWnd = GLFWNativeWin32.glfwGetWin32Window(MinecraftWindow.getHandle(window));
104+
long hWnd = GLFWNativeWin32.glfwGetWin32Window(window.handle());
112105
long currentStyle = User32.GetWindowLongPtr(null, hWnd, User32.GWL_STYLE);
113106
long currentExStyle = User32.GetWindowLongPtr(null, hWnd, User32.GWL_EXSTYLE);
114107
WINDOW_STYLES.put(window, new AbstractMap.SimpleEntry<>(currentStyle, currentExStyle));
@@ -125,7 +118,7 @@ public static void restoreStyle(Window window) {
125118
return;
126119
}
127120

128-
long hWnd = GLFWNativeWin32.glfwGetWin32Window(MinecraftWindow.getHandle(window));
121+
long hWnd = GLFWNativeWin32.glfwGetWin32Window(window.handle());
129122
User32.SetWindowLongPtr(null, hWnd, User32.GWL_STYLE, styles.getKey());
130123
User32.SetWindowLongPtr(null, hWnd, User32.GWL_EXSTYLE, styles.getValue());
131124
}
@@ -155,15 +148,15 @@ public static void setPresentationOptions(long presentationOptions) {
155148
}
156149

157150
public static void setHasShadow(Window window, boolean hasShadow) {
158-
long nsWindowPtr = GLFWNativeCocoa.glfwGetCocoaWindow(MinecraftWindow.getHandle(window));
151+
long nsWindowPtr = GLFWNativeCocoa.glfwGetCocoaWindow(window.handle());
159152
Proxy nsWindow = new Proxy(new Pointer(nsWindowPtr));
160153
nsWindow.send("setHasShadow:", hasShadow);
161154
}
162155

163156
public static void setResizable(Window window, boolean resizable) {
164157
final long NSWindowStyleMaskResizable = 1L << 3;
165158

166-
long nsWindowPtr = GLFWNativeCocoa.glfwGetCocoaWindow(MinecraftWindow.getHandle(window));
159+
long nsWindowPtr = GLFWNativeCocoa.glfwGetCocoaWindow(window.handle());
167160
Proxy nsWindow = new Proxy(new Pointer(nsWindowPtr));
168161
long styleMask = ((Number)nsWindow.send("styleMask")).longValue();
169162
long newStyleMask = (styleMask & ~NSWindowStyleMaskResizable) | (resizable ? NSWindowStyleMaskResizable : 0);
@@ -186,7 +179,7 @@ public static boolean registerWindowWillReturnFieldEditorStub(Window window) {
186179
return false;
187180
}
188181

189-
Proxy nsWindow = new Proxy(new Pointer(GLFWNativeCocoa.glfwGetCocoaWindow(MinecraftWindow.getHandle(window))));
182+
Proxy nsWindow = new Proxy(new Pointer(GLFWNativeCocoa.glfwGetCocoaWindow(window.handle())));
190183
Proxy nsWindowDelegate = nsWindow.sendProxy("delegate");
191184
if (nsWindowDelegate == null || nsWindowDelegate.sendBoolean("respondsToSelector:", "windowWillReturnFieldEditor:toObject:")) {
192185
return false;

src/main/resources/cwb.mixins.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"required": true,
33
"package": "dev.kirant.cwb.mixin",
44
"client": [
5+
"GuiMixin",
56
"MainMixin",
6-
"MinecraftMixin",
77
"VideoSettingsScreenMixin",
88
"WindowMixin"
99
],

0 commit comments

Comments
 (0)