From fc088e8c0d3b087201d2f8007d7a06d1a3e5f1f2 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Wed, 18 Jan 2023 02:08:09 +0100 Subject: [PATCH 1/2] Add ClientSideTime module This patch adds the ClientSideTime module, which allows the user to change their client-side world time. It currently has two modes; TICKS and REAL_WORLD_TIME. The former allows you to specify the world time as ticks, and the latter uses your current computer time as the world time :) --- .../com/lambda/mixin/world/MixinWorld.java | 7 ++++ .../module/modules/render/ClientSideTime.kt | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/kotlin/com/lambda/client/module/modules/render/ClientSideTime.kt diff --git a/src/main/java/com/lambda/mixin/world/MixinWorld.java b/src/main/java/com/lambda/mixin/world/MixinWorld.java index 8889b15e3..0dd75680d 100644 --- a/src/main/java/com/lambda/mixin/world/MixinWorld.java +++ b/src/main/java/com/lambda/mixin/world/MixinWorld.java @@ -1,6 +1,7 @@ package com.lambda.mixin.world; import com.lambda.client.module.modules.misc.AntiWeather; +import com.lambda.client.module.modules.render.ClientSideTime; import com.lambda.client.module.modules.render.NoRender; import net.minecraft.util.math.BlockPos; import net.minecraft.world.EnumSkyBlock; @@ -32,4 +33,10 @@ private void getRainStrengthHead(float delta, CallbackInfoReturnable cir) cir.setReturnValue(0.0f); } } + + @Inject(method = "getWorldTime", at = @At("HEAD"), cancellable = true) + public void onGetWorldTime(CallbackInfoReturnable cir) { + if (ClientSideTime.INSTANCE.isEnabled()) + cir.setReturnValue(ClientSideTime.INSTANCE.getUpdatedTime()); + } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/render/ClientSideTime.kt b/src/main/kotlin/com/lambda/client/module/modules/render/ClientSideTime.kt new file mode 100644 index 000000000..e86d1893b --- /dev/null +++ b/src/main/kotlin/com/lambda/client/module/modules/render/ClientSideTime.kt @@ -0,0 +1,35 @@ +package com.lambda.client.module.modules.render + +import com.lambda.client.module.Category +import com.lambda.client.module.Module +import java.text.SimpleDateFormat +import java.util.* + +object ClientSideTime : Module( + name = "ClientSideTime", + description = "Change the client-side world time", + category = Category.RENDER +) { + private val mode by setting("Mode", ClientSideTimeMode.TICKS) + private val time by setting("Time", 0, 0..24000, 600, { mode == ClientSideTimeMode.TICKS }) + + enum class ClientSideTimeMode { + REAL_WORLD_TIME, TICKS + } + + @JvmStatic + fun getUpdatedTime(): Long { + if (mode == ClientSideTimeMode.REAL_WORLD_TIME) + return dateToMinecraftTime(Calendar.getInstance()) + return time.toLong() + } + + private fun dateToMinecraftTime(calendar: Calendar): Long { + // We subtract 6 (add 18) to convert the real time to minecraft time :) + calendar.add(Calendar.HOUR, 18) + val time = calendar.time + val minecraftHours = SimpleDateFormat("HH").format(time) + val minecraftMinutes = (SimpleDateFormat("mm").format(time).toLong() * 100) / 60 + return "${minecraftHours}${minecraftMinutes}0".toLong() + } +} \ No newline at end of file From dfff253365a416185ace6699c13d567a72c8820a Mon Sep 17 00:00:00 2001 From: Constructor Date: Thu, 2 Feb 2023 05:21:24 +0100 Subject: [PATCH 2/2] Rename --- .../java/com/lambda/mixin/world/MixinWorld.java | 6 +++--- .../render/{ClientSideTime.kt => TimeWarp.kt} | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) rename src/main/kotlin/com/lambda/client/module/modules/render/{ClientSideTime.kt => TimeWarp.kt} (76%) diff --git a/src/main/java/com/lambda/mixin/world/MixinWorld.java b/src/main/java/com/lambda/mixin/world/MixinWorld.java index 0dd75680d..1b9c9cafd 100644 --- a/src/main/java/com/lambda/mixin/world/MixinWorld.java +++ b/src/main/java/com/lambda/mixin/world/MixinWorld.java @@ -1,7 +1,7 @@ package com.lambda.mixin.world; import com.lambda.client.module.modules.misc.AntiWeather; -import com.lambda.client.module.modules.render.ClientSideTime; +import com.lambda.client.module.modules.render.TimeWarp; import com.lambda.client.module.modules.render.NoRender; import net.minecraft.util.math.BlockPos; import net.minecraft.world.EnumSkyBlock; @@ -36,7 +36,7 @@ private void getRainStrengthHead(float delta, CallbackInfoReturnable cir) @Inject(method = "getWorldTime", at = @At("HEAD"), cancellable = true) public void onGetWorldTime(CallbackInfoReturnable cir) { - if (ClientSideTime.INSTANCE.isEnabled()) - cir.setReturnValue(ClientSideTime.INSTANCE.getUpdatedTime()); + if (TimeWarp.INSTANCE.isEnabled()) + cir.setReturnValue(TimeWarp.INSTANCE.getUpdatedTime()); } } diff --git a/src/main/kotlin/com/lambda/client/module/modules/render/ClientSideTime.kt b/src/main/kotlin/com/lambda/client/module/modules/render/TimeWarp.kt similarity index 76% rename from src/main/kotlin/com/lambda/client/module/modules/render/ClientSideTime.kt rename to src/main/kotlin/com/lambda/client/module/modules/render/TimeWarp.kt index e86d1893b..39877b349 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/render/ClientSideTime.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/render/TimeWarp.kt @@ -2,24 +2,28 @@ package com.lambda.client.module.modules.render import com.lambda.client.module.Category import com.lambda.client.module.Module +import com.lambda.mixin.world.MixinWorld import java.text.SimpleDateFormat import java.util.* -object ClientSideTime : Module( - name = "ClientSideTime", +/** + * @see MixinWorld.onGetWorldTime + */ +object TimeWarp : Module( + name = "TimeWarp", description = "Change the client-side world time", category = Category.RENDER ) { - private val mode by setting("Mode", ClientSideTimeMode.TICKS) - private val time by setting("Time", 0, 0..24000, 600, { mode == ClientSideTimeMode.TICKS }) + private val mode by setting("Mode", TimeWarpMode.TICKS) + private val time by setting("Time", 0, 0..24000, 600, { mode == TimeWarpMode.TICKS }) - enum class ClientSideTimeMode { + enum class TimeWarpMode { REAL_WORLD_TIME, TICKS } @JvmStatic fun getUpdatedTime(): Long { - if (mode == ClientSideTimeMode.REAL_WORLD_TIME) + if (mode == TimeWarpMode.REAL_WORLD_TIME) return dateToMinecraftTime(Calendar.getInstance()) return time.toLong() }