Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
## 1.1.1-beta.2
- Added support for 26.2
- Fixed IRL lunar phases not working

## 1.1.1-beta.1
- Full support for 1.21.1-26.1.2
- Full support for 1.21.1-26.1.2
22 changes: 12 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ val modversion = property("mod.version") as String
val mcversion = property("minecraft_version") as String
val versionrange = property("minecraft_version_range")
val loaderversion = property("loader_version")
val oneconfigVersion = "1.0.0-beta.5"

base {
archivesName.set("$modid-$modversion+$mcversion")
Expand All @@ -27,14 +28,15 @@ repositories {
maven("https://maven.parchmentmc.org")
maven("https://repo.polyfrost.org/releases")
maven("https://repo.polyfrost.org/snapshots")
maven("https://central.sonatype.com/repository/maven-snapshots")
maven("https://maven.gegy.dev/releases")
maven("https://maven.logix.dev/snapshots")
maven("https://nexus.prsm.wtf/repository/maven-public/maven-repo/releases/")
maven("https://repo.hypixel.net/repository/Hypixel/")
maven("https://maven.deftu.dev/releases")
maven("https://maven.fabricmc.net/releases")
maven("https://jitpack.io") { content { includeGroupAndSubgroups("com.github") } }
maven("https://maven.bawnorton.com/releases") { content { includeGroup("com.github.bawnorton.mixinsquared") } }
maven("https://maven.teamresourceful.com/repository/maven-public/") { content { includeGroupAndSubgroups("me.owdding"); includeGroup("com.terraformersmc") } }
maven("https://maven.azureaaron.net/releases") { content { includeGroup("net.azureaaron") } }
maven("https://redirector.kotlinlang.org/maven/compose-dev")
mavenCentral()
Expand Down Expand Up @@ -73,15 +75,15 @@ dependencies {
}
}
modImplementation("net.fabricmc:fabric-loader:${property("loader_version")}")
modImplementation("org.polyfrost.oneconfig:${property("minecraft_version")}-fabric:1.0.0-alpha.193")
implementation("org.polyfrost.oneconfig:commands:1.0.0-alpha.193")
implementation("org.polyfrost.oneconfig:config:1.0.0-alpha.193")
implementation("org.polyfrost.oneconfig:config-impl:1.0.0-alpha.193")
implementation("org.polyfrost.oneconfig:events:1.0.0-alpha.193")
implementation("org.polyfrost.oneconfig:internal:1.0.0-alpha.193")
implementation("org.polyfrost.oneconfig:ui:1.0.0-alpha.193")
implementation("org.polyfrost.oneconfig:utils:1.0.0-alpha.193")
implementation("org.polyfrost.oneconfig:hud:1.0.0-alpha.193")
modImplementation("org.polyfrost.oneconfig:${property("minecraft_version")}-fabric:$oneconfigVersion")
implementation("org.polyfrost.oneconfig:commands:$oneconfigVersion")
implementation("org.polyfrost.oneconfig:config:$oneconfigVersion")
implementation("org.polyfrost.oneconfig:config-impl:$oneconfigVersion")
implementation("org.polyfrost.oneconfig:events:$oneconfigVersion")
implementation("org.polyfrost.oneconfig:internal:$oneconfigVersion")
implementation("org.polyfrost.oneconfig:ui:$oneconfigVersion")
implementation("org.polyfrost.oneconfig:utils:$oneconfigVersion")
implementation("org.polyfrost.oneconfig:hud:$oneconfigVersion")

bundleOnly("dev.deftu:commons-suncalc:0.1.0")!!
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod.group=org.polyfrost

publish.modrinth=m3kNp1iP

loomx.loom_version=1.16-SNAPSHOT
loomx.loom_version=1.17-SNAPSHOT
loader_version=0.19.2

org.gradle.daemon=true
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ plugins {

stonecutter {
create(rootProject) {
versions("1.21.1", "1.21.4", "1.21.5", "1.21.8", "1.21.10", "1.21.11", "26.1")
versions("1.21.1", "1.21.4", "1.21.5", "1.21.8", "1.21.10", "1.21.11", "26.1", "26.2")

vcsVersion = "1.21.10"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
@Mixin(ClientClockManager.class)

public class Mixin_ClientClockManager {
@Inject(method = "getTotalTicks", at = @At("HEAD"), cancellable = true)
@Inject(method = "getTotalTicks", at = @At("RETURN"), cancellable = true)
private void polytime$overrideTicks(Holder<WorldClock> definition, CallbackInfoReturnable<Long> cir) {
if (PolyTimeConfig.isEnabled()) {
cir.setReturnValue(PolyTimeClient.getCurrentTime());
long originalTicks = cir.getReturnValue();
cir.setReturnValue(originalTicks - Math.floorMod(originalTicks, 24000L) + PolyTimeClient.getCurrentTime());
}
}
}
*///?}
*///?} else
public class Mixin_ClientClockManager {}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

@Mixin(ClientLevel.ClientLevelData.class)
public class Mixin_ClientLevelData {
@Inject(method = "getDayTime", at = @At("HEAD"), cancellable = true)
@Inject(method = "getDayTime", at = @At("RETURN"), cancellable = true)
private void polytime$overrideDayTime(CallbackInfoReturnable<Long> cir) {
if (PolyTimeConfig.isEnabled()) {
cir.setReturnValue(PolyTimeClient.getCurrentTime());
long originalDayTime = cir.getReturnValue();
cir.setReturnValue(originalDayTime - Math.floorMod(originalDayTime, 24000L) + PolyTimeClient.getCurrentTime());
}
}
}
*///?}
*///?} else
public class Mixin_ClientLevelData {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
package org.polyfrost.polytime.mixin;

//? if >= 1.21.11 {
/*import org.spongepowered.asm.mixin.injection.Inject;
*///?} else {
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
//?}
//? if >= 1.21.11 {
/*import net.minecraft.client.Camera;
//~ if >= 26.1 'state.SkyRenderState' -> 'state.level.SkyRenderState'
import net.minecraft.client.renderer.state.SkyRenderState;
import net.minecraft.world.level.MoonPhase;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
*///?}
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.LevelRenderer;
//? if >= 1.21.10
//? if >= 1.21.10 {
import net.minecraft.client.renderer.SkyRenderer;
//?} else
//import net.minecraft.client.renderer.LevelRenderer;
import org.polyfrost.polytime.client.PolyTimeConfig;
import org.polyfrost.polytime.client.realtime.RealTimeHandler;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -17,12 +29,21 @@
/*@Mixin(LevelRenderer.class)
*///?}
public class Mixin_FixMoonPhases {
@WrapOperation(method = /*? if >= 1.21.10 {*/ "extractRenderState" /*?} else if >= 1.21.4 {*/ /*"method_62215" *//*?} else {*/ /*"renderSky" *//*?}*/ , at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;getMoonPhase()I"))
//? if >= 1.21.11 {
/*@Inject(method = "extractRenderState", at = @At("TAIL"))
private void polytime$fixMoonPhase(ClientLevel level, float partialTicks, Camera camera, SkyRenderState state, CallbackInfo ci) {
if (PolyTimeConfig.isEnabled() && PolyTimeConfig.getIrlLunarPhases()) {
state.moonPhase = MoonPhase.values()[RealTimeHandler.getCurrentLunarPhase()];
}
}
*///?} elif >= 1.21 {
@WrapOperation(method = /*? if 1.21.10 {*/ "extractRenderState" /*?} elif >= 1.21.4 {*/ /*"method_62215" *//*?} else {*/ /*"renderSky" *//*?}*/ , at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientLevel;getMoonPhase()I"))
private int polyweather$fixMoonPhase(ClientLevel instance, Operation<Integer> original) {
if (PolyTimeConfig.isEnabled() && PolyTimeConfig.isIrlTime()) { // TODO: use irlLunarPhases instead?
if (PolyTimeConfig.isEnabled() && PolyTimeConfig.getIrlLunarPhases()) {
return RealTimeHandler.getCurrentLunarPhase();
}

return original.call(instance);
}
}
//?}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.polyfrost.polytime.mixin;

//? if < 1.21.11 {
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.Holder;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.profiling.ProfilerFiller;
//? if 1.21.1
//import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.storage.WritableLevelData;
Expand All @@ -13,15 +15,15 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

import java.util.function.Supplier;
//? if 1.21.1
//import java.util.function.Supplier;

@Mixin(ClientLevel.class)
public abstract class Mixin_ModifyCelestialGradient extends Level {
protected Mixin_ModifyCelestialGradient(WritableLevelData levelData, ResourceKey<Level> dimension, RegistryAccess registryAccess, Holder<DimensionType> dimensionTypeRegistration, /*? if 1.21.1 {*/ /*Supplier<ProfilerFiller> profiler, *//*?}*/ boolean isClientSide, boolean isDebug, long biomeZoomSeed, int maxChainedNeighborUpdates) {
super(levelData, dimension, registryAccess, dimensionTypeRegistration, /*? if 1.21.1 {*/ /*profiler, *//*?}*/ isClientSide, isDebug, biomeZoomSeed, maxChainedNeighborUpdates);
}

/*? if <1.21.11 {*/
@Override
public float getTimeOfDay(float tickDelta) {
if (PolyTimeConfig.isEnabled()) {
Expand All @@ -38,5 +40,6 @@ public float getTimeOfDay(float tickDelta) {
if (f > 1f) f -= 1f;
return 1f - (float) ((Math.cos(f * Math.PI) + 1.0) / 2.0);
}
/*?}*/
}
//?} else
//public class Mixin_ModifyCelestialGradient {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.polyfrost.oneconfig.api.config.v1.annotations.Keybind
import org.polyfrost.oneconfig.api.config.v1.annotations.Slider
import org.polyfrost.oneconfig.api.config.v1.annotations.Switch
import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindHelper
import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager
import org.polyfrost.polytime.PolyTimeConstants

object PolyTimeConfig : Config("${PolyTimeConstants.ID}.json", "/assets/polytime/polytime_dark.svg", PolyTimeConstants.NAME, Category.QOL) {
Expand All @@ -32,7 +31,7 @@ object PolyTimeConfig : Config("${PolyTimeConstants.ID}.json", "/assets/polytime

@Checkbox(
title = "Use IRL lunar phase",
)
) @JvmStatic
var irlLunarPhases = false

@Slider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,43 @@ import java.util.Calendar
object RealTimeHandler {
private val logger = LogManager.getLogger(RealTimeHandler::class.java)

private var currentlyUpdating = false
private var currentlyUpdatingTime = false
private lateinit var sunData: RealTimeData

private lateinit var data: RealTimeData
private var cachedLunarPhase = 0
private var lastLunarPhaseUpdate = 0L
private const val LUNAR_PHASE_UPDATE_INTERVAL_MS = 60L * 60L * 1000L

@JvmStatic
var currentLunarPhase: Int = 0
private set
val currentLunarPhase: Int
get() {
val now = System.currentTimeMillis()

if (now - lastLunarPhaseUpdate >= LUNAR_PHASE_UPDATE_INTERVAL_MS) {
populateCurrentLunarPhase()
lastLunarPhaseUpdate = now
}

return cachedLunarPhase
}

val currentTime: Float
get() {
if (currentlyUpdating) {
return 0f
if (currentlyUpdatingTime) {
return 12f
}

if (!::sunData.isInitialized) {
populateTime() // Hopefully this blocks the thread until the data is initialized
}

if (!::data.isInitialized) {
populate() // Hopefully this blocks the thread until the data is initialized
if (!::sunData.isInitialized) {
return 12f
}

when {
data.isAlwaysUp -> return 6f
data.isAlwaysDown -> return 18f
sunData.isAlwaysUp -> return 6f
sunData.isAlwaysDown -> return 18f

else -> {
fun Float.calculateMappedTime(periodStart: Float, periodEnd: Float, gameStart: Float, gameEnd: Float): Float {
Expand All @@ -52,10 +68,10 @@ object RealTimeHandler {

val irlTime = irlTime // Caches the value
return when {
irlTime.isWithinPeriod(data.sunrise, data.noon) -> irlTime.calculateMappedTime(data.sunrise, data.noon, 5f, 12f)
irlTime.isWithinPeriod(data.noon, data.sunset) -> irlTime.calculateMappedTime(data.noon, data.sunset, 12f, 19f)
irlTime.isWithinPeriod(data.sunset, data.nadir) -> irlTime.calculateMappedTime(data.sunset, data.nadir, 19f, 0f)
else -> irlTime.calculateMappedTime(data.nadir, data.sunrise, 0f, 5f)
irlTime.isWithinPeriod(sunData.sunrise, sunData.noon) -> irlTime.calculateMappedTime(sunData.sunrise, sunData.noon, 5f, 12f)
irlTime.isWithinPeriod(sunData.noon, sunData.sunset) -> irlTime.calculateMappedTime(sunData.noon, sunData.sunset, 12f, 19f)
irlTime.isWithinPeriod(sunData.sunset, sunData.nadir) -> irlTime.calculateMappedTime(sunData.sunset, sunData.nadir, 19f, 0f)
else -> irlTime.calculateMappedTime(sunData.nadir, sunData.sunrise, 0f, 5f)
}
}
}
Expand All @@ -66,32 +82,37 @@ object RealTimeHandler {
return
}

populate()
populateTime()
}

private fun populate() {
if (currentlyUpdating) {
private fun populateTime() {
if (currentlyUpdatingTime) {
return
}

currentlyUpdating = true
currentlyUpdatingTime = true

val (longitude, latitude) = obtainLongitudeLatitude() ?: return
val times = SunTimes.compute()
.at(latitude, longitude)
.today()
.oneDay()
.timezone(Calendar.getInstance().timeZone)
.execute()
data = RealTimeData.from(times) ?: return logger.error("Failed to obtain real-time data")
logger.info("Obtained real-time data: $data")
try {
val (longitude, latitude) = obtainLongitudeLatitude() ?: return
val times = SunTimes.compute()
.at(latitude, longitude)
.today()
.oneDay()
.timezone(Calendar.getInstance().timeZone)
.execute()
sunData = RealTimeData.from(times) ?: return logger.error("Failed to obtain real-time data")
logger.info("Obtained real-time data: $sunData")
} finally {
currentlyUpdatingTime = false
}
}

private fun populateCurrentLunarPhase() {
val illumination = MoonIllumination.compute()
.at(latitude, longitude)
.today()
.timezone(Calendar.getInstance().timeZone)
.execute()
currentLunarPhase = when (illumination.closestPhase) {
cachedLunarPhase = when (illumination.closestPhase) {
MoonPhase.Phase.FULL_MOON -> 0
MoonPhase.Phase.WANING_GIBBOUS -> 1
MoonPhase.Phase.LAST_QUARTER -> 2
Expand All @@ -103,9 +124,7 @@ object RealTimeHandler {
else -> 0
}

logger.info("Obtained lunar phase: $currentLunarPhase")

currentlyUpdating = false
logger.info("Obtained lunar phase: $cachedLunarPhase")
}

private fun obtainLongitudeLatitude(): Pair<Double, Double>? {
Expand Down
5 changes: 5 additions & 0 deletions versions/26.2/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
yalmm_version=3
minecraft_version=26.2
has_official_mappings=false
java_version=25
minecraft_version_range=~26.2