aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/skyblock/ScreenIdentification.kt
blob: 0e7797c6d969433a8595411d6f8fc017fa4b35d1 (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
48
49
50
51
52
package moe.nea.firmament.util.skyblock

import net.minecraft.client.gui.screen.Screen
import net.minecraft.client.gui.screen.ingame.GenericContainerScreen
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
import moe.nea.firmament.util.mc.loreAccordingToNbt
import moe.nea.firmament.util.unformattedString


object ScreenIdentification {
	private var lastScreen: Screen? = null
	private var lastScreenType: ScreenType? = null

	fun getType(screen: Screen?): ScreenType? {
		if (screen == null) return null
		if (screen !== lastScreen) {
			lastScreenType = ScreenType.entries
				.find { it.detector(screen) }
			lastScreen = screen
		}
		return lastScreenType
	}
}

enum class ScreenType(val detector: (Screen) -> Boolean) {
	BAZAAR_ANY({
		it is GenericContainerScreen && (
			it.screenHandler.getSlot(it.screenHandler.rows * 9 - 4)
				.stack
				.displayNameAccordingToNbt
				.unformattedString == "Manage Orders"
				|| it.screenHandler.getSlot(it.screenHandler.rows * 9 - 5)
				.stack
				.loreAccordingToNbt
				.any {
					it.unformattedString == "To Bazaar"
				})
	}),
	ENCHANTMENT_GUIDE({
		it.title.unformattedString.endsWith("Enchantments Guide")
	}),
	SUPER_PAIRS({
		it.title.unformattedString.startsWith("Superpairs")
	}),
	EXPERIMENTATION_RNG_METER({
		it.title.unformattedString.contains("Experimentation Table RNG")
	}),
	DYE_COMPENDIUM({
		it.title.unformattedString.contains("Dye Compendium")
	})
}