/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  net.minecraft.class_1309
 *  net.minecraft.class_1492
 *  net.minecraft.class_1498
 *  net.minecraft.class_1501
 *  net.minecraft.class_1506
 *  net.minecraft.class_1507
 *  net.minecraft.class_1703
 *  net.minecraft.class_1704
 *  net.minecraft.class_1706
 *  net.minecraft.class_1707
 *  net.minecraft.class_1708
 *  net.minecraft.class_1714
 *  net.minecraft.class_1716
 *  net.minecraft.class_1718
 *  net.minecraft.class_1722
 *  net.minecraft.class_1723
 *  net.minecraft.class_1724
 *  net.minecraft.class_1726
 *  net.minecraft.class_1728
 *  net.minecraft.class_1733
 *  net.minecraft.class_3705
 *  net.minecraft.class_3706
 *  net.minecraft.class_3803
 *  net.minecraft.class_3858
 *  net.minecraft.class_3910
 *  net.minecraft.class_3916
 *  net.minecraft.class_3971
 *  net.minecraft.class_481$class_483
 *  net.minecraft.class_4862
 *  net.minecraft.class_7689
 *  net.minecraft.class_7923
 *  net.minecraft.class_8881
 */
package meteordevelopment.meteorclient.utils.player;

import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.mixin.CreativeInventoryScreenAccessor;
import meteordevelopment.meteorclient.mixin.ItemGroupsAccessor;
import meteordevelopment.meteorclient.mixin.MountScreenHandlerAccessor;
import net.minecraft.class_1309;
import net.minecraft.class_1492;
import net.minecraft.class_1498;
import net.minecraft.class_1501;
import net.minecraft.class_1506;
import net.minecraft.class_1507;
import net.minecraft.class_1703;
import net.minecraft.class_1704;
import net.minecraft.class_1706;
import net.minecraft.class_1707;
import net.minecraft.class_1708;
import net.minecraft.class_1714;
import net.minecraft.class_1716;
import net.minecraft.class_1718;
import net.minecraft.class_1722;
import net.minecraft.class_1723;
import net.minecraft.class_1724;
import net.minecraft.class_1726;
import net.minecraft.class_1728;
import net.minecraft.class_1733;
import net.minecraft.class_3705;
import net.minecraft.class_3706;
import net.minecraft.class_3803;
import net.minecraft.class_3858;
import net.minecraft.class_3910;
import net.minecraft.class_3916;
import net.minecraft.class_3971;
import net.minecraft.class_481;
import net.minecraft.class_4862;
import net.minecraft.class_7689;
import net.minecraft.class_7923;
import net.minecraft.class_8881;

public class SlotUtils {
    public static final int HOTBAR_START = 0;
    public static final int HOTBAR_END = 8;
    public static final int MAIN_START = 9;
    public static final int MAIN_END = 35;
    public static final int ARMOR_START = 36;
    public static final int ARMOR_END = 39;
    public static final int OFFHAND = 40;

    private SlotUtils() {
    }

    public static int indexToId(int i) {
        if (MeteorClient.mc.field_1724 == null) {
            return -1;
        }
        class_1703 handler = MeteorClient.mc.field_1724.field_7512;
        if (handler instanceof class_1723) {
            return SlotUtils.survivalInventory(i);
        }
        if (handler instanceof class_481.class_483) {
            return SlotUtils.creativeInventory(i);
        }
        if (handler instanceof class_1707) {
            class_1707 genericContainerScreenHandler = (class_1707)handler;
            return SlotUtils.genericContainer(i, genericContainerScreenHandler.method_17388());
        }
        if (handler instanceof class_1714) {
            return SlotUtils.craftingTable(i);
        }
        if (handler instanceof class_3858) {
            return SlotUtils.furnace(i);
        }
        if (handler instanceof class_3705) {
            return SlotUtils.furnace(i);
        }
        if (handler instanceof class_3706) {
            return SlotUtils.furnace(i);
        }
        if (handler instanceof class_1716) {
            return SlotUtils.generic3x3(i);
        }
        if (handler instanceof class_1718) {
            return SlotUtils.enchantmentTable(i);
        }
        if (handler instanceof class_1708) {
            return SlotUtils.brewingStand(i);
        }
        if (handler instanceof class_1728) {
            return SlotUtils.villager(i);
        }
        if (handler instanceof class_1704) {
            return SlotUtils.beacon(i);
        }
        if (handler instanceof class_1706) {
            return SlotUtils.anvil(i);
        }
        if (handler instanceof class_1722) {
            return SlotUtils.hopper(i);
        }
        if (handler instanceof class_1733) {
            return SlotUtils.genericContainer(i, 3);
        }
        if (handler instanceof class_1724) {
            return SlotUtils.horse(handler, i);
        }
        if (handler instanceof class_3910) {
            return SlotUtils.cartographyTable(i);
        }
        if (handler instanceof class_3803) {
            return SlotUtils.grindstone(i);
        }
        if (handler instanceof class_3916) {
            return SlotUtils.lectern();
        }
        if (handler instanceof class_1726) {
            return SlotUtils.loom(i);
        }
        if (handler instanceof class_3971) {
            return SlotUtils.stonecutter(i);
        }
        if (handler instanceof class_8881) {
            return SlotUtils.crafter(i);
        }
        if (handler instanceof class_4862) {
            return SlotUtils.smithingTable(i);
        }
        return -1;
    }

