-
Notifications
You must be signed in to change notification settings - Fork 20
feat(AutoSpiral): Add AutoSpiral module #234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IceTank
wants to merge
9
commits into
lambda-client:1.21.11
Choose a base branch
from
IceTank:feature/module/AutoSpiral
base: 1.21.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5991d55
feat(AutoSpiral): Add AutoSpiral module that works in the overworld l…
IceTank b0a759c
feat(AutoSpiral): Add buttons
IceTank 361314a
refactor(AutoSpiral): Clean up code formatting and improve readability
IceTank 7391ee1
Revert Configurable.kt lint
IceTank d71a475
refactor(AutoSpiral): Rename variables for clarity and improve code s…
IceTank 97e37f6
Move SpiralIterator2d file
IceTank fc3f97a
Move AutoSpiral module file
IceTank 447f497
Fix pr code comments
IceTank 702b445
Remove GuiButtons implementation for AutoSpiral
IceTank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/main/kotlin/com/lambda/module/modules/movement/AutoSpiral.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * Copyright 2026 Lambda | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.lambda.module.modules.movement | ||
|
|
||
| import baritone.api.pathing.goals.GoalXZ | ||
| import com.lambda.context.SafeContext | ||
| import com.lambda.event.events.TickEvent | ||
| import com.lambda.event.listener.SafeListener.Companion.listen | ||
| import com.lambda.interaction.BaritoneManager | ||
| import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest | ||
| import com.lambda.interaction.managers.rotating.visibilty.lookAt | ||
| import com.lambda.module.Module | ||
| import com.lambda.module.tag.ModuleTag | ||
| import com.lambda.threading.runSafe | ||
| import com.lambda.util.BlockPosIterators | ||
| import com.lambda.util.extension.isNether | ||
| import net.minecraft.util.math.BlockPos | ||
| import kotlin.math.sqrt | ||
|
|
||
| @Suppress("unused") | ||
| object AutoSpiral : Module( | ||
| name = "AutoSpiral", | ||
| description = "Automatically flies in a spiral pattern. Uses Baritone elytra pathing in the Nether.", | ||
| tag = ModuleTag.MOVEMENT, | ||
| ) { | ||
| var iterator: BlockPosIterators.SpiralIterator2d? = null | ||
| var currentWaypoint: BlockPos? = null | ||
|
|
||
| var spiralSpacing by setting("Spiral Spacing", 128, 16..1024, description = "The distance between each loop of the spiral") | ||
| var waypointTriggerDistance by setting("Waypoint Trigger Distance", 4, 2..64, description = "The distance to the waypoint at which a new waypoint is generated. Put in 50-60 range when in the Nether.") | ||
| var setCenterOnEnable by setting("Set Center On Enable", true, description = "Whether to set the center of the spiral to your current position when enabling the module.") | ||
| var setBaritoneGoal by setting("Set Baritone Goal", true, description = "Whether to set Baritone's goal to the current waypoint. Mostly so you can see where the next waypoint is.") | ||
|
|
||
| var center by setting("Center", BlockPos.ORIGIN, description = "Center position for the spiral") | ||
|
|
||
| init { | ||
| onEnable { | ||
| if (iterator == null) { | ||
| iterator = BlockPosIterators.SpiralIterator2d(10000) | ||
| if (setCenterOnEnable) { | ||
| center = BlockPos.ORIGIN | ||
| } | ||
| } | ||
| } | ||
|
|
||
| onDisable { | ||
| iterator = null | ||
| currentWaypoint = null | ||
| BaritoneManager.cancel() | ||
| } | ||
|
|
||
| listen<TickEvent.Pre> { | ||
| if (currentWaypoint == null || waypointReached()) { | ||
| nextWaypoint() | ||
| } | ||
|
|
||
| currentWaypoint?.let { waypoint -> | ||
| if (!world.isNether) { | ||
| rotationRequest { | ||
| lookAt(waypoint.toCenterPos()).yaw | ||
| }.submit(true) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun SafeContext.waypointReached(): Boolean { | ||
| return currentWaypoint?.let { | ||
| val distance = distanceXZ(player.blockPos, it) | ||
| return distance <= waypointTriggerDistance | ||
| } ?: false | ||
| } | ||
|
|
||
| private fun distanceXZ(a: BlockPos, b: BlockPos): Double { | ||
| val dx = (a.x - b.x).toDouble() | ||
| val dz = (a.z - b.z).toDouble() | ||
| return sqrt(dx * dx + dz * dz) | ||
| } | ||
|
|
||
| private fun SafeContext.nextWaypoint() { | ||
| iterator?.next()?.let { pos -> | ||
| val scaled = pos.multiply(spiralSpacing) | ||
| val w = scaled.add(center) | ||
| if (world.isNether) { | ||
| BaritoneManager.setGoalAndElytraPath(GoalXZ(w.x, w.z)) | ||
| } else { | ||
| if (setBaritoneGoal) BaritoneManager.setGoal(GoalXZ(w.x, w.z)) | ||
| } | ||
| currentWaypoint = w | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* | ||
| * Copyright 2026 Lambda | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.lambda.util | ||
|
|
||
| import net.minecraft.util.math.BlockPos | ||
| import kotlin.math.floor | ||
| import kotlin.math.pow | ||
|
|
||
| /** | ||
| * A collection of Block position iterator implementations for various purposes. | ||
IceTank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| object BlockPosIterators { | ||
| /** | ||
| * Spiral outwards from a central position in growing squares. | ||
| * Every point has a constant distance to its previous and following position of 1. First point returned is the starting position. | ||
| * Generates positions like this: | ||
| * ```text | ||
| * 16 15 14 13 12 | ||
| * 17 4 3 2 11 | ||
| * 18 5 0 1 10 | ||
| * 19 6 7 8 9 | ||
| * 20 21 22 23 24 | ||
| * (maxDistance = 2; points returned = 25) | ||
| * ``` | ||
| * | ||
| * @see <a href="https://stackoverflow.com/questions/3706219/algorithm-for-iterating-over-an-outward-spiral-on-a-discrete-2d-grid-from-the-or">StackOverflow: Algorithm for iterating over an outward spiral on a discrete 2d grid</a> | ||
| * | ||
| */ | ||
| class SpiralIterator2d(maxDistance: Int) : MutableIterator<BlockPos?> { | ||
| val totalPoints: Int = floor(((floor(maxDistance.toDouble()) - 0.5) * 2).pow(2.0)).toInt() | ||
| private var deltaX: Int = 1 | ||
| private var deltaZ: Int = 0 | ||
| private var segmentLength: Int = 1 | ||
| private var currentX: Int = 0 | ||
| private var currentZ: Int = 0 | ||
| private var stepsInCurrentSegment: Int = 0 | ||
| var pointsGenerated: Int = 0 | ||
|
|
||
| override fun next(): BlockPos? { | ||
| if (this.pointsGenerated >= this.totalPoints) return null | ||
| val output = BlockPos(this.currentX, 0, this.currentZ) | ||
| this.currentX += this.deltaX | ||
| this.currentZ += this.deltaZ | ||
| this.stepsInCurrentSegment += 1 | ||
| if (this.stepsInCurrentSegment == this.segmentLength) { | ||
| this.stepsInCurrentSegment = 0 | ||
| val buffer = this.deltaX | ||
| this.deltaX = -this.deltaZ | ||
| this.deltaZ = buffer | ||
| if (this.deltaZ == 0) { | ||
| this.segmentLength += 1 | ||
| } | ||
| } | ||
| this.pointsGenerated += 1 | ||
| return output | ||
| } | ||
|
|
||
| override fun hasNext(): Boolean { | ||
| return this.pointsGenerated < this.totalPoints | ||
| } | ||
|
|
||
| override fun remove() { | ||
| throw UnsupportedOperationException("remove") | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.