From 82e37493fd1281fe86e738b7ca4bb0037307f0db Mon Sep 17 00:00:00 2001 From: hayanesuru Date: Wed, 1 Oct 2025 20:36:26 +0900 Subject: [PATCH] fix despawnInPeacefulOverride API and inline check despawn --- build-data/leaf.at | 1 + ...0092-Purpur-Server-Minecraft-Changes.patch | 6 +- .../features/0193-optimize-mob-despawn.patch | 175 +----------------- ...-SparklyPaper-Parallel-world-ticking.patch | 16 +- .../0207-Use-BFS-on-getSlopeDistance.patch | 4 +- ...-Micro-optimizations-for-random-tick.patch | 6 +- .../features/0245-optimize-mob-spawning.patch | 6 +- .../features/0252-optimize-random-tick.patch | 6 +- .../features/0258-Paw-optimization.patch | 8 +- ...Paper-PR-Optimise-temptation-lookups.patch | 6 +- .../0272-fix-temptation-lookups.patch | 4 +- .../features/0294-cache-collision-list.patch | 8 +- .../features/0295-fast-bit-radix-sort.patch | 4 +- ...Pluto-Expose-Direction-Plane-s-faces.patch | 4 +- .../org/dreeam/leaf/world/DespawnMap.java | 91 +++++---- 15 files changed, 99 insertions(+), 246 deletions(-) diff --git a/build-data/leaf.at b/build-data/leaf.at index d3f76e37..d21678b2 100644 --- a/build-data/leaf.at +++ b/build-data/leaf.at @@ -12,6 +12,7 @@ public net.minecraft.world.entity.Entity markHurt()V public net.minecraft.world.entity.Entity position public net.minecraft.world.entity.Entity updateInWaterStateAndDoWaterCurrentPushing()V public net.minecraft.world.entity.LivingEntity canGlide()Z +public net.minecraft.world.entity.LivingEntity noActionTime public net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities lineOfSightTest public net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities nearbyEntities public net.minecraft.world.entity.decoration.ArmorStand noTickEquipmentDirty diff --git a/leaf-server/minecraft-patches/features/0092-Purpur-Server-Minecraft-Changes.patch b/leaf-server/minecraft-patches/features/0092-Purpur-Server-Minecraft-Changes.patch index 38187830..d5e12f07 100644 --- a/leaf-server/minecraft-patches/features/0092-Purpur-Server-Minecraft-Changes.patch +++ b/leaf-server/minecraft-patches/features/0092-Purpur-Server-Minecraft-Changes.patch @@ -1285,7 +1285,7 @@ index cfbf34964288526e93d0a5b212c1b60296c10430..d638821595138ef972163925136eb572 + // Purpur end - Shift right click to use exp for mending } diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java -index 37de0c46b065851ea0f0d01e415980e47cc3cfb5..c5ed0843fdcb066d7fa0aa3075796333862ad923 100644 +index 9f5a5ee6a0acc2b6bad9eb4441e8404a45ae314b..e2265ea4bfffa17082357575616948459f0f4885 100644 --- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java +++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java @@ -56,6 +56,10 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack @@ -2324,11 +2324,11 @@ index aab9adb8313c4b18279c7fd7500ef04bda09c6c1..86a694b94045b47f6e98c480645f7573 protected ParticleOptions getInkParticle() { return ParticleTypes.GLOW_SQUID_INK; diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java -index 66e248f348731318590ebd3bd070b7fddf5f0379..fa5010a42970741b930fddedf11527216c8f9173 100644 +index b148de317698c81218168d68e35070084e97334f..5f781ee441b5d478e6105921c22bcf7f6986f48f 100644 --- a/net/minecraft/world/entity/LivingEntity.java +++ b/net/minecraft/world/entity/LivingEntity.java @@ -236,9 +236,9 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin - protected int noActionTime; + public int noActionTime; public float lastHurt; public boolean jumping; - public float xxa; diff --git a/leaf-server/minecraft-patches/features/0193-optimize-mob-despawn.patch b/leaf-server/minecraft-patches/features/0193-optimize-mob-despawn.patch index a352446c..336c6272 100644 --- a/leaf-server/minecraft-patches/features/0193-optimize-mob-despawn.patch +++ b/leaf-server/minecraft-patches/features/0193-optimize-mob-despawn.patch @@ -5,14 +5,13 @@ Subject: [PATCH] optimize mob despawn diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 105423d248df2647d78e6f1a288e9b41003ad437..06294e4036991a803deefc20e35160c5ff76a81b 100644 +index 105423d248df2647d78e6f1a288e9b41003ad437..b52a3b80bcc7f4b940edbb722a6b5fe6c309942d 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -797,13 +797,19 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -797,13 +797,14 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR -+ + if (org.dreeam.leaf.config.modules.opt.OptimizeDespawn.enabled && tickRateManager.runsNormally()) { despawnMap.tick(this, this.entityTickList); } // Leaf - optimize despawn this.entityTickList .forEach( @@ -21,179 +20,15 @@ index 105423d248df2647d78e6f1a288e9b41003ad437..06294e4036991a803deefc20e35160c5 if (!entity.isRemoved()) { if (!tickRateManager.isEntityFrozen(entity)) { - entity.checkDespawn(); -+ // Leaf start - optimize despawn -+ if (!org.dreeam.leaf.config.modules.opt.OptimizeDespawn.enabled) { -+ entity.checkDespawn(); -+ } -+ // Leaf end - optimize despawn ++ if (!org.dreeam.leaf.config.modules.opt.OptimizeDespawn.enabled) { entity.checkDespawn(); } // Leaf - optimize despawn if (true) { // Paper - rewrite chunk system Entity vehicle = entity.getVehicle(); if (vehicle != null) { -@@ -945,6 +951,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -945,6 +946,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe private int currentIceAndSnowTick = 0; protected void resetIceAndSnowTick() { this.currentIceAndSnowTick = this.simpleRandom.nextInt(16); } // Gale - Airplane - optimize random calls in chunk ticking -+ public final org.dreeam.leaf.world.DespawnMap despawnMap = new org.dreeam.leaf.world.DespawnMap(paperConfig()); // Leaf - optimize despawn ++ public final org.dreeam.leaf.world.DespawnMap despawnMap = new org.dreeam.leaf.world.DespawnMap(); // Leaf - optimize despawn public void tickChunk(LevelChunk chunk, int randomTickSpeed) { final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = this.simpleRandom; // Paper - optimise random ticking // Leaf - Faster random generator - upcasting ChunkPos pos = chunk.getPos(); -diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index 6938961cae73d13a12f30a6ea46725af0728e11d..c18f6f3f8307ae1d221a38cd1dc2191cdc4e767a 100644 ---- a/net/minecraft/world/entity/Entity.java -+++ b/net/minecraft/world/entity/Entity.java -@@ -5100,6 +5100,13 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess - public void checkDespawn() { - } - -+ // Leaf start - optimize despawn -+ public void leaf$checkDespawn(org.dreeam.leaf.world.DespawnMap map) { -+ } -+ public void leaf$checkDespawnFallback(org.dreeam.leaf.world.DespawnMap map) { -+ } -+ // Leaf end - optimize despawn -+ - public Vec3[] getQuadLeashHolderOffsets() { - return Leashable.createQuadLeashOffsets(this, 0.0, 0.5, 0.5, 0.0); - } -diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java -index 751c8c17c3c2968fad358ae8807eaca54de82a34..2eafd8453a70e536bea8c125296fc49a7e3677bf 100644 ---- a/net/minecraft/world/entity/Mob.java -+++ b/net/minecraft/world/entity/Mob.java -@@ -762,6 +762,53 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab - } - } - -+ // Leaf start - optimize despawn -+ @Override -+ public void leaf$checkDespawn(org.dreeam.leaf.world.DespawnMap map) { -+ if (isRemoved()) { -+ } else if (map.difficultyIsPeaceful && this.shouldDespawnInPeaceful()) { -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause -+ } else if (this.isPersistenceRequired() || this.requiresCustomPersistence()) { -+ this.noActionTime = 0; -+ } else { -+ map.checkDespawn(this); -+ } -+ } -+ @Override -+ public void leaf$checkDespawnFallback(org.dreeam.leaf.world.DespawnMap map) { -+ if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldActuallyDespawnInPeaceful()) { //Paper - allow changing despawnInPeaceful -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause -+ } else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) { -+ Entity nearestPlayer = map.checkDespawnFallback(this); // Paper - Affects Spawning API -+ if (nearestPlayer != null) { -+ // Paper start - Configurable despawn distances -+ final io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRangePair despawnRangePair = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory()); -+ final io.papermc.paper.configuration.type.DespawnRange.Shape shape = this.level().paperConfig().entities.spawning.despawnRangeShape; -+ final double dy = Math.abs(nearestPlayer.getY() - this.getY()); -+ final double dySqr = Mth.square(dy); -+ final double dxSqr = Mth.square(nearestPlayer.getX() - this.getX()); -+ final double dzSqr = Mth.square(nearestPlayer.getZ() - this.getZ()); -+ final double distanceSquared = dxSqr + dzSqr + dySqr; -+ // Despawn if hard/soft limit is exceeded -+ if (despawnRangePair.hard().shouldDespawn(shape, dxSqr, dySqr, dzSqr, dy) && this.removeWhenFarAway(distanceSquared)) { -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause -+ } -+ -+ if (despawnRangePair.soft().shouldDespawn(shape, dxSqr, dySqr, dzSqr, dy)) { -+ if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && this.removeWhenFarAway(distanceSquared)) { -+ this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause -+ } -+ } else { -+ // Paper end - Configurable despawn distances -+ this.noActionTime = 0; -+ } -+ } -+ } else { -+ this.noActionTime = 0; -+ } -+ } -+ // Leaf end - optimize despawn -+ - @Override - protected final void serverAiStep() { - this.noActionTime++; -diff --git a/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java b/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java -index de09a91b89661118e460842453e33f383ea08a94..e3cdff55261b2ff2c3d1cb1cf46b633a340458c9 100644 ---- a/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java -+++ b/net/minecraft/world/entity/boss/enderdragon/EnderDragon.java -@@ -956,6 +956,15 @@ public class EnderDragon extends Mob implements Enemy { - public void checkDespawn() { - } - -+ // Leaf start - optimize despawn -+ @Override -+ public void leaf$checkDespawn(org.dreeam.leaf.world.DespawnMap map) { -+ } -+ @Override -+ public void leaf$checkDespawnFallback(org.dreeam.leaf.world.DespawnMap map) { -+ } -+ // Leaf end - optimize despawn -+ - public EnderDragonPart[] getSubEntities() { - return this.subEntities; - } -diff --git a/net/minecraft/world/entity/boss/wither/WitherBoss.java b/net/minecraft/world/entity/boss/wither/WitherBoss.java -index e3c34d5f00ce64b3c08b10cfcb3dd14ebe8c1977..3171868523bc9b767cb9da5f58c43890fc8214da 100644 ---- a/net/minecraft/world/entity/boss/wither/WitherBoss.java -+++ b/net/minecraft/world/entity/boss/wither/WitherBoss.java -@@ -695,6 +695,32 @@ public class WitherBoss extends Monster implements RangedAttackMob { - } - } - -+ -+ // Leaf start - optimize despawn -+ @Override -+ public void leaf$checkDespawn(org.dreeam.leaf.world.DespawnMap map) { -+ if (isRemoved()) { -+ return; -+ } -+ if (map.difficultyIsPeaceful && this.shouldDespawnInPeaceful()) { -+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause -+ } else { -+ this.noActionTime = 0; -+ } -+ } -+ @Override -+ public void leaf$checkDespawnFallback(org.dreeam.leaf.world.DespawnMap map) { -+ if (isRemoved()) { -+ return; -+ } -+ if (map.difficultyIsPeaceful && this.shouldDespawnInPeaceful()) { -+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause -+ } else { -+ this.noActionTime = 0; -+ } -+ } -+ // Leaf end - optimize despawn -+ - @Override - public boolean addEffect(MobEffectInstance effectInstance, @Nullable Entity entity) { - return false; -diff --git a/net/minecraft/world/entity/projectile/ShulkerBullet.java b/net/minecraft/world/entity/projectile/ShulkerBullet.java -index 00154ba80175bcb07b3378f19514fec1700c94e9..ec0a30d76df2a20ceb895b2837b0f24bfe887aba 100644 ---- a/net/minecraft/world/entity/projectile/ShulkerBullet.java -+++ b/net/minecraft/world/entity/projectile/ShulkerBullet.java -@@ -197,6 +197,22 @@ public class ShulkerBullet extends Projectile { - } - } - -+ -+ // Leaf start - optimize despawn -+ @Override -+ public void leaf$checkDespawn(org.dreeam.leaf.world.DespawnMap map) { -+ if (!isRemoved() && map.difficultyIsPeaceful) { -+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause -+ } -+ } -+ @Override -+ public void leaf$checkDespawnFallback(org.dreeam.leaf.world.DespawnMap map) { -+ if (!isRemoved() && map.difficultyIsPeaceful) { -+ this.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause -+ } -+ } -+ // Leaf end - optimize despawn -+ - @Override - protected double getDefaultGravity() { - return 0.04; diff --git a/leaf-server/minecraft-patches/features/0202-SparklyPaper-Parallel-world-ticking.patch b/leaf-server/minecraft-patches/features/0202-SparklyPaper-Parallel-world-ticking.patch index 639394b5..1117c56b 100644 --- a/leaf-server/minecraft-patches/features/0202-SparklyPaper-Parallel-world-ticking.patch +++ b/leaf-server/minecraft-patches/features/0202-SparklyPaper-Parallel-world-ticking.patch @@ -423,7 +423,7 @@ index eaaa66c4d86d4ebda0acf8f1dbe8ecb55aa28285..3a6c894178829cec8daa08ea9f0294f7 continue; } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 06294e4036991a803deefc20e35160c5ff76a81b..78062a93c63da07cf9d92b03fc72e97933342cc9 100644 +index b52a3b80bcc7f4b940edbb722a6b5fe6c309942d..37fdfbafbf05dbe88d536e21f9b8bbecd67eee8b 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -180,7 +180,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -609,7 +609,7 @@ index 06294e4036991a803deefc20e35160c5ff76a81b..78062a93c63da07cf9d92b03fc72e979 int _int = this.getGameRules().getInt(GameRules.RULE_PLAYERS_SLEEPING_PERCENTAGE); if (this.purpurConfig.playersSkipNight && this.sleepStatus.areEnoughSleeping(_int) && this.sleepStatus.areEnoughDeepSleeping(_int, this.players)) { // Purpur - Config for skipping night // Paper start - create time skip event - move up calculations -@@ -831,7 +964,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -826,7 +959,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe entity.discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD); // Paper end - Prevent block entity and entity crashes } @@ -619,7 +619,7 @@ index 06294e4036991a803deefc20e35160c5ff76a81b..78062a93c63da07cf9d92b03fc72e979 // Gale end - Airplane - remove lambda from ticking guard - copied from guardEntityTick } } -@@ -1311,9 +1445,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1306,9 +1440,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe fluidState.tick(this, pos, blockState); } // Paper start - rewrite chunk system @@ -634,7 +634,7 @@ index 06294e4036991a803deefc20e35160c5ff76a81b..78062a93c63da07cf9d92b03fc72e979 // Paper end - rewrite chunk system } -@@ -1324,9 +1461,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1319,9 +1456,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe blockState.tick(this, pos, this.random); } // Paper start - rewrite chunk system @@ -649,7 +649,7 @@ index 06294e4036991a803deefc20e35160c5ff76a81b..78062a93c63da07cf9d92b03fc72e979 // Paper end - rewrite chunk system } -@@ -1591,6 +1731,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1586,6 +1726,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } private void addPlayer(ServerPlayer player) { @@ -658,7 +658,7 @@ index 06294e4036991a803deefc20e35160c5ff76a81b..78062a93c63da07cf9d92b03fc72e979 Entity entity = this.getEntity(player.getUUID()); if (entity != null) { LOGGER.warn("Force-added player with duplicate UUID {}", player.getUUID()); -@@ -1603,7 +1745,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1598,7 +1740,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe // CraftBukkit start private boolean addEntity(Entity entity, @Nullable org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { @@ -728,7 +728,7 @@ index b8f5cc4540c4a992ae4cf5673886ce6107eb82a8..6c2b7818ff6535f73fcbb87ef25b2992 // Paper end - Inventory close reason this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId)); diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java -index 9a2e11ff1ed5b8d07b1d6c66ba1a6109c290ff8b..f4cd57fe41caf6422bfe80ee42cb520515ff4bdc 100644 +index 837fed1c7786d6d3397f70d910cace4cdf2223ce..f61fac2767d2085c10a3d34ec475bb07d625737d 100644 --- a/net/minecraft/server/players/PlayerList.java +++ b/net/minecraft/server/players/PlayerList.java @@ -257,6 +257,8 @@ public abstract class PlayerList { @@ -858,7 +858,7 @@ index f9e7532f86122a379692561a639a209a126e8bba..fab317d6c9a1c914f19bae11846cb576 if (isLocatorBarEnabledFor(player)) { if (!connection.isBroken()) { diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index 74926ada5d16ea6e9986e396b51559f2780c8b90..535bc93decdabcd4f5f9a860a89332fd519ef97f 100644 +index 6938961cae73d13a12f30a6ea46725af0728e11d..34788c43d6b03c6ea570024e918f16dfcecd71b9 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -3477,15 +3477,40 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess diff --git a/leaf-server/minecraft-patches/features/0207-Use-BFS-on-getSlopeDistance.patch b/leaf-server/minecraft-patches/features/0207-Use-BFS-on-getSlopeDistance.patch index 66005f2c..35a0e8b4 100644 --- a/leaf-server/minecraft-patches/features/0207-Use-BFS-on-getSlopeDistance.patch +++ b/leaf-server/minecraft-patches/features/0207-Use-BFS-on-getSlopeDistance.patch @@ -9,10 +9,10 @@ Leaf: ~48ms (-36%) This should help drastically on the farms that use actively changing fluids. diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 75f81fada6e8064add9fc04f25933d4fb8f6dcd7..d2cbdfccd9f98516b8fa67f71c84871ee3167dd3 100644 +index 10d353c2416fcd8302465669c363fef7ede97926..8d356c2ef096af6e161af014cd6d4b97fb57bb21 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1444,6 +1444,10 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1439,6 +1439,10 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.emptyTime = 0; } diff --git a/leaf-server/minecraft-patches/features/0212-Micro-optimizations-for-random-tick.patch b/leaf-server/minecraft-patches/features/0212-Micro-optimizations-for-random-tick.patch index 06acd3d9..74754df5 100644 --- a/leaf-server/minecraft-patches/features/0212-Micro-optimizations-for-random-tick.patch +++ b/leaf-server/minecraft-patches/features/0212-Micro-optimizations-for-random-tick.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Micro optimizations for random tick diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index d2cbdfccd9f98516b8fa67f71c84871ee3167dd3..b3d877089f4eebcd78f1019a91d9d71615a15148 100644 +index 8d356c2ef096af6e161af014cd6d4b97fb57bb21..eaa4709337922a21f7f0156fd550807041643bf7 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1042,7 +1042,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1037,7 +1037,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe // Paper start - optimise random ticking private void optimiseRandomTick(final LevelChunk chunk, final int tickSpeed) { final LevelChunkSection[] sections = chunk.getSections(); @@ -17,7 +17,7 @@ index d2cbdfccd9f98516b8fa67f71c84871ee3167dd3..b3d877089f4eebcd78f1019a91d9d716 final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = this.simpleRandom; // Leaf - Faster random generator - upcasting final boolean doubleTickFluids = !ca.spottedleaf.moonrise.common.PlatformHooks.get().configFixMC224294(); -@@ -1051,41 +1051,41 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1046,41 +1046,41 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe final int offsetZ = cpos.z << 4; for (int sectionIndex = 0, sectionsLen = sections.length; sectionIndex < sectionsLen; sectionIndex++) { diff --git a/leaf-server/minecraft-patches/features/0245-optimize-mob-spawning.patch b/leaf-server/minecraft-patches/features/0245-optimize-mob-spawning.patch index 61d50535..a0ad97c3 100644 --- a/leaf-server/minecraft-patches/features/0245-optimize-mob-spawning.patch +++ b/leaf-server/minecraft-patches/features/0245-optimize-mob-spawning.patch @@ -186,13 +186,13 @@ index 3a6c894178829cec8daa08ea9f0294f7f39a8efe..2721b999dcfcf1cd5a0919221f2d94da } } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index b3d877089f4eebcd78f1019a91d9d71615a15148..b9986a9df48f6986c8151d727893b750557e9a74 100644 +index eaa4709337922a21f7f0156fd550807041643bf7..91536cdd85cc86df756f9a4d1e3e9530754ce154 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1092,6 +1092,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1087,6 +1087,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe private int currentIceAndSnowTick = 0; protected void resetIceAndSnowTick() { this.currentIceAndSnowTick = this.simpleRandom.nextInt(16); } // Gale - Airplane - optimize random calls in chunk ticking - public final org.dreeam.leaf.world.DespawnMap despawnMap = new org.dreeam.leaf.world.DespawnMap(paperConfig()); // Leaf - optimize despawn + public final org.dreeam.leaf.world.DespawnMap despawnMap = new org.dreeam.leaf.world.DespawnMap(); // Leaf - optimize despawn + public final org.dreeam.leaf.world.NatureSpawnChunkMap natureSpawnChunkMap = new org.dreeam.leaf.world.NatureSpawnChunkMap(); // Leaf - optimize mob spawning public void tickChunk(LevelChunk chunk, int randomTickSpeed) { final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = this.simpleRandom; // Paper - optimise random ticking // Leaf - Faster random generator - upcasting diff --git a/leaf-server/minecraft-patches/features/0252-optimize-random-tick.patch b/leaf-server/minecraft-patches/features/0252-optimize-random-tick.patch index 34444671..5ca67c7d 100644 --- a/leaf-server/minecraft-patches/features/0252-optimize-random-tick.patch +++ b/leaf-server/minecraft-patches/features/0252-optimize-random-tick.patch @@ -24,12 +24,12 @@ index 2721b999dcfcf1cd5a0919221f2d94da4c93a6e7..2a1a6a0306b781e9ae5c0e3261cb740f this.level.tickCustomSpawners(this.spawnEnemies, this.spawnFriendlies); } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index b9986a9df48f6986c8151d727893b750557e9a74..88a3f390f615275c84237814e10c969bfe3c6a55 100644 +index 91536cdd85cc86df756f9a4d1e3e9530754ce154..4e637d206dbd587c79b787b0c7f41ba09f0e14b5 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1093,6 +1093,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1088,6 +1088,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe - public final org.dreeam.leaf.world.DespawnMap despawnMap = new org.dreeam.leaf.world.DespawnMap(paperConfig()); // Leaf - optimize despawn + public final org.dreeam.leaf.world.DespawnMap despawnMap = new org.dreeam.leaf.world.DespawnMap(); // Leaf - optimize despawn public final org.dreeam.leaf.world.NatureSpawnChunkMap natureSpawnChunkMap = new org.dreeam.leaf.world.NatureSpawnChunkMap(); // Leaf - optimize mob spawning + public final org.dreeam.leaf.world.RandomTickSystem randomTickSystem = new org.dreeam.leaf.world.RandomTickSystem(); // Leaf - optimize random tick public void tickChunk(LevelChunk chunk, int randomTickSpeed) { diff --git a/leaf-server/minecraft-patches/features/0258-Paw-optimization.patch b/leaf-server/minecraft-patches/features/0258-Paw-optimization.patch index e00febb7..72e4f597 100644 --- a/leaf-server/minecraft-patches/features/0258-Paw-optimization.patch +++ b/leaf-server/minecraft-patches/features/0258-Paw-optimization.patch @@ -117,10 +117,10 @@ index 2a1a6a0306b781e9ae5c0e3261cb740f37be4a8c..7e84b94a4602801e8cc713b28d0d9305 if (!org.dreeam.leaf.config.modules.async.AsyncMobSpawning.enabled || _pufferfish_spawnCountsReady.get()) { diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 88a3f390f615275c84237814e10c969bfe3c6a55..0ad594fe2548cf1c00f8d75fe076d62c3c99f393 100644 +index 4e637d206dbd587c79b787b0c7f41ba09f0e14b5..cbfe17764675be099f3178fd2450f4eabef2e02d 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1496,13 +1496,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1491,13 +1491,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe // Paper end - log detailed entity tick information public void tickNonPassenger(Entity entity) { @@ -134,7 +134,7 @@ index 88a3f390f615275c84237814e10c969bfe3c6a55..0ad594fe2548cf1c00f8d75fe076d62c entity.setOldPosAndRot(); entity.tickCount++; entity.totalEntityAge++; // Paper - age-like counter for all entities -@@ -1515,13 +1509,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1510,13 +1504,6 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe for (Entity entity1 : entity.getPassengers()) { this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2 } @@ -149,7 +149,7 @@ index 88a3f390f615275c84237814e10c969bfe3c6a55..0ad594fe2548cf1c00f8d75fe076d62c private void tickPassenger(Entity ridingEntity, Entity passengerEntity, final boolean isActive) { // Paper - EAR 2 diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index 78ffbd45413f552042e8ec77df4e8d896ae5bec1..f3c0b29d50a001029f0275319b87b75a3ff0bca5 100644 +index db0df2dc1e4ef032d07578ce983ca8c3d16d2058..813cecc98a9ba14c018e36bf254a8b26ccc4240b 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -1138,16 +1138,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess diff --git a/leaf-server/minecraft-patches/features/0271-Paper-PR-Optimise-temptation-lookups.patch b/leaf-server/minecraft-patches/features/0271-Paper-PR-Optimise-temptation-lookups.patch index d5116816..2e84094b 100644 --- a/leaf-server/minecraft-patches/features/0271-Paper-PR-Optimise-temptation-lookups.patch +++ b/leaf-server/minecraft-patches/features/0271-Paper-PR-Optimise-temptation-lookups.patch @@ -117,7 +117,7 @@ index 0000000000000000000000000000000000000000..5f5cdfc538ba9aa6666c019df6706015 + } +} diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 0ad594fe2548cf1c00f8d75fe076d62c3c99f393..5798786e4a9420b2a3cdc95d564947e36cd2abef 100644 +index cbfe17764675be099f3178fd2450f4eabef2e02d..f6a7007c0ea69f1d893b79c2f2dbda7ff7ace717 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -936,6 +936,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -125,10 +125,10 @@ index 0ad594fe2548cf1c00f8d75fe076d62c3c99f393..5798786e4a9420b2a3cdc95d564947e3 io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR + this.globalTemptationLookup.reset(); // Paper - optimise temptation lookups - reset global cache prior to next entity tick - if (org.dreeam.leaf.config.modules.opt.OptimizeDespawn.enabled && tickRateManager.runsNormally()) { despawnMap.tick(this, this.entityTickList); } // Leaf - optimize despawn this.entityTickList -@@ -3039,4 +3040,11 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + .forEach( +@@ -3034,4 +3035,11 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.lagCompensationTick = (System.nanoTime() - MinecraftServer.SERVER_INIT) / (java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(50L)); } // Paper end - lag compensation diff --git a/leaf-server/minecraft-patches/features/0272-fix-temptation-lookups.patch b/leaf-server/minecraft-patches/features/0272-fix-temptation-lookups.patch index 84861755..fa2a2f49 100644 --- a/leaf-server/minecraft-patches/features/0272-fix-temptation-lookups.patch +++ b/leaf-server/minecraft-patches/features/0272-fix-temptation-lookups.patch @@ -70,7 +70,7 @@ index 5f5cdfc538ba9aa6666c019df6706015234d7bae..2dfec8f6d0fe833e5f06cf2165ae14bf } } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 5798786e4a9420b2a3cdc95d564947e36cd2abef..b94f2122da885fe94bd60c7914421968e6a2f3fa 100644 +index f6a7007c0ea69f1d893b79c2f2dbda7ff7ace717..3e9162fd7111fb9d4628db72d33afef96f85c9c6 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -936,7 +936,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -79,9 +79,9 @@ index 5798786e4a9420b2a3cdc95d564947e36cd2abef..b94f2122da885fe94bd60c7914421968 io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR - this.globalTemptationLookup.reset(); // Paper - optimise temptation lookups - reset global cache prior to next entity tick + this.globalTemptationLookup.tick(this); // Paper - optimise temptation lookups - reset global cache prior to next entity tick - if (org.dreeam.leaf.config.modules.opt.OptimizeDespawn.enabled && tickRateManager.runsNormally()) { despawnMap.tick(this, this.entityTickList); } // Leaf - optimize despawn this.entityTickList + .forEach( diff --git a/net/minecraft/world/entity/ai/goal/TemptGoal.java b/net/minecraft/world/entity/ai/goal/TemptGoal.java index 0c9a355344463ea85a3b724d22d53638b1e42394..7cb94eb75a1de0cef02d4953ee5896bd5e3c7abd 100644 --- a/net/minecraft/world/entity/ai/goal/TemptGoal.java diff --git a/leaf-server/minecraft-patches/features/0294-cache-collision-list.patch b/leaf-server/minecraft-patches/features/0294-cache-collision-list.patch index 8b7e1319..94e0453f 100644 --- a/leaf-server/minecraft-patches/features/0294-cache-collision-list.patch +++ b/leaf-server/minecraft-patches/features/0294-cache-collision-list.patch @@ -5,11 +5,11 @@ Subject: [PATCH] cache collision list diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index b94f2122da885fe94bd60c7914421968e6a2f3fa..5178290d060dd8a72f0e6cb77f77d19683a866d0 100644 +index 3e9162fd7111fb9d4628db72d33afef96f85c9c6..45697c6719d3d818d6dc893fc831d451b95286c2 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1095,6 +1095,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe - public final org.dreeam.leaf.world.DespawnMap despawnMap = new org.dreeam.leaf.world.DespawnMap(paperConfig()); // Leaf - optimize despawn +@@ -1090,6 +1090,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + public final org.dreeam.leaf.world.DespawnMap despawnMap = new org.dreeam.leaf.world.DespawnMap(); // Leaf - optimize despawn public final org.dreeam.leaf.world.NatureSpawnChunkMap natureSpawnChunkMap = new org.dreeam.leaf.world.NatureSpawnChunkMap(); // Leaf - optimize mob spawning public final org.dreeam.leaf.world.RandomTickSystem randomTickSystem = new org.dreeam.leaf.world.RandomTickSystem(); // Leaf - optimize random tick + public final org.dreeam.leaf.world.EntityCollisionCache entityCollisionCache = new org.dreeam.leaf.world.EntityCollisionCache(); // Leaf - cache collision list @@ -18,7 +18,7 @@ index b94f2122da885fe94bd60c7914421968e6a2f3fa..5178290d060dd8a72f0e6cb77f77d196 final net.minecraft.world.level.levelgen.BitRandomSource simpleRandom = this.simpleRandom; // Paper - optimise random ticking // Leaf - Faster random generator - upcasting ChunkPos pos = chunk.getPos(); diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index dcae12c34690346cb32780f7143fe05549c84c11..841c90c20525e34177de271983db4c1c6b96b57f 100644 +index 21c9c348066ef833cc4c62e03e7cccb7ee4191c1..d8b4f37c49dc20c8fcd74ce7af22f39175685094 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -1647,8 +1647,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess diff --git a/leaf-server/minecraft-patches/features/0295-fast-bit-radix-sort.patch b/leaf-server/minecraft-patches/features/0295-fast-bit-radix-sort.patch index 91d22755..e8e3fcdc 100644 --- a/leaf-server/minecraft-patches/features/0295-fast-bit-radix-sort.patch +++ b/leaf-server/minecraft-patches/features/0295-fast-bit-radix-sort.patch @@ -6,10 +6,10 @@ Subject: [PATCH] fast bit radix sort Co-authored-by: Taiyou06 diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 5178290d060dd8a72f0e6cb77f77d19683a866d0..c5fea3948be691c42e9a94ddb0acd04fcc0b4415 100644 +index 45697c6719d3d818d6dc893fc831d451b95286c2..c48d381b530b5702ac0692e64088445da05f0780 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1096,6 +1096,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1091,6 +1091,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe public final org.dreeam.leaf.world.NatureSpawnChunkMap natureSpawnChunkMap = new org.dreeam.leaf.world.NatureSpawnChunkMap(); // Leaf - optimize mob spawning public final org.dreeam.leaf.world.RandomTickSystem randomTickSystem = new org.dreeam.leaf.world.RandomTickSystem(); // Leaf - optimize random tick public final org.dreeam.leaf.world.EntityCollisionCache entityCollisionCache = new org.dreeam.leaf.world.EntityCollisionCache(); // Leaf - cache collision list diff --git a/leaf-server/minecraft-patches/features/0297-Pluto-Expose-Direction-Plane-s-faces.patch b/leaf-server/minecraft-patches/features/0297-Pluto-Expose-Direction-Plane-s-faces.patch index 85bd0516..b2819ae3 100644 --- a/leaf-server/minecraft-patches/features/0297-Pluto-Expose-Direction-Plane-s-faces.patch +++ b/leaf-server/minecraft-patches/features/0297-Pluto-Expose-Direction-Plane-s-faces.patch @@ -35,10 +35,10 @@ index 45093451fb25ae3bb1e57d2e53c49a1ae666e31e..c228135032b5f74fd1ec96a2cf52aa3e } } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index c5fea3948be691c42e9a94ddb0acd04fcc0b4415..7f6eda550ad99dad49aa3d47800213b7ba2d341a 100644 +index c48d381b530b5702ac0692e64088445da05f0780..c96e651d33864c3a15bb1103fb95c5f87a3bdb52 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -1179,7 +1179,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1174,7 +1174,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe // We only need to check blocks that are taller than the minimum step height if (org.purpurmc.purpur.PurpurConfig.smoothSnowAccumulationStep > 0 && layersValue >= org.purpurmc.purpur.PurpurConfig.smoothSnowAccumulationStep) { int layersValueMin = layersValue - org.purpurmc.purpur.PurpurConfig.smoothSnowAccumulationStep; diff --git a/leaf-server/src/main/java/org/dreeam/leaf/world/DespawnMap.java b/leaf-server/src/main/java/org/dreeam/leaf/world/DespawnMap.java index fb91c9a9..a6e84bac 100644 --- a/leaf-server/src/main/java/org/dreeam/leaf/world/DespawnMap.java +++ b/leaf-server/src/main/java/org/dreeam/leaf/world/DespawnMap.java @@ -8,6 +8,9 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntitySelector; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.entity.boss.enderdragon.EnderDragon; +import net.minecraft.world.entity.boss.wither.WitherBoss; +import net.minecraft.world.entity.projectile.ShulkerBullet; import net.minecraft.world.level.entity.EntityTickList; import net.minecraft.world.phys.Vec3; import org.bukkit.event.entity.EntityRemoveEvent; @@ -18,22 +21,22 @@ import java.util.OptionalInt; import java.util.function.Consumer; public final class DespawnMap implements Consumer { - private static final ServerPlayer[] EMPTY_PLAYERS = {}; - private final KDTree3D tree = new KDTree3D(); + private static final MobCategory[] CATEGORIES = MobCategory.values(); + private static final ServerPlayer[] EMPTY_PLAYERS = {}; + + private final KDTree3D tree = new KDTree3D(); private final double[] hard = new double[CATEGORIES.length]; private final double[] sort = new double[CATEGORIES.length]; - private final boolean fallback; - public boolean difficultyIsPeaceful = true; - private ServerPlayer[] players = EMPTY_PLAYERS; + private boolean difficultyIsPeaceful = true; - public DespawnMap(WorldConfiguration worldConfiguration) { + public void tick(final ServerLevel world, final EntityTickList entityTickList) { for (int i = 0; i < CATEGORIES.length; i++) { sort[i] = CATEGORIES[i].getNoDespawnDistance(); hard[i] = CATEGORIES[i].getDespawnDistance(); } boolean fallback = false; - for (Map.Entry e : worldConfiguration.entities.spawning.despawnRanges.entrySet()) { + for (Map.Entry e : world.paperConfig().entities.spawning.despawnRanges.entrySet()) { OptionalInt softVertical = e.getValue().soft().verticalLimit.value(); OptionalInt softHorizontal = e.getValue().soft().horizontalLimit.value(); OptionalInt hardVertical = e.getValue().hard().verticalLimit.value(); @@ -56,21 +59,22 @@ public final class DespawnMap implements Consumer { if (hard[i] > 0.0) { hard[i] = hard[i] * hard[i]; } + if (sort[i] > hard[i]) { + sort[i] = hard[i]; + } } - this.fallback = fallback; - } - - public void tick(final ServerLevel world, final EntityTickList entityTickList) { - players = world.players().toArray(EMPTY_PLAYERS); + ServerPlayer[] players = world.players().toArray(EMPTY_PLAYERS); final double[] pxl = new double[players.length]; final double[] pyl = new double[players.length]; final double[] pzl = new double[players.length]; int i = 0; - for (final ServerPlayer p : players) { + for (int j = 0, len = players.length; j < len; j++) { + ServerPlayer p = players[j]; if (EntitySelector.PLAYER_AFFECTS_SPAWNING.test(p)) { pxl[i] = p.getX(); pyl[i] = p.getY(); pzl[i] = p.getZ(); + players[i] = p; i++; } } @@ -81,41 +85,54 @@ public final class DespawnMap implements Consumer { tree.build(new double[][]{pxl, pyl, pzl}, indices); this.difficultyIsPeaceful = world.getDifficulty() == Difficulty.PEACEFUL; if (fallback) { - entityTickList.forEach(entity -> entity.leaf$checkDespawnFallback(this)); + entityTickList.forEach(entity -> { + if (!entity.isRemoved()) { + entity.checkDespawn(); + } + }); } else { entityTickList.forEach(this); } - players = EMPTY_PLAYERS; } - public void checkDespawn(final Mob mob) { - final int i = mob.getType().getCategory().ordinal(); - final double hardDist = this.hard[i]; - final Vec3 vec3 = mob.position; - final double dist = this.tree.nearestSqr(vec3.x, vec3.y, vec3.z, hardDist); - if (dist == Double.POSITIVE_INFINITY) { - return; - } - - if (dist >= hardDist && mob.removeWhenFarAway(dist)) { - mob.discard(EntityRemoveEvent.Cause.DESPAWN); - } else if (dist > this.sort[i]) { - if (mob.getNoActionTime() > 600 && mob.random.nextInt(800) == 0 && mob.removeWhenFarAway(dist)) { - mob.discard(EntityRemoveEvent.Cause.DESPAWN); + private boolean checkDespawn(final Entity entity) { + if (entity instanceof Mob mob) { + if (!(mob instanceof EnderDragon)) { + if (difficultyIsPeaceful && mob.shouldActuallyDespawnInPeaceful()) { + return true; + } else if (mob instanceof WitherBoss || mob.isPersistenceRequired() || mob.requiresCustomPersistence()) { + mob.noActionTime = 0; + return false; + } else { + final int i = mob.getType().getCategory().ordinal(); + final double hardDist = this.hard[i]; + final Vec3 vec3 = mob.position; + final double dist = this.tree.nearestSqr(vec3.x, vec3.y, vec3.z, hardDist); + if (dist == Double.POSITIVE_INFINITY) { + return false; + } else if (dist >= hardDist) { + return mob.removeWhenFarAway(dist); + } else if (dist > this.sort[i]) { + return mob.noActionTime > 600 && mob.random.nextInt(800) == 0 && mob.removeWhenFarAway(dist); + } else { + mob.noActionTime = 0; + return false; + } + } + } else { + return false; } + } else if (!(entity instanceof ShulkerBullet)) { + return false; } else { - mob.setNoActionTime(0); + return difficultyIsPeaceful; } } - public ServerPlayer checkDespawnFallback(final Mob mob) { - final Vec3 vec3 = mob.position; - final int i = tree.nearestIdx(vec3.x, vec3.y, vec3.z, Double.POSITIVE_INFINITY); - return i == -1 ? null : this.players[i]; - } - @Override public void accept(final Entity entity) { - entity.leaf$checkDespawn(this); + if (entity != null && !entity.isRemoved() && checkDespawn(entity)) { + entity.discard(EntityRemoveEvent.Cause.DESPAWN); + } } }