diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt index 4f720d1a..da6ef5b6 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/dungeon/DungeonWorld.kt @@ -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() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt index 504a68fa..aade96f5 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt @@ -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() + val result = ObjectArrayList() 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) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt index 54104c54..d00f27b8 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerChunk.kt @@ -722,7 +722,7 @@ class ServerChunk(world: ServerWorld, pos: ChunkPos) : Chunk Unit>() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/PlantEntity.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/PlantEntity.kt index 2c39be31..3e45041d 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/PlantEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/PlantEntity.kt @@ -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") diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/TileEntity.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/TileEntity.kt index 085a663c..b5d2cee9 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/TileEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/TileEntity.kt @@ -105,7 +105,7 @@ abstract class TileEntity : AbstractEntity() { needToUpdateRoots = true } - private fun updateSpatialPosition() { + protected fun updateSpatialPosition() { val spatialEntry = spatialEntry ?: return spatialEntry.fixture.move(metaBoundingBox) }