Skip to content

Commit

Permalink
refactor(photovoltaic-modules): extract constants
Browse files Browse the repository at this point in the history
  • Loading branch information
chriptus13 committed Jan 2, 2025
1 parent f1afe10 commit eed0c02
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ public int getGenerationRate() {
return 0;
}

int minuteInTicks = 20 * 60;
int minutesPerDay = 20;
int dayInTicks = minuteInTicks * minutesPerDay;

boolean day;
boolean night;
if (soulData != null) {
Expand All @@ -133,12 +129,12 @@ public int getGenerationRate() {
if (day && (night || hasLiquidSunshine())) {
progress = 1;
} else if (day) {
int dayTime = (int) (level.getDayTime() % dayInTicks);
if (dayTime > minuteInTicks * 12) {
int dayTime = (int) (level.getDayTime() % GameTicks.DAY_IN_TICKS);
if (dayTime > GameTicks.minutesToTicks(12)) {
return 0;
}
progress = dayTime > minuteInTicks * 5 ? 10 * minuteInTicks - dayTime : dayTime;
progress = (progress - minuteInTicks) / (4 * minuteInTicks);
progress = dayTime > GameTicks.minutesToTicks(5) ? GameTicks.minutesToTicks(10) - dayTime : dayTime;
progress = (progress - GameTicks.MINUTE_IN_TICKS) / GameTicks.minutesToTicks(4);
} else if (night) {
return 0;
}
Expand Down Expand Up @@ -275,4 +271,22 @@ public void setEntityType(ResourceLocation entityType) {
static void onReload(RecipesUpdatedEvent event) {
reload = !reload;
}

private static final class GameTicks {
static final int TICKS_PER_SECOND = 20;
static final int MINUTE_IN_TICKS = TICKS_PER_SECOND * 60;
static final int DAY_DURATION_MIN = 20;
static final int DAY_IN_TICKS = DAY_DURATION_MIN * MINUTE_IN_TICKS;

/**
* Converts minutes to game ticks.
* @see GameTicks#TICKS_PER_SECOND
*
* @param minutes to convert.
* @return corresponding minutes in game ticks.
*/
static int minutesToTicks(int minutes) {
return minutes * 60 * TICKS_PER_SECOND;
}
}
}

0 comments on commit eed0c02

Please sign in to comment.