blob: bfb21cea5c40aab4c7aab76ee63a515fb7d91d12 (
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
|
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.events.LorenzTickEvent
import at.hannibal2.skyhanni.utils.EntityUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.RenderUtils.drawString
import at.hannibal2.skyhanni.utils.RenderUtils.exactLocation
import at.hannibal2.skyhanni.utils.TimeLimitedCache
import net.minecraft.entity.item.EntityItem
import net.minecraft.init.Items
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
class SlayerItemsOnGround {
private val config get() = SkyHanniMod.feature.slayer.itemsOnGround
private var itemsOnGround = TimeLimitedCache<EntityItem, String>(2.seconds)
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!isEnabled()) return
for (entityItem in EntityUtils.getEntitiesNextToPlayer<EntityItem>(15.0)) {
val itemStack = entityItem.entityItem
if (itemStack.item == Items.spawn_egg) continue
if (itemStack.getInternalName() == NEUInternalName.NONE) continue
val (name, price) = SlayerAPI.getItemNameAndPrice(itemStack.getInternalName(), itemStack.stackSize)
if (config.minimumPrice > price) continue
itemsOnGround[entityItem] = name
}
}
@SubscribeEvent
fun onRenderWorld(event: LorenzRenderWorldEvent) {
if (!isEnabled()) return
for ((item, text) in itemsOnGround) {
val location = event.exactLocation(item).add(y = 0.8)
event.drawString(location, text)
}
}
fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled &&
SlayerAPI.isInCorrectArea && SlayerAPI.hasActiveSlayerQuest()
}
|