aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/notenoughupdates/mixins/MixinMinecraft.java
blob: 17f49e193fe550c9cc12cf12406f647c479241c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package moe.nea.notenoughupdates.mixins;

import moe.nea.notenoughupdates.events.ScreenOpenEvent;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(MinecraftClient.class)
public abstract class MixinMinecraft {
    @Shadow
    @Nullable
    public Screen currentScreen;

    @Inject(method = "setScreen", at = @At("HEAD"), cancellable = true)
    public void onScreenChange(Screen screen, CallbackInfo ci) {
        var event = new ScreenOpenEvent(currentScreen, screen);
        if (ScreenOpenEvent.Companion.publish(event).getCancelled()) {
            ci.cancel();
        }
    }
}