Yatopia/patches/server/0051-Optimised-hallowen-checker.patch
Simon Gardling 22be9f2d6f
Upstream (#502)
* Updated Upstream and Sidestream(s) (Paper/Purpur/Origami)

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:
2299159bb Add option to fix items merging through blocks (#5334)
d8c20ddc7 Fix PlayerBucketEmptyEvent result itemstack (#5698)
ceb3762fb Add PufferFishStateChangeEvent (#5606)
cd4defec0 [CI-SKIP] Update version checker to use V2 downloads API (#5728)
b9f2a673d Limit item frame cursors on maps (#5730)
81a537c1f Add PlayerKickEvent causes (#5648)
b7976b956 Add More Lidded Block API (#5707)

Purpur Changes:
b88aef3a Fix Paper#4748 - Shulkerbox allow oversized stacks
9fec1bae Updated Upstream (Paper)
2aacc766 Update Toothpick to 1.1.0-SNAPSHOT
a08d7470 Configurable anvil cumulative cost (#352)

Origami Changes:
3b8adab Fix importing of classes not working if their directory doesn't exist

* Updated Upstream and Sidestream(s) (Paper/Tuinity/Purpur/Empirecraft/Origami)

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:
525d0e3d3 fix beacon activate/deactivate events (#5646)
e403d6aaf [Auto] Updated Upstream (CraftBukkit)
6bcd8b57c Updated Upstream (CraftBukkit) (#5742)
501cc9448 Reset villager inventory on cancelled pickup event (#5738)
3f72a549b Exit with non-zero exit code when killed by watchdog (#5732)
a8d7ad099 Updated Upstream (Bukkit/CraftBukkit) (#5735)

Tuinity Changes:
e9c8348 Revert entity ticking chunk map for tracker

Purpur Changes:
687936be Updated Upstream (Paper)
4c2d7e56 Fix advancement triggers on entity death
49a0fb90 Fix oversized shulker box dupe
e92d259e Fix raid captains not giving voluntary exile advancement
a97fdc48 Config to broadcast the death message to the affected player (#363)
9bf8e165 Add burn in daylight API for LivingEntity (#331)
96460068 Fix dupe bug caused by SPIGOT-6452
2618c24f Revert "allow disabling offline mode message on an ONLINE MODE proxy"
aa79fa5c allow disabling offline mode message on an ONLINE MODE proxy
830141ca Bee can work when raining or at night (#365)
ae6ca468 Updated Upstream (Paper)
d99cc6e8 [ci-skip] Add better issue templates (#360)

Empirecraft Changes:
12009c31 Updated Paper
5305540d Updated Paper
1043bd94 Revert "Call EntityPickupItemEvent for villagers" CB commit
820b9bdf Updated Paper

Origami Changes:
64fba4f Fix importing of classes not working if their directory doesn't exist
3b8adab Fix importing of classes not working if their directory doesn't exist

* rebuild Patches
2021-05-29 19:17:00 -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 2572b5ab8c13f20a4f7efc168fdd8c7adafbcfcd..5392a9bc509008ecfcdad44189c903fd5b57285c 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1478,6 +1478,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 5c9e4724d46b6864cdb85f7d3c8fb0fe37032444..b8ff1af80e87d0715d71d62256f78f1646d82e01 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 1676fbb80e5573c2591c1de7a6a858cf4824b48f..9b4ec2ae5df12fc605770ad6243970a7753dd8dc 100644
--- a/src/main/java/net/minecraft/world/entity/monster/EntitySkeletonAbstract.java
+++ b/src/main/java/net/minecraft/world/entity/monster/EntitySkeletonAbstract.java
@@ -163,11 +163,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 bce7b674ef4450c1f6e932cba1b06ae8730cedfe..446d967f87ce252f62e568c18af54c50d63cb586 100644
--- a/src/main/java/net/minecraft/world/entity/monster/EntityZombie.java
+++ b/src/main/java/net/minecraft/world/entity/monster/EntityZombie.java
@@ -590,11 +590,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;
+ }
+
+}