Terrain fixes

This commit is contained in:
DBotThePony 2024-04-18 16:27:33 +07:00
parent 46900554c3
commit dbef69d6e6
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 24 additions and 21 deletions

View File

@ -214,7 +214,7 @@ data class ItemDescriptor(
return ref.type.factory(ref, jConfig, jParameters, count)
} catch (err: Throwable) {
LOGGER.error("Error while generating randomized item '$name' using script $builder", err)
LOGGER.error("Error while building item '$name' using script $builder", err)
return ref.type.factory(ref, ref.json, parameters.deepCopy(), count)
}
}

View File

@ -50,7 +50,7 @@ data class TileDefinition(
val cascading: Boolean = false,
val falling: Boolean = false,
val foregroundOnly: Boolean = collisionKind != CollisionType.BLOCK,
val supportsMods: Boolean = !(falling || !cascading || collisionKind != CollisionType.BLOCK),
val supportsMods: Boolean = !(falling || cascading || collisionKind != CollisionType.BLOCK),
val blocksLiquidFlow: Boolean = collisionKind.isSolidCollision,
) : IRenderableTile, IThingWithDescription by descriptionData {
init {

View File

@ -12,7 +12,7 @@ data class TerrainSelectorParameters(
val baseHeight: Double,
val worldHeight: Int = 0,
val seed: Long = 0L,
val commonality: Double = 0.0
val commonality: Double = 1.0
) {
fun withSeed(seed: Long) = copy(seed = seed)
fun withCommonality(commonality: Double) = copy(commonality = commonality)

View File

@ -74,8 +74,8 @@ class RidgeBlocksTerrainSelector(data: Data, parameters: TerrainSelectorParamete
if (parameters.commonality <= 0.0) {
return 0.0
} else {
val x = perlin[x.toDouble(), y.toDouble()]
val y = perlin[y.toDouble(), x]
val x = x + perlin[x.toDouble(), y.toDouble()]
val y = y + perlin[y.toDouble(), x]
return (ridge1[x, y] - ridge2[x, y]) * parameters.commonality + data.bias
}
}

View File

@ -96,31 +96,34 @@ class WormCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters)
else
1.0
wormRadius *= taperFactor
//wormRadius *= taperFactor
// carve out worm area
val size = ceil(wormRadius)
var dx = -size
var dy = -size
if (wormRadius >= 1.0) {
val size = ceil(wormRadius)
var dx = -size
var dy = -size
while (dx <= size) {
while (dy <= size) {
val m = sqrt(dx * dx + dy * dy)
while (dx <= size) {
while (dy <= size) {
val m = sqrt(dx * dx + dy * dy)
if (m <= wormRadius) {
// TODO: maybe roundToInt()?
val x = (dx + worm.pos.x).toInt()
val y = (dy + worm.pos.y).toInt()
if (m < wormRadius) {
// TODO: maybe roundToInt()?
val x = (dx + worm.pos.x).toInt()
val y = (dy + worm.pos.y).toInt()
if (isInside(x, y)) {
this[x, y] = this[x, y].coerceAtLeast(wormRadius - m)
if (isInside(x, y)) {
this[x, y] = this[x, y].coerceAtLeast(wormRadius - m)
}
}
dy += 1.0
}
dy += 1.0
dy = -size
dx += 1.0
}
dx += 1.0
}
// move the worm, slowing down a bit as we