From 47e98403650639ae3ca3d06be774b3926a64aca6 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 15 Sep 2022 15:54:59 +0700 Subject: [PATCH] Accumulate how much ticks player exist in world --- .../otm/capability/MatteryPlayerCapability.kt | 34 +++++++------------ .../dbotthepony/mc/otm/client/MatteryGUI.kt | 2 +- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt index 7960f1be1..14cddff5a 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt @@ -177,10 +177,12 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial private var invalidateNetworkIn = 10 - var sleepTicks = 0 val isEverAndroid: Boolean get() = isAndroid || willBecomeAndroid var lastJumpTicks = 14 + var ticksIExist = 0 + private set + var willBecomeAndroid by synchronizer.bool() var isAndroid by synchronizer.bool() @@ -356,6 +358,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial override fun serializeNBT(): CompoundTag { val tag = CompoundTag() + tag["ticksIExist"] = ticksIExist + // iteration tag["iteration"] = iteration tag["shouldSendIteration"] = shouldSendIteration @@ -403,6 +407,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial } override fun deserializeNBT(tag: CompoundTag) { + ticksIExist = tag.getInt("ticksIExist") + // iterations iteration = tag.getInt("iteration") shouldSendIteration = tag.getBoolean("shouldSendIteration") @@ -492,14 +498,6 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial return } - if (willBecomeAndroid) { - if (ply.isSleeping) { - sleepTicks++ - } else { - sleepTicks = 0 - } - } - if (isAndroid) { for (feature in features.values) { feature.tickClient() @@ -512,19 +510,13 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial fun tick() { if (!ply.isAlive) return + ticksIExist++ + if (willBecomeAndroid) { - if (ply.isSleeping) { - sleepTicks++ - - if (sleepTicks > SLEEP_TICKS_LIMIT) { - becomeAndroid() - shouldPlaySound = true - sleepTicks = 0 - - (ply as? ServerPlayer)?.displayClientMessage(TranslatableComponent("otm.pill.message_finish").withStyle(ChatFormatting.DARK_RED), false) - } - } else { - sleepTicks = 0 + if (ply.isSleeping && ply.sleepTimer > SLEEP_TICKS_LIMIT) { + becomeAndroid() + shouldPlaySound = true + (ply as? ServerPlayer)?.displayClientMessage(TranslatableComponent("otm.pill.message_finish").withStyle(ChatFormatting.DARK_RED), false) } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt index deb3896d1..9dda57c4e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/MatteryGUI.kt @@ -59,7 +59,7 @@ object MatteryGUI { return@ifPresentK } - val dispersion = (10.0 * Math.max(0, it.sleepTicks - 20) / (MatteryPlayerCapability.SLEEP_TICKS_LIMIT - 20)).toInt() + val dispersion = (10.0 * Math.max(0, it.ply.sleepTimer - 20) / (MatteryPlayerCapability.SLEEP_TICKS_LIMIT - 20)).toInt() screen.leaveBedButton.x = originalBedButtonX - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()