mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 01:16:46 -04:00
use entity data delegate more
This commit is contained in:
parent
8e845e5212
commit
e525d4c88a
@ -22,8 +22,7 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
abstract class AgeableMob(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : PathfinderMob(connection, entityType, data, position, rotation) {
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
open val isBaby: Boolean
|
||||
get() = data.getBoolean(BABY, false)
|
||||
open val isBaby: Boolean by data(BABY, false)
|
||||
|
||||
|
||||
companion object {
|
||||
|
@ -23,24 +23,20 @@ import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
||||
import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.data.registries.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
import de.bixilon.minosoft.util.KUtil
|
||||
|
||||
class AreaEffectCloud(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : Entity(connection, entityType, data, position, rotation) {
|
||||
|
||||
override val dimensions: Vec2
|
||||
get() = Vec2(radius * 2, super.dimensions.y)
|
||||
get() = Vec2(radius * 2, super.dimensions.y) // TODO: observe radius
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val ignoreRadius: Boolean
|
||||
get() = data.getBoolean(IGNORE_RADIUS_DATA, false)
|
||||
val ignoreRadius: Boolean by data(IGNORE_RADIUS_DATA, false)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val radius: Float
|
||||
get() = data.get(RADIUS_DATA, 0.5f)
|
||||
val radius: Float by data(RADIUS_DATA, 0.5f)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val color: Int
|
||||
get() = data.get(COLOR_DATA, 0)
|
||||
val color: Int by data(COLOR_DATA, 0)
|
||||
|
||||
// ignore radius???
|
||||
@get:SynchronizedEntityData
|
||||
@ -48,8 +44,7 @@ class AreaEffectCloud(connection: PlayConnection, entityType: EntityType, data:
|
||||
get() = data.getBoolean(WAITING_DATA, false)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val particle: ParticleData?
|
||||
get() = data.get(PARTICLE_DATA, null)
|
||||
val particle: ParticleData? by data(PARTICLE_DATA, null)
|
||||
|
||||
|
||||
companion object : EntityFactory<AreaEffectCloud> {
|
||||
|
@ -170,9 +170,9 @@ abstract class Entity(
|
||||
val isSilent: Boolean
|
||||
get() = data.get(SILENT_DATA, false)
|
||||
|
||||
private var _hasNoGravity by data(NO_GRAVITY_DATA, false)
|
||||
@get:SynchronizedEntityData
|
||||
open val hasGravity: Boolean
|
||||
get() = !data.get(NO_GRAVITY_DATA, false)
|
||||
open val hasGravity: Boolean get() = !_hasNoGravity
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val ticksFrozen: Int
|
||||
|
@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.entities.entities
|
||||
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kotlinglm.vec3.Vec3i
|
||||
import de.bixilon.kutil.bit.BitByte.isBitMask
|
||||
import de.bixilon.kutil.cast.CastUtil.nullCast
|
||||
import de.bixilon.kutil.cast.CastUtil.unsafeCast
|
||||
import de.bixilon.minosoft.data.container.equipment.EntityEquipment
|
||||
@ -49,8 +50,9 @@ abstract class LivingEntity(connection: PlayConnection, entityType: EntityType,
|
||||
override val canRaycast: Boolean get() = super.canRaycast && health > 0.0
|
||||
override val name: ChatComponent? get() = super.name
|
||||
|
||||
private var flags by data(FLAGS_DATA, 0x00)
|
||||
private fun getLivingEntityFlag(bitMask: Int): Boolean {
|
||||
return data.getBitMask(FLAGS_DATA, bitMask, 0x00)
|
||||
return flags.isBitMask(bitMask)
|
||||
}
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
@ -83,16 +85,13 @@ abstract class LivingEntity(connection: PlayConnection, entityType: EntityType,
|
||||
get() = data.getBoolean(EFFECT_AMBIENT_DATA, false)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val arrowCount: Int
|
||||
get() = data.get(ARROW_COUNT_DATA, 0)
|
||||
val arrowCount: Int by data(ARROW_COUNT_DATA, 0)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val absorptionHearts: Int
|
||||
get() = data.get(ABSORPTION_HEARTS_DATA, 0)
|
||||
val absorptionHearts: Int by data(ABSORPTION_HEARTS_DATA, 0)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val bedPosition: Vec3i?
|
||||
get() = data.get(BED_POSITION_DATA, null)
|
||||
val bedPosition: Vec3i? by data(BED_POSITION_DATA, null)
|
||||
|
||||
open val isSleeping: Boolean
|
||||
get() = bedPosition != null
|
||||
|
@ -13,6 +13,7 @@
|
||||
package de.bixilon.minosoft.data.entities.entities
|
||||
|
||||
import de.bixilon.kotlinglm.vec3.Vec3d
|
||||
import de.bixilon.kutil.bit.BitByte.isBitMask
|
||||
import de.bixilon.minosoft.data.entities.EntityRotation
|
||||
import de.bixilon.minosoft.data.entities.data.EntityData
|
||||
import de.bixilon.minosoft.data.entities.data.EntityDataField
|
||||
@ -20,9 +21,10 @@ import de.bixilon.minosoft.data.registries.entities.EntityType
|
||||
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) {
|
||||
private var flags by data(FLAGS_DATA, 0x00)
|
||||
|
||||
private fun getMobFlags(bitMask: Int): Boolean {
|
||||
return data.getBitMask(FLAGS_DATA, bitMask, 0x00)
|
||||
return flags.isBitMask(bitMask)
|
||||
}
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
|
@ -70,28 +70,22 @@ class ArmorStand(connection: PlayConnection, entityType: EntityType, data: Entit
|
||||
get() = getArmorStandFlag(0x10)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val headRotation: Vec3
|
||||
get() = data.get(HEAD_ROTATION_DATA, Vec3(0.0f, 0.0f, 0.0f))
|
||||
val headRotation: Vec3 by data(HEAD_ROTATION_DATA, HEAD_ROTATION)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val bodyRotation: Vec3
|
||||
get() = data.get(BODY_ROTATION_DATA, Vec3(0.0f, 0.0f, 0.0f))
|
||||
val bodyRotation: Vec3 by data(BODY_ROTATION_DATA, BODY_ROTATION)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val leftArmRotation: Vec3
|
||||
get() = data.get(LEFT_ARM_ROTATION_DATA, Vec3(-10.0f, 0.0f, -10.0f))
|
||||
val leftArmRotation: Vec3 by data(LEFT_ARM_ROTATION_DATA, LEFT_ARM_ROTATION)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val rightArmRotation: Vec3
|
||||
get() = data.get(RIGHT_ARM_ROTATION_DATA, Vec3(-15.0f, 0.0f, 10.0f))
|
||||
val rightArmRotation: Vec3 by data(RIGHT_ARM_ROTATION_DATA, RIGHT_ARM_ROTATION)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val leftLegRotation: Vec3
|
||||
get() = data.get(LEFT_LEG_ROTATION_DATA, Vec3(-1.0f, 0.0f, -1.0f))
|
||||
val leftLegRotation: Vec3 by data(LEFT_LEG_ROTATION_DATA, LEFT_LEG_ROTATION)
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val rightLegRotation: Vec3
|
||||
get() = data.get(RIGHT_LEG_ROTATION_DATA, Vec3(1.0f, 0.0f, 1.0f))
|
||||
val rightLegRotation: Vec3 by data(RIGHT_LEG_ROTATION_DATA, RIGHT_LEG_ROTATION)
|
||||
|
||||
|
||||
override fun tick() {
|
||||
@ -119,6 +113,13 @@ class ArmorStand(connection: PlayConnection, entityType: EntityType, data: Entit
|
||||
private val DIMENSIONS_MARKER = Vec2(0.0f)
|
||||
private val DIMENSIONS_SMALL = DIMENSIONS * 0.5f
|
||||
|
||||
private val HEAD_ROTATION = Vec3(0.0f, 0.0f, 0.0f)
|
||||
private val BODY_ROTATION = Vec3(0.0f, 0.0f, 0.0f)
|
||||
private val LEFT_ARM_ROTATION = Vec3(-10.0f, 0.0f, -10.0f)
|
||||
private val RIGHT_ARM_ROTATION = Vec3(-15.0f, 0.0f, 10.0f)
|
||||
private val LEFT_LEG_ROTATION = Vec3(-1.0f, 0.0f, -1.0f)
|
||||
private val RIGHT_LEG_ROTATION = Vec3(1.0f, 0.0f, 1.0f)
|
||||
|
||||
override fun build(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation): ArmorStand {
|
||||
return ArmorStand(connection, entityType, data, position, rotation)
|
||||
}
|
||||
|
@ -30,8 +30,7 @@ import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||
class PrimedTNT(connection: PlayConnection, entityType: EntityType, data: EntityData, position: Vec3d, rotation: EntityRotation) : Entity(connection, entityType, data, position, rotation) {
|
||||
|
||||
@get:SynchronizedEntityData
|
||||
val fuseTime: Int
|
||||
get() = data.get(FUSE_TIME_DATA, 80)
|
||||
val fuseTime: Int by data(FUSE_TIME_DATA, 80)
|
||||
|
||||
override fun tick() {
|
||||
if (fuseTime <= 0) return
|
||||
|
@ -146,7 +146,7 @@ open class ItemFeature(
|
||||
|
||||
fun ItemRenderDistance.getCount(count: Int) = when (this) {
|
||||
CLOSE -> when {
|
||||
count <= 16 -> count
|
||||
count <= 12 -> count
|
||||
else -> 16
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user