Skip to content

Commit

Permalink
Fix tps lag in orespawn dimensions caused by the onSpawn methods (#28)
Browse files Browse the repository at this point in the history
* 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.

* Revert "Fix tps lag introduced by onSpawn methods"

This reverts commit 76a23a2.

* Fix tps lags in orespawn dimension
  • Loading branch information
quentin452 authored May 5, 2023
1 parent 5ba45cb commit 33a26a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package vazkii.botania.common.brew.potion;

import java.util.List;
import java.util.stream.Collectors;

import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -31,17 +32,20 @@ public PotionBloodthirst() {
super(ConfigHandler.potionIDBloodthirst, LibPotionNames.BLOODTHIRST, false, 0xC30000, 3);
MinecraftForge.EVENT_BUS.register(this);
}

@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 (event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) {
double rangeSq = RANGE * RANGE;
List<EntityPlayer> players = (List<EntityPlayer>) event.world.playerEntities.stream()
.filter(player -> ((EntityPlayer) player).getDistanceSq(event.x, event.y, event.z) <= rangeSq)
.map(player -> (EntityPlayer) player)
.collect(Collectors.toList());
for (EntityPlayer player : players) {
if(hasEffect(player) && !hasEffect(player, ModPotions.emptiness)) {
event.setResult(Result.ALLOW);
return;
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package vazkii.botania.common.brew.potion;

import java.util.List;
import java.util.stream.Collectors;

import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -33,14 +34,18 @@ public PotionEmptiness() {

@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)) {
if (event.getResult() != Result.ALLOW && event.entityLiving instanceof IMob) {
double rangeSq = RANGE * RANGE;
List<EntityPlayer> players = (List<EntityPlayer>) event.world.playerEntities.stream()
.filter(player -> ((EntityPlayer) player).getDistanceSq(event.x, event.y, event.z) <= rangeSq)
.map(player -> (EntityPlayer) player)
.collect(Collectors.toList());
for (EntityPlayer player : players) {
if (hasEffect(player)) {
event.setResult(Result.DENY);
return;
}
}
}
}

}

0 comments on commit 33a26a5

Please sign in to comment.