Fix crash related to starbound data structure being dumb

This commit is contained in:
DBotThePony 2024-05-22 18:59:02 +07:00
parent 1b7076f04f
commit b4902559ac
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 15 additions and 6 deletions

View File

@ -19,6 +19,12 @@ fun String.sbIntern(): String {
val JsonElement.asStringOrNull: String?
get() = if (isJsonNull) null else asString
val JsonElement.asDoubleOrNull: Double?
get() = if (isJsonNull) null else asDouble
val JsonElement.asBooleanOrNull: Boolean?
get() = if (isJsonNull) null else asBoolean
val JsonElement.coalesceNull: JsonElement?
get() = if (isJsonNull) null else this

View File

@ -29,6 +29,9 @@ import ru.dbotthepony.kstarbound.network.syncher.networkedBoolean
import ru.dbotthepony.kstarbound.network.syncher.networkedEventCounter
import ru.dbotthepony.kstarbound.util.AssetPathStack
import ru.dbotthepony.kstarbound.util.Directives
import ru.dbotthepony.kstarbound.util.asBooleanOrNull
import ru.dbotthepony.kstarbound.util.asDoubleOrNull
import ru.dbotthepony.kstarbound.util.asStringOrNull
import ru.dbotthepony.kstarbound.util.valueOf
import java.io.DataInputStream
import java.io.DataOutputStream
@ -80,11 +83,11 @@ class ProjectileEntity private constructor(val config: Registry.Entry<Projectile
var damageKind = parameters.get("damageKind", config.value.damageKind)
var damageType = DamageType.entries.valueOf(parameters.get("damageType", config.value.damageType))
var rayCheckToSource = parameters.get("rayCheckToSource", config.value.rayCheckToSource)
var damageRepeatGroup = parameters["damageRepeatGroup"]?.asString ?: config.value.damageRepeatGroup
var damageRepeatTimeout = parameters["damageRepeatTimeout"]?.asDouble ?: config.value.damageRepeatTimeout
var falldown = parameters["falldown"]?.asBoolean ?: config.value.falldown
var hydrophobic = parameters["hydrophobic"]?.asBoolean ?: config.value.hydrophobic
var onlyHitTerrain = parameters["onlyHitTerrain"]?.asBoolean ?: config.value.onlyHitTerrain
var damageRepeatGroup = parameters["damageRepeatGroup"]?.asStringOrNull ?: config.value.damageRepeatGroup
var damageRepeatTimeout = parameters["damageRepeatTimeout"]?.asDoubleOrNull ?: config.value.damageRepeatTimeout
var falldown = parameters["falldown"]?.asBooleanOrNull ?: config.value.falldown
var hydrophobic = parameters["hydrophobic"]?.asBooleanOrNull ?: config.value.hydrophobic
var onlyHitTerrain = parameters["onlyHitTerrain"]?.asBooleanOrNull ?: config.value.onlyHitTerrain
init {
if ("damageTeam" in parameters) {
@ -106,7 +109,7 @@ class ProjectileEntity private constructor(val config: Registry.Entry<Projectile
movement.applyParameters(movementParams)
}
var initialSpeed = parameters["speed"]?.asDouble ?: config.value.speed
var initialSpeed = parameters["speed"]?.asDoubleOrNull ?: config.value.speed
private var lastSourceEntityPosition: Vector2d? = null
var sourceEntityId: Int = 0