diff --git a/src/main/java/de/bixilon/minosoft/data/world/World.kt b/src/main/java/de/bixilon/minosoft/data/world/World.kt index f84518ac6..24444e133 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/World.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/World.kt @@ -71,7 +71,7 @@ class World( var dimension: DimensionProperties? by watched(null) var difficulty: WorldDifficulty? by watched(null) var hashedSeed = 0L - val time = WorldTime(this) + var time by watched(WorldTime(this)) val weather = WorldWeather() val view = WorldView(connection) val border = WorldBorder() diff --git a/src/main/java/de/bixilon/minosoft/data/world/time/MoonPhases.kt b/src/main/java/de/bixilon/minosoft/data/world/time/MoonPhases.kt new file mode 100644 index 000000000..62ebdfd22 --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/world/time/MoonPhases.kt @@ -0,0 +1,35 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.data.world.time + +import de.bixilon.kutil.enums.EnumUtil +import de.bixilon.kutil.enums.ValuesEnum + +// see https://minecraft.fandom.com/wiki/Moon +enum class MoonPhases { + FULL_MOON, + WANING_GIBBOUS, + LAST_QUARTER, + WANING_CRESCENT, + NEW_MOON, + WAXING_CRESCENT, + FIRST_QUARTER, + WAXING_GIBBOUS, + ; + + companion object : ValuesEnum { + override val VALUES = values() + override val NAME_MAP = EnumUtil.getEnumValues(VALUES) + } +} diff --git a/src/main/java/de/bixilon/minosoft/data/world/time/WorldTime.kt b/src/main/java/de/bixilon/minosoft/data/world/time/WorldTime.kt index 97e1b7eb8..c92ef7068 100644 --- a/src/main/java/de/bixilon/minosoft/data/world/time/WorldTime.kt +++ b/src/main/java/de/bixilon/minosoft/data/world/time/WorldTime.kt @@ -15,19 +15,21 @@ package de.bixilon.minosoft.data.world.time import de.bixilon.kotlinglm.func.common.clamp import de.bixilon.kutil.math.simple.DoubleMath.fractional -import de.bixilon.kutil.watcher.DataWatcher.Companion.watched import de.bixilon.minosoft.data.world.World import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import kotlin.math.PI import kotlin.math.abs import kotlin.math.cos -@Deprecated("make values final") class WorldTime( private val world: World, + time: Int = 0, + val age: Long = 0L, ) { - var time by watched(0L) - var age by watched(0L) + val time = abs(time) % ProtocolDefinition.TICKS_PER_DAY + val cycling = time >= 0 + + val moonPhase = MoonPhases[age % ProtocolDefinition.TICKS_PER_DAY % MoonPhases.VALUES.size] // ToDo: Verify val skyAngle: Float diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt index 1e9a5c1f1..992b392e9 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/hud/elements/other/DebugHUDElement.kt @@ -174,11 +174,9 @@ class DebugHUDElement(guiRenderer: GUIRenderer) : Element(guiRenderer), Layouted } layout += TextElement(guiRenderer, "Time TBA").apply { - fun update(time: Long, age: Long) { - text = BaseComponent("Time ", abs(time % ProtocolDefinition.TICKS_PER_DAY), ", moving=", time >= 0, ", day=", abs(age) / ProtocolDefinition.TICKS_PER_DAY) + connection.world::time.observe(this) { + text = BaseComponent("Time ", abs(it.time % ProtocolDefinition.TICKS_PER_DAY), ", moving=", it.cycling, ", day=", abs(it.age) / ProtocolDefinition.TICKS_PER_DAY) } - connection.world.time::time.observe(this) { update(it, connection.world.time.age) } - connection.world.time::age.observe(this) { update(connection.world.time.time, it) } } layout += AutoTextElement(guiRenderer, 1) { "Fun effect: " + renderWindow.framebufferManager.world.`fun`.effect?.resourceLocation.format() } diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/TimeS2CP.kt b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/TimeS2CP.kt index a0c4680cd..8d252482e 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/TimeS2CP.kt +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/s2c/play/TimeS2CP.kt @@ -12,11 +12,11 @@ */ package de.bixilon.minosoft.protocol.packets.s2c.play +import de.bixilon.minosoft.data.world.time.WorldTime import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.packets.factory.LoadPacket import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer -import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition import de.bixilon.minosoft.util.logging.Log import de.bixilon.minosoft.util.logging.LogLevels import de.bixilon.minosoft.util.logging.LogMessageType @@ -27,8 +27,7 @@ class TimeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket { val time = buffer.readLong() override fun handle(connection: PlayConnection) { - connection.world.time.age = age - connection.world.time.time = time % ProtocolDefinition.TICKS_PER_DAY + connection.world.time = WorldTime(connection.world, time = time.toInt(), age = age) } override fun log(reducedLog: Boolean) {