From 76a23a28dbd09698106539578cd8bff4d5c01523 Mon Sep 17 00:00:00 2001 From: QUENTIN453 Date: Sun, 30 Apr 2023 16:48:45 +0200 Subject: [PATCH] Fix tps lag introduced by onSpawn methods Especially in Orespawn dimensions like unstable dimension theses methods destroys tps before Tested in my modpack spark profiler before : ~ 13 ms https://spark.lucko.me/6KkG1Tq4Su spark profiler after : ~ 8.5 ms https://spark.lucko.me/6m2vv9Hb1X However, originals versions may be more appropriate in some situations where you need to find all players in a given area rather than the closest player. --- .../common/brew/potion/PotionBloodthirst.java | 12 +++++------- .../botania/common/brew/potion/PotionEmptiness.java | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java b/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java index 44eadad2b..b9782a413 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionBloodthirst.java @@ -34,13 +34,11 @@ public class PotionBloodthirst extends PotionMod { @SubscribeEvent public void onSpawn(LivingSpawnEvent.CheckSpawn event) { - if(event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) { - List players = event.world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(event.x - RANGE, event.y - RANGE, event.z - RANGE, event.x + RANGE, event.y + RANGE, event.z + RANGE)); - for(EntityPlayer player : players) - if(hasEffect(player) && !hasEffect(player, ModPotions.emptiness)) { - event.setResult(Result.ALLOW); - return; - } + if (event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) { + EntityPlayer player = event.world.getClosestPlayerToEntity(event.entityLiving, RANGE); + if (player != null && hasEffect(player) && !hasEffect(player, ModPotions.emptiness)) { + event.setResult(Result.ALLOW); + } } } diff --git a/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java b/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java index 6d2b77ea0..da19ccb9a 100644 --- a/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java +++ b/src/main/java/vazkii/botania/common/brew/potion/PotionEmptiness.java @@ -33,13 +33,11 @@ public class PotionEmptiness extends PotionMod { @SubscribeEvent public void onSpawn(LivingSpawnEvent.CheckSpawn event) { - if(event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) { - List players = event.world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(event.x - RANGE, event.y - RANGE, event.z - RANGE, event.x + RANGE, event.y + RANGE, event.z + RANGE)); - for(EntityPlayer player : players) - if(hasEffect(player)) { - event.setResult(Result.DENY); - return; - } + if (event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) { + EntityPlayer player = event.world.getClosestPlayerToEntity(event.entityLiving, RANGE); + if (player != null && hasEffect(player)) { + event.setResult(Result.DENY); + } } }