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.skyhannimodule.SkyHanniModule 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 @SkyHanniModule object SlayerItemsOnGround { private val config get() = SkyHanniMod.feature.slayer.itemsOnGround private var itemsOnGround = TimeLimitedCache(2.seconds) @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return for (entityItem in EntityUtils.getEntitiesNextToPlayer(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() }