Skip to content

Commit

Permalink
Fix loading screen hide (And force hide)
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Jan 16, 2024
1 parent e051309 commit 7e94f09
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

package com.github.dimadencep.mods.rrls.accessor;

import com.github.dimadencep.mods.rrls.Rrls;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.MessageScreen;
import net.minecraft.client.gui.screen.Screen;

@SuppressWarnings("unused")
public interface SplashAccessor {
Expand All @@ -34,6 +37,19 @@ public interface SplashAccessor {
default void rrls$progress(float progress) {
}

default AttachType rrls$filterAttachType(Screen screen, boolean reloading) {
if (!Rrls.MOD_CONFIG.hideType.canHide(reloading))
return AttachType.DEFAULT;

if (reloading || Rrls.MOD_CONFIG.forceClose)
return AttachType.HIDE;

if (screen instanceof MessageScreen msg) // Loading Minecraft
return AttachType.WAIT;

return screen != null ? AttachType.HIDE : AttachType.WAIT;
}

enum AttachType {
DEFAULT,
HIDE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class ModConfig implements ConfigData {
@ConfigEntry.Gui.Tooltip
public boolean rgbProgress = false;

@ConfigEntry.Gui.Tooltip
public boolean forceClose = false;

@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
public ShowIn showIn = ShowIn.ALL;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.concurrent.CompletableFuture;

Expand All @@ -32,6 +33,18 @@ public abstract class MinecraftClientMixin {
@Shadow
protected abstract CompletableFuture<Void> reloadResources(boolean force, @Nullable MinecraftClient.LoadingContext loadingContext);

@Inject(
method = "isFinishedLoading",
at = @At(
value = "HEAD"
),
cancellable = true
)
public void rrls$forceClose(CallbackInfoReturnable<Boolean> cir) {
if (Rrls.MOD_CONFIG.forceClose)
cir.setReturnValue(true);
}

@Inject(
method = "onResourceReloadFailure",
at = @At(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.github.dimadencep.mods.rrls.Rrls;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.MessageScreen;
import net.minecraft.client.gui.screen.Overlay;
import net.minecraft.client.gui.screen.SplashOverlay;
import net.minecraft.resource.ResourceReload;
Expand Down Expand Up @@ -69,13 +68,7 @@ public abstract class SplashOverlayMixin extends Overlay {
)
)
private void rrls$init(MinecraftClient client, ResourceReload monitor, Consumer<Optional<Throwable>> exceptionHandler, boolean reloading, CallbackInfo ci) {
if (Rrls.MOD_CONFIG.hideType.canHide(reloading)) {
if (reloading) {
this.rrls$attach = AttachType.HIDE;
} else {
this.rrls$attach = client.currentScreen != null && !(client.currentScreen instanceof MessageScreen /* FORGE COMPAT */) ? AttachType.HIDE : AttachType.WAIT;
}
}
this.rrls$attach = rrls$filterAttachType(client.currentScreen, reloading);
}

@Override
Expand Down Expand Up @@ -164,9 +157,7 @@ public abstract class SplashOverlayMixin extends Overlay {
cancellable = true
)
public void rrls$render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (this.client.currentScreen != null && this.rrls$attach == AttachType.WAIT) {
this.rrls$attach = AttachType.HIDE;
}
this.rrls$attach = rrls$filterAttachType(client.currentScreen, this.rrls$attach != AttachType.WAIT);

if (this.rrls$attach == AttachType.HIDE) {
ci.cancel();
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/resources/assets/rrls/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
"text.autoconfig.rrls.option.earlyPackStatusSend.@Tooltip[0]": "Some servers specifically wait for the player to load resources, because of this the game may be displayed incorrectly",
"text.autoconfig.rrls.option.earlyPackStatusSend.@Tooltip[1]": "Example: You were underground while reloading resources",
"text.autoconfig.rrls.option.animationSpeed": "Splash animation speed",
"text.autoconfig.rrls.option.animationSpeed.@Tooltip": "In milliseconds"
"text.autoconfig.rrls.option.animationSpeed.@Tooltip": "In milliseconds",
"text.autoconfig.rrls.option.forceClose": "Remove the boot screen, even if there is nothing behind it",
"text.autoconfig.rrls.option.forceClose.@Tooltip": "Actually now there is, I've been planning a workaround for a long time, but now there is one in minecraft :)"
}
4 changes: 3 additions & 1 deletion common/src/main/resources/assets/rrls/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
"text.autoconfig.rrls.option.earlyPackStatusSend.@Tooltip[0]": "Некоторые серверы специально ждут, пока игрок загрузит ресурсы, из-за этого игра может отображаться некорректно",
"text.autoconfig.rrls.option.earlyPackStatusSend.@Tooltip[1]": "Например: Вы оказались под землей во время перезагрузки ресурсов",
"text.autoconfig.rrls.option.animationSpeed": "Скорость анимации сплеша",
"text.autoconfig.rrls.option.animationSpeed.@Tooltip": "В милисекундах"
"text.autoconfig.rrls.option.animationSpeed.@Tooltip": "В милисекундах",
"text.autoconfig.rrls.option.forceClose": "Убирать загрузочный экран, даже если за ним ничего нет",
"text.autoconfig.rrls.option.forceClose.@Tooltip": "На самом деле теперь есть, я давно планировал обходной путь, но теперь он есть в minecraft :)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.SplashOverlay;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.resource.ResourceReload;
import net.neoforged.fml.earlydisplay.DisplayWindow;
import net.neoforged.fml.loading.progress.ProgressMeter;
Expand Down Expand Up @@ -69,9 +68,7 @@ public ForgeLoadingOverlayMixin(MinecraftClient client, ResourceReload monitor,
cancellable = true
)
public void rrls$render(DrawContext context, int mouseX, int mouseY, float delta, CallbackInfo ci) {
if (this.minecraft.currentScreen instanceof TitleScreen && rrls$getAttachType() == SplashAccessor.AttachType.WAIT) {
rrls$setAttachType(SplashAccessor.AttachType.HIDE);
}
rrls$setAttachType(rrls$filterAttachType(minecraft.currentScreen, rrls$getAttachType() != AttachType.WAIT));

if (rrls$getAttachType() == SplashAccessor.AttachType.HIDE) {
ci.cancel();
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ org.gradle.jvmargs=-Xmx4G
# Properties
minecraft_version = 1.20.4
yarn_mappings = 1.20.4+build.3
loader_version = 0.15.3
forge_version = 20.4.73-beta
loader_version = 0.15.5
forge_version = 20.4.108-beta

# Mod Properties
mod_version = 3.2.6
Expand Down

0 comments on commit 7e94f09

Please sign in to comment.