Skip to content

Commit

Permalink
Fix issues with initial screens
Browse files Browse the repository at this point in the history
  • Loading branch information
isXander committed May 5, 2024
1 parent 595fd8a commit 3407d89
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ val mcSemverVersion = stonecutter.current.version
val mcDep = property("fmj.mcDep").toString()

group = "dev.isxander"
val versionWithoutMC = "2.0.0-beta.7"
val versionWithoutMC = "2.0.0-beta.8"
version = "$versionWithoutMC+${stonecutter.current.project}"

val isAlpha = "alpha" in version.toString()
Expand Down
11 changes: 11 additions & 0 deletions changelogs/2.0.0-beta.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Controlify 2.0.0 (Beta 8)

This version has the following builds - make sure you select the right one for your Minecraft version:
- 1.20.1
- 1.20.4
- 1.20.6 (also supports 1.20.5)

## Bug fixes

- Fix 1.20.1 specific issue where Controlify never initialised
- Fix issue where Controlify would not initialise in quiet mode
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ public boolean fromJson(JsonObject json) {
return clean;
}

@SuppressWarnings("UnreachableCode")
private void registerModdedKeybinds() {
for (KeyMapping keyMapping : KeyBindingRegistryImplAccessor.getCustomKeys()) {
if (EXCLUDED_VANILLA_BINDS.contains(keyMapping))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.isxander.controlify.mixins.core;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import dev.isxander.controlify.Controlify;
import dev.isxander.controlify.api.ControlifyApi;
import dev.isxander.controlify.controllermanager.ControllerManager;
Expand All @@ -10,7 +9,6 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.MouseHandler;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.server.packs.resources.ReloadInstance;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -30,9 +28,10 @@ public abstract class MinecraftMixin implements InitialScreenRegistryDuck {
@Shadow public abstract float getDeltaFrameTime();

@Shadow @Final public MouseHandler mouseHandler;
@Unique private boolean initNextTick = false;
@Shadow @Nullable public Screen screen;

@Unique private final List<Function<Runnable, Screen>> initialScreenCallbacks = new ArrayList<>();
@Unique private boolean initialScreensHappened = false;

// Ideally, this would be done in MouseHandler#releaseMouse, but moving
// the mouse before the screen init is bad, because some mods (e.g. PuzzleLib)
Expand All @@ -55,20 +54,9 @@ private void hideMouseAfterRelease(Screen screen, CallbackInfo ci) {
}
}

@ModifyExpressionValue(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/packs/resources/ReloadableResourceManager;createReload(Ljava/util/concurrent/Executor;Ljava/util/concurrent/Executor;Ljava/util/concurrent/CompletableFuture;Ljava/util/List;)Lnet/minecraft/server/packs/resources/ReloadInstance;"))
private ReloadInstance onInputInitialized(ReloadInstance resourceReload) {
// Controllers need to be initialized extremely late due to the data-driven nature of controllers.
// We need to bypass thenRun because any runnable is ran inside of a `minecraft.execute()`, which suppresses exceptions
resourceReload.done().thenRun(() -> initNextTick = true);
return resourceReload;
}

@Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;runAllTasks()V"))
private void initControlifyNow(boolean tick, CallbackInfo ci) {
if (initNextTick) {
Controlify.instance().initializeControlify();
initNextTick = false;
}
@Inject(method = "onGameLoadFinished", at = @At("RETURN"))
private void initControlifyNow(CallbackInfo ci) {
Controlify.instance().initializeControlify();
}

/*? if >1.20.4 {*/
Expand All @@ -90,13 +78,26 @@ private void tickAnimator(boolean tick, CallbackInfo ci) {
Animator.INSTANCE.tick(this.getDeltaFrameTime());
}

/*? if >1.20.1 {*/
@Inject(method = "addInitialScreens", at = @At("TAIL"))
private void injectCustomInitialScreens(List<Function<Runnable, Screen>> output, CallbackInfo ci) {
output.addAll(initialScreenCallbacks);
initialScreensHappened = true;
}
/*?}*/

@Override
public void controlify$registerInitialScreen(Function<Runnable, Screen> screenFactory) {
initialScreenCallbacks.add(screenFactory);
boolean doNow = initialScreensHappened;
/*? if <=1.20.1 {*//*
doNow = true;
*//*?}*/

if (doNow) {
Screen lastScreen = this.screen;
setScreen(screenFactory.apply(() -> setScreen(lastScreen)));
} else {
initialScreenCallbacks.add(screenFactory);
}
}
}

0 comments on commit 3407d89

Please sign in to comment.