Skip to content

Commit

Permalink
move time constant to WorldTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Bixilon committed Nov 27, 2023
1 parent 45f26ed commit 4cc551d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 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.
*
Expand All @@ -13,12 +13,13 @@

package de.bixilon.minosoft.commands.parser.minecraft.time

import de.bixilon.minosoft.data.world.time.WorldTime
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition

enum class TimeUnit(val multiplier: Int) {
TICKS(1),
SECONDS(ProtocolDefinition.TICKS_PER_SECOND),
DAYS(ProtocolDefinition.TICKS_PER_DAY),
DAYS(WorldTime.TICKS_PER_DAY),
;

companion object {
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/de/bixilon/minosoft/data/world/time/WorldTime.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 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.
*
Expand All @@ -13,21 +13,26 @@

package de.bixilon.minosoft.data.world.time

import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import kotlin.math.abs

class WorldTime(
time: Int = 0,
age: Long = 0L,
) {
val time = abs(time) % ProtocolDefinition.TICKS_PER_DAY
val time = abs(time) % TICKS_PER_DAY
val cycling = time >= 0

val age = abs(age)

val moonPhase = MoonPhases[(this.age / ProtocolDefinition.TICKS_PER_DAY % MoonPhases.VALUES.size).toInt()] // ToDo: Verify
val moonPhase = MoonPhases[(this.age / TICKS_PER_DAY % MoonPhases.VALUES.size).toInt()] // ToDo: Verify
val phase = DayPhases.of(this.time)
val progress = phase.getProgress(this.time)

val day = (this.age + 6000) / ProtocolDefinition.TICKS_PER_DAY // day changes at midnight (18k)
val day = (this.age + 6000) / TICKS_PER_DAY // day changes at midnight (18k)


companion object {
const val TICKS_PER_DAY = 24000
const val TICKS_PER_DAYf = TICKS_PER_DAY.toFloat()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import de.bixilon.minosoft.data.world.time.MoonPhases
import de.bixilon.minosoft.data.world.time.WorldTime
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import java.util.*

class MoonRenderer(
Expand All @@ -48,7 +47,7 @@ class MoonRenderer(
override fun calculateAngle(): Float {
val time = sky.context.connection.world.time

return ((time.time / ProtocolDefinition.TICKS_PER_DAYf) - 0.75f) * 360.0f
return ((time.time / WorldTime.TICKS_PER_DAYf) - 0.75f) * 360.0f
}

override fun calculateIntensity(): Float {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import de.bixilon.kutil.random.RandomUtil.nextFloat
import de.bixilon.minosoft.data.entities.EntityRotation.Companion.CIRCLE_DEGREE
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
import de.bixilon.minosoft.data.world.time.DayPhases
import de.bixilon.minosoft.data.world.time.WorldTime
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import java.util.*
import kotlin.math.pow

Expand All @@ -38,7 +38,7 @@ class SunRenderer(
// 180: night (13k-23k)


return ((time.time / ProtocolDefinition.TICKS_PER_DAYf) - 0.25f) * CIRCLE_DEGREE
return ((time.time / WorldTime.TICKS_PER_DAYf) - 0.25f) * CIRCLE_DEGREE
}

override fun calculateIntensity(): Float {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import de.bixilon.minosoft.config.DebugOptions
import de.bixilon.minosoft.data.world.time.WorldTime
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
Expand All @@ -30,7 +29,7 @@ class TimeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
if (DebugOptions.SIMULATE_TIME) {
return
}
connection.world.time = WorldTime(time = (time % ProtocolDefinition.TICKS_PER_DAY).toInt(), age = age)
connection.world.time = WorldTime(time = (time % WorldTime.TICKS_PER_DAY).toInt(), age = age)
}

override fun log(reducedLog: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ public final class ProtocolDefinition {

public static final RGBColor DEFAULT_COLOR = ChatColors.WHITE;

public static final int TICKS_PER_DAY = 24000;
public static final float TICKS_PER_DAYf = (float) TICKS_PER_DAY;

public static final byte LIGHT_LEVELS = 16;
public static final byte MAX_LIGHT_LEVEL = LIGHT_LEVELS - 1;
public static final int MAX_LIGHT_LEVEL_I = MAX_LIGHT_LEVEL;
Expand Down

0 comments on commit 4cc551d

Please sign in to comment.