Skip to content

Commit

Permalink
use quiver item for quiverapi
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsEmpa committed Mar 15, 2024
1 parent c9e1fa7 commit cea67a7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 51 deletions.
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class OwnInventoryData {
if (packet is S2FPacketSetSlot) {
val windowId = packet.func_149175_c()
if (windowId == 0) {
val slot = packet.func_149173_d()
val item = packet.func_149174_e() ?: return
DelayedRun.runNextTick {
OwnInventoryItemUpdateEvent(item).postAndCatch()
OwnInventoryItemUpdateEvent(item, slot).postAndCatch()
}
}
}
Expand Down
80 changes: 31 additions & 49 deletions src/main/java/at/hannibal2/skyhanni/data/QuiverAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.jsonobjects.repo.ArrowTypeJson
import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemsJson
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.ItemInHandChangeEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent
import at.hannibal2.skyhanni.events.PlaySoundEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemCategory
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getExtraAttributes
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils.removeResets
Expand All @@ -33,6 +39,9 @@ private var infinityQuiverLevelMultiplier = 0.03f

object QuiverAPI {
private val storage get() = ProfileStorageData.profileSpecific
//private var bows = listOf<NEUInternalName>()
private var bows = listOf("JUJU_SHORTBOW".asInternalName())
var holdingBow = false
var currentArrow: ArrowType?
get() = storage?.arrows?.currentArrow?.asInternalName()?.let { getArrowByNameOrNull(it) } ?: NONE_ARROW_TYPE
set(value) {
Expand All @@ -59,7 +68,7 @@ object QuiverAPI {

private val group = RepoPattern.group("data.quiver")
private val chatGroup = group.group("chat")
private val selectPattern by chatGroup.pattern("select", "§aYou set your selected arrow type to §f(?<arrow>.*)§a!")
private val selectPattern by chatGroup.pattern("select", "§aYou set your selected arrow type to §.(?<arrow>.*)§a!")
private val fillUpJaxPattern by chatGroup.pattern(
"fillupjax",
"(§.)*Jax forged (§.)*(?<type>.*?)(§.)* x(?<amount>[\\d,]+)( (§.)*for (§.)*(?<coins>[\\d,]+) Coins)?(§.)*!"
Expand All @@ -78,6 +87,10 @@ object QuiverAPI {
// Bows that don't use the players arrows, checked using the SkyBlock Id
private val fakeBowsPattern by group.pattern("fakebows", "^(BOSS_SPIRIT_BOW|CRYPT_BOW)$")
private val quiverInventoryNamePattern by group.pattern("quivername", "^Quiver$")
private val quiverInventoryPattern by group.pattern(
"quiver.inventory",
"§7Active Arrow: §.(?<type>.*) §7\\(§e(?<amount>.*)§7\\)"
)

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
Expand Down Expand Up @@ -167,57 +180,26 @@ object QuiverAPI {
}
}

/*
Modified method to remove arrows from SkyblockFeatures QuiverOverlay
Original method source:
https://github.com/MrFast-js/SkyblockFeatures/blob/ae4bf0b91ed0fb17114d9cdaccaa9aef9a6c8d01/src/main/java/mrfast/sbf/features/overlays/QuiverOverlay.java#L127
Changes made:
- Added "fake bows" check
- Added "infinite quiver" check
- Added "sneaking" check
- Added "bow sound distance" check
- Added "skeleton master chestplate" check
*/
@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onPlaySound(event: PlaySoundEvent) {
if (!isEnabled()) return
if (event.soundName != "random.bow") return

val holdingBow = InventoryUtils.getItemInHand()?.item is ItemBow
&& !fakeBowsPattern.matches(InventoryUtils.getItemInHand()?.getInternalNameOrNull()?.asString() ?: "")

if (!holdingBow) return

// check if sound location is more than configAmount block away from player
val soundLocation = event.distanceToPlayer
if (soundLocation > SkyHanniMod.feature.dev.bowSoundDistance) return

val arrowType = currentArrow?.internalName ?: return
val amount = arrowAmount[arrowType] ?: return
if (amount <= 0) return

if (InventoryUtils.getChestplate()
// The chestplate has the ability to not use arrows
// https://hypixel-skyblock.fandom.com/wiki/Skeleton_Master_Armor
?.getInternalNameOrNull() == SKELETON_MASTER_CHESTPLATE
) return

val infiniteQuiverLevel = InventoryUtils.getItemInHand()?.getEnchantments()?.get("infinite_quiver") ?: 0

val amountToRemove = {
when (Minecraft.getMinecraft().thePlayer.isSneaking) {
true -> 1.0f
false -> {
when (infiniteQuiverLevel) {
in 1..10 -> 1 - (infinityQuiverLevelMultiplier * infiniteQuiverLevel)
else -> 1.0f
}
@SubscribeEvent
fun onInventoryUpdate(event: OwnInventoryItemUpdateEvent) {
if (!isEnabled() && (event.slot != 44)) return
val stack = event.itemStack
if (stack.getExtraAttributes()?.hasKey("quiver_arrow") == true) {
for (line in stack.getLore()) {
quiverInventoryPattern.matchMatcher(line) {
val type = group("type")
val amount = group("amount").formatNumber().toFloat()
val currentArrowType = getArrowByNameOrNull(type)
?: return ErrorManager.logErrorWithData(
UnknownArrowType("Unknown arrow type: $type"),
"Unknown arrow type: $type"
)
currentArrow = currentArrowType
arrowAmount[currentArrowType.internalName] = amount
return
}
}
}

arrowAmount[arrowType] = amount - amountToRemove()
}

fun Int.asArrowPercentage() = ((this.toFloat() / MAX_ARROW_AMOUNT) * 100).round(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package at.hannibal2.skyhanni.events

import net.minecraft.item.ItemStack

data class OwnInventoryItemUpdateEvent(val itemStack: ItemStack) : LorenzEvent()
data class OwnInventoryItemUpdateEvent(val itemStack: ItemStack, val slot: Int) : LorenzEvent()

0 comments on commit cea67a7

Please sign in to comment.