Skip to content

Commit

Permalink
Allow to force close loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
dima-dencep committed Jan 16, 2024
1 parent f5018e9 commit 91d7cf9
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright 2023 dima_dencep.
*
* Licensed under the Open Software License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* https://github.com/dima-dencep/rrls/blob/HEAD/LICENSE
*/

package com.github.dimadencep.mods.rrls;

import com.github.dimadencep.mods.rrls.config.AprilFool;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright 2023 dima_dencep.
*
* Licensed under the Open Software License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* https://github.com/dima-dencep/rrls/blob/HEAD/LICENSE
*/

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

import java.util.Calendar;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright 2023 dima_dencep.
*
* Licensed under the Open Software License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* https://github.com/dima-dencep/rrls/blob/HEAD/LICENSE
*/

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

public enum HideType {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright 2023 dima_dencep.
*
* Licensed under the Open Software License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* https://github.com/dima-dencep/rrls/blob/HEAD/LICENSE
*/

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

public enum ShowIn {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright 2023 dima_dencep.
*
* Licensed under the Open Software License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* https://github.com/dima-dencep/rrls/blob/HEAD/LICENSE
*/

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

public enum Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

import com.github.dimadencep.mods.rrls.ConfigExpectPlatform;
import com.github.dimadencep.mods.rrls.Rrls;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.client.gui.screen.Overlay;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
Expand All @@ -22,28 +24,27 @@
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;

@Mixin(MinecraftClient.class)
public abstract class MinecraftClientMixin {
@Shadow
protected abstract void showResourceReloadFailureToast(@Nullable Text description);

@Shadow
protected abstract CompletableFuture<Void> reloadResources(boolean force, @Nullable MinecraftClient.LoadingContext loadingContext);
@Shadow
protected abstract void onFinishedLoading(@Nullable MinecraftClient.LoadingContext loadingContext);

@Inject(
method = "isFinishedLoading",
method = "<init>",
at = @At(
value = "HEAD"
),
cancellable = true
value = "RETURN"
)
)
public void rrls$forceClose(CallbackInfoReturnable<Boolean> cir) {
public void rrls$init(RunArgs args, CallbackInfo ci, @Local(ordinal = 0) MinecraftClient.LoadingContext loadingContext) {
if (ConfigExpectPlatform.forceClose())
cir.setReturnValue(true);
onFinishedLoading(loadingContext);
}

@Inject(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.github.dimadencep.mods.rrls.mixins.workaround;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.texture.GuiAtlasManager;
import net.minecraft.client.texture.Scaling;
import net.minecraft.client.texture.Sprite;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(DrawContext.class)
public abstract class DrawContentMixin {
@WrapOperation(
method = "*",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/texture/GuiAtlasManager;getSprite(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/texture/Sprite;"
)
)
public Sprite rrls$fixSpriteCrash(GuiAtlasManager instance, Identifier objectId, Operation<Sprite> original) {
try {
return original.call(instance, objectId);
} catch (Throwable th) {
return null;
}
}

@WrapOperation(
method = "*",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/texture/GuiAtlasManager;getScaling(Lnet/minecraft/client/texture/Sprite;)Lnet/minecraft/client/texture/Scaling;"
)
)
public Scaling rrls$fixSpriteCrash(GuiAtlasManager instance, Sprite sprite, Operation<Scaling> original) {
if (sprite == null)
return null;

return original.call(instance, sprite);
}

@WrapOperation(
method = "drawGuiTexture(Lnet/minecraft/util/Identifier;IIIIIIIII)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/DrawContext;drawSprite(Lnet/minecraft/client/texture/Sprite;IIIII)V"
)
)
public void rrls$fixSpriteCrash(DrawContext instance, Sprite sprite, int x, int y, int z, int width, int height, Operation<Void> original) {
if (sprite == null)
return;

original.call(instance, sprite, x, y, z, width, height);
}
}
5 changes: 3 additions & 2 deletions common/src/main/resources/rrls-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"MinecraftClientMixin",
"SplashOverlayMixin",
"TitleScreenMixin",
"compat.ServerResourcePackManagerMixin",
"compat.OverlayMixin",
"compat.SplashUseFix"
"compat.ServerResourcePackManagerMixin",
"compat.SplashUseFix",
"workaround.DrawContentMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright 2023 dima_dencep.
*
* Licensed under the Open Software License, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* https://github.com/dima-dencep/rrls/blob/HEAD/LICENSE
*/

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

import com.github.dimadencep.mods.rrls.Rrls;
Expand Down
7 changes: 0 additions & 7 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,3 @@ type = "required"
versionRange = "[1.20,)"
ordering = "NONE"
side = "BOTH"

[[dependencies.rrls]]
modId = "cloth_config"
type = "required"
versionRange = "*"
ordering = "NONE"
side = "CLIENT"
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pluginManagement {
}
}

rootProject.name = "rrls"

include("common")
include("fabric")
include("forge")

0 comments on commit 91d7cf9

Please sign in to comment.