aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/mixin/HandledScreenProviderMixin.java
blob: 94eb53a5530c8ca8c1057ed7c4bb787e48c7dc4b (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package de.hysky.skyblocker.mixin;


import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.dungeon.partyfinder.PartyFinderScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.HandledScreens;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.text.Text;
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(HandledScreens.Provider.class)
public interface HandledScreenProviderMixin<T extends ScreenHandler> {
    @Inject(method = "open", at = @At("HEAD"), cancellable = true)
    default void skyblocker$open(Text name, ScreenHandlerType<T> type, MinecraftClient client, int id, CallbackInfo ci) {
        if (!SkyblockerConfigManager.get().general.betterPartyFinder) return;
        ClientPlayerEntity player = client.player;
        if (player == null) return;
        T screenHandler = type.create(id, player.getInventory());
        if (screenHandler instanceof GenericContainerScreenHandler containerScreenHandler && PartyFinderScreen.possibleInventoryNames.contains(name.getString().toLowerCase())) {
            if (client.currentScreen != null) {
                String lowerCase = client.currentScreen.getTitle().getString().toLowerCase();
                if (lowerCase.contains("group builder")) return;
                if (lowerCase.contains("select tier")) {
                    PartyFinderScreen.isInKuudraPartyFinder = true;
                } else if (lowerCase.contains("catacombs")) {
                    PartyFinderScreen.isInKuudraPartyFinder = false;
                }
            }
            if (PartyFinderScreen.isInKuudraPartyFinder) return;
            client.player.currentScreenHandler = containerScreenHandler;
            if (client.currentScreen instanceof PartyFinderScreen screen) {
                screen.updateHandler(containerScreenHandler, name);
            } else {
                client.setScreen(new PartyFinderScreen(containerScreenHandler, player.getInventory(), name));
            }

            ci.cancel();
        }
    }
}