mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 01:16:46 -04:00
move time constant to WorldTime
This commit is contained in:
parent
45f26edd41
commit
4cc551d919
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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.
|
||||||
*
|
*
|
||||||
@ -13,12 +13,13 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.commands.parser.minecraft.time
|
package de.bixilon.minosoft.commands.parser.minecraft.time
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.data.world.time.WorldTime
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||||
|
|
||||||
enum class TimeUnit(val multiplier: Int) {
|
enum class TimeUnit(val multiplier: Int) {
|
||||||
TICKS(1),
|
TICKS(1),
|
||||||
SECONDS(ProtocolDefinition.TICKS_PER_SECOND),
|
SECONDS(ProtocolDefinition.TICKS_PER_SECOND),
|
||||||
DAYS(ProtocolDefinition.TICKS_PER_DAY),
|
DAYS(WorldTime.TICKS_PER_DAY),
|
||||||
;
|
;
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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.
|
||||||
*
|
*
|
||||||
@ -13,21 +13,26 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.data.world.time
|
package de.bixilon.minosoft.data.world.time
|
||||||
|
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
class WorldTime(
|
class WorldTime(
|
||||||
time: Int = 0,
|
time: Int = 0,
|
||||||
age: Long = 0L,
|
age: Long = 0L,
|
||||||
) {
|
) {
|
||||||
val time = abs(time) % ProtocolDefinition.TICKS_PER_DAY
|
val time = abs(time) % TICKS_PER_DAY
|
||||||
val cycling = time >= 0
|
val cycling = time >= 0
|
||||||
|
|
||||||
val age = abs(age)
|
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 phase = DayPhases.of(this.time)
|
||||||
val progress = phase.getProgress(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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import de.bixilon.minosoft.data.world.time.MoonPhases
|
|||||||
import de.bixilon.minosoft.data.world.time.WorldTime
|
import de.bixilon.minosoft.data.world.time.WorldTime
|
||||||
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
import de.bixilon.minosoft.gui.rendering.sky.SkyRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MoonRenderer(
|
class MoonRenderer(
|
||||||
@ -48,7 +47,7 @@ class MoonRenderer(
|
|||||||
override fun calculateAngle(): Float {
|
override fun calculateAngle(): Float {
|
||||||
val time = sky.context.connection.world.time
|
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 {
|
override fun calculateIntensity(): Float {
|
||||||
|
@ -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.entities.EntityRotation.Companion.CIRCLE_DEGREE
|
||||||
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft
|
||||||
import de.bixilon.minosoft.data.world.time.DayPhases
|
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.sky.SkyRenderer
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ class SunRenderer(
|
|||||||
// 180: night (13k-23k)
|
// 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 {
|
override fun calculateIntensity(): Float {
|
||||||
|
@ -16,7 +16,6 @@ import de.bixilon.minosoft.config.DebugOptions
|
|||||||
import de.bixilon.minosoft.data.world.time.WorldTime
|
import de.bixilon.minosoft.data.world.time.WorldTime
|
||||||
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
|
||||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
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.protocol.protocol.buffers.play.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
import de.bixilon.minosoft.util.logging.LogLevels
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
@ -30,7 +29,7 @@ class TimeS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
|
|||||||
if (DebugOptions.SIMULATE_TIME) {
|
if (DebugOptions.SIMULATE_TIME) {
|
||||||
return
|
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) {
|
override fun log(reducedLog: Boolean) {
|
||||||
|
@ -74,9 +74,6 @@ public final class ProtocolDefinition {
|
|||||||
|
|
||||||
public static final RGBColor DEFAULT_COLOR = ChatColors.WHITE;
|
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 LIGHT_LEVELS = 16;
|
||||||
public static final byte MAX_LIGHT_LEVEL = LIGHT_LEVELS - 1;
|
public static final byte MAX_LIGHT_LEVEL = LIGHT_LEVELS - 1;
|
||||||
public static final int MAX_LIGHT_LEVEL_I = MAX_LIGHT_LEVEL;
|
public static final int MAX_LIGHT_LEVEL_I = MAX_LIGHT_LEVEL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user