Plants without occupied spaces no longer crash server

This commit is contained in:
DBotThePony 2024-04-22 22:16:48 +07:00
parent c2cb8dd208
commit 934e8f8479
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -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() {