Skip to content

Commit

Permalink
Show a custom message when shaderpack compilation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
embeddedt committed Oct 20, 2024
1 parent c137f4c commit ca2e01f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.ferriarnus.monocle.irisCompatibility.mixin;

import net.irisshaders.iris.Iris;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientPacketListener.class)
public class ClientPacketListenerMixin {
/**
* @author embeddedt
* @reason make sure the message directs users to us, not Iris, as our transformer likely has different behavior
* from theirs
*/
@Inject(method = "handleLogin", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundLoginPacket;enforcesSecureChat()Z"))
private void printMonocleErrorForIrisError(CallbackInfo ci) {
var player = Minecraft.getInstance().player;

if (player == null) {
return;
}

// Same logic as Iris' mixin, but run earlier to suppress their logic
Iris.getStoredError().ifPresent(e -> {
player.displayClientMessage(Component.translatable(
"monocle.shader_load_exception"
).append(Component.literal("Copy Info").withStyle(arg ->
arg.withUnderlined(true).withColor(ChatFormatting.BLUE)
.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, e.getMessage()))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.translatable("chat.copy.click")))
)), false);
});
}
}
3 changes: 3 additions & 0 deletions mod/src/main/resources/assets/monocle/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"monocle.shader_load_exception": "An internal error was encountered while loading the shaderpack. Please report this to the Monocle team. "
}
1 change: 1 addition & 0 deletions mod/src/main/resources/mixins.monocle.compat.iris.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"conformVisibility": true
},
"client": [
"ClientPacketListenerMixin",
"CrashReportExtenderMixin",
"DebugScreenOverlayMixin",
"IrisRenderingPipelineMixin",
Expand Down

0 comments on commit ca2e01f

Please sign in to comment.