aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerItemsOnGround.kt
blob: f0f80ace448e5b1d28907cbba566b756790fc2db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package at.hannibal2.skyhanni.features.slayer

import at.hannibal2.skyhanni.SkyHanniMod
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.LocationUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.RenderUtils.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation
import com.google.common.cache.CacheBuilder
import net.minecraft.entity.item.EntityItem
import net.minecraft.init.Items
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.concurrent.TimeUnit

class SlayerItemsOnGround {
    private val config get() = SkyHanniMod.feature.slayer.itemsOnGround

    private var itemsOnGround =
        CacheBuilder.newBuilder().expireAfterWrite(2, TimeUnit.SECONDS)
            .build<EntityItem, Pair<LorenzVec, String>>()

    @SubscribeEvent
    fun onRenderWorld(event: LorenzRenderWorldEvent) {
        if (!LorenzUtils.inSkyBlock) return
        if (!config.enabled) return
        if (!SlayerAPI.isInCorrectArea) return
        if (!SlayerAPI.hasActiveSlayerQuest()) return

        for (entityItem in EntityUtils.getEntities<EntityItem>()) {
            val location = event.exactLocation(entityItem).add(y = 0.8)
            if (location.distance(LocationUtils.playerLocation()) > 15) continue

            val itemStack = entityItem.entityItem
            // happens in spiders den sometimes
            if (itemStack.item == Items.spawn_egg) continue
            if (itemStack.getInternalName().equals("")) continue // TODO remove, should never happen
            if (itemStack.getInternalName() == NEUInternalName.NONE) continue

            val (itemName, price) = SlayerAPI.getItemNameAndPrice(itemStack.getInternalName(), itemStack.stackSize)
            if (config.minimumPrice > price) continue

            itemsOnGround.put(entityItem, location to itemName)
        }

        for ((location, text) in itemsOnGround.asMap().values) {
            event.drawString(location, text)
        }
    }
}