Fix warp near X functionality not removing warps

This commit is contained in:
Linnea Gräf
2024-09-02 18:17:34 +02:00
parent 5ed74f2df4
commit 20db57b43c
3 changed files with 26 additions and 4 deletions

1
.gitignore vendored
View File

@@ -9,6 +9,7 @@
/buildSrc/.gradle /buildSrc/.gradle
/buildSrc/build/ /buildSrc/build/
/*/build /*/build
.kotlin
# Ignore Gradle GUI config # Ignore Gradle GUI config
gradle-app.setting gradle-app.setting

View File

@@ -1,4 +1,3 @@
package moe.nea.firmament.util package moe.nea.firmament.util
import io.github.moulberry.repo.constants.Islands import io.github.moulberry.repo.constants.Islands
@@ -9,6 +8,9 @@ import kotlin.math.sqrt
import kotlin.time.Duration.Companion.seconds import kotlin.time.Duration.Companion.seconds
import net.minecraft.text.Text import net.minecraft.text.Text
import net.minecraft.util.math.Position import net.minecraft.util.math.Position
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.commands.thenExecute
import moe.nea.firmament.events.CommandEvent
import moe.nea.firmament.events.ProcessChatEvent import moe.nea.firmament.events.ProcessChatEvent
import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.repo.RepoManager
import moe.nea.firmament.util.data.ProfileSpecificDataHolder import moe.nea.firmament.util.data.ProfileSpecificDataHolder
@@ -45,17 +47,32 @@ object WarpUtil {
fun teleportToNearestWarp(island: SkyBlockIsland, pos: Position) { fun teleportToNearestWarp(island: SkyBlockIsland, pos: Position) {
val nearestWarp = findNearestWarp(island, pos) val nearestWarp = findNearestWarp(island, pos)
if (nearestWarp == null) { if (nearestWarp == null) {
MC.sendChat(Text.literal("Could not find an unlocked warp in ${island.userFriendlyName}")) MC.sendChat(Text.translatable("firmament.warp-util.no-warp-found", island.userFriendlyName))
return return
} }
if (island == SBData.skyblockLocation if (island == SBData.skyblockLocation
&& sqrt(squaredDist(pos, nearestWarp)) > 1.1 * sqrt(squaredDist((MC.player ?: return).pos, nearestWarp)) && sqrt(squaredDist(pos, nearestWarp)) > 1.1 * sqrt(squaredDist((MC.player ?: return).pos, nearestWarp))
) { ) {
MC.sendChat(Text.translatable("firmament.warp-util.already-close", nearestWarp.warp))
return return
} }
MC.sendChat(Text.translatable("firmament.warp-util.attempting-to-warp", nearestWarp.warp))
lastWarpAttempt = TimeMark.now()
lastAttemptedWarp = nearestWarp.warp
MC.sendServerCommand("warp ${nearestWarp.warp}") MC.sendServerCommand("warp ${nearestWarp.warp}")
} }
@Subscribe
fun clearUnlockedWarpsCommand(event: CommandEvent.SubCommand) {
event.subcommand("clearwarps") {
thenExecute {
DConfig.data?.excludedWarps?.clear()
DConfig.markDirty()
source.sendFeedback(Text.translatable("firmament.warp-util.clear-excluded"))
}
}
}
init { init {
ProcessChatEvent.subscribe("WarpUtil:processChat") { ProcessChatEvent.subscribe("WarpUtil:processChat") {
if (it.unformattedString == "You haven't unlocked this fast travel destination!" if (it.unformattedString == "You haven't unlocked this fast travel destination!"
@@ -66,7 +83,7 @@ object WarpUtil {
MC.sendChat(Text.stringifiedTranslatable("firmament.warp-util.mark-excluded", lastAttemptedWarp)) MC.sendChat(Text.stringifiedTranslatable("firmament.warp-util.mark-excluded", lastAttemptedWarp))
lastWarpAttempt = TimeMark.farPast() lastWarpAttempt = TimeMark.farPast()
} }
if (it.unformattedString == "You may now fast travel to") { if (it.unformattedString.startsWith("You may now fast travel to")) {
DConfig.data?.excludedWarps?.clear() DConfig.data?.excludedWarps?.clear()
DConfig.markDirty() DConfig.markDirty()
} }

View File

@@ -201,5 +201,9 @@
"firmament.config.pickaxe-info": "Pickaxes", "firmament.config.pickaxe-info": "Pickaxes",
"firmament.config.pickaxe-info.ability-cooldown": "Pickaxe Ability Cooldown", "firmament.config.pickaxe-info.ability-cooldown": "Pickaxe Ability Cooldown",
"firmament.config.pickaxe-info.ability-scale": "Ability Cooldown Scale", "firmament.config.pickaxe-info.ability-scale": "Ability Cooldown Scale",
"firmament.config.pickaxe-info.fuel-bar": "Drill Fuel Durability Bar" "firmament.config.pickaxe-info.fuel-bar": "Drill Fuel Durability Bar",
"firmament.warp-util.no-warp-found": "Could not find an unlocked warp in %s",
"firmament.warp-util.already-close": "Already closer to destination than /warp %s",
"firmament.warp-util.attempting-to-warp": "Trying to warp to /warp %s",
"firmament.warp-util.clear-excluded": "Marked all /warp commands as potentially available."
} }