Proper biome item placement
This commit is contained in:
parent
82c2d1315e
commit
81492f2985
@ -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.TileDefinition
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.TileModifierDefinition
|
import ru.dbotthepony.kstarbound.defs.tile.TileModifierDefinition
|
||||||
import ru.dbotthepony.kstarbound.defs.tile.isNotEmptyTile
|
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.defs.world.FloatingDungeonWorldParameters
|
||||||
import ru.dbotthepony.kstarbound.math.AABB
|
import ru.dbotthepony.kstarbound.math.AABB
|
||||||
import ru.dbotthepony.kstarbound.server.world.ServerChunk
|
import ru.dbotthepony.kstarbound.server.world.ServerChunk
|
||||||
import ru.dbotthepony.kstarbound.server.world.ServerWorld
|
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.ChunkPos
|
||||||
import ru.dbotthepony.kstarbound.world.ChunkState
|
import ru.dbotthepony.kstarbound.world.ChunkState
|
||||||
import ru.dbotthepony.kstarbound.world.Direction
|
import ru.dbotthepony.kstarbound.world.Direction
|
||||||
@ -538,8 +540,27 @@ class DungeonWorld(val parent: ServerWorld, val random: RandomGenerator, val mar
|
|||||||
}, Starbound.EXECUTOR)
|
}, 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>()
|
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) {
|
for (biomeItem in biomeItemsFutures) {
|
||||||
try {
|
try {
|
||||||
val (placeables, pos) = biomeItem.await()
|
val (placeables, pos) = biomeItem.await()
|
||||||
|
@ -2,6 +2,7 @@ package ru.dbotthepony.kstarbound.defs.world
|
|||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine
|
import com.github.benmanes.caffeine.cache.Caffeine
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList
|
||||||
import org.apache.logging.log4j.LogManager
|
import org.apache.logging.log4j.LogManager
|
||||||
import ru.dbotthepony.kstarbound.math.AABBi
|
import ru.dbotthepony.kstarbound.math.AABBi
|
||||||
import ru.dbotthepony.kommons.util.Either
|
import ru.dbotthepony.kommons.util.Either
|
||||||
@ -209,7 +210,7 @@ class WorldTemplate(val geometry: WorldGeometry) {
|
|||||||
if (thisBlock.biomeTransition)
|
if (thisBlock.biomeTransition)
|
||||||
return emptyList()
|
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 lowerBlock = cellInfo(geometry.x.cell(x), geometry.y.cell(y - 1))
|
||||||
val upperBlock = 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)
|
val potential = potentialBiomeItemsAt(x, y)
|
||||||
|
@ -722,7 +722,7 @@ class ServerChunk(world: ServerWorld, pos: ChunkPos) : Chunk<ServerWorld, Server
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
placements.sortByDescending { it.priority }
|
placements.sortBy { it.priority }
|
||||||
placements
|
placements
|
||||||
}, Starbound.EXECUTOR).await()
|
}, 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 random = random(staticRandom64(world.template.seed, pos.x, pos.y, "biome placement"))
|
||||||
val funcs = ArrayList<() -> Unit>()
|
val funcs = ArrayList<() -> Unit>()
|
||||||
|
@ -651,6 +651,7 @@ class PlantEntity() : TileEntity() {
|
|||||||
this.occupySpaces = this.calculatedOccupySpaces.stream().map { it + tilePosition }.collect(ImmutableSet.toImmutableSet())
|
this.occupySpaces = this.calculatedOccupySpaces.stream().map { it + tilePosition }.collect(ImmutableSet.toImmutableSet())
|
||||||
this.roots = this.calculatedRoots.stream().map { it + tilePosition }.collect(ImmutableSet.toImmutableSet())
|
this.roots = this.calculatedRoots.stream().map { it + tilePosition }.collect(ImmutableSet.toImmutableSet())
|
||||||
markSpacesDirty()
|
markSpacesDirty()
|
||||||
|
updateSpatialPosition()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPositionUpdated() {
|
override fun onPositionUpdated() {
|
||||||
@ -663,6 +664,10 @@ class PlantEntity() : TileEntity() {
|
|||||||
return false
|
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 {
|
fun plant(world: ServerWorld, position: Vector2i, ignoreDungeonID: Int = NO_DUNGEON_ID): Boolean {
|
||||||
if (isInWorld)
|
if (isInWorld)
|
||||||
throw IllegalStateException("Already in world")
|
throw IllegalStateException("Already in world")
|
||||||
|
@ -105,7 +105,7 @@ abstract class TileEntity : AbstractEntity() {
|
|||||||
needToUpdateRoots = true
|
needToUpdateRoots = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSpatialPosition() {
|
protected fun updateSpatialPosition() {
|
||||||
val spatialEntry = spatialEntry ?: return
|
val spatialEntry = spatialEntry ?: return
|
||||||
spatialEntry.fixture.move(metaBoundingBox)
|
spatialEntry.fixture.move(metaBoundingBox)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user