Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClientSideTime module #467

Merged
merged 2 commits into from
Feb 18, 2023
Merged
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
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;
@@ -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()
}
}