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
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)
}
}

View File

@ -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()