blob: 9be28436815db19dd7eff2cfdb5d6fc8a9a6dd0b (
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
|
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.events.LorenzKeyPressEvent
import at.hannibal2.skyhanni.events.LorenzRenderWorldEvent
import at.hannibal2.skyhanni.features.garden.GardenPlotAPI.renderPlot
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LocationUtils.distanceSqToPlayer
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.input.Keyboard
import kotlin.time.Duration.Companion.milliseconds
@SkyHanniModule
object GardenPlotBorders {
private val config get() = GardenAPI.config.plotBorders
private var timeLastSaved = SimpleTimeMark.farPast()
private var showBorders = false
@SubscribeEvent
fun onKeyClick(event: LorenzKeyPressEvent) {
if (!isEnabled()) return
if (timeLastSaved.passedSince() < 250.milliseconds) return
if (event.keyCode == Keyboard.KEY_G && Keyboard.isKeyDown(Keyboard.KEY_F3)) {
timeLastSaved = SimpleTimeMark.now()
showBorders = !showBorders
}
if (event.keyCode == Keyboard.KEY_F3 && Keyboard.isKeyDown(Keyboard.KEY_G)) {
timeLastSaved = SimpleTimeMark.now()
showBorders = !showBorders
}
}
@SubscribeEvent
fun render(event: LorenzRenderWorldEvent) {
if (!isEnabled()) return
if (!showBorders) return
val plot = GardenPlotAPI.getCurrentPlot() ?: getClosestPlot() ?: return
event.renderPlot(plot, LorenzColor.YELLOW.toColor(), LorenzColor.DARK_BLUE.toColor(), showBuildLimit = true)
}
private fun getClosestPlot(): GardenPlotAPI.Plot? =
GardenPlotAPI.plots.minByOrNull { it.middle.distanceSqToPlayer() }
fun isEnabled() = GardenAPI.inGarden() && config
}
|