Accumulate how much ticks player exist in world

This commit is contained in:
DBotThePony 2022-09-15 15:54:59 +07:00
parent c47b9c52fe
commit 47e9840365
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 14 additions and 22 deletions

View File

@ -177,10 +177,12 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
private var invalidateNetworkIn = 10 private var invalidateNetworkIn = 10
var sleepTicks = 0
val isEverAndroid: Boolean get() = isAndroid || willBecomeAndroid val isEverAndroid: Boolean get() = isAndroid || willBecomeAndroid
var lastJumpTicks = 14 var lastJumpTicks = 14
var ticksIExist = 0
private set
var willBecomeAndroid by synchronizer.bool() var willBecomeAndroid by synchronizer.bool()
var isAndroid by synchronizer.bool() var isAndroid by synchronizer.bool()
@ -356,6 +358,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
override fun serializeNBT(): CompoundTag { override fun serializeNBT(): CompoundTag {
val tag = CompoundTag() val tag = CompoundTag()
tag["ticksIExist"] = ticksIExist
// iteration // iteration
tag["iteration"] = iteration tag["iteration"] = iteration
tag["shouldSendIteration"] = shouldSendIteration tag["shouldSendIteration"] = shouldSendIteration
@ -403,6 +407,8 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
} }
override fun deserializeNBT(tag: CompoundTag) { override fun deserializeNBT(tag: CompoundTag) {
ticksIExist = tag.getInt("ticksIExist")
// iterations // iterations
iteration = tag.getInt("iteration") iteration = tag.getInt("iteration")
shouldSendIteration = tag.getBoolean("shouldSendIteration") shouldSendIteration = tag.getBoolean("shouldSendIteration")
@ -492,14 +498,6 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
return return
} }
if (willBecomeAndroid) {
if (ply.isSleeping) {
sleepTicks++
} else {
sleepTicks = 0
}
}
if (isAndroid) { if (isAndroid) {
for (feature in features.values) { for (feature in features.values) {
feature.tickClient() feature.tickClient()
@ -512,19 +510,13 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial
fun tick() { fun tick() {
if (!ply.isAlive) return if (!ply.isAlive) return
ticksIExist++
if (willBecomeAndroid) { if (willBecomeAndroid) {
if (ply.isSleeping) { if (ply.isSleeping && ply.sleepTimer > SLEEP_TICKS_LIMIT) {
sleepTicks++ becomeAndroid()
shouldPlaySound = true
if (sleepTicks > SLEEP_TICKS_LIMIT) { (ply as? ServerPlayer)?.displayClientMessage(TranslatableComponent("otm.pill.message_finish").withStyle(ChatFormatting.DARK_RED), false)
becomeAndroid()
shouldPlaySound = true
sleepTicks = 0
(ply as? ServerPlayer)?.displayClientMessage(TranslatableComponent("otm.pill.message_finish").withStyle(ChatFormatting.DARK_RED), false)
}
} else {
sleepTicks = 0
} }
} }

View File

@ -59,7 +59,7 @@ object MatteryGUI {
return@ifPresentK 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 = screen.leaveBedButton.x =
originalBedButtonX - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt() originalBedButtonX - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()