Archiviert
13
0

Optimize entity activation with multiple player on one spot #3

Zusammengeführt
Lixfel hat 1 Commits von optimizeEntityActivation nach master 2021-02-19 08:50:56 +01:00 zusammengeführt
Nur Änderungen aus Commit 6a5030832a werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -0,0 +1,71 @@
Index: src/main/java/org/spigotmc/ActivationRange.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
--- a/src/main/java/org/spigotmc/ActivationRange.java (revision 3e58cc3e7eddba8b9206c076a5a3aab5d857269a)
+++ b/src/main/java/org/spigotmc/ActivationRange.java (date 1613658671569)
@@ -1,5 +1,6 @@
package org.spigotmc;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.minecraft.server.AxisAlignedBB;
@@ -122,28 +123,37 @@
maxRange = Math.max( maxRange, miscActivationRange );
maxRange = Math.min( ( world.spigotConfig.viewDistance << 4 ) - 8, maxRange );
- for ( EntityHuman player : world.getPlayers() )
- {
+ List<AxisAlignedBB> 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);
- 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 = Math.min(i, MathHelper.floor(maxBB.minX / 16.0D));
+ j = Math.max(j, MathHelper.floor(maxBB.maxX / 16.0D));
+ k = Math.min(k, MathHelper.floor(maxBB.minZ / 16.0D));
+ l = Math.max(l, MathHelper.floor(maxBB.maxZ / 16.0D));
+ }
- for ( int i1 = i; i1 <= j; ++i1 )
- {
- for ( int j1 = k; j1 <= l; ++j1 )
- {
- if ( world.getWorld().isChunkLoaded( i1, j1 ) )
- {
- activateChunkEntities( world.getChunkAt( i1, j1 ) );
+ 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;
}
}
}