Skip to content

Commit

Permalink
Add TimeWarp module (#467)
Browse files Browse the repository at this point in the history
* 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 :)

* Rename

---------

Co-authored-by: Constructor <fractalminds@protonmail.com>
  • Loading branch information
Baitinq and Avanatiker authored Feb 18, 2023
1 parent 9aebfc0 commit b3175e2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/com/lambda/mixin/world/MixinWorld.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lambda.mixin.world;

import com.lambda.client.module.modules.misc.AntiWeather;
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;
Expand Down Expand Up @@ -32,4 +33,10 @@ private void getRainStrengthHead(float delta, CallbackInfoReturnable<Float> cir)
cir.setReturnValue(0.0f);
}
}

@Inject(method = "getWorldTime", at = @At("HEAD"), cancellable = true)
public void onGetWorldTime(CallbackInfoReturnable<Long> cir) {
if (TimeWarp.INSTANCE.isEnabled())
cir.setReturnValue(TimeWarp.INSTANCE.getUpdatedTime());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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.*

/**
* @see MixinWorld.onGetWorldTime
*/
object TimeWarp : Module(
name = "TimeWarp",
description = "Change the client-side world time",
category = Category.RENDER
) {
private val mode by setting("Mode", TimeWarpMode.TICKS)
private val time by setting("Time", 0, 0..24000, 600, { mode == TimeWarpMode.TICKS })

enum class TimeWarpMode {
REAL_WORLD_TIME, TICKS
}

@JvmStatic
fun getUpdatedTime(): Long {
if (mode == TimeWarpMode.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()
}
}

0 comments on commit b3175e2

Please sign in to comment.