From 6a5030832aa7d5c1a66d71bb811cbb9558b5620f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 18 Feb 2021 15:37:14 +0100 Subject: [PATCH] Optimize entity activation with multiple player on one spot --- ...ion_for_multiple_players_on_one_spot.patch | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 SteamWar-Patches/Optimize_EntityActivation_for_multiple_players_on_one_spot.patch diff --git a/SteamWar-Patches/Optimize_EntityActivation_for_multiple_players_on_one_spot.patch b/SteamWar-Patches/Optimize_EntityActivation_for_multiple_players_on_one_spot.patch new file mode 100644 index 0000000..2c54d96 --- /dev/null +++ b/SteamWar-Patches/Optimize_EntityActivation_for_multiple_players_on_one_spot.patch @@ -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 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; + } + } + } -- 2.39.2