mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-19 15:09:27 +00:00
Update to 1.21.1
This commit is contained in:
209
patches/server/0010-Spooky-month-optimizations.patch
Normal file
209
patches/server/0010-Spooky-month-optimizations.patch
Normal file
@@ -0,0 +1,209 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||
Date: Tue, 21 Nov 2023 16:50:04 -0300
|
||||
Subject: [PATCH] Spooky month optimizations
|
||||
|
||||
The quintessential patch that other performance forks also have for... some reason??? I thought that this optimization was too funny to not do it in SparklyPaper.
|
||||
|
||||
Caches when Bat's spooky season starts and ends, and when Skeleton and Zombies halloween starts and ends. The epoch is updated every 90 days. If your server is running for 90+ days straight without restarts, congratulations!
|
||||
|
||||
Avoids unnecessary date checks, even tho that this shouldn't really improve performance that much... unless you have a lot of bats/zombies/skeletons spawning.
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 7f2e25b2ebb8fb698a4adb12d77670e126549405..b198e2b7a1a96972ecf761e1713085d618aadead 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -324,7 +324,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
public volatile boolean abnormalExit = false; // Paper
|
||||
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
|
||||
public final Set<Entity> entitiesWithScheduledTasks = java.util.concurrent.ConcurrentHashMap.newKeySet(); // SparklyPaper - skip EntityScheduler's executeTick checks if there isn't any tasks to be run (concurrent because plugins may schedule tasks async)
|
||||
-
|
||||
+ public net.sparklypower.sparklypaper.HalloweenManager halloweenManager = new net.sparklypower.sparklypaper.HalloweenManager(); // SparklyPaper - Spooky month optimizations
|
||||
+
|
||||
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
|
||||
AtomicReference<S> atomicreference = new AtomicReference();
|
||||
Thread thread = new ca.spottedleaf.moonrise.common.util.TickThread(() -> { // Paper - rewrite chunk system
|
||||
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
index b7c39d2e93abbc5f988271d738490de68ce50b3b..1395e8f98bd87a060fb609c65a3311c220f5e9a8 100644
|
||||
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
||||
@@ -247,6 +247,10 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
||||
}
|
||||
net.sparklypower.sparklypaper.SparklyPaperCommands.INSTANCE.registerCommands(this);
|
||||
// SparklyPaper end
|
||||
+ // SparklyPaper start - Spooky month optimizations
|
||||
+ halloweenManager.startHalloweenEpochTask();
|
||||
+ halloweenManager.waitUntilEpochHasBeenUpdated();
|
||||
+ // SparklyPaper end
|
||||
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
|
||||
|
||||
this.setPvpAllowed(dedicatedserverproperties.pvp);
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/ambient/Bat.java b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
|
||||
index dc27ddf5131e7398a5390a5187261d4c7fb6ccaa..6c8664c9cf75a88007e43348059fad7e5c60f963 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/ambient/Bat.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
|
||||
@@ -229,7 +229,7 @@ public class Bat extends AmbientCreature {
|
||||
int i = world.getMaxLocalRawBrightness(pos);
|
||||
byte b0 = 4;
|
||||
|
||||
- if (Bat.isHalloween()) {
|
||||
+ if (world.getServer().halloweenManager.isSpookySeason()) { // SparklyPaper - Spooky month optimizations
|
||||
b0 = 7;
|
||||
} else if (random.nextBoolean()) {
|
||||
return false;
|
||||
@@ -239,6 +239,8 @@ public class Bat extends AmbientCreature {
|
||||
}
|
||||
}
|
||||
|
||||
+ // SparklyPaper - Spooky month optimizations
|
||||
+ /*
|
||||
private static boolean isHalloween() {
|
||||
LocalDate localdate = LocalDate.now();
|
||||
int i = localdate.get(ChronoField.DAY_OF_MONTH);
|
||||
@@ -246,6 +248,7 @@ public class Bat extends AmbientCreature {
|
||||
|
||||
return j == 10 && i >= 20 || j == 11 && i <= 3;
|
||||
}
|
||||
+ */
|
||||
|
||||
private void setupAnimationStates() {
|
||||
if (this.isResting()) {
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
||||
index 3b5cf6ffb74d11bea5eb21bd66d679734ff5000c..97bdeb56fee6fb4ae924973730e34dbf933eef68 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
|
||||
@@ -157,10 +157,12 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
|
||||
this.setCanPickUpLoot(this.level().paperConfig().entities.behavior.mobsCanAlwaysPickUpLoot.skeletons || randomsource.nextFloat() < 0.55F * difficulty.getSpecialMultiplier()); // Paper - Add world settings for mobs picking up loot
|
||||
if (this.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) {
|
||||
LocalDate localdate = LocalDate.now();
|
||||
- int i = localdate.get(ChronoField.DAY_OF_MONTH);
|
||||
- int j = localdate.get(ChronoField.MONTH_OF_YEAR);
|
||||
+ // SparklyPaper start - Spooky month optimizations
|
||||
+ // int i = localdate.get(ChronoField.DAY_OF_MONTH);
|
||||
+ // int j = localdate.get(ChronoField.MONTH_OF_YEAR);
|
||||
|
||||
- if (j == 10 && i == 31 && randomsource.nextFloat() < 0.25F) {
|
||||
+ if (this.getServer().halloweenManager.isHalloween() /* j == 10 && i == 31 */&& randomsource.nextFloat() < 0.25F) {
|
||||
+ // SparklyPaper end
|
||||
this.setItemSlot(EquipmentSlot.HEAD, new ItemStack(randomsource.nextFloat() < 0.1F ? Blocks.JACK_O_LANTERN : Blocks.CARVED_PUMPKIN));
|
||||
this.armorDropChances[EquipmentSlot.HEAD.getIndex()] = 0.0F;
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/monster/Zombie.java b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
|
||||
index 2280004638fd19ed018cb3e77d53a018b34ec516..fb15112f920174d7ea6a3bd683418772c0910780 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
|
||||
@@ -553,10 +553,11 @@ public class Zombie extends Monster {
|
||||
|
||||
if (this.getItemBySlot(EquipmentSlot.HEAD).isEmpty()) {
|
||||
LocalDate localdate = LocalDate.now();
|
||||
- int i = localdate.get(ChronoField.DAY_OF_MONTH);
|
||||
- int j = localdate.get(ChronoField.MONTH_OF_YEAR);
|
||||
+ // SparklyPaper start - Spooky month optimizations
|
||||
+ // int i = localdate.get(ChronoField.DAY_OF_MONTH);
|
||||
+ // int j = localdate.get(ChronoField.MONTH_OF_YEAR);
|
||||
|
||||
- if (j == 10 && i == 31 && randomsource.nextFloat() < 0.25F) {
|
||||
+ if (this.getServer().halloweenManager.isHalloween() /* j == 10 && i == 31 */&& randomsource.nextFloat() < 0.25F) {
|
||||
this.setItemSlot(EquipmentSlot.HEAD, new ItemStack(randomsource.nextFloat() < 0.1F ? Blocks.JACK_O_LANTERN : Blocks.CARVED_PUMPKIN));
|
||||
this.armorDropChances[EquipmentSlot.HEAD.getIndex()] = 0.0F;
|
||||
}
|
||||
diff --git a/src/main/kotlin/net/sparklypower/sparklypaper/HalloweenManager.kt b/src/main/kotlin/net/sparklypower/sparklypaper/HalloweenManager.kt
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..8dd82e727872c0d6c4d0827ac63d5fecb9218c61
|
||||
--- /dev/null
|
||||
+++ b/src/main/kotlin/net/sparklypower/sparklypaper/HalloweenManager.kt
|
||||
@@ -0,0 +1,93 @@
|
||||
+package net.sparklypower.sparklypaper
|
||||
+
|
||||
+import com.mojang.logging.LogUtils
|
||||
+import java.time.LocalDateTime
|
||||
+import java.time.Month
|
||||
+import java.time.ZoneOffset
|
||||
+import java.util.concurrent.*
|
||||
+
|
||||
+class HalloweenManager {
|
||||
+ companion object {
|
||||
+ private val LOGGER = LogUtils.getLogger()
|
||||
+ }
|
||||
+ private var spookySeasonStartEpoch = 0L
|
||||
+ private var spookySeasonEndEpoch = 0L
|
||||
+ private var halloweenStartEpoch = 0L
|
||||
+ private var halloweenEndEpoch = 0L
|
||||
+ private var executor = Executors.newSingleThreadScheduledExecutor(object: ThreadFactory {
|
||||
+ override fun newThread(p0: Runnable): Thread {
|
||||
+ val thread = Thread(p0)
|
||||
+ thread.name = "halloween-timer-updater"
|
||||
+ thread.priority = 1 // Minimum priority
|
||||
+ return thread
|
||||
+ }
|
||||
+ })
|
||||
+ private var latch = CountDownLatch(1)
|
||||
+
|
||||
+ fun startHalloweenEpochTask() {
|
||||
+ var isFirst = true
|
||||
+ executor.scheduleAtFixedRate({
|
||||
+ updateEpoch()
|
||||
+ if (isFirst)
|
||||
+ latch.countDown()
|
||||
+ isFirst = false
|
||||
+ }, 0L, 90L, TimeUnit.DAYS) // Every 90 days
|
||||
+ }
|
||||
+
|
||||
+ fun waitUntilEpochHasBeenUpdated() {
|
||||
+ latch.await()
|
||||
+ }
|
||||
+
|
||||
+ fun updateEpoch() {
|
||||
+ LOGGER.info("Updating Spooky Season and Halloween Time")
|
||||
+ this.spookySeasonStartEpoch = getEpochMillisAtDate(20, Month.OCTOBER, false)
|
||||
+ this.spookySeasonEndEpoch = getEpochMillisAtDate(3, Month.NOVEMBER, true)
|
||||
+ this.halloweenStartEpoch = getEpochMillisAtDate(31, Month.OCTOBER, false)
|
||||
+ this.halloweenEndEpoch = getEpochMillisAtDate(31, Month.OCTOBER, true)
|
||||
+ LOGGER.info("Updated Spooky Season and Halloween Time!")
|
||||
+ }
|
||||
+
|
||||
+ fun isSpookySeason() = System.currentTimeMillis() in spookySeasonStartEpoch until spookySeasonEndEpoch
|
||||
+ fun isHalloween() = System.currentTimeMillis() in halloweenStartEpoch until halloweenEndEpoch
|
||||
+
|
||||
+ private fun getEpochMillisAtDate(dayOfMonth: Int, month: Month, isEnd: Boolean): Long {
|
||||
+ // Get the current year
|
||||
+ val currentYear = LocalDateTime.now().year
|
||||
+
|
||||
+ // Define the target date (20/10/CurrentYear at midnight)
|
||||
+ val targetDate = LocalDateTime.of(
|
||||
+ currentYear,
|
||||
+ month,
|
||||
+ dayOfMonth,
|
||||
+ if (isEnd)
|
||||
+ 23
|
||||
+ else
|
||||
+ 0,
|
||||
+ if (isEnd)
|
||||
+ 59
|
||||
+ else
|
||||
+ 0,
|
||||
+ if (isEnd)
|
||||
+ 59
|
||||
+ else
|
||||
+ 0,
|
||||
+ if (isEnd)
|
||||
+ 999_999_999
|
||||
+ else
|
||||
+ 0,
|
||||
+ )
|
||||
+
|
||||
+ // Check if the target date is in the past
|
||||
+ val now = LocalDateTime.now()
|
||||
+ val adjustedDate = if (now.isAfter(targetDate)) {
|
||||
+ // If in the past, adjust to the same date in the next year
|
||||
+ targetDate.plusYears(1)
|
||||
+ } else {
|
||||
+ // If in the future or today, use the original target date
|
||||
+ targetDate
|
||||
+ }
|
||||
+
|
||||
+ // Convert the adjusted date to epoch time in milliseconds
|
||||
+ return adjustedDate.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli()
|
||||
+ }
|
||||
+}
|
||||
\ No newline at end of file
|
||||
Reference in New Issue
Block a user