From f902bccf154aa7ace793282c30219c9e637d9e34 Mon Sep 17 00:00:00 2001 From: Ivan Kh <47220198+Ivan-Khar@users.noreply.github.com> Date: Sun, 28 Jan 2024 16:16:09 +0300 Subject: [PATCH] synced isFlipped boolean between server and client --- .../aquatic/entity/critter/KarkinosEntity.kt | 14 +++++++++++++- .../entity/shark/HybridAquaticSharkEntity.kt | 12 ++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/entity/critter/KarkinosEntity.kt b/src/main/kotlin/dev/hybridlabs/aquatic/entity/critter/KarkinosEntity.kt index 5aaa02d42..7b2e2b726 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/entity/critter/KarkinosEntity.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/entity/critter/KarkinosEntity.kt @@ -10,6 +10,9 @@ import net.minecraft.entity.attribute.EntityAttributes import net.minecraft.entity.damage.DamageSource import net.minecraft.entity.damage.DamageType import net.minecraft.entity.damage.DamageTypes +import net.minecraft.entity.data.DataTracker +import net.minecraft.entity.data.TrackedData +import net.minecraft.entity.data.TrackedDataHandlerRegistry import net.minecraft.entity.mob.Angerable import net.minecraft.entity.mob.WaterCreatureEntity import net.minecraft.entity.player.PlayerEntity @@ -23,11 +26,18 @@ import java.util.* class KarkinosEntity(entityType: EntityType, world: World) : HybridAquaticCrabEntity(entityType, world), Angerable { - private var isFlipped: Boolean = false private var flipTimer: Int = 0 private val flipDuration: Int = 10 private var angerTime = 0 private var angryAt: UUID? = null + private var isFlipped: Boolean + get() = dataTracker.get(FLIPPED) + set(bool) = dataTracker.set(FLIPPED, bool) + + override fun initDataTracker() { + super.initDataTracker() + dataTracker.startTracking(FLIPPED, false) + } override fun initGoals() { goalSelector.add(1, AttackGoal(this)) @@ -132,5 +142,7 @@ class KarkinosEntity(entityType: EntityType, wor .add(EntityAttributes.GENERIC_FOLLOW_RANGE, 32.0) .add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 10.0) } + + val FLIPPED: TrackedData = DataTracker.registerData(KarkinosEntity::class.java, TrackedDataHandlerRegistry.BOOLEAN) } } \ No newline at end of file diff --git a/src/main/kotlin/dev/hybridlabs/aquatic/entity/shark/HybridAquaticSharkEntity.kt b/src/main/kotlin/dev/hybridlabs/aquatic/entity/shark/HybridAquaticSharkEntity.kt index 5d739f1d9..af77c21a5 100644 --- a/src/main/kotlin/dev/hybridlabs/aquatic/entity/shark/HybridAquaticSharkEntity.kt +++ b/src/main/kotlin/dev/hybridlabs/aquatic/entity/shark/HybridAquaticSharkEntity.kt @@ -92,6 +92,12 @@ open class HybridAquaticSharkEntity( set(attemptAttack) { dataTracker.set(ATTEMPT_ATTACK, attemptAttack) } + var size: Int + get() = dataTracker.get(SHARK_SIZE) + set(size) { + dataTracker.set(SHARK_SIZE, size) + } + init { setPathfindingPenalty(PathNodeType.WATER, 0.0f) moveControl = AquaticMoveControl(this, 85, 10, 0.02F, 0.1F, true) @@ -345,12 +351,6 @@ open class HybridAquaticSharkEntity( override fun chooseRandomAngerTime() { setAngerTime(ANGER_TIME_RANGE.get(random)) } - - var size: Int - get() = dataTracker.get(SHARK_SIZE) - set(size) { - dataTracker.set(SHARK_SIZE, size) - } //#endregion private fun getHungerValue(entityType: EntityType<*>): Int {