Skip to content

Commit

Permalink
style: Rename time step per tick variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed Oct 8, 2023
1 parent 99ce98f commit 03ecdb4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin extends World {
@Unique
public double nightTimeStepPerTick = 2;
public double timeStepPerTick = 2;
@Unique
public int nightTimeStepPerTickRounded = 1;
public int timeStepPerTickRounded = 1;
@Unique
public long tickDelay;
@Unique
Expand Down Expand Up @@ -86,11 +86,11 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
int sleepingPlayerCount = sleepManager.getSleeping();
int playerCount = getPlayers().size();
double sleepingRatio = (double) sleepingPlayerCount / playerCount;
nightTimeStepPerTick = SleepMathUtil.calculateNightTimeStepPerTick(
sleepingRatio, config.sleepSpeedMultiplier, nightTimeStepPerTick);
timeStepPerTick = SleepMathUtil.calculateTimeStepPerTick(
sleepingRatio, config.sleepSpeedMultiplier, timeStepPerTick);
int timeOfDay = (int) worldProperties.getTimeOfDay() % DAY_LENGTH;
// TODO: Don't assume the TPS is 20
int secondsUntilAwake = Math.abs(SleepMathUtil.calculateSecondsUntilAwake(timeOfDay, nightTimeStepPerTick, 20));
int secondsUntilAwake = Math.abs(SleepMathUtil.calculateSecondsUntilAwake(timeOfDay, timeStepPerTick, 20));

// Check if the night has (almost) ended and the weather should be skipped
if (secondsUntilAwake <= 2 && shouldSkipWeather) {
Expand All @@ -104,7 +104,7 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
}

// Fetch config values and do calculations
nightTimeStepPerTickRounded = (int) Math.round(nightTimeStepPerTick);
timeStepPerTickRounded = (int) Math.round(timeStepPerTick);
int ticksUntilAwake = Math.abs(SleepMathUtil.calculateTicksUntilAwake(timeOfDay));
double sleepingPercentage = sleepingRatio * 100;
var isNight = SleepMathUtil.isNightTime(timeOfDay);
Expand Down Expand Up @@ -138,7 +138,7 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {

// Advance time
if (doDayLightCycle) {
worldProperties.setTimeOfDay(worldProperties.getTimeOfDay() + nightTimeStepPerTickRounded);
worldProperties.setTimeOfDay(worldProperties.getTimeOfDay() + timeStepPerTickRounded);
}

// Tick block entities
Expand Down Expand Up @@ -186,8 +186,8 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
// Wake up sleeping players
this.wakeSleepingPlayers();

// Reset night time step per tick, to reset the exponential sleep speed curve calculation
nightTimeStepPerTick = 2;
// Reset time step per tick, to reset the exponential sleep speed curve calculation
timeStepPerTick = 2;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class SleepMathUtil {
public static final int DUSK_WAKE_UP_TIME = 12449;
public static final double WAKE_UP_GRACE_PERIOD_TICKS = Math.max(config.sleepSpeedMultiplier, 20);

public static double calculateNightTimeStepPerTick(double sleepingRatio, double multiplier, double lastTimeStepPerTick) {
public static double calculateTimeStepPerTick(double sleepingRatio, double multiplier, double lastTimeStepPerTick) {
return switch (config.sleepSpeedCurve) {
case LINEAR -> sleepingRatio * multiplier;
case EXPONENTIAL -> Math.pow(lastTimeStepPerTick, 1 + sleepingRatio * multiplier);
Expand Down

0 comments on commit 03ecdb4

Please sign in to comment.