Skip to content

Commit ba1ded8

Browse files
committed
Build in n long slices
1 parent 66675f2 commit ba1ded8

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

common/src/main/kotlin/com/lambda/module/modules/player/HighwayTools.kt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.lambda.task.tasks.BuildStructure.Companion.buildStructure
1010
import com.lambda.util.BaritoneUtils.primary
1111
import com.lambda.util.Communication.info
1212
import com.lambda.util.KeyCode
13-
import com.lambda.util.player.MovementUtils.direction
13+
import com.lambda.util.player.MovementUtils.octant
1414
import com.lambda.util.primitives.extension.Structure
1515
import com.lambda.util.world.StructureUtils.generateDirectionalTube
1616
import net.minecraft.block.Blocks
@@ -31,18 +31,19 @@ object HighwayTools : Module(
3131
private val cornerBlock by setting("Corner Block", false, description = "Include corner blocks in the highway")
3232
private val material = Blocks.OBSIDIAN
3333
private val distance by setting("Distance", -1, -1..1000000, 1, description = "Distance to build the highway (negative for infinite)")
34+
private val sliceSize by setting("Slice Size", 3, 1..5, 1, description = "Number of slices to build at once")
3435
// ToDo: Fix block setting
3536
// private val material by setting("Material", Blocks.OBSIDIAN, description = "Material to build the highway with")
3637

37-
private var direction = EightWayDirection.NORTH
38+
private var octant = EightWayDirection.NORTH
3839
private var distanceMoved = 0
3940
private var startPos = BlockPos.ORIGIN
4041
private var currentPos = BlockPos.ORIGIN
4142
private var runningTask: Task<*>? = null
4243

4344
init {
4445
onEnable {
45-
direction = player.direction()
46+
octant = player.octant
4647
startPos = player.blockPos
4748
currentPos = startPos
4849
buildSlice()
@@ -55,22 +56,22 @@ object HighwayTools : Module(
5556
}
5657

5758
private fun buildSlice() {
58-
val blueprint = generateHighway()
59-
.map { it.key.add(currentPos) to it.value }
60-
.toMap()
61-
.toBlueprint()
59+
distanceMoved += sliceSize
60+
61+
var structure: Structure = mutableMapOf()
62+
val slice = highwaySlice()
63+
repeat(sliceSize) {
64+
val vec = Vec3i(octant.offsetX, 0, octant.offsetZ)
65+
currentPos = currentPos.add(vec)
66+
structure += slice.map { it.key.add(currentPos) to it.value }
67+
}
6268

6369
buildStructure {
64-
blueprint
70+
structure.toBlueprint()
6571
}.apply {
6672
runningTask = this
67-
primary.customGoalProcess.setGoalAndPath(GoalNear(currentPos, 1))
73+
primary.customGoalProcess.setGoalAndPath(GoalNear(currentPos, sliceSize))
6874
onSuccess { _, _ ->
69-
distanceMoved++
70-
71-
val vec = Vec3i(direction.offsetX, 0, direction.offsetZ)
72-
currentPos = currentPos.add(vec)
73-
7475
if (distanceMoved < distance || distance < 0) {
7576
buildSlice()
7677
} else {
@@ -82,9 +83,9 @@ object HighwayTools : Module(
8283
}
8384
}
8485

85-
private fun generateHighway(): Structure {
86+
private fun highwaySlice(): Structure {
8687
val structure = mutableMapOf<BlockPos, TargetState>()
87-
val orthogonal = EightWayDirection.entries[(direction.ordinal + 2).mod(8)]
88+
val orthogonal = EightWayDirection.entries[(octant.ordinal + 2).mod(8)]
8889
val center = (width / 2.0).roundToInt()
8990

9091
// Area to clear

common/src/main/kotlin/com/lambda/util/player/MovementUtils.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,16 @@ object MovementUtils {
8484
val Entity.moveDelta get() = moveDiff.let { hypot(it.x, it.z) }
8585
val Entity.motionDelta get() = hypot(this.velocity.x, this.velocity.z)
8686

87-
fun Entity.direction(): EightWayDirection {
88-
// Normalize the yaw to be within the range of -180 to 179 degrees
89-
var normalizedYaw = (yaw + 180.0) % 360.0
90-
if (normalizedYaw < 0) {
91-
normalizedYaw += 360.0
87+
val Entity.octant: EightWayDirection
88+
get() {
89+
// Normalize the yaw to be within the range of -180 to 179 degrees
90+
var normalizedYaw = (yaw + 180.0) % 360.0
91+
if (normalizedYaw < 0) {
92+
normalizedYaw += 360.0
93+
}
94+
95+
// Calculate the index of the closest direction
96+
val directionIndex = ((normalizedYaw + 22.5) / 45.0).toInt() % 8
97+
return EightWayDirection.entries[directionIndex]
9298
}
93-
94-
// Calculate the index of the closest direction
95-
val directionIndex = ((normalizedYaw + 22.5) / 45.0).toInt() % 8
96-
return EightWayDirection.entries[directionIndex]
97-
}
9899
}

0 commit comments

Comments
 (0)