mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 03:15:35 -04:00
make WorldTime values final, calculate moon phases
This commit is contained in:
parent
824065cb9c
commit
05ff4647a2
@ -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()
|
||||
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* 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<MoonPhases> {
|
||||
override val VALUES = values()
|
||||
override val NAME_MAP = EnumUtil.getEnumValues(VALUES)
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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() }
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user