Yatopia/patches/server/0053-Optimised-hallowen-checker.patch
Simon Gardling cc91a8080f
Upstream (#461)
* Updated Upstream and Sidestream(s) (Paper)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
8a29f5894 [Auto] Updated Upstream (Bukkit/CraftBukkit)
8756d232c Expose server protocol version (#5416)

* Updated Upstream and Sidestream(s) (Tuinity/Purpur)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
32b4d52 Updated Upstream (Paper)
ac5adca Make sure lit is set for pre 1.14 chunks

Purpur Changes:
24d9e61 Piglin portal spawn modifier
5866f36 Fix #263 - NPE on TPSBar when player disconnects
7f7f024 Updated Upstream (Paper, Tuinity, & Airplane)

* bump kotlin-stdlib

* Updated Upstream and Sidestream(s) (Paper/Airplane/Purpur)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
606cdac60 Update the view distance before scheduling chunk loads (#5269)

Airplane Changes:
0789789 Updated Upstream (Tuinity)
c1e4d71 Fluid cache patch

Purpur Changes:
04f73c5 Fix error when using non living entity on monster egg
76c35fc Fix #287 - TPSBarTask NPE (again)

* Updated Upstream and Sidestream(s) (Purpur)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Purpur Changes:
2e62618 Fix #280 - Ridables do not reset idle timer
2021-04-15 14:46:34 -04:00

145 lines
6.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Mon, 4 Jan 2021 20:12:36 +0200
Subject: [PATCH] Optimised hallowen checker
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index d90deadd51fe2fadbd972f029204bee92640663d..01775d93c5cc6eda99c0a7190b5ce43be36d52cc 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1464,6 +1464,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// Paper end
com.tuinity.tuinity.util.CachedLists.reset(); // Tuinity
+ org.yatopiamc.yatopia.server.entity.HalloweenChecker.tick(); // Yatopia
// Paper start
long endTime = System.nanoTime();
diff --git a/src/main/java/net/minecraft/world/entity/ambient/EntityBat.java b/src/main/java/net/minecraft/world/entity/ambient/EntityBat.java
index e6c5d21da445c9b66dcca33d9029d1768bbe046a..56dbac9b4d97bf012a99e138add98fcc8ae453e4 100644
--- a/src/main/java/net/minecraft/world/entity/ambient/EntityBat.java
+++ b/src/main/java/net/minecraft/world/entity/ambient/EntityBat.java
@@ -307,11 +307,16 @@ public class EntityBat extends EntityAmbient {
}
private static boolean eJ() {
+ // Yatopia start - optimised halloween checker
+ /*
LocalDate localdate = LocalDate.now();
int i = localdate.get(ChronoField.DAY_OF_MONTH);
int j = localdate.get(ChronoField.MONTH_OF_YEAR);
return j == 10 && i >= 20 || j == 11 && i <= 3;
+ */
+ return org.yatopiamc.yatopia.server.entity.HalloweenChecker.isHalloweenSeason();
+ // Yatopia end
}
@Override
diff --git a/src/main/java/net/minecraft/world/entity/monster/EntitySkeletonAbstract.java b/src/main/java/net/minecraft/world/entity/monster/EntitySkeletonAbstract.java
index 7ec60987229927e5fe7164f1d4eae8222832e920..faae6cdd816c86b3c7b86104a2017974c05e3452 100644
--- a/src/main/java/net/minecraft/world/entity/monster/EntitySkeletonAbstract.java
+++ b/src/main/java/net/minecraft/world/entity/monster/EntitySkeletonAbstract.java
@@ -154,11 +154,15 @@ public abstract class EntitySkeletonAbstract extends EntityMonster implements IR
this.eL();
this.setCanPickupLoot(this.world.paperConfig.skeletonsAlwaysCanPickUpLoot || this.random.nextFloat() < 0.55F * difficultydamagescaler.d()); // Paper
if (this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
+ /* // Yatopia start - optimised halloween checker
LocalDate localdate = LocalDate.now();
int i = localdate.get(ChronoField.DAY_OF_MONTH);
int j = localdate.get(ChronoField.MONTH_OF_YEAR);
if (j == 10 && i == 31 && this.random.nextFloat() < 0.25F) {
+ */
+ if (org.yatopiamc.yatopia.server.entity.HalloweenChecker.isHalloweenDay() && this.random.nextFloat() < 0.25F) {
+ // Yatopia end
this.setSlot(EnumItemSlot.HEAD, new ItemStack(this.random.nextFloat() < 0.1F ? Blocks.JACK_O_LANTERN : Blocks.CARVED_PUMPKIN));
this.dropChanceArmor[EnumItemSlot.HEAD.b()] = 0.0F;
}
diff --git a/src/main/java/net/minecraft/world/entity/monster/EntityZombie.java b/src/main/java/net/minecraft/world/entity/monster/EntityZombie.java
index 7112db516e62ca75a445482005c524129b84f54c..5060c8c32ceb13475c60f831e0f4fd132cf952b3 100644
--- a/src/main/java/net/minecraft/world/entity/monster/EntityZombie.java
+++ b/src/main/java/net/minecraft/world/entity/monster/EntityZombie.java
@@ -585,11 +585,15 @@ public class EntityZombie extends EntityMonster {
}
if (this.getEquipment(EnumItemSlot.HEAD).isEmpty()) {
+ /* // Yatopia start - optimised halloween checker
LocalDate localdate = LocalDate.now();
int i = localdate.get(ChronoField.DAY_OF_MONTH);
int j = localdate.get(ChronoField.MONTH_OF_YEAR);
if (j == 10 && i == 31 && this.random.nextFloat() < 0.25F) {
+ */
+ if (org.yatopiamc.yatopia.server.entity.HalloweenChecker.isHalloweenDay() && this.random.nextFloat() < 0.25F) {
+ // Yatopia end
this.setSlot(EnumItemSlot.HEAD, new ItemStack(this.random.nextFloat() < 0.1F ? Blocks.JACK_O_LANTERN : Blocks.CARVED_PUMPKIN));
this.dropChanceArmor[EnumItemSlot.HEAD.b()] = 0.0F;
}
diff --git a/src/main/java/org/yatopiamc/yatopia/server/entity/HalloweenChecker.java b/src/main/java/org/yatopiamc/yatopia/server/entity/HalloweenChecker.java
new file mode 100644
index 0000000000000000000000000000000000000000..b9e8c25fa4c4cc088a12c2b865887751c8cdbcd8
--- /dev/null
+++ b/src/main/java/org/yatopiamc/yatopia/server/entity/HalloweenChecker.java
@@ -0,0 +1,59 @@
+package org.yatopiamc.yatopia.server.entity;
+
+import java.time.LocalDate;
+import java.time.temporal.ChronoField;
+import net.minecraft.server.MinecraftServer;
+
+/**
+ * Entity halloween checker
+ * <p>
+ * Checks whether or not it is halloween at a specific rate rather than every time when
+ * a entity is being spawned.
+ * <p>
+ * The rate changes depending on how much TPS the server has. By default, the rate is every
+ * 2 hours, or every 144k ticks (if the server has _that_ much uptime)
+ *
+ * @author MrIvanPlays
+ */
+public class HalloweenChecker {
+
+ private static boolean halloweenSeason = false;
+ private static boolean halloweenDay = false;
+
+ private static int delay = (20 * 60 * 60) * 2;
+ private static int lastCheckTick = -delay;
+
+ public static void tick() {
+ if (MinecraftServer.currentTick % 100 == 0) {
+ // update the delay every 100 ticks
+ if (MinecraftServer.TPS >= 20) {
+ delay = (20 * 60 * 60) * 2;
+ }
+ if (MinecraftServer.TPS < 15) {
+ delay = delay + (20 * 60 * 15);
+ }
+ if (MinecraftServer.TPS < 10) {
+ delay = delay + (20 * 60 * 30);
+ }
+ }
+ if (MinecraftServer.currentTick - lastCheckTick > delay) {
+ LocalDate now = LocalDate.now();
+ int day = now.getDayOfMonth();
+ int month = now.get(ChronoField.MONTH_OF_YEAR);
+
+ halloweenDay = (month == 10) && (day == 31);
+ halloweenSeason = ((month == 10) && (day >= 20)) || ((month == 11) && (day <= 3));
+
+ lastCheckTick = MinecraftServer.currentTick;
+ }
+ }
+
+ public static boolean isHalloweenSeason() {
+ return halloweenSeason;
+ }
+
+ public static boolean isHalloweenDay() {
+ return halloweenDay;
+ }
+
+}