diff options
Diffstat (limited to 'src/main/kotlin/features/world')
| -rw-r--r-- | src/main/kotlin/features/world/ColeWeightCompat.kt | 40 | ||||
| -rw-r--r-- | src/main/kotlin/features/world/FairySouls.kt | 214 | ||||
| -rw-r--r-- | src/main/kotlin/features/world/FirmWaypointManager.kt | 24 | ||||
| -rw-r--r-- | src/main/kotlin/features/world/FirmWaypoints.kt | 2 | ||||
| -rw-r--r-- | src/main/kotlin/features/world/NavigableWaypoint.kt | 2 | ||||
| -rw-r--r-- | src/main/kotlin/features/world/NavigationHelper.kt | 24 | ||||
| -rw-r--r-- | src/main/kotlin/features/world/NpcWaypointGui.kt | 3 | ||||
| -rw-r--r-- | src/main/kotlin/features/world/TemporaryWaypoints.kt | 23 | ||||
| -rw-r--r-- | src/main/kotlin/features/world/Waypoints.kt | 119 |
9 files changed, 231 insertions, 220 deletions
diff --git a/src/main/kotlin/features/world/ColeWeightCompat.kt b/src/main/kotlin/features/world/ColeWeightCompat.kt index b92a91e..3597d6d 100644 --- a/src/main/kotlin/features/world/ColeWeightCompat.kt +++ b/src/main/kotlin/features/world/ColeWeightCompat.kt @@ -1,8 +1,8 @@ package moe.nea.firmament.features.world import kotlinx.serialization.Serializable -import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos +import net.minecraft.network.chat.Component +import net.minecraft.core.BlockPos import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.commands.DefaultSource @@ -16,9 +16,9 @@ import moe.nea.firmament.util.tr object ColeWeightCompat { @Serializable data class ColeWeightWaypoint( - val x: Int, - val y: Int, - val z: Int, + val x: Int?, + val y: Int?, + val z: Int?, val r: Int = 0, val g: Int = 0, val b: Int = 0, @@ -31,9 +31,9 @@ object ColeWeightCompat { } fun intoFirm(waypoints: List<ColeWeightWaypoint>, relativeTo: BlockPos): FirmWaypoints { - val w = waypoints.map { - FirmWaypoints.Waypoint(it.x + relativeTo.x, it.y + relativeTo.y, it.z + relativeTo.z) - } + val w = waypoints + .filter { it.x != null && it.y != null && it.z != null } + .map { FirmWaypoints.Waypoint(it.x!! + relativeTo.x, it.y!! + relativeTo.y, it.z!! + relativeTo.z) } return FirmWaypoints( "Imported Waypoints", "imported", @@ -44,9 +44,9 @@ object ColeWeightCompat { } fun copyAndInform( - source: DefaultSource, - origin: BlockPos, - positiveFeedback: (Int) -> Text, + source: DefaultSource, + origin: BlockPos, + positiveFeedback: (Int) -> Component, ) { val waypoints = Waypoints.useNonEmptyWaypoints() ?.let { fromFirm(it, origin) } @@ -61,12 +61,12 @@ object ColeWeightCompat { } fun importAndInform( - source: DefaultSource, - pos: BlockPos?, - positiveFeedback: (Int) -> Text + source: DefaultSource, + pos: BlockPos?, + positiveFeedback: (Int) -> Component ) { val text = ClipboardUtils.getTextContents() - val wr = tryParse(text).map { intoFirm(it, pos ?: BlockPos.ORIGIN) } + val wr = tryParse(text).map { intoFirm(it, pos ?: BlockPos.ZERO) } val waypoints = wr.getOrElse { source.sendError( tr("firmament.command.waypoint.import.cw.error", @@ -84,7 +84,7 @@ object ColeWeightCompat { event.subcommand(Waypoints.WAYPOINTS_SUBCOMMAND) { thenLiteral("exportcw") { thenExecute { - copyAndInform(source, BlockPos.ORIGIN) { + copyAndInform(source, BlockPos.ZERO) { tr("firmament.command.waypoint.export.cw", "Copied $it waypoints to clipboard in ColeWeight format.") } @@ -92,7 +92,7 @@ object ColeWeightCompat { } thenLiteral("exportrelativecw") { thenExecute { - copyAndInform(source, MC.player?.blockPos ?: BlockPos.ORIGIN) { + copyAndInform(source, MC.player?.blockPosition() ?: BlockPos.ZERO) { tr("firmament.command.waypoint.export.cw.relative", "Copied $it relative waypoints to clipboard in ColeWeight format. Make sure to stand in the same position when importing.") } @@ -101,14 +101,14 @@ object ColeWeightCompat { thenLiteral("importcw") { thenExecute { importAndInform(source, null) { - Text.stringifiedTranslatable("firmament.command.waypoint.import.cw", - it) + tr("firmament.command.waypoint.import.cw.success", + "Imported $it waypoints from ColeWeight.") } } } thenLiteral("importrelativecw") { thenExecute { - importAndInform(source, MC.player!!.blockPos) { + importAndInform(source, MC.player!!.blockPosition()) { tr("firmament.command.waypoint.import.cw.relative", "Imported $it relative waypoints from clipboard. Make sure you stand in the same position as when you exported these waypoints for them to line up correctly.") } diff --git a/src/main/kotlin/features/world/FairySouls.kt b/src/main/kotlin/features/world/FairySouls.kt index 1263074..b073726 100644 --- a/src/main/kotlin/features/world/FairySouls.kt +++ b/src/main/kotlin/features/world/FairySouls.kt @@ -1,131 +1,123 @@ - - package moe.nea.firmament.features.world import io.github.moulberry.repo.data.Coordinate +import me.shedaniel.math.Color import kotlinx.serialization.Serializable import kotlinx.serialization.serializer -import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Vec3d import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ProcessChatEvent import moe.nea.firmament.events.SkyblockServerUpdateEvent import moe.nea.firmament.events.WorldRenderLastEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.blockPos +import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.data.ProfileSpecificDataHolder -import moe.nea.firmament.util.render.RenderInWorldContext import moe.nea.firmament.util.render.RenderInWorldContext.Companion.renderInWorld import moe.nea.firmament.util.unformattedString -object FairySouls : FirmamentFeature { - - - @Serializable - data class Data( - val foundSouls: MutableMap<SkyBlockIsland, MutableSet<Int>> = mutableMapOf() - ) - - override val config: ManagedConfig - get() = TConfig - - object DConfig : ProfileSpecificDataHolder<Data>(serializer(), "found-fairysouls", ::Data) - - - object TConfig : ManagedConfig("fairy-souls", Category.MISC) { - val displaySouls by toggle("show") { false } - val resetSouls by button("reset") { - DConfig.data?.foundSouls?.clear() != null - updateMissingSouls() - } - } - - - override val identifier: String get() = "fairy-souls" - - val playerReach = 5 - val playerReachSquared = playerReach * playerReach - - var currentLocationName: SkyBlockIsland? = null - var currentLocationSouls: List<Coordinate> = emptyList() - var currentMissingSouls: List<Coordinate> = emptyList() - - fun updateMissingSouls() { - currentMissingSouls = emptyList() - val c = DConfig.data ?: return - val fi = c.foundSouls[currentLocationName] ?: setOf() - val cms = currentLocationSouls.toMutableList() - fi.asSequence().sortedDescending().filter { it in cms.indices }.forEach { cms.removeAt(it) } - currentMissingSouls = cms - } - - fun updateWorldSouls() { - currentLocationSouls = emptyList() - val loc = currentLocationName ?: return - currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc.locrawMode] ?: return - } - - fun findNearestClickableSoul(): Coordinate? { - val player = MC.player ?: return null - val pos = player.pos - val location = SBData.skyblockLocation ?: return null - val soulLocations: List<Coordinate> = - RepoManager.neuRepo.constants.fairySouls.soulLocations[location.locrawMode] ?: return null - return soulLocations - .map { it to it.blockPos.getSquaredDistance(pos) } - .filter { it.second < playerReachSquared } - .minByOrNull { it.second } - ?.first - } - - private fun markNearestSoul() { - val nearestSoul = findNearestClickableSoul() ?: return - val c = DConfig.data ?: return - val loc = currentLocationName ?: return - val idx = currentLocationSouls.indexOf(nearestSoul) - c.foundSouls.computeIfAbsent(loc) { mutableSetOf() }.add(idx) - DConfig.markDirty() - updateMissingSouls() - } - - @Subscribe - fun onWorldRender(it: WorldRenderLastEvent) { - if (!TConfig.displaySouls) return - renderInWorld(it) { - currentMissingSouls.forEach { - block(it.blockPos, 0x80FFFF00.toInt()) - } - color(1f, 0f, 1f, 1f) - currentLocationSouls.forEach { - wireframeCube(it.blockPos) - } - } - } - - @Subscribe - fun onProcessChat(it: ProcessChatEvent) { - when (it.text.unformattedString) { - "You have already found that Fairy Soul!" -> { - markNearestSoul() - } - - "SOUL! You found a Fairy Soul!" -> { - markNearestSoul() - } - } - } - - @Subscribe - fun onLocationChange(it: SkyblockServerUpdateEvent) { - currentLocationName = it.newLocraw?.skyblockLocation - updateWorldSouls() - updateMissingSouls() - } +object FairySouls { + + + @Serializable + data class Data( + val foundSouls: MutableMap<SkyBlockIsland, MutableSet<Int>> = mutableMapOf() + ) + + @Config + object DConfig : ProfileSpecificDataHolder<Data>(serializer(), "found-fairysouls", ::Data) + + @Config + object TConfig : ManagedConfig("fairy-souls", Category.MISC) { + val displaySouls by toggle("show") { false } + val resetSouls by button("reset") { + DConfig.data?.foundSouls?.clear() != null + updateMissingSouls() + } + } + + + val identifier: String get() = "fairy-souls" + + val playerReach = 5 + val playerReachSquared = playerReach * playerReach + + var currentLocationName: SkyBlockIsland? = null + var currentLocationSouls: List<Coordinate> = emptyList() + var currentMissingSouls: List<Coordinate> = emptyList() + + fun updateMissingSouls() { + currentMissingSouls = emptyList() + val c = DConfig.data ?: return + val fi = c.foundSouls[currentLocationName] ?: setOf() + val cms = currentLocationSouls.toMutableList() + fi.asSequence().sortedDescending().filter { it in cms.indices }.forEach { cms.removeAt(it) } + currentMissingSouls = cms + } + + fun updateWorldSouls() { + currentLocationSouls = emptyList() + val loc = currentLocationName ?: return + currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc.locrawMode] ?: return + } + + fun findNearestClickableSoul(): Coordinate? { + val player = MC.player ?: return null + val pos = player.position + val location = SBData.skyblockLocation ?: return null + val soulLocations: List<Coordinate> = + RepoManager.neuRepo.constants.fairySouls.soulLocations[location.locrawMode] ?: return null + return soulLocations + .map { it to it.blockPos.distToCenterSqr(pos) } + .filter { it.second < playerReachSquared } + .minByOrNull { it.second } + ?.first + } + + private fun markNearestSoul() { + val nearestSoul = findNearestClickableSoul() ?: return + val c = DConfig.data ?: return + val loc = currentLocationName ?: return + val idx = currentLocationSouls.indexOf(nearestSoul) + c.foundSouls.computeIfAbsent(loc) { mutableSetOf() }.add(idx) + DConfig.markDirty() + updateMissingSouls() + } + + @Subscribe + fun onWorldRender(it: WorldRenderLastEvent) { + if (!TConfig.displaySouls) return + renderInWorld(it) { + currentMissingSouls.forEach { + block(it.blockPos, Color.ofRGBA(176, 0, 255, 128).color) + } + currentLocationSouls.forEach { + wireframeCube(it.blockPos) + } + } + } + + @Subscribe + fun onProcessChat(it: ProcessChatEvent) { + when (it.text.unformattedString) { + "You have already found that Fairy Soul!" -> { + markNearestSoul() + } + + "SOUL! You found a Fairy Soul!" -> { + markNearestSoul() + } + } + } + + @Subscribe + fun onLocationChange(it: SkyblockServerUpdateEvent) { + currentLocationName = it.newLocraw?.skyblockLocation + updateWorldSouls() + updateMissingSouls() + } } diff --git a/src/main/kotlin/features/world/FirmWaypointManager.kt b/src/main/kotlin/features/world/FirmWaypointManager.kt index d18483c..c6e2610 100644 --- a/src/main/kotlin/features/world/FirmWaypointManager.kt +++ b/src/main/kotlin/features/world/FirmWaypointManager.kt @@ -2,7 +2,7 @@ package moe.nea.firmament.features.world import com.mojang.brigadier.arguments.StringArgumentType import kotlinx.serialization.serializer -import net.minecraft.text.Text +import net.minecraft.network.chat.Component import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.commands.DefaultSource import moe.nea.firmament.commands.RestArgumentType @@ -16,11 +16,11 @@ import moe.nea.firmament.util.ClipboardUtils import moe.nea.firmament.util.FirmFormatters import moe.nea.firmament.util.MC import moe.nea.firmament.util.TemplateUtil -import moe.nea.firmament.util.data.MultiFileDataHolder +import moe.nea.firmament.util.data.DataHolder import moe.nea.firmament.util.tr object FirmWaypointManager { - object DataHolder : MultiFileDataHolder<FirmWaypoints>(serializer(), "waypoints") + object DConfig : DataHolder<MutableMap<String, FirmWaypoints>>(serializer(), "waypoints", ::mutableMapOf) val SHARE_PREFIX = "FIRM_WAYPOINTS/" val ENCODED_SHARE_PREFIX = TemplateUtil.getPrefixComparisonSafeBase64Encoding(SHARE_PREFIX) @@ -46,10 +46,10 @@ object FirmWaypointManager { return copy } - fun loadWaypoints(waypoints: FirmWaypoints, sendFeedback: (Text) -> Unit) { + fun loadWaypoints(waypoints: FirmWaypoints, sendFeedback: (Component) -> Unit) { val copy = waypoints.deepCopy() if (copy.isRelativeTo != null) { - val origin = MC.player!!.blockPos + val origin = MC.player!!.blockPosition() copy.waypoints.replaceAll { it.copy( x = it.x + origin.x, @@ -57,7 +57,7 @@ object FirmWaypointManager { z = it.z + origin.z, ) } - copy.lastRelativeImport = origin.toImmutable() + copy.lastRelativeImport = origin.immutable() sendFeedback(tr("firmament.command.waypoint.import.ordered.success", "Imported ${copy.size} relative waypoints. Make sure you stand in the correct spot while loading the waypoints: ${copy.isRelativeTo}.")) } else { @@ -70,7 +70,7 @@ object FirmWaypointManager { fun setOrigin(source: DefaultSource, text: String?) { val waypoints = Waypoints.useEditableWaypoints() waypoints.isRelativeTo = text ?: waypoints.isRelativeTo ?: "" - val pos = MC.player!!.blockPos + val pos = MC.player!!.blockPosition() waypoints.lastRelativeImport = pos source.sendFeedback(tr("firmament.command.waypoint.originset", "Set the origin of waypoints to ${FirmFormatters.formatPosition(pos)}. Run /firm waypoints export to save the waypoints relative to this position.")) @@ -100,7 +100,7 @@ object FirmWaypointManager { } thenLiteral("save") { thenArgument("name", StringArgumentType.string()) { name -> - suggestsList { DataHolder.list().keys } + suggestsList { DConfig.data.keys } thenExecute { val waypoints = Waypoints.useNonEmptyWaypoints() if (waypoints == null) { @@ -109,8 +109,8 @@ object FirmWaypointManager { } waypoints.id = get(name) val exportableWaypoints = createExportableCopy(waypoints) - DataHolder.insert(get(name), exportableWaypoints) - DataHolder.save() + DConfig.data[get(name)] = exportableWaypoints + DConfig.markDirty() source.sendFeedback(tr("firmament.command.waypoint.saved", "Saved waypoints locally as ${get(name)}. Use /firm waypoints load to load them again.")) } @@ -118,10 +118,10 @@ object FirmWaypointManager { } thenLiteral("load") { thenArgument("name", StringArgumentType.string()) { name -> - suggestsList { DataHolder.list().keys } + suggestsList { DConfig.data.keys } thenExecute { val name = get(name) - val waypoints = DataHolder.list()[name] + val waypoints = DConfig.data[name] if (waypoints == null) { source.sendError( tr("firmament.command.waypoint.nosaved", diff --git a/src/main/kotlin/features/world/FirmWaypoints.kt b/src/main/kotlin/features/world/FirmWaypoints.kt index d0cd55a..0b018cb 100644 --- a/src/main/kotlin/features/world/FirmWaypoints.kt +++ b/src/main/kotlin/features/world/FirmWaypoints.kt @@ -2,7 +2,7 @@ package moe.nea.firmament.features.world import kotlinx.serialization.Serializable import kotlinx.serialization.Transient -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos @Serializable data class FirmWaypoints( diff --git a/src/main/kotlin/features/world/NavigableWaypoint.kt b/src/main/kotlin/features/world/NavigableWaypoint.kt index 28a517f..653fd87 100644 --- a/src/main/kotlin/features/world/NavigableWaypoint.kt +++ b/src/main/kotlin/features/world/NavigableWaypoint.kt @@ -1,7 +1,7 @@ package moe.nea.firmament.features.world import io.github.moulberry.repo.data.NEUItem -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos import moe.nea.firmament.util.SkyBlockIsland abstract class NavigableWaypoint { diff --git a/src/main/kotlin/features/world/NavigationHelper.kt b/src/main/kotlin/features/world/NavigationHelper.kt index acdfb86..ea886bf 100644 --- a/src/main/kotlin/features/world/NavigationHelper.kt +++ b/src/main/kotlin/features/world/NavigationHelper.kt @@ -1,10 +1,10 @@ package moe.nea.firmament.features.world import io.github.moulberry.repo.constants.Islands -import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Position -import net.minecraft.util.math.Vec3i +import net.minecraft.network.chat.Component +import net.minecraft.core.BlockPos +import net.minecraft.core.Position +import net.minecraft.core.Vec3i import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.SkyblockServerUpdateEvent import moe.nea.firmament.events.TickEvent @@ -72,7 +72,7 @@ object NavigationHelper { fun onMovement(event: TickEvent) { // TODO: add a movement tick event maybe? val tp = targetWaypoint ?: return val p = MC.player ?: return - if (p.squaredDistanceTo(tp.position.toCenterPos()) < 5 * 5) { + if (p.distanceToSqr(tp.position.center) < 5 * 5) { targetWaypoint = null } } @@ -84,11 +84,11 @@ object NavigationHelper { RenderInWorldContext.renderInWorld(event) { if (nt != null) { waypoint(nt.blockPos, - Text.literal("Teleporter to " + nt.toIsland.userFriendlyName), - Text.literal("(towards " + tp.name + "§f)")) + Component.literal("Teleporter to " + nt.toIsland.userFriendlyName), + Component.literal("(towards " + tp.name + "§f)")) } else if (tp.island == SBData.skyblockLocation) { waypoint(tp.position, - Text.literal(tp.name)) + Component.literal(tp.name)) } } } @@ -96,7 +96,7 @@ object NavigationHelper { fun tryWarpNear() { val tp = targetWaypoint if (tp == null) { - MC.sendChat(Text.literal("Could not find a waypoint to warp you to. Select one first.")) + MC.sendChat(Component.literal("Could not find a waypoint to warp you to. Select one first.")) return } WarpUtil.teleportToNearestWarp(tp.island, tp.position.asPositionView()) @@ -106,15 +106,15 @@ object NavigationHelper { fun Vec3i.asPositionView(): Position { return object : Position { - override fun getX(): Double { + override fun x(): Double { return this@asPositionView.x.toDouble() } - override fun getY(): Double { + override fun y(): Double { return this@asPositionView.y.toDouble() } - override fun getZ(): Double { + override fun z(): Double { return this@asPositionView.z.toDouble() } } diff --git a/src/main/kotlin/features/world/NpcWaypointGui.kt b/src/main/kotlin/features/world/NpcWaypointGui.kt index 6146e50..3bae3e8 100644 --- a/src/main/kotlin/features/world/NpcWaypointGui.kt +++ b/src/main/kotlin/features/world/NpcWaypointGui.kt @@ -2,6 +2,7 @@ package moe.nea.firmament.features.world import io.github.notenoughupdates.moulconfig.observer.ObservableList import io.github.notenoughupdates.moulconfig.xml.Bind +import net.minecraft.network.chat.Component import moe.nea.firmament.features.events.anniversity.AnniversaryFeatures.atOnce import moe.nea.firmament.keybindings.SavedKeyBinding @@ -11,7 +12,7 @@ class NpcWaypointGui( data class NavigableWaypointW(val waypoint: NavigableWaypoint) { @Bind - fun name() = waypoint.name + fun name() = Component.literal(waypoint.name) @Bind fun isSelected() = NavigationHelper.targetWaypoint == waypoint diff --git a/src/main/kotlin/features/world/TemporaryWaypoints.kt b/src/main/kotlin/features/world/TemporaryWaypoints.kt index b36c49d..ac1600e 100644 --- a/src/main/kotlin/features/world/TemporaryWaypoints.kt +++ b/src/main/kotlin/features/world/TemporaryWaypoints.kt @@ -1,10 +1,9 @@ package moe.nea.firmament.features.world -import kotlin.compareTo -import kotlin.text.clear +import me.shedaniel.math.Color import kotlin.time.Duration.Companion.seconds -import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos +import net.minecraft.network.chat.Component +import net.minecraft.core.BlockPos import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ProcessChatEvent import moe.nea.firmament.events.WorldReadyEvent @@ -16,8 +15,8 @@ import moe.nea.firmament.util.render.RenderInWorldContext object TemporaryWaypoints { data class TemporaryWaypoint( - val pos: BlockPos, - val postedAt: TimeMark, + val pos: BlockPos, + val postedAt: TimeMark, ) val temporaryPlayerWaypointList = mutableMapOf<String, TemporaryWaypoint>() val temporaryPlayerWaypointMatcher = "(?i)x: (-?[0-9]+),? y: (-?[0-9]+),? z: (-?[0-9]+)".toPattern() @@ -38,24 +37,24 @@ object TemporaryWaypoints { if (temporaryPlayerWaypointList.isEmpty()) return RenderInWorldContext.renderInWorld(event) { temporaryPlayerWaypointList.forEach { (_, waypoint) -> - block(waypoint.pos, 0xFFFFFF00.toInt()) + block(waypoint.pos, Color.ofRGBA(255, 255, 0, 128).color) } temporaryPlayerWaypointList.forEach { (player, waypoint) -> val skin = - MC.networkHandler?.listedPlayerListEntries?.find { it.profile.name == player }?.skinTextures?.texture - withFacingThePlayer(waypoint.pos.toCenterPos()) { - waypoint(waypoint.pos, Text.stringifiedTranslatable("firmament.waypoint.temporary", player)) + MC.networkHandler?.listedOnlinePlayers?.find { it.profile.name == player }?.skin?.body + withFacingThePlayer(waypoint.pos.center) { + waypoint(waypoint.pos, Component.translatableEscape("firmament.waypoint.temporary", player)) if (skin != null) { matrixStack.translate(0F, -20F, 0F) // Head front texture( - skin, 16, 16, + skin.id(), 16, 16, // TODO: 1.21.10 test 1 / 8f, 1 / 8f, 2 / 8f, 2 / 8f, ) // Head overlay texture( - skin, 16, 16, + skin.id(), 16, 16, // TODO: 1.21.10 5 / 8f, 1 / 8f, 6 / 8f, 2 / 8f, ) diff --git a/src/main/kotlin/features/world/Waypoints.kt b/src/main/kotlin/features/world/Waypoints.kt index b5c2b66..9097d3a 100644 --- a/src/main/kotlin/features/world/Waypoints.kt +++ b/src/main/kotlin/features/world/Waypoints.kt @@ -4,9 +4,9 @@ import com.mojang.brigadier.arguments.IntegerArgumentType import me.shedaniel.math.Color import kotlin.time.Duration.Companion.hours import kotlin.time.Duration.Companion.seconds -import net.minecraft.command.argument.BlockPosArgumentType -import net.minecraft.text.Text -import net.minecraft.util.math.Vec3d +import net.minecraft.commands.arguments.coordinates.BlockPosArgument +import net.minecraft.network.chat.Component +import net.minecraft.world.phys.Vec3 import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.commands.get import moe.nea.firmament.commands.thenArgument @@ -16,17 +16,18 @@ import moe.nea.firmament.events.CommandEvent import moe.nea.firmament.events.TickEvent import moe.nea.firmament.events.WorldReadyEvent import moe.nea.firmament.events.WorldRenderLastEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.MC +import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.mc.asFakeServer import moe.nea.firmament.util.render.RenderInWorldContext import moe.nea.firmament.util.tr -object Waypoints : FirmamentFeature { - override val identifier: String +object Waypoints { + val identifier: String get() = "waypoints" + @Config object TConfig : ManagedConfig(identifier, Category.MINING) { // TODO: add to misc val tempWaypointDuration by duration("temp-waypoint-duration", 0.seconds, 1.hours) { 30.seconds } val showIndex by toggle("show-index") { true } @@ -35,7 +36,6 @@ object Waypoints : FirmamentFeature { // TODO: look ahead size } - override val config get() = TConfig var waypoints: FirmWaypoints? = null var orderedIndex = 0 @@ -45,25 +45,26 @@ object Waypoints : FirmamentFeature { RenderInWorldContext.renderInWorld(event) { if (!w.isOrdered) { w.waypoints.withIndex().forEach { - block(it.value.blockPos, 0x800050A0.toInt()) - if (TConfig.showIndex) withFacingThePlayer(it.value.blockPos.toCenterPos()) { - text(Text.literal(it.index.toString())) + block(it.value.blockPos, Color.ofRGBA(0, 80, 160, 128).color) + if (TConfig.showIndex) withFacingThePlayer(it.value.blockPos.center) { + text(Component.literal(it.index.toString())) } } } else { orderedIndex %= w.waypoints.size val firstColor = Color.ofRGBA(0, 200, 40, 180) - color(firstColor) - tracer(w.waypoints[orderedIndex].blockPos.toCenterPos(), lineWidth = 3f) - w.waypoints.withIndex().toList().wrappingWindow(orderedIndex, 3).zip(listOf( - firstColor, - Color.ofRGBA(180, 200, 40, 150), - Color.ofRGBA(180, 80, 20, 140), - )).reversed().forEach { (waypoint, col) -> + tracer(w.waypoints[orderedIndex].blockPos.center, color = firstColor.color, lineWidth = 3f) + w.waypoints.withIndex().toList().wrappingWindow(orderedIndex, 3).zip( + listOf( + firstColor, + Color.ofRGBA(180, 200, 40, 150), + Color.ofRGBA(180, 80, 20, 140), + ) + ).reversed().forEach { (waypoint, col) -> val (index, pos) = waypoint block(pos.blockPos, col.color) - if (TConfig.showIndex) withFacingThePlayer(pos.blockPos.toCenterPos()) { - text(Text.literal(index.toString())) + if (TConfig.showIndex) withFacingThePlayer(pos.blockPos.center) { + text(Component.literal(index.toString())) } } } @@ -75,13 +76,13 @@ object Waypoints : FirmamentFeature { val w = useNonEmptyWaypoints() ?: return if (!w.isOrdered) return orderedIndex %= w.waypoints.size - val p = MC.player?.pos ?: return + val p = MC.player?.position ?: return if (TConfig.skipToNearest) { orderedIndex = - (w.waypoints.withIndex().minBy { it.value.blockPos.getSquaredDistance(p) }.index + 1) % w.waypoints.size + (w.waypoints.withIndex().minBy { it.value.blockPos.distToCenterSqr(p) }.index + 1) % w.waypoints.size } else { - if (w.waypoints[orderedIndex].blockPos.isWithinDistance(p, 3.0)) { + if (w.waypoints[orderedIndex].blockPos.closerToCenterThan(p, 3.0)) { orderedIndex = (orderedIndex + 1) % w.waypoints.size } } @@ -116,16 +117,20 @@ object Waypoints : FirmamentFeature { @Subscribe fun onCommand(event: CommandEvent.SubCommand) { event.subcommand("waypoint") { - thenArgument("pos", BlockPosArgumentType.blockPos()) { pos -> + thenArgument("pos", BlockPosArgument.blockPos()) { pos -> thenExecute { source - val position = pos.get(this).toAbsoluteBlockPos(source.asFakeServer()) + val position = pos.get(this).getBlockPos(source.asFakeServer()) val w = useEditableWaypoints() w.waypoints.add(FirmWaypoints.Waypoint.from(position)) - source.sendFeedback(Text.stringifiedTranslatable("firmament.command.waypoint.added", - position.x, - position.y, - position.z)) + source.sendFeedback( + Component.translatableEscape( + "firmament.command.waypoint.added", + position.x, + position.y, + position.z + ) + ) } } } @@ -133,9 +138,12 @@ object Waypoints : FirmamentFeature { thenLiteral("reset") { thenExecute { orderedIndex = 0 - source.sendFeedback(tr( - "firmament.command.waypoint.reset", - "Reset your ordered waypoint index back to 0. If you want to delete all waypoints use /firm waypoints clear instead.")) + source.sendFeedback( + tr( + "firmament.command.waypoint.reset", + "Reset your ordered waypoint index back to 0. If you want to delete all waypoints use /firm waypoints clear instead." + ) + ) } } thenLiteral("changeindex") { @@ -157,10 +165,13 @@ object Waypoints : FirmamentFeature { w.waypoints.add( if (toIndex > fromIndex) toIndex - 1 else toIndex, - waypoint) + waypoint + ) source.sendFeedback( - tr("firmament.command.waypoint.indexchange", - "Moved waypoint from index $fromIndex to $toIndex. Note that this only matters for ordered waypoints.") + tr( + "firmament.command.waypoint.indexchange", + "Moved waypoint from index $fromIndex to $toIndex. Note that this only matters for ordered waypoints." + ) ) } } @@ -169,7 +180,7 @@ object Waypoints : FirmamentFeature { thenLiteral("clear") { thenExecute { waypoints = null - source.sendFeedback(Text.translatable("firmament.command.waypoint.clear")) + source.sendFeedback(Component.translatable("firmament.command.waypoint.clear")) } } thenLiteral("toggleordered") { @@ -177,11 +188,11 @@ object Waypoints : FirmamentFeature { val w = useEditableWaypoints() w.isOrdered = !w.isOrdered if (w.isOrdered) { - val p = MC.player?.pos ?: Vec3d.ZERO + val p = MC.player?.position ?: Vec3.ZERO orderedIndex = // TODO: this should be extracted to a utility method - w.waypoints.withIndex().minByOrNull { it.value.blockPos.getSquaredDistance(p) }?.index ?: 0 + w.waypoints.withIndex().minByOrNull { it.value.blockPos.distToCenterSqr(p) }?.index ?: 0 } - source.sendFeedback(Text.translatable("firmament.command.waypoint.ordered.toggle.${w.isOrdered}")) + source.sendFeedback(Component.translatable("firmament.command.waypoint.ordered.toggle.${w.isOrdered}")) } } thenLiteral("skip") { @@ -189,9 +200,9 @@ object Waypoints : FirmamentFeature { val w = useNonEmptyWaypoints() if (w != null && w.isOrdered) { orderedIndex = (orderedIndex + 1) % w.size - source.sendFeedback(Text.translatable("firmament.command.waypoint.skip")) + source.sendFeedback(Component.translatable("firmament.command.waypoint.skip")) } else { - source.sendError(Text.translatable("firmament.command.waypoint.skip.error")) + source.sendError(Component.translatable("firmament.command.waypoint.skip.error")) } } } @@ -202,10 +213,14 @@ object Waypoints : FirmamentFeature { val w = useNonEmptyWaypoints() if (w != null && index in w.waypoints.indices) { w.waypoints.removeAt(index) - source.sendFeedback(Text.stringifiedTranslatable("firmament.command.waypoint.remove", - index)) + source.sendFeedback( + Component.translatableEscape( + "firmament.command.waypoint.remove", + index + ) + ) } else { - source.sendError(Text.stringifiedTranslatable("firmament.command.waypoint.remove.error")) + source.sendError(Component.translatableEscape("firmament.command.waypoint.remove.error")) } } } @@ -214,12 +229,16 @@ object Waypoints : FirmamentFeature { } fun textInvalidIndex(index: Int) = - tr("firmament.command.waypoint.invalid-index", - "Invalid index $index provided.") - - fun textNothingToExport(): Text = - tr("firmament.command.waypoint.export.nowaypoints", - "No waypoints to export found. Add some with /firm waypoint ~ ~ ~.") + tr( + "firmament.command.waypoint.invalid-index", + "Invalid index $index provided." + ) + + fun textNothingToExport(): Component = + tr( + "firmament.command.waypoint.export.nowaypoints", + "No waypoints to export found. Add some with /firm waypoint ~ ~ ~." + ) } fun <E> List<E>.wrappingWindow(startIndex: Int, windowSize: Int): List<E> { |
