aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/features/dungeon/ShortbowClicker.kt
blob: 7cce15d07c3b724b6973779de4a6ae505ad8f732 (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
package com.ambientaddons.features.dungeon

import AmbientAddons.Companion.config
import AmbientAddons.Companion.mc
import com.ambientaddons.utils.Extensions.skyblockID
import com.ambientaddons.utils.SBLocation
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.math.roundToLong

// credit Floppa
object ShortbowClicker {
    private var lastClickTime = System.currentTimeMillis()
    private val shortbows = listOf("TERMINATOR", "JUJU_SHORTBOW", "ITEM_SPIRIT_BOW")

    @SubscribeEvent
    fun onRender(event: RenderWorldLastEvent) {
        if (!SBLocation.inSkyblock) return
        if (config.terminatorCps == 0) return
        if (!mc.gameSettings.keyBindUseItem.isKeyDown) return
        val itemStack = mc.thePlayer?.inventory?.getCurrentItem()
        if (itemStack?.skyblockID?.let { shortbows.contains(it) } != true) return
        val delay = (1000.0 / config.terminatorCps).roundToLong()
        val currentTime = System.currentTimeMillis()
        if ((currentTime - lastClickTime) >= delay) {
            lastClickTime = currentTime - (currentTime - lastClickTime) % delay
            if (mc.playerController.sendUseItem(mc.thePlayer, mc.theWorld, itemStack)) {
                mc.entityRenderer.itemRenderer.resetEquippedProgress2()
            }
        }
    }
}