|
| 1 | +package dev.spiritstudios.umbra_express.mixin.client.qol; |
| 2 | + |
| 3 | +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; |
| 5 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 6 | +import dev.doctor4t.trainmurdermystery.client.TMMClient; |
| 7 | +import dev.doctor4t.trainmurdermystery.client.gui.RoundTextRenderer; |
| 8 | +import dev.spiritstudios.umbra_express.UmbraExpress; |
| 9 | +import net.minecraft.client.font.TextRenderer; |
| 10 | +import net.minecraft.client.gui.DrawContext; |
| 11 | +import net.minecraft.client.network.ClientPlayerEntity; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.Shadow; |
| 14 | +import org.spongepowered.asm.mixin.Unique; |
| 15 | +import org.spongepowered.asm.mixin.injection.At; |
| 16 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 18 | + |
| 19 | +@Mixin(value = RoundTextRenderer.class, remap = false) |
| 20 | +public class RoundTextRendererMixin { |
| 21 | + |
| 22 | + @Shadow |
| 23 | + private static int welcomeTime; |
| 24 | + @Unique |
| 25 | + private static boolean umbra_express$forceShowWelcome = false; |
| 26 | + |
| 27 | + @WrapMethod(method = "renderHud") |
| 28 | + private static void showWelcomeWhenPressingPlayerList(TextRenderer renderer, ClientPlayerEntity player, DrawContext context, Operation<Void> original) { |
| 29 | + if (umbra_express$forceShowWelcome) { |
| 30 | + int realWelcomeTime = welcomeTime; |
| 31 | + welcomeTime = 2; |
| 32 | + try { |
| 33 | + original.call(renderer, player, context); |
| 34 | + } catch (Throwable throwable) { |
| 35 | + UmbraExpress.LOGGER.error("An error occurred when wrapping RoundTextRenderer.renderHud", throwable); |
| 36 | + } |
| 37 | + welcomeTime = realWelcomeTime; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @Inject(method = "tick", at = @At("HEAD")) |
| 42 | + private static void assumeFalse(CallbackInfo ci) { |
| 43 | + umbra_express$forceShowWelcome = false; |
| 44 | + } |
| 45 | + |
| 46 | + @ModifyExpressionValue(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z")) |
| 47 | + private static boolean updatePressingPlayerList(boolean original) { |
| 48 | + umbra_express$forceShowWelcome = original && TMMClient.gameComponent != null && TMMClient.gameComponent.isRunning(); |
| 49 | + return original; |
| 50 | + } |
| 51 | +} |
0 commit comments