entity flags: fix class cast exception

Flags are mostly in the protocol a byte, but we will just work with ints. Fine. But observers are registered on ints, but the actual type is a byte, hence it crashes.
This commit is contained in:
Moritz Zwerger 2024-06-09 23:20:39 +02:00
parent 6d0db5fae8
commit fa9981204b
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 18 additions and 11 deletions

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger * Copyright (C) 2020-2024 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -13,4 +13,7 @@
package de.bixilon.minosoft.data.entities.data package de.bixilon.minosoft.data.entities.data
class EntityDataField(vararg val names: String) class EntityDataField(vararg val names: String) {
override fun toString() = names.contentToString()
}

View File

@ -19,6 +19,7 @@ import de.bixilon.kutil.bit.BitByte.isBitMask
import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.cast.CastUtil.unsafeNull import de.bixilon.kutil.cast.CastUtil.unsafeNull
import de.bixilon.kutil.primitive.BooleanUtil.toBoolean import de.bixilon.kutil.primitive.BooleanUtil.toBoolean
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.kutil.reflection.ReflectionUtil.field import de.bixilon.kutil.reflection.ReflectionUtil.field
import de.bixilon.kutil.reflection.ReflectionUtil.getFieldOrNull import de.bixilon.kutil.reflection.ReflectionUtil.getFieldOrNull
import de.bixilon.kutil.time.TimeUtil.millis import de.bixilon.kutil.time.TimeUtil.millis
@ -52,7 +53,7 @@ abstract class Entity(
private var initialPosition: Vec3d, private var initialPosition: Vec3d,
private var initialRotation: EntityRotation, private var initialRotation: EntityRotation,
) : Initializable, EntityAttachable { ) : Initializable, EntityAttachable {
private var flags: Int by data(FLAGS_DATA, 0x00) private var flags: Int by data(FLAGS_DATA, 0x00) { it.toInt() }
protected val random = Random() protected val random = Random()
val id: Int? val id: Int?
get() = connection.world.entities.getId(this) get() = connection.world.entities.getId(this)

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger * Copyright (C) 2020-2024 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -17,6 +17,7 @@ import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.kutil.bit.BitByte.isBitMask import de.bixilon.kutil.bit.BitByte.isBitMask
import de.bixilon.kutil.cast.CastUtil.nullCast import de.bixilon.kutil.cast.CastUtil.nullCast
import de.bixilon.kutil.cast.CastUtil.unsafeCast import de.bixilon.kutil.cast.CastUtil.unsafeCast
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.container.equipment.EntityEquipment import de.bixilon.minosoft.data.container.equipment.EntityEquipment
import de.bixilon.minosoft.data.entities.EntityRotation import de.bixilon.minosoft.data.entities.EntityRotation
import de.bixilon.minosoft.data.entities.Poses import de.bixilon.minosoft.data.entities.Poses
@ -50,7 +51,7 @@ abstract class LivingEntity(connection: PlayConnection, entityType: EntityType,
override val canRaycast: Boolean get() = super.canRaycast && health > 0.0 override val canRaycast: Boolean get() = super.canRaycast && health > 0.0
override val name: ChatComponent? get() = super.name override val name: ChatComponent? get() = super.name
private var flags by data(FLAGS_DATA, 0x00) private var flags by data(FLAGS_DATA, 0x00) { it.toInt() }
private fun getLivingEntityFlag(bitMask: Int): Boolean { private fun getLivingEntityFlag(bitMask: Int): Boolean {
return flags.isBitMask(bitMask) return flags.isBitMask(bitMask)
} }

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger * Copyright (C) 2020-2024 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.entities.entities
import de.bixilon.kotlinglm.vec3.Vec3d import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.kutil.bit.BitByte.isBitMask import de.bixilon.kutil.bit.BitByte.isBitMask
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.entities.EntityRotation import de.bixilon.minosoft.data.entities.EntityRotation
import de.bixilon.minosoft.data.entities.data.EntityData import de.bixilon.minosoft.data.entities.data.EntityData
import de.bixilon.minosoft.data.entities.data.EntityDataField import de.bixilon.minosoft.data.entities.data.EntityDataField
@ -21,7 +22,7 @@ import de.bixilon.minosoft.data.registries.entities.EntityType
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
abstract class Mob(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : LivingEntity(connection, entityType, data, position, rotation) { abstract class Mob(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : LivingEntity(connection, entityType, data, position, rotation) {
private var flags by data(FLAGS_DATA, 0x00) private var flags by data(FLAGS_DATA, 0x00) { it.toInt() }
private fun getMobFlags(bitMask: Int): Boolean { private fun getMobFlags(bitMask: Int): Boolean {
return flags.isBitMask(bitMask) return flags.isBitMask(bitMask)

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger * Copyright (C) 2020-2024 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -17,6 +17,7 @@ import de.bixilon.kotlinglm.vec3.Vec3
import de.bixilon.kotlinglm.vec3.Vec3d import de.bixilon.kotlinglm.vec3.Vec3d
import de.bixilon.kutil.bit.BitByte.isBitMask import de.bixilon.kutil.bit.BitByte.isBitMask
import de.bixilon.kutil.observer.DataObserver.Companion.observe import de.bixilon.kutil.observer.DataObserver.Companion.observe
import de.bixilon.kutil.primitive.IntUtil.toInt
import de.bixilon.minosoft.data.entities.EntityRotation import de.bixilon.minosoft.data.entities.EntityRotation
import de.bixilon.minosoft.data.entities.data.EntityData import de.bixilon.minosoft.data.entities.data.EntityData
import de.bixilon.minosoft.data.entities.data.EntityDataField import de.bixilon.minosoft.data.entities.data.EntityDataField
@ -31,7 +32,7 @@ import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
class ArmorStand(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : LivingEntity(connection, entityType, data, position, rotation) { class ArmorStand(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : LivingEntity(connection, entityType, data, position, rotation) {
private var flags by data(FLAGS_DATA, 0x00) private var flags: Int by data(FLAGS_DATA, 0x00) { it.toInt() }
private fun updateFlags() { private fun updateFlags() {
this.dimensions = when { this.dimensions = when {

View File

@ -1,6 +1,6 @@
/* /*
* Minosoft * Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger * Copyright (C) 2020-2024 Moritz Zwerger
* *
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* *
@ -110,7 +110,7 @@ abstract class PlayerEntity(
data.observe(SKIN_PARTS_DATA) { raw: Any? -> updateSkinParts(raw?.toInt() ?: 0xFF) } data.observe(SKIN_PARTS_DATA) { raw: Any? -> updateSkinParts(raw?.toInt() ?: 0xFF) }
} }
private var _mainArm by data(MAIN_ARM_DATA, 0x01) private var _mainArm by data(MAIN_ARM_DATA, 0x01) { it.toInt() }
@get:SynchronizedEntityData @get:SynchronizedEntityData
open val mainArm: Arms open val mainArm: Arms