Proper biome item placement

This commit is contained in:
DBotThePony 2024-04-21 23:32:29 +07:00
parent 82c2d1315e
commit 81492f2985
Signed by: DBot
GPG Key ID: DCC23B5715498507
5 changed files with 31 additions and 4 deletions

View File

@ -19,10 +19,12 @@ import ru.dbotthepony.kstarbound.defs.tile.NO_DUNGEON_ID
import ru.dbotthepony.kstarbound.defs.tile.TileDefinition
import ru.dbotthepony.kstarbound.defs.tile.TileModifierDefinition
import ru.dbotthepony.kstarbound.defs.tile.isNotEmptyTile
import ru.dbotthepony.kstarbound.defs.world.BiomePlaceables
import ru.dbotthepony.kstarbound.defs.world.FloatingDungeonWorldParameters
import ru.dbotthepony.kstarbound.math.AABB
import ru.dbotthepony.kstarbound.server.world.ServerChunk
import ru.dbotthepony.kstarbound.server.world.ServerWorld
import ru.dbotthepony.kstarbound.util.random.random
import ru.dbotthepony.kstarbound.world.ChunkPos
import ru.dbotthepony.kstarbound.world.ChunkState
import ru.dbotthepony.kstarbound.world.Direction
@ -538,8 +540,27 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
}, Starbound.EXECUTOR)
}
val biomeTreesFutures = biomeTrees.map {
CompletableFuture.supplyAsync(Supplier {
parent.template.potentialBiomeItemsAt(it.x, it.y).surfaceBiomeItems to it
}, Starbound.EXECUTOR)
}
val biomeItems = ArrayList<() -> Unit>()
for (biomeTree in biomeTreesFutures) {
try {
val (placeables, pos) = biomeTree.await()
val trees = placeables.filter { it.item is BiomePlaceables.Tree }
if (trees.isNotEmpty()) {
biomeItems.add(trees.random(random).item.createPlacementFunc(parent, random, pos))
}
} catch (err: Throwable) {
LOGGER.error("Exception while evaluating dungeon biome tree placeables", err)
}
}
for (biomeItem in biomeItemsFutures) {
try {
val (placeables, pos) = biomeItem.await()

View File

@ -2,6 +2,7 @@ package ru.dbotthepony.kstarbound.defs.world
import com.github.benmanes.caffeine.cache.Caffeine
import com.google.gson.JsonObject
import it.unimi.dsi.fastutil.objects.ObjectArrayList
import org.apache.logging.log4j.LogManager
import ru.dbotthepony.kstarbound.math.AABBi
import ru.dbotthepony.kommons.util.Either
@ -209,7 +210,7 @@ class WorldTemplate(val geometry: WorldGeometry) {
if (thisBlock.biomeTransition)
return emptyList()
val result = ArrayList<BiomePlaceables.Placement>()
val result = ObjectArrayList<BiomePlaceables.Placement>()
val lowerBlock = cellInfo(geometry.x.cell(x), geometry.y.cell(y - 1))
val upperBlock = cellInfo(geometry.x.cell(x), geometry.y.cell(y + 1))
val potential = potentialBiomeItemsAt(x, y)

View File

@ -722,7 +722,7 @@ class ServerChunk(world: ServerWorld, pos: ChunkPos) : Chunk<ServerWorld, Server
}
}
placements.sortByDescending { it.priority }
placements.sortBy { it.priority }
placements
}, Starbound.EXECUTOR).await()
@ -1114,7 +1114,7 @@ class ServerChunk(world: ServerWorld, pos: ChunkPos) : Chunk<ServerWorld, Server
}
}
placements.sortByDescending { it.priority }
placements.sortBy { it.priority }
val random = random(staticRandom64(world.template.seed, pos.x, pos.y, "biome placement"))
val funcs = ArrayList<() -> Unit>()

View File

@ -651,6 +651,7 @@ class PlantEntity() : TileEntity() {
this.occupySpaces = this.calculatedOccupySpaces.stream().map { it + tilePosition }.collect(ImmutableSet.toImmutableSet())
this.roots = this.calculatedRoots.stream().map { it + tilePosition }.collect(ImmutableSet.toImmutableSet())
markSpacesDirty()
updateSpatialPosition()
}
override fun onPositionUpdated() {
@ -663,6 +664,10 @@ class PlantEntity() : TileEntity() {
return false
}
override fun toString(): String {
return "PlantEntity[at=$tilePosition, pieces=${pieces.size}]"
}
fun plant(world: ServerWorld, position: Vector2i, ignoreDungeonID: Int = NO_DUNGEON_ID): Boolean {
if (isInWorld)
throw IllegalStateException("Already in world")

View File

@ -105,7 +105,7 @@ abstract class TileEntity : AbstractEntity() {
needToUpdateRoots = true
}
private fun updateSpatialPosition() {
protected fun updateSpatialPosition() {
val spatialEntry = spatialEntry ?: return
spatialEntry.fixture.move(metaBoundingBox)
}