Skip to content

Commit 094c874

Browse files
committed
More dynamic configuration of the highway
1 parent e5f4256 commit 094c874

File tree

3 files changed

+131
-71
lines changed

3 files changed

+131
-71
lines changed

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

Lines changed: 115 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import com.lambda.util.BaritoneUtils
1010
import com.lambda.util.Communication.info
1111
import com.lambda.util.player.MovementUtils.octant
1212
import com.lambda.util.extension.Structure
13+
import com.lambda.util.extension.moveY
14+
import com.lambda.util.math.MathUtils.ceilToInt
15+
import com.lambda.util.math.MathUtils.floorToInt
16+
import com.lambda.util.math.VecUtils.rotateClockwise
1317
import com.lambda.util.world.StructureUtils.generateDirectionalTube
1418
import net.minecraft.block.Blocks
1519
import net.minecraft.util.math.BlockPos
@@ -23,22 +27,38 @@ object HighwayTools : Module(
2327
description = "Auto highway builder",
2428
defaultTags = setOf(ModuleTag.PLAYER, ModuleTag.AUTOMATION)
2529
) {
26-
private val height by setting("Height", 4, 1..10, 1)
30+
private val height by setting("Height", 4, 2..10, 1)
2731
private val width by setting("Width", 6, 1..30, 1)
28-
private val rimHeight by setting("Rim Height", 1, 0..6, 1)
29-
private val cornerBlock by setting("Corner Block", false, description = "Include corner blocks in the highway")
30-
private val ceiling by setting("Ceiling", false, description = "Smooth roof over the highway")
31-
private val ceilingMaterial by setting("Ceiling Material", Blocks.OBSIDIAN, description = "Material to build the ceiling with") { ceiling }
32-
private val distance by setting("Distance", -1, -1..1000000, 1, description = "Distance to build the highway (negative for infinite)")
32+
private val pavement by setting("Pavement", Material.Block, description = "Material for the pavement")
33+
private val rimHeight by setting("Pavement Rim Height", 1, 0..6, 1) { pavement != Material.Any }
34+
private val cornerBlock by setting("Corner", Corner.None, description = "Include corner blocks in the highway") { pavement != Material.Any }
35+
private val pavementMaterial by setting("Pavement Material", Blocks.OBSIDIAN, description = "Material to build the highway with") { pavement == Material.Block }
36+
private val floor by setting("Floor", Material.Any, description = "Material for the floor")
37+
private val floorMaterial by setting("Floor Material", Blocks.NETHERRACK, description = "Material to build the floor with") { floor == Material.Block }
38+
private val walls by setting("Walls", Material.Any, description = "Material for the walls")
39+
private val wallMaterial by setting("Wall Material", Blocks.NETHERRACK, description = "Material to build the walls with") { walls == Material.Block }
40+
private val ceiling by setting("Ceiling", Material.Any, description = "Material for the ceiling")
41+
private val ceilingMaterial by setting("Ceiling Material", Blocks.OBSIDIAN, description = "Material to build the ceiling with") { ceiling == Material.Block }
42+
private val distance by setting("Distance", -1, -1..1000000, 1, description = "Distance to build the highway/tunnel (negative for infinite)")
3343
private val sliceSize by setting("Slice Size", 3, 1..5, 1, description = "Number of slices to build at once")
34-
private val material by setting("Highway Material", Blocks.OBSIDIAN, description = "Material to build the highway with")
3544

3645
private var octant = EightWayDirection.NORTH
3746
private var distanceMoved = 0
3847
private var startPos = BlockPos.ORIGIN
3948
private var currentPos = BlockPos.ORIGIN
4049
private var runningTask: Task<*>? = null
4150

51+
enum class Material {
52+
Any,
53+
Solid,
54+
Block,
55+
}
56+
57+
enum class Corner {
58+
None,
59+
Solid,
60+
}
61+
4262
init {
4363
onEnable {
4464
octant = player.octant
@@ -58,7 +78,7 @@ object HighwayTools : Module(
5878
distanceMoved += sliceSize
5979

6080
var structure: Structure = mutableMapOf()
61-
val slice = highwaySlice()
81+
val slice = generateSlice()
6282
repeat(sliceSize) {
6383
val vec = Vec3i(octant.offsetX, 0, octant.offsetZ)
6484
currentPos = currentPos.add(vec)
@@ -77,93 +97,121 @@ object HighwayTools : Module(
7797
}.start(null)
7898
}
7999

80-
private fun highwaySlice(): Structure {
100+
private fun generateSlice(): Structure {
81101
val structure = mutableMapOf<BlockPos, TargetState>()
82-
val orthogonal = EightWayDirection.entries[(octant.ordinal + 2).mod(8)]
83-
val center = (width / 2.0).roundToInt()
102+
val orthogonal = octant.rotateClockwise(2)
103+
val center = (width / 2.0).floorToInt()
84104

85-
// Area to clear
105+
// Hole
86106
structure += generateDirectionalTube(
87107
orthogonal,
88108
width,
89109
height,
90110
-center,
91-
-1,
92-
).associateWith { TargetState.Air }
93-
94-
// Highway
95-
structure += generateDirectionalTube(
96-
orthogonal,
97-
width,
98-
1,
99-
-center,
100-
-1,
101-
).associateWith { TargetState.Block(material) }
102-
103-
// Left rim
104-
structure += generateDirectionalTube(
105-
orthogonal,
106-
1,
107-
rimHeight,
108-
-center + width - 1,
109-
0,
110-
).associateWith { TargetState.Block(material) }
111-
112-
// Right rim
113-
structure += generateDirectionalTube(
114-
orthogonal,
115-
1,
116-
rimHeight,
117-
-center,
118111
0,
119-
).associateWith { TargetState.Block(material) }
112+
).associateWith { TargetState.Air }
120113

121-
if (!cornerBlock) {
122-
structure -= generateDirectionalTube(
114+
if (pavement != Material.Any) {
115+
structure += generateDirectionalTube(
123116
orthogonal,
117+
width,
124118
1,
119+
-center,
120+
0,
121+
).associateWith { target(pavement, pavementMaterial) }
122+
123+
// Left rim
124+
structure += generateDirectionalTube(
125+
orthogonal,
125126
1,
127+
rimHeight,
126128
-center + width - 1,
127-
-1,
128-
)
129+
1,
130+
).associateWith { target(pavement, pavementMaterial) }
129131

130-
structure -= generateDirectionalTube(
132+
// Right rim
133+
structure += generateDirectionalTube(
131134
orthogonal,
132135
1,
136+
rimHeight,
137+
-center,
138+
1,
139+
).associateWith { target(pavement, pavementMaterial) }
140+
141+
if (cornerBlock == Corner.None) {
142+
// Support for the left rim
143+
structure += generateDirectionalTube(
144+
orthogonal,
145+
1,
146+
1,
147+
-center + width - 1,
148+
0,
149+
).associateWith { TargetState.Support(Direction.UP) }
150+
151+
// Support for the right rim
152+
structure += generateDirectionalTube(
153+
orthogonal,
154+
1,
155+
1,
156+
-center,
157+
0,
158+
).associateWith { TargetState.Support(Direction.UP) }
159+
}
160+
}
161+
162+
if (ceiling != Material.Any) {
163+
structure += generateDirectionalTube(
164+
orthogonal,
165+
width,
133166
1,
134167
-center,
135-
-1,
136-
)
168+
height,
169+
).associateWith { target(ceiling, ceilingMaterial) }
137170
}
138171

139-
// Support for the left corner
140-
structure += generateDirectionalTube(
141-
orthogonal,
142-
1,
143-
1,
144-
-center + width - 1,
145-
-1,
146-
).associateWith { TargetState.Support(Direction.UP) }
172+
if (walls != Material.Any) {
173+
// Left wall
174+
structure += generateDirectionalTube(
175+
orthogonal,
176+
1,
177+
height,
178+
-center + width,
179+
0,
180+
).associateWith { target(walls, wallMaterial) }
147181

148-
// Support for the right corner
149-
structure += generateDirectionalTube(
150-
orthogonal,
151-
1,
152-
1,
153-
-center,
154-
-1,
155-
).associateWith { TargetState.Support(Direction.UP) }
182+
// Right wall
183+
structure += generateDirectionalTube(
184+
orthogonal,
185+
1,
186+
height,
187+
-center - 1,
188+
0,
189+
).associateWith { target(walls, wallMaterial) }
190+
}
156191

157-
if (ceiling) {
192+
if (floor != Material.Any) {
158193
structure += generateDirectionalTube(
159194
orthogonal,
160195
width,
161196
1,
162197
-center,
163-
height - 1,
164-
).associateWith { TargetState.Block(ceilingMaterial) }
198+
-1,
199+
).associateWith { target(floor, floorMaterial) }
200+
}
201+
202+
val transformed = when {
203+
pavement != Material.Any -> structure.moveY(-1)
204+
else -> structure
165205
}
166206

167-
return structure
207+
return transformed
208+
}
209+
210+
private fun target(target: Material, material: net.minecraft.block.Block): TargetState {
211+
return when (target) {
212+
Material.Solid -> TargetState.Solid
213+
Material.Block -> TargetState.Block(material)
214+
else -> throw IllegalStateException("Invalid material")
215+
}
168216
}
169217
}

common/src/main/kotlin/com/lambda/util/extension/Aliases.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@ import net.minecraft.util.math.BlockPos
77

88
typealias CommandBuilder = LiteralArgumentBuilder<CommandSource>
99
typealias Structure = Map<BlockPos, TargetState>
10+
11+
fun Structure.move(offset: BlockPos): Structure =
12+
mapKeys { (pos, _) -> pos.add(offset) }
13+
14+
fun Structure.moveX(x: Int): Structure =
15+
mapKeys { (pos, _) -> pos.east(x) }
16+
17+
fun Structure.moveY(y: Int): Structure =
18+
mapKeys { (pos, _) -> pos.up(y) }
19+
20+
fun Structure.moveZ(z: Int): Structure =
21+
mapKeys { (pos, _) -> pos.south(z) }

common/src/main/kotlin/com/lambda/util/math/VecUtils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package com.lambda.util.math
22

33
import com.lambda.util.math.MathUtils.sq
4-
import com.lambda.util.world.FastVector
5-
import com.lambda.util.world.x
6-
import com.lambda.util.world.y
7-
import com.lambda.util.world.z
84
import net.minecraft.entity.Entity
95
import net.minecraft.util.math.BlockPos
106
import net.minecraft.util.math.Direction
7+
import net.minecraft.util.math.EightWayDirection
118
import net.minecraft.util.math.Vec3d
129
import net.minecraft.util.math.Vec3i
1310
import kotlin.math.pow
@@ -25,6 +22,9 @@ object VecUtils {
2522
val Direction.hitVecOffset get() =
2623
CENTER + vector.vec3d * 0.5
2724

25+
fun EightWayDirection.rotateClockwise(steps: Int) =
26+
EightWayDirection.entries[(ordinal + steps) % 8]
27+
2828
infix fun Vec3d.dist(other: Vec3d): Double = this.distanceTo(other)
2929

3030
infix fun Vec3d.distSq(other: Vec3d): Double = this.squaredDistanceTo(other)

0 commit comments

Comments
 (0)