Skip to content

Commit 202d099

Browse files
committed
port: Chaos Cubed (MC 26.2)
Known issues: - Breaking blocks at touch position doesn't work correctly
1 parent 158d718 commit 202d099

38 files changed

Lines changed: 400 additions & 195 deletions

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ deps.neoforge_loader=[VERSIONED]
3232
deps.neoforge_patch=[VERSIONED]
3333

3434
# Mod dependencies
35-
deps.midnightlib_version=1.9.2
35+
deps.midnightlib_version=1.9.3
3636

3737
# Integrations
3838
deps.sodium_version=mc1.21.11-0.8.2

settings.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ stonecutter {
2727
version("$version-$loader", version).buildscript(buildscript)
2828
}
2929
}
30-
mc("fabric", "1.21.11", "26.1")
31-
mc("neoforge", "1.21.11", "26.1")
30+
mc("fabric", "1.21.11", "26.1", "26.2")
31+
mc("neoforge", "1.21.11", "26.1", "26.2")
3232
}
3333
create(rootProject)
3434
}

src/main/java/eu/midnightdust/midnightcontrols/client/MidnightControlsClient.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package eu.midnightdust.midnightcontrols.client;
1111

12+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
1213
import com.mojang.blaze3d.platform.InputConstants;
1314
import eu.midnightdust.lib.util.PlatformFunctions;
1415
import eu.midnightdust.midnightcontrols.ControlsMode;
@@ -126,7 +127,8 @@ public static void onMcInit(@NotNull Minecraft client) {
126127
* Shows a toast popup to notify the user about an event.
127128
*/
128129
public static void showToastMessage(Component title, Component description) {
129-
client.getToastManager().addToast(new SystemToast(SystemToast.SystemToastId.PERIODIC_NOTIFICATION, title, description));
130+
//~ if >= 26.2 'client.getToastManager()' -> 'client.gui.toastManager()'
131+
client.gui.toastManager().addToast(new SystemToast(SystemToast.SystemToastId.PERIODIC_NOTIFICATION, title, description));
130132
}
131133

132134
/**
@@ -188,7 +190,8 @@ public static void onTick(@NotNull Minecraft client) {
188190

189191
if (BINDING_RING.consumeClick()) {
190192
ring.loadFromUnbound();
191-
client.setScreen(new RingScreen());
193+
//~ if >= 26.2 'client.setScreen' -> 'client.gui.setScreen'
194+
client.gui.setScreen(new RingScreen());
192195
}
193196
if (client.level != null && MidnightControlsConfig.enableHints && !MidnightControlsConfig.autoSwitchMode && MidnightControlsConfig.controlsMode == ControlsMode.DEFAULT && MidnightControlsConfig.getController().isGamepad()) {
194197
showToastMessage(Component.translatable("midnightcontrols.controller.tutorial.title"),
@@ -220,16 +223,21 @@ public static void onCameraTick() {
220223
/**
221224
* Called when opening a screen.
222225
*/
223-
public static void onScreenOpen(Screen screen) {
226+
public static void onScreenOpen(Screen screen, Operation<Void> original) {
224227
client = Minecraft.getInstance();
225228
if (screen == null && MidnightControlsConfig.controlsMode == ControlsMode.TOUCHSCREEN) {
226229
screen = new TouchscreenOverlay();
227230
screen.init(client.getWindow().getGuiScaledWidth(), client.getWindow().getGuiScaledHeight());
228-
//client.noRender = false; TODO: Why would this be needed?
229-
client.screen = screen;
230231
} else if (screen != null) {
231232
input.onScreenOpen(client.getWindow().getScreenWidth(), client.getWindow().getScreenHeight());
232233
}
234+
235+
if (MidnightControlsConfig.hideNormalMouse) {
236+
if (screen != null && !(screen instanceof TouchscreenOverlay)) GLFW.glfwSetInputMode(Minecraft.getInstance().getWindow().handle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
237+
else GLFW.glfwSetInputMode(Minecraft.getInstance().getWindow().handle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED);
238+
}
239+
240+
original.call(screen);
233241
}
234242

235243
public static void onJoinServer() {

src/main/java/eu/midnightdust/midnightcontrols/client/MidnightControlsConfig.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ public boolean centered() {
249249

250250
Button editButton = Button.builder(Component.nullToEmpty("OPEN"),
251251
button -> {
252-
client.setScreen(new MidnightControlsSettingsScreen(client.screen, false));
252+
//~ if >= 26.2 'client.screen' -> 'client.gui.screen()'
253+
//~ if >= 26.2 'client.setScreen(' -> 'client.gui.setScreen('
254+
client.gui.setScreen(new MidnightControlsSettingsScreen(client.gui.screen(), false));
253255
}).bounds(screen.width - 185, 0, 175, 20).build();
254256
list.addButton(List.of(editButton), Component.nullToEmpty("Legacy Config UI"), new EntryInfo(null, screen.modid));
255257
}
@@ -482,7 +484,8 @@ public static boolean isMovementAxis(int axis) {
482484
* @return true if analog movement is possible, false otherwise
483485
*/
484486
public static boolean isAnalogMovementAllowed() {
485-
return client.screen != null || (analogMovement && (currentServerIp == null || MidnightControlsConfig.anticheatServers.stream().noneMatch(currentServerIp::matches)));
487+
//~ if >= 26.2 'client.screen' -> 'client.gui.screen()'
488+
return client.gui.screen() != null || (analogMovement && (currentServerIp == null || MidnightControlsConfig.anticheatServers.stream().noneMatch(currentServerIp::matches)));
486489
}
487490

488491
public static void reset() {

src/main/java/eu/midnightdust/midnightcontrols/client/MidnightInput.java

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
* @version 1.10.0
8585
* @since 1.0.0
8686
*/
87+
//~ if >= 26.2 'client.screen' -> 'client.gui.screen()' {
8788
public class MidnightInput {
8889
public static final Map<Integer, Integer> BUTTON_COOLDOWNS = new HashMap<>();
8990
public static final KeyEvent ENTER_KEY_INPUT = new KeyEvent(GLFW_KEY_ENTER, 0, 0);
@@ -211,7 +212,7 @@ public void onPreRenderScreen(@NotNull Screen screen) {
211212
* This method is called to update the camera
212213
*/
213214
public void updateCamera() {
214-
if (!(client.screen == null || client.screen instanceof TouchscreenOverlay))
215+
if (!(client.gui.screen() == null || client.gui.screen() instanceof TouchscreenOverlay))
215216
return;
216217

217218
var player = client.player;
@@ -239,10 +240,10 @@ public void updateCamera() {
239240
* @param windowHeight the window height
240241
*/
241242
public void onScreenOpen(int windowWidth, int windowHeight) {
242-
if (client.screen == null) {
243+
if (client.gui.screen() == null) {
243244
this.mouseSpeedX = this.mouseSpeedY = 0.0F;
244245
InputManager.INPUT_MANAGER.resetMousePosition(windowWidth, windowHeight);
245-
} else if (isScreenInteractive(client.screen) && MidnightControlsConfig.virtualMouse) {
246+
} else if (isScreenInteractive(client.gui.screen()) && MidnightControlsConfig.virtualMouse) {
246247
((MouseAccessor) client.mouseHandler).midnightcontrols$onCursorPos(client.getWindow().handle(), 0, 0);
247248
InputManager.INPUT_MANAGER.resetMouseTarget(client);
248249
}
@@ -293,7 +294,7 @@ private void fetchJoystickInput(@NotNull GLFWGamepadState gamepadState, boolean
293294
float rightX = polarUtil.polarX;
294295
float rightY = polarUtil.polarY;
295296

296-
boolean isRadialMenu = client.screen instanceof RingScreen || (PlatformFunctions.isModLoaded("emotecraft") && EmotecraftCompat.isEmotecraftScreen(client.screen));
297+
boolean isRadialMenu = client.gui.screen() instanceof RingScreen || (PlatformFunctions.isModLoaded("emotecraft") && EmotecraftCompat.isEmotecraftScreen(client.gui.screen()));
297298

298299
if (!isRadialMenu) {
299300
for (int i = cameraTick ? GLFW_GAMEPAD_AXIS_RIGHT_X : 0; i < (cameraTick ? GLFW_GAMEPAD_AXIS_LEFT_TRIGGER : GLFW_GAMEPAD_AXIS_RIGHT_X); i++) {
@@ -351,20 +352,20 @@ public void handleButton(ButtonStorage storage) {
351352
return;
352353
}
353354

354-
if (client.screen != null && storage.state.isPressed() && storage.button == GLFW_GAMEPAD_BUTTON_Y &&
355-
MidnightControlsConfig.arrowScreens.contains(client.screen.getClass().getCanonicalName())) {
355+
if (client.gui.screen() != null && storage.state.isPressed() && storage.button == GLFW_GAMEPAD_BUTTON_Y &&
356+
MidnightControlsConfig.arrowScreens.contains(client.gui.screen().getClass().getCanonicalName())) {
356357
pressKeyboardKey(client, GLFW.GLFW_KEY_ENTER);
357358
this.screenCloseCooldown = 5;
358359
}
359360
else if (storage.state.isPressed()) {
360-
if (client.screen != null && storage.isDpad() && this.actionGuiCooldown == 0) {
361+
if (client.gui.screen() != null && storage.isDpad() && this.actionGuiCooldown == 0) {
361362
switch (storage.button) {
362-
case GLFW_GAMEPAD_BUTTON_DPAD_UP -> this.changeFocus(client.screen, ScreenDirection.UP);
363-
case GLFW_GAMEPAD_BUTTON_DPAD_DOWN -> this.changeFocus(client.screen, ScreenDirection.DOWN);
364-
case GLFW_GAMEPAD_BUTTON_DPAD_LEFT -> this.handleLeftRight(client.screen, false);
365-
case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT -> this.handleLeftRight(client.screen, true);
363+
case GLFW_GAMEPAD_BUTTON_DPAD_UP -> this.changeFocus(client.gui.screen(), ScreenDirection.UP);
364+
case GLFW_GAMEPAD_BUTTON_DPAD_DOWN -> this.changeFocus(client.gui.screen(), ScreenDirection.DOWN);
365+
case GLFW_GAMEPAD_BUTTON_DPAD_LEFT -> this.handleLeftRight(client.gui.screen(), false);
366+
case GLFW_GAMEPAD_BUTTON_DPAD_RIGHT -> this.handleLeftRight(client.gui.screen(), true);
366367
}
367-
if (MidnightControlsConfig.wasdScreens.contains(client.screen.getClass().getCanonicalName())) {
368+
if (MidnightControlsConfig.wasdScreens.contains(client.gui.screen().getClass().getCanonicalName())) {
368369
switch (storage.button) {
369370
case GLFW_GAMEPAD_BUTTON_DPAD_UP -> pressKeyboardKey(client, GLFW.GLFW_KEY_W);
370371
case GLFW_GAMEPAD_BUTTON_DPAD_DOWN -> pressKeyboardKey(client, GLFW.GLFW_KEY_S);
@@ -376,52 +377,52 @@ else if (storage.state.isPressed()) {
376377
}
377378
}
378379
else {
379-
if (storage.button == GLFW.GLFW_GAMEPAD_BUTTON_A && client.screen != null) {
380+
if (storage.button == GLFW.GLFW_GAMEPAD_BUTTON_A && client.gui.screen() != null) {
380381
if (this.actionGuiCooldown == 0) {
381-
var focused = client.screen.getFocused();
382-
if (focused != null && isScreenInteractive(client.screen)) {
383-
if (this.handleAButton(client.screen, focused)) {
382+
var focused = client.gui.screen().getFocused();
383+
if (focused != null && isScreenInteractive(client.gui.screen())) {
384+
if (this.handleAButton(client.gui.screen(), focused)) {
384385
this.actionGuiCooldown = 5; // Set the cooldown to 5 ticks to avoid unintended button presses.
385386
return;
386387
}
387388
}
388389
//? fabric
389-
else if (PlatformFunctions.isModLoaded("libgui")) LibGuiCompat.handlePress(client.screen);
390+
else if (PlatformFunctions.isModLoaded("libgui")) LibGuiCompat.handlePress(client.gui.screen());
390391
}
391392
}
392393
}
393394

394-
if (storage.button == GLFW.GLFW_GAMEPAD_BUTTON_A && client.screen != null && !isScreenInteractive(client.screen)
395+
if (storage.button == GLFW.GLFW_GAMEPAD_BUTTON_A && client.gui.screen() != null && !isScreenInteractive(client.gui.screen())
395396
&& this.actionGuiCooldown == 0) {
396-
if (client.screen instanceof AbstractContainerScreen<?> handledScreen && ((HandledScreenAccessor) handledScreen).midnightcontrols$getSlotAt(
397+
if (client.gui.screen() instanceof AbstractContainerScreen<?> handledScreen && ((HandledScreenAccessor) handledScreen).midnightcontrols$getSlotAt(
397398
client.mouseHandler.xpos() * (double) client.getWindow().getGuiScaledWidth() / (double) client.getWindow().getScreenWidth(),
398399
client.mouseHandler.ypos() * (double) client.getWindow().getGuiScaledHeight() / (double) client.getWindow().getScreenHeight()) != null) return;
399-
if (!this.ignoreNextARelease && client.screen != null) {
400+
if (!this.ignoreNextARelease && client.gui.screen() != null) {
400401
var accessor = (MouseAccessor) client.mouseHandler;
401402
accessor.midnightcontrols$onCursorPos(client.getWindow().handle(), client.mouseHandler.xpos(), client.mouseHandler.ypos());
402403
switch (storage.state) {
403404
// Button pressed
404405
case PRESS -> accessor.midnightcontrols$onMouseButton(client.getWindow().handle(), new MouseButtonInfo(GLFW_MOUSE_BUTTON_LEFT, 0), 1);
405406
case RELEASE -> { // Button released
406407
accessor.midnightcontrols$onMouseButton(client.getWindow().handle(), new MouseButtonInfo(GLFW_MOUSE_BUTTON_LEFT, 0), 0);
407-
client.screen.setDragging(false);
408+
client.gui.screen().setDragging(false);
408409
}
409-
case REPEAT -> client.screen.setDragging(true); // Button held down / dragging
410+
case REPEAT -> client.gui.screen().setDragging(true); // Button held down / dragging
410411
}
411412
this.screenCloseCooldown = 5;
412413
} else {
413414
this.ignoreNextARelease = false;
414415
}
415416
}
416-
else if (storage.button == GLFW.GLFW_GAMEPAD_BUTTON_X && client.screen != null && !isScreenInteractive(client.screen)
417+
else if (storage.button == GLFW.GLFW_GAMEPAD_BUTTON_X && client.gui.screen() != null && !isScreenInteractive(client.gui.screen())
417418
&& this.actionGuiCooldown == 0) {
418419
double mouseX = client.mouseHandler.xpos() * (double) client.getWindow().getGuiScaledWidth() / (double) client.getWindow().getScreenWidth();
419420
double mouseY = client.mouseHandler.ypos() * (double) client.getWindow().getGuiScaledHeight() / (double) client.getWindow().getScreenHeight();
420-
if (client.screen instanceof AbstractContainerScreen<?> handledScreen && ((HandledScreenAccessor) handledScreen).midnightcontrols$getSlotAt(
421+
if (client.gui.screen() instanceof AbstractContainerScreen<?> handledScreen && ((HandledScreenAccessor) handledScreen).midnightcontrols$getSlotAt(
421422
mouseX, mouseY) != null) return;
422-
if (!this.ignoreNextXRelease && client.screen != null) {
423-
if (storage.state == ButtonState.PRESS) client.screen.mouseClicked(new MouseButtonEvent(mouseX, mouseY, new MouseButtonInfo(GLFW.GLFW_MOUSE_BUTTON_2, 1)), false);
424-
else if (storage.state == ButtonState.RELEASE) client.screen.mouseReleased(new MouseButtonEvent(mouseX, mouseY, new MouseButtonInfo(GLFW.GLFW_MOUSE_BUTTON_2, 0)));
423+
if (!this.ignoreNextXRelease && client.gui.screen() != null) {
424+
if (storage.state == ButtonState.PRESS) client.gui.screen().mouseClicked(new MouseButtonEvent(mouseX, mouseY, new MouseButtonInfo(GLFW.GLFW_MOUSE_BUTTON_2, 1)), false);
425+
else if (storage.state == ButtonState.RELEASE) client.gui.screen().mouseReleased(new MouseButtonEvent(mouseX, mouseY, new MouseButtonInfo(GLFW.GLFW_MOUSE_BUTTON_2, 0)));
425426
this.screenCloseCooldown = 5;
426427
} else {
427428
this.ignoreNextXRelease = false;
@@ -437,24 +438,24 @@ private void handleJoystickAxis(AxisStorage storage) {
437438

438439
this.handleJoystickMovement(storage);
439440

440-
if (this.handleScreenScrolling(client.screen, storage)) return;
441+
if (this.handleScreenScrolling(client.gui.screen(), storage)) return;
441442

442443
storage.absValue = (float) Mth.clamp(storage.absValue / MidnightControlsConfig.getAxisMaxValue(storage.axis), 0.f, 1.f);
443-
if (client.screen == null) {
444+
if (client.gui.screen() == null) {
444445
// Handles the look direction.
445446
this.handleLook(storage);
446447
} else {
447448
boolean allowMouseControl = true;
448449

449-
if (this.actionGuiCooldown == 0 && MidnightControlsConfig.isMovementAxis(storage.axis) && isScreenInteractive(client.screen)) {
450+
if (this.actionGuiCooldown == 0 && MidnightControlsConfig.isMovementAxis(storage.axis) && isScreenInteractive(client.gui.screen())) {
450451
if (MidnightControlsConfig.isForwardButton(storage.axis, false, storage.buttonState)) {
451-
allowMouseControl = this.changeFocus(client.screen, ScreenDirection.UP);
452+
allowMouseControl = this.changeFocus(client.gui.screen(), ScreenDirection.UP);
452453
} else if (MidnightControlsConfig.isBackButton(storage.axis, false, storage.buttonState)) {
453-
allowMouseControl = this.changeFocus(client.screen, ScreenDirection.DOWN);
454+
allowMouseControl = this.changeFocus(client.gui.screen(), ScreenDirection.DOWN);
454455
} else if (MidnightControlsConfig.isLeftButton(storage.axis, false, storage.buttonState)) {
455-
allowMouseControl = this.handleLeftRight(client.screen, false);
456+
allowMouseControl = this.handleLeftRight(client.gui.screen(), false);
456457
} else if (MidnightControlsConfig.isRightButton(storage.axis, false, storage.buttonState)) {
457-
allowMouseControl = this.handleLeftRight(client.screen, true);
458+
allowMouseControl = this.handleLeftRight(client.gui.screen(), true);
458459
}
459460
}
460461

@@ -471,7 +472,7 @@ private void handleJoystickAxis(AxisStorage storage) {
471472
movementX = storage.absValue;
472473
}
473474

474-
if (client.screen != null && allowMouseControl) {
475+
if (client.gui.screen() != null && allowMouseControl) {
475476
boolean moving = movementY != 0 || movementX != 0;
476477
if (moving) {
477478
/*
@@ -496,7 +497,7 @@ private void handleJoystickAxis(AxisStorage storage) {
496497
);
497498
}
498499

499-
InventoryUtil.moveMouseToClosestSlot(client.screen);
500+
InventoryUtil.moveMouseToClosestSlot(client.gui.screen());
500501
}
501502

502503
this.prevXAxis = movementX;
@@ -592,8 +593,8 @@ public void handleRadialMenu(float x, float y) {
592593
if (y < -border) index = 1;
593594
else if (y > border) index = 6;
594595
}
595-
if (client.screen instanceof RingScreen && index > -1) RingPage.selected = index;
596-
if (PlatformFunctions.isModLoaded("emotecraft") && EmotecraftCompat.isEmotecraftScreen(client.screen)) EmotecraftCompat.handleEmoteSelector(index);
596+
if (client.gui.screen() instanceof RingScreen && index > -1) RingPage.selected = index;
597+
if (PlatformFunctions.isModLoaded("emotecraft") && EmotecraftCompat.isEmotecraftScreen(client.gui.screen())) EmotecraftCompat.handleEmoteSelector(index);
597598
}
598599

599600
public boolean handleListWidgetScrolling(List<? extends GuiEventListener> children, float value) {
@@ -822,3 +823,4 @@ public void pressKeyboardKey(Screen screen, int key) {
822823
screen.keyPressed(new KeyEvent(key, 0, 0));
823824
}
824825
}
826+
//~}

src/main/java/eu/midnightdust/midnightcontrols/client/compat/EmotecraftCompat.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class EmotecraftCompat {
1313
private static final Minecraft client = Minecraft.getInstance();
1414

1515
public static void openEmotecraftScreen(Screen parent) {
16-
client.setScreen(new FastMenuScreen(parent));
16+
//~ if >= 26.2 'client.setScreen(' -> 'client.gui.setScreen('
17+
client.gui.setScreen(new FastMenuScreen(parent));
1718
}
1819
public static boolean isEmotecraftScreen(Screen screen) {
1920
return screen instanceof FastMenuScreen;
@@ -22,7 +23,8 @@ public static boolean isEmotecraftScreen(Screen screen) {
2223
static int prevIndex = -1;
2324
public static void handleEmoteSelector(int index) {
2425
try {
25-
if (client.screen instanceof FastMenuScreen) {
26+
//~ if >= 26.2 'client.screen' -> 'client.gui.screen()'
27+
if (client.gui.screen() instanceof FastMenuScreen) {
2628
boolean stickReleased = index == -1 && prevIndex != -1;
2729
var pos = calcMousePos(stickReleased ? prevIndex : index);
2830
InputManager.queueMousePosition(pos.x, pos.y);

0 commit comments

Comments
 (0)