Skip to content

Commit

Permalink
Fix Optimize mob spawning temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Sep 26, 2023
1 parent ecb834e commit 31990e0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 53 deletions.
18 changes: 3 additions & 15 deletions patches/server/0005-Pufferfish-Optimize-mob-spawning.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ and, in my opinion, worth the low risk of minor mob-spawning-related
inconsistencies.

diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 889886a949df9eb49a26c6fec9a32ddfbf938847..3c8c30829298adc1eb1b1b34160480dcbbb446b6 100644
index 889886a949df9eb49a26c6fec9a32ddfbf938847..a8535f791188b2d8ba8d663372e688a1bfebe3c0 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -295,6 +295,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -295,6 +295,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public static final long SERVER_INIT = System.nanoTime();
// Paper end - lag compensation

+ public gg.pufferfish.pufferfish.util.AsyncExecutor mobSpawnExecutor = new gg.pufferfish.pufferfish.util.AsyncExecutor("MobSpawning"); // Pufferfish - optimize mob spawning
+
public static <S extends MinecraftServer> S spin(Function<Thread, S> serverFactory) {
AtomicReference<S> atomicreference = new AtomicReference();
Thread thread = new io.papermc.paper.util.TickThread(() -> { // Paper - rewrite chunk system
Expand All @@ -43,19 +44,6 @@ index f74efb12626a3f027d716bcd3bdb69d9225b3fac..6ae953902a9ed246246660c8da7654c7
return true;
}
}
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index 1d6b75467166def7f0573f5cabe19aafb18de3c7..e7ba192bd8493e273afb36f8c7da374147c337cd 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -206,7 +206,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
// Paper end
// Paper start - optimise chunk tick iteration
public final it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<ChunkHolder> needsChangeBroadcasting = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>();
- public final com.destroystokyo.paper.util.misc.PlayerAreaMap playerMobSpawnMap = new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets);
+ public final com.destroystokyo.paper.util.misc.PlayerAreaMap playerMobSpawnMap = org.dreeam.leaf.LeafConfig.enableAsyncMobSpawning ? new gg.pufferfish.pufferfish.util.AsyncPlayerAreaMap(this.pooledLinkedPlayerHashSets) : new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets); // Pufferfish
// Paper end - optimise chunk tick iteration

