Skip to content

Commit

Permalink
Better DayCycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Jan 25, 2024
1 parent b8f3f0f commit 94804a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,46 @@ package io.github.addoncommunity.galactifun.api.objects.properties

import org.bukkit.GameRule
import org.bukkit.World
import kotlin.time.Duration
import kotlin.time.Duration.Companion.days

class DayCycle {

companion object {

val ETERNAL_DAY = DayCycle(6000)
val ETERNAL_NIGHT = DayCycle(18000)
val EARTH_LIKE = DayCycle(days = 1)
val EARTH_LIKE = DayCycle(1.days)

fun eternal(time: Long) = DayCycle(time)

fun relativeToEarth(ratio: Double) = DayCycle(days = ratio.toInt(), hours = (ratio * 24).toInt())
}

val description: String
private val perFiveSeconds: Long
private val startTime: Long

constructor(days: Int = 0, hours: Int = 0) {
constructor(duration: Duration) {
val days = duration.inWholeDays
val hours = duration.inWholeHours - days * 24
require(days * 24 + hours > 0) { "A day cycle must last longer than 1 hour" }
description = buildString {
if (days > 0) {
append(days)
append(" day")
if (days != 1) {
if (days != 1L) {
append('s')
}
append(' ')
}
if (hours > 0) {
append(hours)
append(" hour")
if (hours != 1) {
if (hours != 1L) {
append('s')
}
}
}
perFiveSeconds = days * 100L + hours * 4L
perFiveSeconds = days * 100L + hours * 4L // magic happens here, do not touch
startTime = -1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import io.github.addoncommunity.galactifun.api.objects.properties.atmosphere.Atm
import org.bukkit.Material
import org.bukkit.inventory.ItemStack
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours

object Moon : AlienWorld("Moon", ItemStack(Material.END_STONE)) {
override val atmosphere = Atmosphere.NONE
override val dayCycle = DayCycle(days = 29, hours = 12)
override val dayCycle = DayCycle(29.days + 12.hours)
override val orbiting = Earth
override val orbit = Orbit(382500.kilometers, 27.days)
override val generator: WorldGenerator = MoonGenerator()
Expand Down

0 comments on commit 94804a2

Please sign in to comment.