diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
8 files changed, 80 insertions, 29 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index d3b123c7f..04eb04834 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -22,7 +22,7 @@ import at.hannibal2.skyhanni.data.HypixelData import at.hannibal2.skyhanni.data.ItemClickData import at.hannibal2.skyhanni.data.ItemRenderBackground import at.hannibal2.skyhanni.data.ItemTipHelper -import at.hannibal2.skyhanni.data.LocationData +import at.hannibal2.skyhanni.data.LocationFixData import at.hannibal2.skyhanni.data.MayorElection import at.hannibal2.skyhanni.data.MinecraftData import at.hannibal2.skyhanni.data.OtherInventoryData @@ -338,7 +338,7 @@ class SkyHanniMod { loadModule(this) loadModule(ChatManager) loadModule(HypixelData()) - loadModule(LocationData) + loadModule(LocationFixData) loadModule(DungeonAPI()) loadModule(ScoreboardData()) loadModule(SeaCreatureFeatures()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 498b2f489..fd185996e 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.config import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity import at.hannibal2.skyhanni.features.misc.update.UpdateManager import at.hannibal2.skyhanni.utils.LorenzLogger @@ -95,6 +96,15 @@ class ConfigManager { return LorenzRarity.valueOf(reader.nextString()) } }.nullSafe()) + .registerTypeAdapter(IslandType::class.java, object : TypeAdapter<IslandType>() { + override fun write(out: JsonWriter, value: IslandType) { + out.value(value.name) + } + + override fun read(reader: JsonReader): IslandType { + return IslandType.valueOf(reader.nextString()) + } + }.nullSafe()) .enableComplexMapKeySerialization() .create() } diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index 8b58086a9..22beb125e 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -79,7 +79,7 @@ class HypixelData { .firstOrNull { it.startsWith(" §7⏣ ") || it.startsWith(" §5ф ") } ?.substring(5)?.removeColor() ?: "?" - skyBlockArea = LocationData.fixLocation(skyBlockIsland) ?: originalLocation + skyBlockArea = LocationFixData.fixLocation(skyBlockIsland) ?: originalLocation checkProfileName() } @@ -174,7 +174,7 @@ class HypixelData { } private fun getIslandType(newIsland: String, guesting: Boolean): IslandType { - val islandType = IslandType.getBySidebarName(newIsland) + val islandType = IslandType.getByNameOrUnknown(newIsland) if (guesting) { if (islandType == IslandType.PRIVATE_ISLAND) return IslandType.PRIVATE_ISLAND_GUEST if (islandType == IslandType.GARDEN) return IslandType.GARDEN_GUEST diff --git a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt index 15195dec4..3ab213025 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/IslandType.kt @@ -28,8 +28,9 @@ enum class IslandType(val displayName: String, val apiName: String = "null") { ; companion object { - fun getBySidebarName(name: String): IslandType { - return entries.firstOrNull { it.displayName == name } ?: UNKNOWN - } + fun getByNameOrUnknown(name: String) = getByNameOrNull(name) ?: UNKNOWN + fun getByName(name: String) = getByNameOrNull(name) ?: error("IslandType not found: '$name'") + + fun getByNameOrNull(name: String) = entries.firstOrNull { it.displayName == name } } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/LocationData.kt b/src/main/java/at/hannibal2/skyhanni/data/LocationData.kt deleted file mode 100644 index 58ffec3f8..000000000 --- a/src/main/java/at/hannibal2/skyhanni/data/LocationData.kt +++ /dev/null @@ -1,22 +0,0 @@ -package at.hannibal2.skyhanni.data - -import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside -import net.minecraft.util.AxisAlignedBB - -object LocationData { - private val westVillageFarmArea = AxisAlignedBB(-54.0, 69.0, -115.0, -40.0, 75.0, -127.0) - private val howlingCaveArea = AxisAlignedBB(-401.0, 50.0, -104.0, -337.0, 90.0, 36.0) - private val fakeZealotBruiserHideoutArea = AxisAlignedBB(-520.0, 66.0, -332.0, -558.0, 85.0, -280.0) - private val realZealotBruiserHideoutArea = AxisAlignedBB(-552.0, 50.0, -245.0, -580.0, 72.0, -209.0) - private val leftStronghold = AxisAlignedBB(-463.7, 94.0, -518.3, -435.3, 115.0, -547.7) - - fun fixLocation(skyBlockIsland: IslandType) = when { - skyBlockIsland == IslandType.THE_RIFT && westVillageFarmArea.isPlayerInside() -> "Dreadfarm" - skyBlockIsland == IslandType.THE_PARK && howlingCaveArea.isPlayerInside() -> "Howling Cave" - skyBlockIsland == IslandType.THE_END && fakeZealotBruiserHideoutArea.isPlayerInside() -> "The End" - skyBlockIsland == IslandType.THE_END && realZealotBruiserHideoutArea.isPlayerInside() -> "Zealot Bruiser Hideout" - skyBlockIsland == IslandType.CRIMSON_ISLE && leftStronghold.isPlayerInside() -> "Stronghold" - - else -> null - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt b/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt new file mode 100644 index 000000000..2bd6a9dcb --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/LocationFixData.kt @@ -0,0 +1,33 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.utils.LocationUtils.isPlayerInside +import at.hannibal2.skyhanni.utils.jsonobjects.LocationFixJson +import net.minecraft.util.AxisAlignedBB +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +object LocationFixData { + private var locationFixes = mutableListOf<LocationFix>() + + class LocationFix(val island: IslandType, 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.island_name) + val area = fix.a.axisAlignedTo(fix.b) + val realLocation = fix.real_location + + locationFixes.add(LocationFix(island, area, realLocation)) + } + } + + fun fixLocation(skyBlockIsland: IslandType) = locationFixes + .firstOrNull { skyBlockIsland == it.island && it.area.isPlayerInside() } + ?.realLocation +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt index 339a16efc..fd38fd441 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt @@ -130,6 +130,8 @@ data class LorenzVec( return LorenzVec(scalar * x, scalar * y, scalar * z) } + fun axisAlignedTo(other: LorenzVec) = AxisAlignedBB(x, y, z, other.x, other.y, other.z) + companion object { fun getFromYawPitch(yaw: Double, pitch: Double): LorenzVec { val yaw: Double = (yaw + 90) * Math.PI / 180 diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/LocationFixJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/LocationFixJson.java new file mode 100644 index 000000000..802627e7a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/LocationFixJson.java @@ -0,0 +1,27 @@ +package at.hannibal2.skyhanni.utils.jsonobjects; + +import at.hannibal2.skyhanni.utils.LorenzVec; +import com.google.gson.annotations.Expose; + +import java.util.Map; + +public class LocationFixJson { + + @Expose + public Map<String, LocationFix> locationFixes; + + public static class LocationFix { + @Expose + public LorenzVec a; + + @Expose + public LorenzVec b; + + @Expose + public String island_name; + + @Expose + public String real_location; + } + +} |