public ChunkMap(ServerLevel world, LevelStorageSource.LevelStorageAccess session, DataFixer dataFixer, StructureTemplateManager structureTemplateManager, Executor executor, BlockableEventLoop<Runnable> mainThreadExecutor, LightChunkGetter chunkProvider, ChunkGenerator chunkGenerator, ChunkProgressListener worldGenerationProgressListener, ChunkStatusUpdateListener chunkStatusChangeListener, Supplier<DimensionDataStorage> persistentStateManagerFactory, int viewDistance, boolean dsync) {
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 18e521e77e58a9f786937192249c884aa317988c..f5584de85ca4b95be9b107df562ebf3963ad1b5a 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
Expand Down
34 changes: 17 additions & 17 deletions patches/server/0009-Purpur-Server-Changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ index 9ec6145fe04ec64bbee8ec6a837719caebdbc6f5..358d610ad020cada1bb83e393deeeaae
public ClientboundSetTimePacket(long time, long timeOfDay, boolean doDaylightCycle) {
this.gameTime = time;
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 3c8c30829298adc1eb1b1b34160480dcbbb446b6..b22ac919761c54b5f466bd35740710445ce3dd8f 100644
index a8535f791188b2d8ba8d663372e688a1bfebe3c0..995dd071082e482785448678b9189f0715a75308 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -273,6 +273,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Expand All @@ -726,7 +726,7 @@ index 3c8c30829298adc1eb1b1b34160480dcbbb446b6..b22ac919761c54b5f466bd3574071044

public volatile Thread shutdownThread; // Paper
public volatile boolean abnormalExit = false; // Paper
@@ -914,6 +917,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -915,6 +918,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
MinecraftServer.LOGGER.info("Stopping server");
Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Shutdown and don't bother finishing
MinecraftTimings.stopServer(); // Paper
Expand All @@ -742,7 +742,7 @@ index 3c8c30829298adc1eb1b1b34160480dcbbb446b6..b22ac919761c54b5f466bd3574071044
// CraftBukkit start
if (this.server != null) {
this.server.disablePlugins();
@@ -994,6 +1006,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -995,6 +1007,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.safeShutdown(waitForShutdown, false);
}
public void safeShutdown(boolean waitForShutdown, boolean isRestarting) {
Expand All @@ -751,7 +751,7 @@ index 3c8c30829298adc1eb1b1b34160480dcbbb446b6..b22ac919761c54b5f466bd3574071044
this.isRestarting = isRestarting;
this.hasLoggedStop = true; // Paper
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper
@@ -1131,10 +1145,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1132,10 +1146,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
tps5.add(currentTps, diff);
tps15.add(currentTps, diff);
// Backwards compat with bad plugins
Expand All @@ -769,7 +769,7 @@ index 3c8c30829298adc1eb1b1b34160480dcbbb446b6..b22ac919761c54b5f466bd3574071044
tickSection = curTime;
}
// Spigot end
@@ -1146,7 +1164,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1147,7 +1165,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.tickServer(this::haveTime);
lastTickProperTime = (System.nanoTime() - tickProperStart) / 1000000L; // Gale - YAPFA - last tick time
this.mayHaveDelayedTasks = true;
Expand All @@ -784,7 +784,7 @@ index 3c8c30829298adc1eb1b1b34160480dcbbb446b6..b22ac919761c54b5f466bd3574071044
this.waitUntilNextTick();
this.isReady = true;
JvmProfiler.INSTANCE.onServerTick(this.averageTickTime);
@@ -1491,7 +1515,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1492,7 +1516,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
long worldTime = level.getGameTime();
final ClientboundSetTimePacket worldPacket = new ClientboundSetTimePacket(worldTime, dayTime, doDaylight);
for (Player entityhuman : level.players()) {
Expand All @@ -793,23 +793,23 @@ index 3c8c30829298adc1eb1b1b34160480dcbbb446b6..b22ac919761c54b5f466bd3574071044
continue;
}
ServerPlayer entityplayer = (ServerPlayer) entityhuman;
@@ -1505,6 +1529,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1506,6 +1530,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper

this.isIteratingOverLevels = true; // Paper
+ net.minecraft.network.FriendlyByteBuf.hasItemSerializeEvent = org.purpurmc.purpur.event.packet.NetworkItemSerializeEvent.getHandlerList().getRegisteredListeners().length > 0; // Purpur
Iterator iterator = this.getAllLevels().iterator(); // Paper - move down
while (iterator.hasNext()) {
ServerLevel worldserver = (ServerLevel) iterator.next();
@@ -1512,6 +1537,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1513,6 +1538,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper
worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
+ worldserver.hasRidableMoveEvent = org.purpurmc.purpur.event.entity.RidableMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Purpur

/* Drop global time updates
if (this.tickCount % 20 == 0) {
@@ -2541,6 +2567,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2542,6 +2568,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper

public ChatDecorator getChatDecorator() {
Expand Down Expand Up @@ -3890,7 +3890,7 @@ index 09bc539502dada5dfdd95e50141e587c1c3dee4c..bac374f348363cd0f8b981dc444d419b
if (baseEntity == null) {
if (this.isCombat && (!targetEntity.canBeSeenAsEnemy() || targetEntity.level().getDifficulty() == Difficulty.PEACEFUL)) {
diff --git a/src/main/java/net/minecraft/world/entity/ambient/Bat.java b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
index ba809ea753df1f1c347d0410c4ff255ce6a55532..cf5ecd9247cb01a829fde97a81ee5fb5dc36609d 100644
index ba809ea753df1f1c347d0410c4ff255ce6a55532..53e2dc684099c9593bdb764bad11f24934c13ca7 100644
--- a/src/main/java/net/minecraft/world/entity/ambient/Bat.java
+++ b/src/main/java/net/minecraft/world/entity/ambient/Bat.java
@@ -18,6 +18,7 @@ import net.minecraft.world.entity.EntityDimensions;
Expand Down Expand Up @@ -8717,7 +8717,7 @@ index 4ce3e69970dd9eb251d0538a2d233ca30e9e5e47..afc65b8bb7e7f7f70a25f2d869412ed3
+ // Purpur end - Shears can defuse TNT
}
diff --git a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
index b319021b22c5dceba6199ed27814b2dcf47b8d50..28eb98d383d6846a25c29f8cd8ff211c360a56dc 100644
index b319021b22c5dceba6199ed27814b2dcf47b8d50..8d53b54f11bd79855121a7c3f6ba2b810086b6ef 100644
--- a/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
+++ b/src/main/java/net/minecraft/world/entity/monster/AbstractSkeleton.java
@@ -66,16 +66,19 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
Expand Down Expand Up @@ -8777,8 +8777,8 @@ index b319021b22c5dceba6199ed27814b2dcf47b8d50..28eb98d383d6846a25c29f8cd8ff211c
+ // Purpur start - implemented in LivingEntity
super.aiStep();
}

@@ -205,7 +182,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
@@ -205,7 +187,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
double d2 = target.getZ() - this.getZ();
double d3 = Math.sqrt(d0 * d0 + d2 * d2);

Expand All @@ -8787,7 +8787,7 @@ index b319021b22c5dceba6199ed27814b2dcf47b8d50..28eb98d383d6846a25c29f8cd8ff211c
// CraftBukkit start
org.bukkit.event.entity.EntityShootBowEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(this, this.getMainHandItem(), entityarrow.getPickupItem(), entityarrow, net.minecraft.world.InteractionHand.MAIN_HAND, 0.8F, true); // Paper
if (event.isCancelled()) {
@@ -236,7 +213,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
@@ -236,7 +218,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
this.reassessWeaponGoal();
// Paper start
if (nbt.contains("Paper.ShouldBurnInDay")) {
Expand All @@ -8796,7 +8796,7 @@ index b319021b22c5dceba6199ed27814b2dcf47b8d50..28eb98d383d6846a25c29f8cd8ff211c
}
// Paper end
}
@@ -245,7 +222,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
@@ -245,7 +227,7 @@ public abstract class AbstractSkeleton extends Monster implements RangedAttackMo
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
Expand Down Expand Up @@ -11776,7 +11776,7 @@ index 3e79562f51efbac51785fa0998d6a1a6e3036939..4f242ba9131f341606af13ac543af8a0
this.updateActivity();
}
diff --git a/src/main/java/net/minecraft/world/entity/monster/Zombie.java b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
index 1ddbba72a5fd3d225b651815a38d178941fba289..97ed65885f43c712953d6d8b3c231bac6f031390 100644
index 1ddbba72a5fd3d225b651815a38d178941fba289..929cbdb6cc7b40329fe65705aecf4f36b1c40a48 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Zombie.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Zombie.java
@@ -96,22 +96,69 @@ public class Zombie extends Monster {
Expand Down Expand Up @@ -11964,7 +11964,7 @@ index 1ddbba72a5fd3d225b651815a38d178941fba289..97ed65885f43c712953d6d8b3c231bac
}
}
}
@@ -596,7 +631,7 @@ public class Zombie extends Monster {
@@ -596,7 +635,7 @@ public class Zombie extends Monster {
}

protected void randomizeReinforcementsChance() {
Expand Down
Loading

0 comments on commit 31990e0

Please sign in to comment.