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.
This commit is contained in:
QUENTIN453 committed 2023-04-30 16:48:45 +02:00
1 parent 2f47326c7f
commit 76a23a28db
2 files changed
+10 -14

No files matched your search

@@ -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<EntityPlayer> 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);
}
}
}
@@ -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<EntityPlayer> 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);
}
}
}