More performance improvements.

This commit is contained in:
Brianna 2020-04-05 17:15:08 -04:00
parent d229e65388
commit 5874b3bcad
2 changed files with 11 additions and 6 deletions

View File

@ -146,9 +146,11 @@ public class StackingTask extends BukkitRunnable {
int maxEntityStackSize = getEntityStackSize(livingEntity);
// Get similar entities around our entity and make sure those entities are both compatible and stackable.
List<LivingEntity> stackableFriends = plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location)
.stream().filter(entity -> isEntityStackable(entity, location))
.collect(Collectors.toCollection(LinkedList::new));
List<LivingEntity> stackableFriends = new LinkedList<>();
for (LivingEntity entity : plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity, location)) {
if (!isEntityStackable(entity, location)) continue;
stackableFriends.add(entity);
}
// Loop through our similar stackable entities.
for (LivingEntity entity : stackableFriends) {

View File

@ -254,9 +254,12 @@ public class EntityUtils {
public List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initialEntity, Location location) {
// Create a list of all entities around the initial entity of the same type.
List<LivingEntity> entityList = getNearbyEntities(location, searchRadius, stackWholeChunk)
.stream().filter(entity -> entity.getType() == initialEntity.getType() && entity != initialEntity)
.collect(Collectors.toCollection(LinkedList::new));
List<LivingEntity> entityList = new LinkedList<>();
for (LivingEntity entity : getNearbyEntities(location, searchRadius, stackWholeChunk)) {
if (entity.getType() != initialEntity.getType() || entity == initialEntity)
continue;
entityList.add(entity);
}
if (stackFlyingDown && Methods.canFly(initialEntity))
entityList.removeIf(entity -> entity.getLocation().getY() > initialEntity.getLocation().getY());