Skip to content

Commit da6f338

Browse files
committed
melhor estado ate agora sinoidal resolvi a questao do tempo do cyclo ta bem bom mas agr vou adicionar novas cores para fases do dia
1 parent 82b0e86 commit da6f338

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

src/main/java/com/example/DayNightCyclePlugin.java

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void onBeforeRender(BeforeRender event)
129129
if (client.getGameState() != GameState.LOGGED_IN)
130130
return;
131131

132-
// get latitude, longitude and timezone
132+
// Obter latitude, longitude e timezone
133133
double latitude, longitude;
134134
ZoneId zone;
135135

@@ -150,13 +150,13 @@ public void onBeforeRender(BeforeRender event)
150150

151151
LocalDate today = LocalDate.now(zone);
152152

153-
// Calculate solar event using algorithm
153+
// Calcular eventos solares
154154
ZonedDateTime sunrise = SunCalculator.calculateSunrise(today.getYear(), today.getMonthValue(), today.getDayOfMonth(),
155155
latitude, longitude, zone);
156156
ZonedDateTime sunset = SunCalculator.calculateSunset(today.getYear(), today.getMonthValue(), today.getDayOfMonth(),
157157
latitude, longitude, zone);
158158

159-
// Start Transition 30m before solar event
159+
// Transições 30min antes do evento
160160
ZonedDateTime sunriseStart = sunrise.minusMinutes(30);
161161
ZonedDateTime sunsetStart = sunset.minusMinutes(30);
162162

@@ -171,25 +171,60 @@ public void onBeforeRender(BeforeRender event)
171171
Color skyColor;
172172

173173
if (nowSec < sunriseStartSec)
174+
{
175+
// Noite
174176
skyColor = config.getNightColor();
177+
}
175178
else if (nowSec < sunriseEndSec)
176179
{
180+
// Amanhecer realista: Night → Sunrise → Day
177181
float progress = (float)(nowSec - sunriseStartSec) / (sunriseEndSec - sunriseStartSec);
178-
skyColor = interpolateColor(config.getNightColor(), config.getDayColor(), progress);
182+
183+
if (progress < 0.7f)
184+
{
185+
// Mantém tons quentes do sunrise
186+
float curveProgress = (float) Math.sin(progress / 0.7 * (Math.PI / 2));
187+
skyColor = interpolateColor(config.getNightColor(), config.getSunriseColor(), curveProgress);
188+
}
189+
else
190+
{
191+
// Transição suave final para o DayColor
192+
float curveProgress = (float) Math.sin((progress - 0.7f) / 0.3 * (Math.PI / 2));
193+
skyColor = interpolateColor(config.getSunriseColor(), config.getDayColor(), curveProgress);
194+
}
179195
}
180196
else if (nowSec < sunsetStartSec)
197+
{
198+
// Dia
181199
skyColor = config.getDayColor();
200+
}
182201
else if (nowSec < sunsetEndSec)
183202
{
203+
// Entardecer realista: Day → Sunset → Night
184204
float progress = (float)(nowSec - sunsetStartSec) / (sunsetEndSec - sunsetStartSec);
185-
skyColor = interpolateColor(config.getDayColor(), config.getNightColor(), progress);
205+
206+
if (progress < 0.7f)
207+
{
208+
float curveProgress = (float) Math.sin(progress / 0.7 * (Math.PI / 2));
209+
skyColor = interpolateColor(config.getDayColor(), config.getSunsetColor(), curveProgress);
210+
}
211+
else
212+
{
213+
float curveProgress = (float) Math.sin((progress - 0.7f) / 0.3 * (Math.PI / 2));
214+
skyColor = interpolateColor(config.getSunsetColor(), config.getNightColor(), curveProgress);
215+
}
186216
}
187217
else
218+
{
219+
// Noite
188220
skyColor = config.getNightColor();
221+
}
189222

190223
client.setSkyboxColor(skyColor.getRGB());
191224
}
192225

226+
227+
193228
private Color interpolateColor(Color start, Color end, float t)
194229
{
195230
int r = (int)(start.getRed() * (1 - t) + end.getRed() * t);
@@ -234,14 +269,21 @@ public ZonedDateTime getVirtualTime()
234269

235270
if (config.useCustomHour() && customHourStartTime != null)
236271
{
272+
// tempo real desde que customHour foi definido
237273
long elapsedMillis = System.currentTimeMillis() - realMillisAtCustomStart;
238-
return customHourStartTime.plusNanos(elapsedMillis * 1_000_000L).withZoneSameInstant(zone);
274+
275+
// calcular fator de aceleração do ciclo
276+
double cycleSeconds = config.cycleDuration(); // duração completa do ciclo em segundos
277+
double factor = 24 * 60 * 60 / cycleSeconds; // quantos segundos virtuais por segundo real
278+
279+
long virtualMillis = (long)(elapsedMillis * factor);
280+
return customHourStartTime.plusNanos(virtualMillis * 1_000_000L).withZoneSameInstant(zone);
239281
}
240282

241283
if (config.useRealTimeCycle())
242284
return ZonedDateTime.now(zone);
243285

244-
// Fast Test
286+
// Ciclo rápido (modo teste)
245287
long millis = System.currentTimeMillis();
246288
float t = (millis % (config.cycleDuration() * 1000L)) / (float)(config.cycleDuration() * 1000L);
247289
int totalSeconds = (int)(t * 24 * 60 * 60);
@@ -251,6 +293,7 @@ public ZonedDateTime getVirtualTime()
251293

252294
return ZonedDateTime.now(zone).withHour(hour).withMinute(minute).withSecond(second).withNano(0);
253295
}
296+
254297
}
255298

256299
// https://web.archive.org/web/20161202180207/http://williams.best.vwh.net/sunrise_sunset_algorithm.htm

0 commit comments

Comments
 (0)