/* * SPDX-FileCopyrightText: 2023 Linnea Gräf * * SPDX-License-Identifier: GPL-3.0-or-later */ package moe.nea.firmament.mixins; import moe.nea.firmament.events.ScreenChangeEvent; 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 ScreenChangeEventPatch { @Shadow @Nullable public Screen currentScreen; @Inject(method = "setScreen", at = @At("HEAD"), cancellable = true) public void onScreenChange(Screen screen, CallbackInfo ci) { var event = new ScreenChangeEvent(currentScreen, screen); if (ScreenChangeEvent.Companion.publish(event).getCancelled()) { ci.cancel(); } } }