Reduce allocation in unlistened spawn events
This commit is contained in:
+86
@@ -0,0 +1,86 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: NanaChiyo0721 <nanachiyo0721@163.com>
|
||||||
|
Date: Fri, 7 Aug 2026 14:07:55 +0800
|
||||||
|
Subject: [PATCH] Reduce allocation in unlistened spawn events
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/net/minecraft/util/SpawnUtil.java b/net/minecraft/util/SpawnUtil.java
|
||||||
|
index 625ee78221324ce4959770fe36e4334d057cbc74..ed0e28761b1f14b7907e8e6bfac0690aa2d0b962 100644
|
||||||
|
--- a/net/minecraft/util/SpawnUtil.java
|
||||||
|
+++ b/net/minecraft/util/SpawnUtil.java
|
||||||
|
@@ -57,6 +57,7 @@ public class SpawnUtil {
|
||||||
|
&& moveToPossibleSpawnPosition(level, spawnRangeY, searchPos, strategy)
|
||||||
|
&& (!checkCollisions || level.noCollision(entityType.getSpawnAABB(searchPos.getX() + 0.5, searchPos.getY(), searchPos.getZ() + 0.5)))) {
|
||||||
|
// Paper start - PreCreatureSpawnEvent
|
||||||
|
+ if (com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent.getHandlerList().getRegisteredListeners().length != 0) { // Shiroha - Reduce allocation in unlistened spawn events
|
||||||
|
final com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
|
||||||
|
org.bukkit.craftbukkit.util.CraftLocation.toBukkit(start, level),
|
||||||
|
org.bukkit.craftbukkit.entity.CraftEntityType.minecraftToBukkit(entityType),
|
||||||
|
@@ -71,6 +72,7 @@ public class SpawnUtil {
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
+ } // Shiroha - Reduce allocation in unlistened spawn events
|
||||||
|
// Paper end - PreCreatureSpawnEvent
|
||||||
|
T mob = (T)entityType.create(level, null, searchPos, spawnReason, false, false);
|
||||||
|
if (mob != null) {
|
||||||
|
diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java
|
||||||
|
index 6efaa78faca15c7a48bdffb24480d1bac29f3ba8..93f94d5b8f66b97bfd6a2fe3a35bbcbcfb18d699 100644
|
||||||
|
--- a/net/minecraft/world/entity/EntityType.java
|
||||||
|
+++ b/net/minecraft/world/entity/EntityType.java
|
||||||
|
@@ -230,6 +230,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T>,
|
||||||
|
) {
|
||||||
|
// CraftBukkit end
|
||||||
|
// Paper start - PreCreatureSpawnEvent
|
||||||
|
+ if (com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent.getHandlerList().getRegisteredListeners().length != 0) { // Shiroha - Reduce allocation in unlistened spawn events
|
||||||
|
com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
|
||||||
|
org.bukkit.craftbukkit.util.CraftLocation.toBukkit(spawnPos, level),
|
||||||
|
org.bukkit.craftbukkit.entity.CraftEntityType.minecraftToBukkit(this),
|
||||||
|
@@ -238,6 +239,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T>,
|
||||||
|
if (!event.callEvent()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
+ } // Shiroha - Reduce allocation in unlistened spawn events
|
||||||
|
// Paper end - PreCreatureSpawnEvent
|
||||||
|
T entity = this.create(level, postSpawnConfig, spawnPos, spawnReason, tryMoveDown, movedUp);
|
||||||
|
if (entity != null) {
|
||||||
|
diff --git a/net/minecraft/world/level/BaseSpawner.java b/net/minecraft/world/level/BaseSpawner.java
|
||||||
|
index 2f89a9145902e514089924462003709f256ac3f4..6ef921e08c52e9611e261066724d8893b531fcd8 100644
|
||||||
|
--- a/net/minecraft/world/level/BaseSpawner.java
|
||||||
|
+++ b/net/minecraft/world/level/BaseSpawner.java
|
||||||
|
@@ -140,6 +140,7 @@ public abstract class BaseSpawner {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Paper start - PreCreatureSpawnEvent
|
||||||
|
+ if (com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent.getHandlerList().getRegisteredListeners().length != 0) { // Shiroha - Reduce allocation in unlistened spawn events
|
||||||
|
com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent event = new com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent(
|
||||||
|
org.bukkit.craftbukkit.util.CraftLocation.toBukkit(spawnPos, level),
|
||||||
|
org.bukkit.craftbukkit.entity.CraftEntityType.minecraftToBukkit(entityType.get()),
|
||||||
|
@@ -152,6 +153,7 @@ public abstract class BaseSpawner {
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
+ } // Shiroha - Reduce allocation in unlistened spawn events
|
||||||
|
// Paper end - PreCreatureSpawnEvent
|
||||||
|
|
||||||
|
Entity entity = EntityType.loadEntityRecursive(input, level, EntitySpawnReason.SPAWNER, e -> {
|
||||||
|
diff --git a/net/minecraft/world/level/NaturalSpawner.java b/net/minecraft/world/level/NaturalSpawner.java
|
||||||
|
index 500dcbe924fca160bd673592e1aba384f6eb9ed2..ecdd27be9ac86c396d1cf430356637ee237cf368 100644
|
||||||
|
--- a/net/minecraft/world/level/NaturalSpawner.java
|
||||||
|
+++ b/net/minecraft/world/level/NaturalSpawner.java
|
||||||
|
@@ -391,6 +391,7 @@ public final class NaturalSpawner {
|
||||||
|
) {
|
||||||
|
// Paper start - PreCreatureSpawnEvent
|
||||||
|
EntityType<?> type = currentSpawnData.type();
|
||||||
|
+ if (com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent.getHandlerList().getRegisteredListeners().length != 0) { // Shiroha - Reduce allocation in unlistened spawn events
|
||||||
|
com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent event = new com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent(
|
||||||
|
org.bukkit.craftbukkit.util.CraftLocation.toBukkit(pos, level),
|
||||||
|
org.bukkit.craftbukkit.entity.CraftEntityType.minecraftToBukkit(type), org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NATURAL
|
||||||
|
@@ -401,6 +402,7 @@ public final class NaturalSpawner {
|
||||||
|
}
|
||||||
|
return PreSpawnStatus.CANCELLED;
|
||||||
|
}
|
||||||
|
+ } // Shiroha - Reduce allocation in unlistened spawn events
|
||||||
|
final boolean success = type.getCategory() != MobCategory.MISC
|
||||||
|
// Paper end - PreCreatureSpawnEvent
|
||||||
|
&& (type.canSpawnFarFromPlayer() || !(nearestPlayerDistanceSqr > type.getCategory().getDespawnDistance() * type.getCategory().getDespawnDistance()))
|
||||||
+1
-1
@@ -54,7 +54,7 @@ index 878a00bb28223b2719b4ce7c5d715e0346364770..e89d2af26ffe83e71cfb733cfdbec542
|
|||||||
if (this.paperConfig().unsupportedSettings.ticking.blockEntities) { // Paper - option to disable ticking
|
if (this.paperConfig().unsupportedSettings.ticking.blockEntities) { // Paper - option to disable ticking
|
||||||
profiler.popPush("blockEntities");
|
profiler.popPush("blockEntities");
|
||||||
diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java
|
diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java
|
||||||
index 6efaa78faca15c7a48bdffb24480d1bac29f3ba8..31619890f1bd4f458b6f9a31fac8cefaafe09e8e 100644
|
index 93f94d5b8f66b97bfd6a2fe3a35bbcbcfb18d699..c164e3fa59b47d58c57d65d4330df3a2b31795c6 100644
|
||||||
--- a/net/minecraft/world/entity/EntityType.java
|
--- a/net/minecraft/world/entity/EntityType.java
|
||||||
+++ b/net/minecraft/world/entity/EntityType.java
|
+++ b/net/minecraft/world/entity/EntityType.java
|
||||||
@@ -73,6 +73,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T>,
|
@@ -73,6 +73,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T>,
|
||||||
Reference in New Issue
Block a user