day phases

This commit is contained in:
Bixilon 2022-11-02 13:40:01 +01:00
parent f484f107dc
commit c3af75874c
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
8 changed files with 89 additions and 18 deletions

View File

@ -22,6 +22,6 @@ object RainGradientSetGameEventHandler : GameEventHandler {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:rain_gradient_set".toResourceLocation()
override fun handle(data: Float, connection: PlayConnection) {
connection.world.weather = connection.world.weather.copy(rainGradient = data)
connection.world.weather = connection.world.weather.copy(rain = data)
}
}

View File

@ -22,6 +22,6 @@ object ThunderGradientSetGameEventHandler : GameEventHandler {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:thunder_gradient_set".toResourceLocation()
override fun handle(data: Float, connection: PlayConnection) {
connection.world.weather = connection.world.weather.copy(thunderGradient = data)
connection.world.weather = connection.world.weather.copy(thunder = data)
}
}

View File

@ -22,6 +22,6 @@ object RainStartGameEventHandler : GameEventHandler {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:rain_start".toResourceLocation()
override fun handle(data: Float, connection: PlayConnection) {
connection.world.weather = connection.world.weather.copy(raining = true, rainGradient = 1.0f)
connection.world.weather = connection.world.weather.copy(rain = 1.0f)
}
}

View File

@ -22,6 +22,6 @@ object RainStopGameEventHandler : GameEventHandler {
override val RESOURCE_LOCATION: ResourceLocation = "minecraft:rain_stop".toResourceLocation()
override fun handle(data: Float, connection: PlayConnection) {
connection.world.weather = connection.world.weather.copy(raining = false, rainGradient = 0.0f)
connection.world.weather = connection.world.weather.copy(rain = 0.0f)
}
}

View File

@ -0,0 +1,41 @@
/*
* 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
enum class DayPhases(private val progressCalculator: (Int) -> Float) {
SUNRISE({ (it - 23000) / 1000.0f }),
DAY({ it / 12000.0f }),
SUNSET({ (it - 12000) / 1000.0f }), // I love this song: https://www.youtube.com/watch?v=URma_gu1aNE
NIGHT({ (it - 13000) / 10000.9f }),
;
fun getProgress(time: Int): Float {
return progressCalculator(time)
}
companion object {
fun of(time: Int): DayPhases {
if (time > 23000) {
return SUNRISE
}
if (time < 12000) {
return DAY
}
if (time in 12000 until 13000) {
return SUNSET
}
return NIGHT
}
}
}

View File

@ -30,6 +30,7 @@ class WorldTime(
val cycling = time >= 0
val moonPhase = MoonPhases[age.toInt() % ProtocolDefinition.TICKS_PER_DAY % MoonPhases.VALUES.size] // ToDo: Verify
val phase = DayPhases.of(time)
val skyAngle: Float
@ -46,9 +47,8 @@ class WorldTime(
base = base.clamp(0.0, 1.0)
base = 1.0 - base
base *= 1.0 - ((world.weather.rainGradient * 5.0) / 16.0)
base *= 1.0 - (((world.weather.thunderGradient * world.weather.rainGradient) * 5.0) / 16.0)
base *= 1.0 - ((world.weather.rain * 5.0) / 16.0)
base *= 1.0 - (((world.weather.thunder * world.weather.rain) * 5.0) / 16.0)
return base * 0.8 + 0.2
}
}

View File

@ -14,7 +14,8 @@
package de.bixilon.minosoft.data.world.weather
data class WorldWeather(
val raining: Boolean = false,
val rainGradient: Float = 0.0f,
val thunderGradient: Float = 0.0f,
)
val rain: Float = 0.0f,
val thunder: Float = 0.0f,
) {
val raining: Boolean get() = rain > 0.0f
}

View File

@ -21,6 +21,7 @@ import de.bixilon.minosoft.data.text.formatting.color.ChatColors
import de.bixilon.minosoft.data.text.formatting.color.RGBColor
import de.bixilon.minosoft.data.text.formatting.color.RGBColor.Companion.asColor
import de.bixilon.minosoft.data.world.positions.ChunkPositionUtil.chunkPosition
import de.bixilon.minosoft.data.world.time.DayPhases
import de.bixilon.minosoft.data.world.time.WorldTime
import de.bixilon.minosoft.gui.rendering.sky.SkyChildRenderer
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
@ -123,6 +124,30 @@ class SkyboxRenderer(
return RGBColor(red / count, green / count, blue / count)
}
private fun calculateThunder(rain: Float, thunder: Float): RGBColor {
return ChatColors.DARK_GRAY
}
private fun calculateRain(rain: Float): RGBColor {
return ChatColors.GRAY
}
private fun calculateSunrise(progress: Float): RGBColor {
return ChatColors.YELLOW
}
private fun calculateDaytime(progress: Float): RGBColor {
return ChatColors.BLUE
}
private fun calculateSunset(progress: Float): RGBColor {
return ChatColors.RED
}
private fun calculateNight(progress: Float): RGBColor {
return ChatColors.DARK_BLUE
}
private fun calculateSkyColor(): RGBColor? {
val properties = sky.properties
if (properties.fixedTexture != null) {
@ -135,18 +160,22 @@ class SkyboxRenderer(
}
val weather = sky.renderWindow.connection.world.weather
if (weather.thunderGradient > 0.0f) {
return ChatColors.DARK_GRAY
if (weather.thunder > 0.0f) {
return calculateThunder(weather.rain, weather.thunder)
}
if (weather.raining) {
return ChatColors.GRAY
return calculateRain(weather.rain)
}
if (time.time in 13000..23000) {
return ChatColors.DARK_BLUE
}
val phase = time.phase
val progress = phase.getProgress(time.time)
return ChatColors.BLUE
return when (phase) {
DayPhases.SUNRISE -> calculateSunrise(progress)
DayPhases.DAY -> calculateDaytime(progress)
DayPhases.SUNSET -> calculateSunset(progress)
DayPhases.NIGHT -> calculateNight(progress)
}
}
companion object {