Skip to content

Commit

Permalink
synced isFlipped boolean between server and client
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Khar committed Jan 28, 2024
1 parent 38bdedc commit f902bcc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,11 +26,18 @@ import java.util.*
class KarkinosEntity(entityType: EntityType<out HybridAquaticCritterEntity>, 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))
Expand Down Expand Up @@ -132,5 +142,7 @@ class KarkinosEntity(entityType: EntityType<out HybridAquaticCritterEntity>, wor
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 32.0)
.add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 10.0)
}

val FLIPPED: TrackedData<Boolean> = DataTracker.registerData(KarkinosEntity::class.java, TrackedDataHandlerRegistry.BOOLEAN)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f902bcc

Please sign in to comment.