-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: CalMWolfs <[email protected]> Co-authored-by: Cal <[email protected]> Co-authored-by: hannibal2 <[email protected]>
- Loading branch information
1 parent
94f5809
commit b8d4c50
Showing
7 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package at.hannibal2.skyhanni.api | ||
|
||
import at.hannibal2.skyhanni.api.event.HandleEvent | ||
import at.hannibal2.skyhanni.data.ProfileStorageData | ||
import at.hannibal2.skyhanni.data.model.TabWidget | ||
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent | ||
import at.hannibal2.skyhanni.events.WidgetUpdateEvent | ||
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule | ||
import at.hannibal2.skyhanni.utils.ItemUtils.getLore | ||
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher | ||
import at.hannibal2.skyhanni.utils.RegexUtils.matches | ||
import at.hannibal2.skyhanni.utils.UtilsPatterns | ||
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern | ||
|
||
@SkyHanniModule | ||
object SkyBlockXPAPI { | ||
|
||
private val group = RepoPattern.group("skyblockxpapi.inventory") | ||
|
||
private val itemNamePattern by group.pattern("itemname", "§aSkyBlock Leveling") | ||
|
||
/** | ||
* REGEX-TEST: §7Your SkyBlock Level: §8[§9287§8] | ||
*/ | ||
private val levelPattern by group.pattern("level", "§7Your SkyBlock Level: §8\\[§.(?<level>\\d+)§8\\]") | ||
|
||
/** | ||
* REGEX-TEST: §3§l§m §f§l§m §r §b24§3/§b100 §bXP | ||
*/ | ||
private val xpPattern by group.pattern("xp", "[§\\w\\s]+§b(?<xp>\\d+)§3\\/§b100 §bXP") | ||
|
||
val levelXpPair get() = storage?.toLevelXpPair() | ||
|
||
// Stored as 12345, 123 is the level, 45 is the xp | ||
private var storage | ||
get() = ProfileStorageData.profileSpecific?.totalSkyBlockXP | ||
set(value) { | ||
ProfileStorageData.profileSpecific?.totalSkyBlockXP = value | ||
} | ||
|
||
private fun Int.toLevelXpPair() = this / 100 to this % 100 | ||
|
||
@HandleEvent | ||
fun onWidgetUpdate(event: WidgetUpdateEvent) { | ||
if (!event.isWidget(TabWidget.SB_LEVEL)) return | ||
|
||
TabWidget.SB_LEVEL.matchMatcherFirstLine { | ||
val level = group("level")?.toIntOrNull() | ||
val xp = group("xp")?.toIntOrNull() | ||
|
||
updateStorage(level, xp) | ||
} | ||
} | ||
|
||
@HandleEvent | ||
fun onInventoryFullyOpened(event: InventoryFullyOpenedEvent) { | ||
if (!UtilsPatterns.skyblockMenuGuiPattern.matches(event.inventoryName)) return | ||
|
||
val stack = event.inventoryItems.values.find { itemNamePattern.matches(it.displayName) } ?: return | ||
|
||
var level: Int? = null | ||
var xp: Int? = null | ||
|
||
loop@ for (line in stack.getLore()) { | ||
if (level != null && xp != null) break@loop | ||
|
||
if (level == null) { | ||
levelPattern.matchMatcher(line) { | ||
level = group("level")?.toIntOrNull() | ||
continue@loop | ||
} | ||
} | ||
|
||
if (xp == null) { | ||
xpPattern.matchMatcher(line) { | ||
xp = group("xp")?.toIntOrNull() | ||
continue@loop | ||
} | ||
} | ||
} | ||
|
||
updateStorage(level, xp) | ||
} | ||
|
||
private fun updateStorage(level: Int?, xp: Int?) { | ||
storage = calculateTotalXp(level ?: return, xp ?: return) | ||
} | ||
|
||
fun calculateTotalXp(level: Int, xp: Int): Int = level * 100 + xp | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/at/hannibal2/skyhanni/features/inventory/SkyBlockXPBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package at.hannibal2.skyhanni.features.inventory | ||
|
||
import at.hannibal2.skyhanni.SkyHanniMod | ||
import at.hannibal2.skyhanni.api.SkyBlockXPAPI | ||
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule | ||
import at.hannibal2.skyhanni.utils.LorenzUtils | ||
import net.minecraft.client.Minecraft | ||
import net.minecraftforge.client.event.RenderGameOverlayEvent | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent | ||
|
||
@SkyHanniModule | ||
object SkyBlockXPBar { | ||
private val config get() = SkyHanniMod.feature.misc | ||
|
||
@SubscribeEvent | ||
fun onRenderScoreboard(event: RenderGameOverlayEvent.Pre) { | ||
if (!isEnabled()) return | ||
if (event.type != RenderGameOverlayEvent.ElementType.EXPERIENCE) return | ||
val (level, xp) = SkyBlockXPAPI.levelXpPair ?: return | ||
Minecraft.getMinecraft().thePlayer.setXPStats(xp / 100f, 100, level) | ||
} | ||
|
||
private fun isEnabled() = LorenzUtils.inSkyBlock && config.skyblockXpBar | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters