From 5bedd8978dc05f60ef752a95a2062e99be41281c Mon Sep 17 00:00:00 2001 From: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:37:14 +1000 Subject: Waypoint saver (#282) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../at/hannibal2/skyhanni/test/WaypointSaver.kt | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/test/WaypointSaver.kt (limited to 'src/main/java/at/hannibal2/skyhanni/test') diff --git a/src/main/java/at/hannibal2/skyhanni/test/WaypointSaver.kt b/src/main/java/at/hannibal2/skyhanni/test/WaypointSaver.kt new file mode 100644 index 000000000..670129e27 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/test/WaypointSaver.kt @@ -0,0 +1,65 @@ +package at.hannibal2.skyhanni.test + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled +import at.hannibal2.skyhanni.utils.* +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.gui.inventory.GuiEditSign +import net.minecraft.client.gui.inventory.GuiInventory +import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import org.lwjgl.input.Keyboard + +class WaypointSaver { + private val config get() = SkyHanniMod.feature.dev.waypoint + private var timeLastSaved: Long = 0 + private var locations = mutableListOf() + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!Keyboard.getEventKeyState()) return + if (NEUItems.neuHasFocus()) return + if (System.currentTimeMillis() - timeLastSaved < 250) return + + Minecraft.getMinecraft().currentScreen?.let { + if (it !is GuiInventory && it !is GuiChest && it !is GuiEditSign) return + } + + val key = if (Keyboard.getEventKey() == 0) Keyboard.getEventCharacter().code + 256 else Keyboard.getEventKey() + if (config.deleteKey == key) { + locations = locations.dropLast(1).toMutableList() + locations.copyLocations() + } + if (config.saveKey == key) { + val newLocation = LocationUtils.playerLocation().roundLocation() + if (locations.isNotEmpty()) { + if (newLocation == locations.last()) return + } + locations.add(newLocation) + locations.copyLocations() + } + } + + private fun MutableList.copyLocations() { + val resultList = mutableListOf() + timeLastSaved = System.currentTimeMillis() + for (location in this) { + val x = location.z.toString().replace(",", ".") + val y = location.z.toString().replace(",", ".") + val z = location.z.toString().replace(",", ".") + resultList.add("\"$x:$y:$z\"") + } + OSUtils.copyToClipboard(resultList.joinToString((",\n"))) + } + + @SubscribeEvent + fun onRenderWorld(event: RenderWorldLastEvent) { + if (!LorenzUtils.inSkyBlock) return + for (location in locations) { + event.drawWaypointFilled(location, LorenzColor.GREEN.toColor()) + } + } +} \ No newline at end of file -- cgit