Skip to content

Commit

Permalink
Merge pull request #84 from dima-dencep/1.20.x/dev
Browse files Browse the repository at this point in the history
4.0.7
  • Loading branch information
dima-dencep authored Jun 6, 2024
2 parents dbaa50f + a803324 commit 2a94d0b
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static boolean miniRender() {
throw new AssertionError();
}

@ExpectPlatform
public static boolean enableScissor() {
throw new AssertionError();
}

@ExpectPlatform
public static Type type() {
throw new AssertionError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* https://spdx.org/licenses/OSL-3.0.txt
*/

package org.redlance.dima_dencep.mods.rrls.mixins.compat;
package org.redlance.dima_dencep.mods.rrls.mixins;

import org.redlance.dima_dencep.mods.rrls.ConfigExpectPlatform;
import org.redlance.dima_dencep.mods.rrls.Rrls;
Expand All @@ -22,6 +22,7 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -44,14 +45,31 @@ public class GameRendererMixin {
Overlay overlay = this.minecraft.overlay;

if (OverlayHelper.isRenderingState(overlay)) {
overlay.render(DummyGuiGraphics.INSTANCE, 0, 0, minecraft.getDeltaFrameTime());
rrls$enableScissor(graphics, () ->
overlay.render(DummyGuiGraphics.INSTANCE, 0, 0, minecraft.getDeltaFrameTime())
);

if (ConfigExpectPlatform.miniRender())
overlay.rrls$miniRender(graphics);
}

} catch (RuntimeException ex) {
Rrls.LOGGER.error(ex);
Rrls.LOGGER.error("Failed to draw overlay!", ex);
}
}

@Unique
private static void rrls$enableScissor(GuiGraphics graphics, Runnable runnable) {
if (ConfigExpectPlatform.enableScissor()) {
graphics.pose().pushPose();
graphics.enableScissor(0, 0, 0, 0);

runnable.run();

graphics.disableScissor();
graphics.pose().popPose();
} else {
runnable.run();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ public abstract class MinecraftClientMixin {
@Inject(
method = "<init>",
at = @At(
value = "RETURN"
value = "TAIL"
)
)
public void rrls$init(GameConfig args, CallbackInfo ci, @Local(ordinal = 0) Minecraft.GameLoadCookie loadingContext) {
if (ConfigExpectPlatform.forceClose())
onResourceLoadFinished(loadingContext);
public void rrls$init(GameConfig gameConfig, CallbackInfo ci, @Local(ordinal = 0) Minecraft.GameLoadCookie gameLoadCookie) {
if (ConfigExpectPlatform.forceClose()) {
onResourceLoadFinished(gameLoadCookie);
}
}

@Inject(
Expand All @@ -58,16 +59,17 @@ public abstract class MinecraftClientMixin {
value = "HEAD"
),
cancellable = true
) // TODO refactor when @WrapMethod
public void rrls$onResourceReloadFailure(Throwable exception, Component resourceName, Minecraft.GameLoadCookie loadingContext, CallbackInfo ci) {
)
public void rrls$onResourceReloadFailure(Throwable throwable, Component errorMessage, Minecraft.GameLoadCookie gameLoadCookie, CallbackInfo ci) {
if (!ConfigExpectPlatform.resetResources()) {
Rrls.LOGGER.error("Caught error loading resourcepacks!", exception);
ci.cancel();

if (ConfigExpectPlatform.doubleLoad().isLoad())
reloadResourcePacks(ConfigExpectPlatform.doubleLoad() == DoubleLoad.FORCE_LOAD, loadingContext)
.thenRun(() -> addResourcePackLoadFailToast(resourceName));
Rrls.LOGGER.error("Caught error loading resourcepacks!", throwable);

ci.cancel();
if (ConfigExpectPlatform.doubleLoad().isLoad()) {
reloadResourcePacks(ConfigExpectPlatform.doubleLoad() == DoubleLoad.FORCE_LOAD, gameLoadCookie)
.thenRun(() -> addResourcePackLoadFailToast(errorMessage));
}
}
}

Expand All @@ -80,9 +82,10 @@ public abstract class MinecraftClientMixin {
),
cancellable = true
)
public void rrls$doubleLoad(Throwable exception, Component resourceName, Minecraft.GameLoadCookie loadingContext, CallbackInfo ci) {
if (!ConfigExpectPlatform.doubleLoad().isLoad())
public void rrls$doubleLoad(Throwable throwable, Component errorMessage, Minecraft.GameLoadCookie gameLoadCookie, CallbackInfo ci) {
if (!ConfigExpectPlatform.doubleLoad().isLoad()) {
ci.cancel();
}
}

@ModifyArg(
Expand All @@ -94,7 +97,7 @@ public abstract class MinecraftClientMixin {
),
require = 0
)
public boolean rrls$doubleLoad(boolean force) {
public boolean rrls$doubleLoad(boolean error) { // always true
return ConfigExpectPlatform.doubleLoad() == DoubleLoad.FORCE_LOAD;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2023 - 2024 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://spdx.org/licenses/OSL-3.0.txt
*/

package org.redlance.dima_dencep.mods.rrls.mixins.workaround;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiSpriteManager;
import net.minecraft.client.gui.font.FontManager;
import net.minecraft.client.resources.SplashManager;
import net.minecraft.client.resources.language.LanguageManager;
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.minecraft.util.Unit;
import org.redlance.dima_dencep.mods.rrls.ConfigExpectPlatform;
import org.redlance.dima_dencep.mods.rrls.Rrls;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.BiFunction;

@Mixin(targets = "net.minecraft.server.packs.resources.SimpleReloadInstance$1")
public class SimpleReloadInstanceMixin {
@Shadow
@Final
PreparableReloadListener val$listener;

@WrapOperation(
method = "wait",
at = @At(
value = "INVOKE",
target = "Ljava/util/concurrent/CompletableFuture;thenCombine(Ljava/util/concurrent/CompletionStage;Ljava/util/function/BiFunction;)Ljava/util/concurrent/CompletableFuture;"
)
)
public <U, V> CompletableFuture<V> rrls$async(CompletableFuture<Unit> instance, CompletionStage<? extends U> other, BiFunction<?, ? super U, ? extends V> fn, Operation<CompletableFuture<V>> original) {
if (ConfigExpectPlatform.forceClose() && rrls$filterListener()) {
Rrls.LOGGER.info("Skip wait for {}!", val$listener.getName());

return CompletableFuture.completedFuture(fn.apply(null, null));
}

return original.call(instance, other, fn);
}

@Unique
private boolean rrls$filterListener() {
if (this.val$listener instanceof FontManager fontManager) {
return !fontManager.fontSets.containsKey(Minecraft.DEFAULT_FONT);
}

if (this.val$listener instanceof LanguageManager languageManager) {
return languageManager.getLanguages().size() == 1;
}

if (this.val$listener instanceof SplashManager splashManager) {
return splashManager.splashes.isEmpty();
}

if (this.val$listener instanceof GuiSpriteManager spriteManager) {
return spriteManager.textureAtlas.texturesByName.isEmpty();
}

return false;
}
}
Loading

0 comments on commit 2a94d0b

Please sign in to comment.