mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 18:39:23 +00:00
85 lines
3.5 KiB
Diff
85 lines
3.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Martijn Muijsers <martijnmuijsers@live.nl>
|
|
Date: Wed, 23 Nov 2022 16:29:01 +0100
|
|
Subject: [PATCH] Predict Halloween
|
|
|
|
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
|
|
Gale - https://galemc.org
|
|
|
|
The Halloween begins at 10/20 0:00 a.m., and end with 11/04 0:00 a.m.
|
|
Cache the date result to prevent calculate in every call
|
|
|
|
The JMH benchmark of this patch can be found in SunBox's `PredictHalloween`
|
|
|
|
diff --git a/net/minecraft/world/entity/ambient/Bat.java b/net/minecraft/world/entity/ambient/Bat.java
|
|
index 912b099a51269f92f250c7d6094ad41817749f93..a6487b63a277f7ca9681924850718f1dced746b1 100644
|
|
--- a/net/minecraft/world/entity/ambient/Bat.java
|
|
+++ b/net/minecraft/world/entity/ambient/Bat.java
|
|
@@ -245,11 +245,62 @@ public class Bat extends AmbientCreature {
|
|
}
|
|
}
|
|
|
|
+ // Gale start - predict Halloween
|
|
+ /**
|
|
+ * The 1-indexed month of the year that Halloween starts (inclusive).
|
|
+ */
|
|
+ private static final int halloweenStartMonthOfYear = 10;
|
|
+
|
|
+ /**
|
|
+ * The 1-indexed day of the month that Halloween starts (inclusive).
|
|
+ */
|
|
+ private static final int halloweenStartDayOfMonth = 20;
|
|
+
|
|
+ /**
|
|
+ * The 1-indexed month of the year that Halloween ends (exclusive).
|
|
+ */
|
|
+ private static final int halloweenEndMonthOfYear = 11;
|
|
+
|
|
+ /**
|
|
+ * The 1-indexed day of the month that Halloween ends (exclusive).
|
|
+ */
|
|
+ private static final int halloweenEndDayOfMonth = 4;
|
|
+
|
|
+ /**
|
|
+ * The next start of Halloween, given as milliseconds since the Unix epoch.
|
|
+ * Will be 0 while not computed yet.
|
|
+ */
|
|
+ private static long nextHalloweenStart = 0;
|
|
+
|
|
+ /**
|
|
+ * The next end of Halloween, given as milliseconds since the Unix epoch.
|
|
+ * Will be 0 while not computed yet.
|
|
+ */
|
|
+ private static long nextHalloweenEnd = 0;
|
|
+
|
|
private static boolean isHalloween() {
|
|
- LocalDate localDate = LocalDate.now();
|
|
- int i = localDate.get(ChronoField.DAY_OF_MONTH);
|
|
- int i1 = localDate.get(ChronoField.MONTH_OF_YEAR);
|
|
- return i1 == 10 && i >= 20 || i1 == 11 && i <= 3;
|
|
+ long currentEpochMillis = System.currentTimeMillis();
|
|
+
|
|
+ // Update predicate
|
|
+ if (nextHalloweenEnd == 0 || currentEpochMillis >= nextHalloweenEnd) {
|
|
+ java.time.OffsetDateTime currentDate = java.time.OffsetDateTime.ofInstant(java.time.Instant.ofEpochMilli(currentEpochMillis), java.time.ZoneId.systemDefault())
|
|
+ .withHour(0).withMinute(0).withSecond(0).withNano(0); // Adjust to directly start or end at zero o'clock
|
|
+
|
|
+ java.time.OffsetDateTime thisHalloweenStart = currentDate.withMonth(halloweenStartMonthOfYear).withDayOfMonth(halloweenStartDayOfMonth);
|
|
+ java.time.OffsetDateTime thisHalloweenEnd = currentDate.withMonth(halloweenEndMonthOfYear).withDayOfMonth(halloweenEndDayOfMonth);
|
|
+
|
|
+ // Move to next year date if current passed
|
|
+ if (currentDate.isAfter(thisHalloweenEnd)) {
|
|
+ thisHalloweenStart = thisHalloweenStart.plusYears(1);
|
|
+ thisHalloweenEnd = thisHalloweenEnd.plusYears(1);
|
|
+ }
|
|
+
|
|
+ nextHalloweenStart = thisHalloweenStart.toInstant().toEpochMilli();
|
|
+ nextHalloweenEnd = thisHalloweenEnd.toInstant().toEpochMilli();
|
|
+ }
|
|
+
|
|
+ return currentEpochMillis >= nextHalloweenStart && currentEpochMillis < nextHalloweenEnd;
|
|
+ // Gale end - predict Halloween
|
|
}
|
|
|
|
private void setupAnimationStates() {
|