Some code for allowing multiple worms

This commit is contained in:
DBotThePony 2025-03-09 12:49:53 +07:00
parent 274b5c059a
commit 7736762c86
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -40,29 +40,29 @@ class WormPlacement(
val maxTravelDown: Int = Int.MAX_VALUE,
val maxTravelUp: Int = Int.MAX_VALUE,
) : AbstractEnormousPlacement(parameters) {
override fun getPositions(center: BlockPos, random: RandomSource): Stream<BlockPos> {
var position = Vector.ZERO
val maxDistance = length.sample(random)
// determine initial worm facing angle
var xzRotation = random.nextDouble(-PI / 2.0, PI / 2.0)
var xyRotation = normalizeAngle(initialAngleXY.sample(random).toDouble())
private inner class Worm(private val random: RandomSource, private var position: Vector) {
private var remainingDistance = length.sample(random)
private var xzRotation = random.nextDouble(-PI / 2.0, PI / 2.0)
private var xyRotation = normalizeAngle(initialAngleXY.sample(random).toDouble())
private var xzTargetRotation = random.nextDouble(-PI / 2.0, PI / 2.0)
private var xyTargetRotation = normalizeAngle(initialAngleXY.sample(random).toDouble())
// determine initial "turn to" angle
var xzTargetRotation = random.nextDouble(-PI / 2.0, PI / 2.0)
var xyTargetRotation = normalizeAngle(initialAngleXY.sample(random).toDouble())
private var xzSin = sin(xzRotation)
private var xzCos = cos(xzRotation)
private var xySin = sin(xyRotation)
var xzSin = sin(xzRotation)
var xzCos = cos(xzRotation)
var xySin = sin(xyRotation)
private val turnChanceXZ = this@WormPlacement.turnChanceXZ.instance()
private val turnChanceXY = this@WormPlacement.turnChanceXY.instance()
val positions = ArrayList<BlockPos>()
var prevPos = position.toBlockPos()
positions.add(prevPos)
val hasFinished: Boolean
get() = remainingDistance <= 0
val turnChanceXZ = turnChanceXZ.instance()
val turnChanceXY = turnChanceXY.instance()
private var prevPos = BlockPos.ZERO
fun follow(): BlockPos? {
if (hasFinished) return null
remainingDistance--
for (traveledDistance in 0 .. maxDistance) {
// wormy turn
if (turnChanceXZ.sample(random)) {
// wormy angle
@ -122,7 +122,24 @@ class WormPlacement(
if (calc != prevPos) {
// if worm made a wurm, add new position to set
prevPos = calc
positions.add(calc)
return calc
}
return null
}
}
override fun getPositions(center: BlockPos, random: RandomSource): Stream<BlockPos> {
val worms = ArrayList<Worm>()
worms.add(Worm(random, Vector.ZERO))
val positions = ArrayList<BlockPos>()
positions.add(BlockPos.ZERO)
while (worms.isNotEmpty()) {
worms.removeIf {
val pos = it.follow()
if (pos != null) positions.add(pos)
it.hasFinished
}
}