aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-09 21:47:06 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-11-09 21:47:06 +0100
commitc98bbe34efab04cf46dde6a573b57275a69c5722 (patch)
tree998cb4d4a8c04b82b06d00edae197ea4fcc9ad35 /src/main/java/at/hannibal2/skyhanni
parent6157bc46e3355cf353767572c46bba3fb6f8d02f (diff)
downloadskyhanni-c98bbe34efab04cf46dde6a573b57275a69c5722.tar.gz
skyhanni-c98bbe34efab04cf46dde6a573b57275a69c5722.tar.bz2
skyhanni-c98bbe34efab04cf46dde6a573b57275a69c5722.zip
Added support for slayer tracker items for loot from area mini-bosses. Fixed a bug where some items were counted twice.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt10
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/entity/ItemAddInInventoryEvent.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt31
7 files changed, 31 insertions, 69 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
index 2476cbe73..29ce97471 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.api
import at.hannibal2.skyhanni.events.CollectionUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
+import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -66,6 +67,17 @@ class CollectionAPI {
}
}
+ @SubscribeEvent
+ fun onItemAdd(event: ItemAddInInventoryEvent) {
+ // TODO add support for replenish (higher collection than actual items in inv)
+ val internalName = event.internalName
+ if (internalName.getItemStackOrNull() == null) {
+ LorenzUtils.debug("CollectionAPI.addFromInventory: item is null for '$internalName'")
+ return
+ }
+ collectionValue.addOrPut(internalName, event.amount.toLong())
+ }
+
companion object {
// TODO USE SH-REPO
val collectionValue = mutableMapOf<NEUInternalName, Long>()
@@ -74,14 +86,5 @@ class CollectionAPI {
fun isCollectionTier0(lore: List<String>) = lore.map { collectionTier0Pattern.matcher(it) }.any { it.matches() }
fun getCollectionCounter(internalName: NEUInternalName): Long? = collectionValue[internalName]
-
- // TODO add support for replenish (higher collection than actual items in inv)
- fun addFromInventory(internalName: NEUInternalName, amount: Int) {
- if (internalName.getItemStackOrNull() == null) {
- LorenzUtils.debug("CollectionAPI.addFromInventory: item is null for '$internalName'")
- return
- }
- collectionValue.addOrPut(internalName, amount.toLong())
- }
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt
index 7e2032077..da505f409 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt
@@ -1,14 +1,13 @@
package at.hannibal2.skyhanni.data
-import at.hannibal2.skyhanni.api.CollectionAPI
import at.hannibal2.skyhanni.events.InventoryCloseEvent
import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent
import at.hannibal2.skyhanni.events.PacketEvent
+import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent
import at.hannibal2.skyhanni.features.bazaar.BazaarApi
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import net.minecraft.item.ItemStack
import net.minecraft.network.play.server.S2FPacketSetSlot
@@ -92,10 +91,7 @@ class OwnInventoryData {
val (_, amount) = NEUItems.getMultiplier(internalName)
if (amount > 1) return
- addMultiplier(internalName, add)
+ ItemAddInInventoryEvent(internalName, add).postAndCatch()
}
- private fun addMultiplier(internalName: NEUInternalName, amount: Int) {
- CollectionAPI.addFromInventory(internalName, amount)
- }
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
index f3c23700d..c827a9f53 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt
@@ -15,7 +15,6 @@ import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull
import at.hannibal2.skyhanni.utils.NEUItems.getPrice
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.RecalculatingValue
-import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import com.google.common.cache.CacheBuilder
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.concurrent.TimeUnit
@@ -40,22 +39,6 @@ object SlayerAPI {
System.currentTimeMillis()
} else latestProgressChangeTime
-
- // TODO use repo
- fun ignoreSlayerDrop(name: String) = when (name.removeColor()) {
- // maybe everywhere?
- "Stone" -> true
- "Head" -> true
-
- // Spider
- "Cobweb" -> true
-
- // Blaze
- "Water Bottle" -> true
-
- else -> false
- }
-
fun getItemNameAndPrice(internalName: NEUInternalName, amount: Int): Pair<String, Double> {
val key = internalName to amount
nameCache.getIfPresent(key)?.let {
@@ -178,4 +161,4 @@ object SlayerAPI {
else -> null
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/events/entity/ItemAddInInventoryEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/entity/ItemAddInInventoryEvent.kt
new file mode 100644
index 000000000..6b9747adf
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/entity/ItemAddInInventoryEvent.kt
@@ -0,0 +1,6 @@
+package at.hannibal2.skyhanni.events.entity
+
+import at.hannibal2.skyhanni.events.LorenzEvent
+import at.hannibal2.skyhanni.utils.NEUInternalName
+
+class ItemAddInInventoryEvent(val internalName: NEUInternalName, val amount: Int) : LorenzEvent()
diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt
index 1615838ae..091197b53 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt
@@ -1,8 +1,8 @@
package at.hannibal2.skyhanni.features.minion
-import at.hannibal2.skyhanni.api.CollectionAPI
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.events.MinionOpenEvent
+import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName
@@ -43,10 +43,10 @@ class MinionCollectLogic {
val diff = amount - old
if (diff > 0) {
- CollectionAPI.addFromInventory(internalId, diff)
+ ItemAddInInventoryEvent(internalId, diff).postAndCatch()
}
}
oldMap = emptyMap()
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt
index 0c80973c4..0cb129c7d 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt
@@ -5,7 +5,6 @@ import at.hannibal2.skyhanni.data.SlayerAPI
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
-import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
@@ -37,8 +36,6 @@ class SlayerItemsOnGround {
if (location.distance(LocationUtils.playerLocation()) > 15) continue
val itemStack = entityItem.entityItem
- val name = itemStack.name ?: continue
- if (SlayerAPI.ignoreSlayerDrop(name)) continue
// happens in spiders den sometimes
if (itemStack.item == Items.spawn_egg) continue
if (itemStack.getInternalName().equals("")) continue // TODO remove, should never happen
@@ -54,4 +51,4 @@ class SlayerItemsOnGround {
event.drawString(location, text)
}
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt
index 229d9007c..43f609f10 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerProfitTracker.kt
@@ -4,18 +4,15 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.Storage
import at.hannibal2.skyhanni.data.SlayerAPI
import at.hannibal2.skyhanni.events.GuiRenderEvent
-import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.PurseChangeCause
import at.hannibal2.skyhanni.events.PurseChangeEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.events.SackChangeEvent
import at.hannibal2.skyhanni.events.SlayerChangeEvent
import at.hannibal2.skyhanni.events.SlayerQuestCompleteEvent
+import at.hannibal2.skyhanni.events.entity.ItemAddInInventoryEvent
import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData
import at.hannibal2.skyhanni.test.PriceSource
-import at.hannibal2.skyhanni.utils.EntityUtils
-import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull
-import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -33,18 +30,12 @@ import at.hannibal2.skyhanni.utils.jsonobjects.SlayerProfitTrackerItemsJson
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import at.hannibal2.skyhanni.utils.tracker.TrackerData
-import com.google.common.cache.CacheBuilder
import com.google.gson.annotations.Expose
-import net.minecraft.entity.item.EntityItem
-import net.minecraft.network.play.server.S0DPacketCollectItem
-import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.seconds
object SlayerProfitTracker {
private val config get() = SkyHanniMod.feature.slayer.itemProfitTracker
- private var collectedCache = CacheBuilder.newBuilder().expireAfterWrite(2, TimeUnit.SECONDS).build<Int, Unit>()
private var itemLogCategory = ""
private var baseSlayerType = ""
@@ -186,27 +177,13 @@ object SlayerProfitTracker {
}
}
- @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
- fun onChatPacket(event: PacketEvent.ReceiveEvent) {
+ @SubscribeEvent
+ fun onItemAdd(event: ItemAddInInventoryEvent) {
if (!isEnabled()) return
if (!SlayerAPI.isInCorrectArea) return
if (!SlayerAPI.hasActiveSlayerQuest()) return
- val packet = event.packet
- if (packet !is S0DPacketCollectItem) return
-
- val entityID = packet.collectedItemEntityID
- val item = EntityUtils.getEntityByID(entityID) ?: return
- if (item !is EntityItem) return
-
- if (collectedCache.getIfPresent(entityID) != null) return
- collectedCache.put(entityID, Unit)
-
- val itemStack = item.entityItem
- val name = itemStack.name ?: return
- if (SlayerAPI.ignoreSlayerDrop(name)) return
- val internalName = itemStack.getInternalNameOrNull() ?: return
- addItem(internalName, itemStack.stackSize)
+ addItem(event.internalName, event.amount)
}
private fun addItem(internalName: NEUInternalName, amount: Int) {