    private static int survivalInventory(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 36 + i;
        }
        if (SlotUtils.isArmor(i)) {
            return 5 + (i - 36);
        }
        if (i == 40) {
            return 45;
        }
        return i;
    }

    private static int creativeInventory(int i) {
        if (CreativeInventoryScreenAccessor.meteor$getSelectedTab() != class_7923.field_44687.method_29107(ItemGroupsAccessor.meteor$getInventory())) {
            return -1;
        }
        return SlotUtils.survivalInventory(i);
    }

    private static int genericContainer(int i, int rows) {
        if (SlotUtils.isHotbar(i)) {
            return (rows + 3) * 9 + i;
        }
        if (SlotUtils.isMain(i)) {
            return rows * 9 + (i - 9);
        }
        return -1;
    }

    private static int craftingTable(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 37 + i;
        }
        if (SlotUtils.isMain(i)) {
            return i + 1;
        }
        return -1;
    }

    private static int furnace(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 30 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 3 + (i - 9);
        }
        return -1;
    }

    private static int generic3x3(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 36 + i;
        }
        if (SlotUtils.isMain(i)) {
            return i;
        }
        return -1;
    }

    private static int enchantmentTable(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 29 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 2 + (i - 9);
        }
        return -1;
    }

    private static int brewingStand(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 32 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 5 + (i - 9);
        }
        return -1;
    }

    private static int villager(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 30 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 3 + (i - 9);
        }
        return -1;
    }

    private static int beacon(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 28 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 1 + (i - 9);
        }
        return -1;
    }

    private static int anvil(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 30 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 3 + (i - 9);
        }
        return -1;
    }

    private static int hopper(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 32 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 5 + (i - 9);
        }
        return -1;
    }

    private static int horse(class_1703 handler, int i) {
        class_1309 entity = ((MountScreenHandlerAccessor)handler).meteor$getMount();
        if (entity instanceof class_1501) {
            class_1501 llamaEntity = (class_1501)entity;
            int strength = llamaEntity.method_6803();
            if (SlotUtils.isHotbar(i)) {
                return 2 + 3 * strength + 28 + i;
            }
            if (SlotUtils.isMain(i)) {
                return 2 + 3 * strength + 1 + (i - 9);
            }
        } else if (entity instanceof class_1498 || entity instanceof class_1506 || entity instanceof class_1507 || entity instanceof class_7689) {
            if (SlotUtils.isHotbar(i)) {
                return 29 + i;
            }
            if (SlotUtils.isMain(i)) {
                return 2 + (i - 9);
            }
        } else if (entity instanceof class_1492) {
            class_1492 abstractDonkeyEntity = (class_1492)entity;
            boolean chest = abstractDonkeyEntity.method_6703();
            if (SlotUtils.isHotbar(i)) {
                return (chest ? 44 : 29) + i;
            }
            if (SlotUtils.isMain(i)) {
                return (chest ? 17 : 2) + (i - 9);
            }
        }
        return -1;
    }

    private static int cartographyTable(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 30 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 3 + (i - 9);
        }
        return -1;
    }

    private static int grindstone(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 30 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 3 + (i - 9);
        }
        return -1;
    }

    private static int lectern() {
        return -1;
    }

    private static int loom(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 31 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 4 + (i - 9);
        }
        return -1;
    }

    private static int stonecutter(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 29 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 2 + (i - 9);
        }
        return -1;
    }

    private static int crafter(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 36 + i;
        }
        if (SlotUtils.isMain(i)) {
            return i;
        }
        return -1;
    }

    private static int smithingTable(int i) {
        if (SlotUtils.isHotbar(i)) {
            return 31 + i;
        }
        if (SlotUtils.isMain(i)) {
            return 4 + (i - 9);
        }
        return -1;
    }

    public static boolean isHotbar(int slotIndex) {
        return slotIndex >= 0 && slotIndex <= 8;
    }

    public static boolean isMain(int slotIndex) {
        return slotIndex >= 9 && slotIndex <= 35;
    }

    public static boolean isArmor(int slotIndex) {
        return slotIndex >= 36 && slotIndex <= 39;
    }
}

