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

Estimate tps and not hard-code it #76

Open
wants to merge 1 commit into
base: 1.20-1.20.1
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,25 @@ protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey<World>
private boolean stevesrealisticsleep$shouldSkipWeather = false;
@Unique
private int stevesrealisticsleep$consecutiveSleepTicks = 0;
@Unique
private int stevesrealisticsleep$ticksSinceLastChecked = 0;
@Unique
private long stevesrealisticsleep$previousTime = System.currentTimeMillis();
@Unique
private double stevesrealisticsleep$estimatedTps = 20.0;

@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/GameRules;getInt(Lnet/minecraft/world/GameRules$Key;)I"))
public void stevesrealisticsleep$tick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
if (stevesrealisticsleep$ticksSinceLastChecked >= 10) {
long currentTime = System.currentTimeMillis();
stevesrealisticsleep$estimatedTps = (double) stevesrealisticsleep$ticksSinceLastChecked / (currentTime - stevesrealisticsleep$previousTime) * 1000;
stevesrealisticsleep$ticksSinceLastChecked = 0;
stevesrealisticsleep$previousTime = currentTime;
System.out.println(stevesrealisticsleep$estimatedTps);
}
stevesrealisticsleep$ticksSinceLastChecked += 1;


// Calculate seconds until awake
int sleepingPlayerCount = sleepManager.getSleeping();
int playerCount = getPlayers().size();
Expand All @@ -120,8 +136,7 @@ protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey<World>
stevesrealisticsleep$timeStepPerTick
);
int timeOfDay = StevesRealisticSleepApi.getTimeOfDay(this);
// TODO: Don't assume the TPS is 20
int secondsUntilAwake = Math.abs(SleepMathUtil.calculateSecondsUntilAwake(timeOfDay, stevesrealisticsleep$timeStepPerTick, 20));
int secondsUntilAwake = Math.abs(SleepMathUtil.calculateSecondsUntilAwake(timeOfDay, stevesrealisticsleep$timeStepPerTick, stevesrealisticsleep$estimatedTps));

// Check if the night has (almost) ended and the weather should be skipped
if (secondsUntilAwake <= 2 && stevesrealisticsleep$shouldSkipWeather) {
Expand Down
Loading