diff options
Diffstat (limited to 'src/main/kotlin/features/world/Waypoints.kt')
| -rw-r--r-- | src/main/kotlin/features/world/Waypoints.kt | 119 |
1 files changed, 69 insertions, 50 deletions
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> { |
