aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt
blob: 20dfbb6157227a2aad91ffb5713803aad90edda6 (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
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.data.jsonobjects.repo.LocationFixJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside
import net.minecraft.util.AxisAlignedBB
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object LocationFixData {

    private var locationFixes = mutableMapOf<IslandType, List<LocationFix>>()

    private data class LocationFix(val area: AxisAlignedBB, val realLocation: String)

    // priority set to low so that IslandType can load their island names from repo earlier
    @SubscribeEvent(priority = EventPriority.LOW)
    fun onRepoReload(event: RepositoryReloadEvent) {
        val data = event.getConstant<LocationFixJson>("LocationFix")
        locationFixes.clear()

        for (fix in data.locationFixes.values) {
            val island = IslandType.getByName(fix.islandName)
            val area = fix.a.axisAlignedTo(fix.b)
            val realLocation = fix.realLocation

            val list = locationFixes[island]

            val locationFix = LocationFix(area, realLocation)

            if (list == null) locationFixes[island] = listOf(locationFix)
            else locationFixes[island] = list + locationFix
        }
    }

    fun fixLocation(skyBlockIsland: IslandType): String? =
        locationFixes[skyBlockIsland]
            ?.find { it.area.isPlayerInside() }
            ?.realLocation

}