mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 04:09:40 +00:00
Fix tps lag in orespawn dimensions caused by the onSpawn methods (#28)
* 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 76a23a28db.
* Fix tps lags in orespawn dimension
This commit is contained in:
1 parent
5ba45cb86d
commit
33a26a5059
2 files changed
+19
-10
No files matched your search
@@ -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;
|
||||
@@ -31,17 +32,20 @@ public class PotionBloodthirst extends PotionMod {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
@@ -33,14 +34,18 @@ 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)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user