diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-09 21:47:06 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-09 21:47:06 +0100 |
commit | c98bbe34efab04cf46dde6a573b57275a69c5722 (patch) | |
tree | 998cb4d4a8c04b82b06d00edae197ea4fcc9ad35 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 6157bc46e3355cf353767572c46bba3fb6f8d02f (diff) | |
download | skyhanni-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/features')
3 files changed, 8 insertions, 34 deletions
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) { |