From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Zeanon Date: Wed, 14 Apr 2021 16:34:39 +0200 Subject: [PATCH] Optimize EntityActivation for multiple players on one spot paper diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java index f735217e7a99bf8286ea60158f9fe137e84ad75c..e92a237b841b70ed274352e6dc9bfc2671ae538e 100644 --- a/src/main/java/org/spigotmc/ActivationRange.java +++ b/src/main/java/org/spigotmc/ActivationRange.java @@ -1,5 +1,6 @@ package org.spigotmc; +import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -203,34 +204,41 @@ public class ActivationRange // Paper end maxRange = Math.min( ( ((net.minecraft.server.WorldServer)world).getChunkProvider().playerChunkMap.getEffectiveViewDistance() << 4 ) - 8, maxRange ); // Paper - no-tick view distance - for ( EntityHuman player : world.getPlayers() ) - { + //Steamwar Start + List boundingBoxes = new ArrayList<>(); + int i = Integer.MAX_VALUE; + int j = Integer.MIN_VALUE; + int k = Integer.MAX_VALUE; + int l = Integer.MIN_VALUE; + for ( EntityHuman player : world.getPlayers() ) { player.activatedTick = MinecraftServer.currentTick; - maxBB = player.getBoundingBox().grow( maxRange, 256, maxRange ); - ActivationType.MISC.boundingBox = player.getBoundingBox().grow( miscActivationRange, 256, miscActivationRange ); - ActivationType.RAIDER.boundingBox = player.getBoundingBox().grow( raiderActivationRange, 256, raiderActivationRange ); - ActivationType.ANIMAL.boundingBox = player.getBoundingBox().grow( animalActivationRange, 256, animalActivationRange ); - ActivationType.MONSTER.boundingBox = player.getBoundingBox().grow( monsterActivationRange, 256, monsterActivationRange ); + maxBB = player.getBoundingBox().grow(maxRange, 256, maxRange); + ActivationType.MISC.boundingBox = player.getBoundingBox().grow(miscActivationRange, 256, miscActivationRange); + ActivationType.RAIDER.boundingBox = player.getBoundingBox().grow(raiderActivationRange, 256, raiderActivationRange); + ActivationType.ANIMAL.boundingBox = player.getBoundingBox().grow(animalActivationRange, 256, animalActivationRange); + ActivationType.MONSTER.boundingBox = player.getBoundingBox().grow(monsterActivationRange, 256, monsterActivationRange); // Paper start - ActivationType.WATER.boundingBox = player.getBoundingBox().grow( waterActivationRange, 256, waterActivationRange ); - ActivationType.FLYING_MONSTER.boundingBox = player.getBoundingBox().grow( flyingActivationRange, 256, flyingActivationRange ); - ActivationType.VILLAGER.boundingBox = player.getBoundingBox().grow( villagerActivationRange, 256, waterActivationRange ); + ActivationType.WATER.boundingBox = player.getBoundingBox().grow(waterActivationRange, 256, waterActivationRange); + ActivationType.FLYING_MONSTER.boundingBox = player.getBoundingBox().grow(flyingActivationRange, 256, flyingActivationRange); + ActivationType.VILLAGER.boundingBox = player.getBoundingBox().grow(villagerActivationRange, 256, waterActivationRange); // Paper end - int i = MathHelper.floor( maxBB.minX / 16.0D ); - int j = MathHelper.floor( maxBB.maxX / 16.0D ); - int k = MathHelper.floor( maxBB.minZ / 16.0D ); - int l = MathHelper.floor( maxBB.maxZ / 16.0D ); + boundingBoxes.add(maxBB); + i = MathHelper.floor(maxBB.minX / 16.0D); + j = MathHelper.floor(maxBB.maxX / 16.0D); + k = MathHelper.floor(maxBB.minZ / 16.0D); + l = MathHelper.floor(maxBB.maxZ / 16.0D); + } - for ( int i1 = i; i1 <= j; ++i1 ) - { - for ( int j1 = k; j1 <= l; ++j1 ) - { - Chunk chunk = chunkProvider.getChunkAtIfLoadedMainThreadNoCache( i1, j1 ); // Paper - if ( chunk != null ) - { - activateChunkEntities( chunk ); + for ( int i1 = i; i1 <= j; ++i1 ) { + for (int j1 = k; j1 <= l; ++j1) { + for (AxisAlignedBB bb : boundingBoxes) { + if (bb.minX <= i1 && bb.maxX >= i1 && bb.minZ <= j1 && bb.maxZ >= j1) { + Chunk chunk = world.getChunkProvider().getChunkAt(i1, j1, false); + if (chunk != null) + activateChunkEntities(chunk); + break; } } }