From 934e8f8479f551bab28aff14065de02b37677b9a Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 22 Apr 2024 22:16:48 +0700 Subject: [PATCH] Plants without occupied spaces no longer crash server --- .../world/entities/tile/PlantPieceEntity.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/PlantPieceEntity.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/PlantPieceEntity.kt index 0e0f8785..71d5cb52 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/PlantPieceEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/entities/tile/PlantPieceEntity.kt @@ -148,22 +148,26 @@ class PlantPieceEntity() : DynamicEntity() { piecesInternal.add(Piece(piece)) } - calculatedMetaBoundingBox = AABB.ofPoints(allSpaces) + if (allSpaces.isNotEmpty()) { + calculatedMetaBoundingBox = AABB.ofPoints(allSpaces) - if (pieces.any { it.isStructuralSegment } && stemSpaces.isNotEmpty()) { - calculatedCollisionBox = AABB.ofPoints(stemSpaces) + if (pieces.any { it.isStructuralSegment } && stemSpaces.isNotEmpty()) { + calculatedCollisionBox = AABB.ofPoints(stemSpaces) - if (stemSpaces.size >= 2) { - calculatedCollisionHull = Poly.quickhull(stemSpaces.map { it.toDoubleVector() }) + if (stemSpaces.size >= 2) { + calculatedCollisionHull = Poly.quickhull(stemSpaces.map { it.toDoubleVector() }) + } else { + calculatedCollisionHull = Poly(calculatedCollisionBox) + } } else { - calculatedCollisionHull = Poly(calculatedCollisionBox) + calculatedCollisionBox = calculatedMetaBoundingBox + calculatedCollisionHull = Poly(calculatedMetaBoundingBox) } } else { + calculatedMetaBoundingBox = AABB.rectangle(Vector2d.ZERO, 0.1, 0.1) calculatedCollisionBox = calculatedMetaBoundingBox calculatedCollisionHull = Poly(calculatedMetaBoundingBox) } - - //calculatedCollisionHull = calculatedCollisionHull * 0.5 + calculatedCollisionHull.aabb.centre * 0.5 } constructor(stream: DataInputStream, isLegacy: Boolean) : this() {