Skip to content

Commit

Permalink
huge performance boost for entity limit
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelvlad committed Nov 7, 2022
1 parent f726492 commit 97006d2
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,12 @@ AtLimitResult atLimit(Island island, Entity ent) {
// We have to count the entities
if (limitAmount >= 0)
{
int count = (int) ent.getWorld().getEntities().stream()
// int count = (int) ent.getWorld().getEntities().stream()
// .filter(e -> e.getType().equals(ent.getType()))
// .filter(e -> island.inIslandSpace(e.getLocation()))
// .count();
int count = (int) ent.getWorld().getNearbyEntities(island.getBoundingBox()).stream()
.filter(e -> e.getType().equals(ent.getType()))
.filter(e -> island.inIslandSpace(e.getLocation()))
.count();
int max = limitAmount + (ibc == null ? 0 : ibc.getEntityLimitOffset(ent.getType()));
if (count >= max) {
Expand All @@ -424,9 +427,12 @@ AtLimitResult atLimit(Island island, Entity ent) {
for (Map.Entry<Settings.EntityGroup, Integer> group : groupsLimits.entrySet()) { //do not use lambda
if (group.getValue() < 0)
continue;
int count = (int) ent.getWorld().getEntities().stream()
// int count = (int) ent.getWorld().getEntities().stream()
// .filter(e -> group.getKey().contains(e.getType()))
// .filter(e -> island.inIslandSpace(e.getLocation())).count();
int count = (int) ent.getWorld().getNearbyEntities(island.getBoundingBox()).stream()
.filter(e -> group.getKey().contains(e.getType()))
.filter(e -> island.inIslandSpace(e.getLocation())).count();
.count();
int max = group.getValue() + + (ibc == null ? 0 : ibc.getEntityGroupLimitOffset(group.getKey().getName()));
if (count >= max) {
return new AtLimitResult(group.getKey(), max);
Expand Down

0 comments on commit 97006d2

Please sign in to comment.