Files
Purpur/patches/server/0074-PaperPR-Projectile-load-save-limit-per-chunk.patch
jmp 7174d63c4e PaperPR - Projectile load/save limit per chunk
- Dropped "Add option to disable saving projectiles to disk" in favor of the above patch
 - Config migration is automatic. If "gameplay-mechanics.save-projectiles-to-disk" was set to false in purpur.yml, "projectile-load-save-per-chunk-limit" will be set to 0 in paper.yml (resulting in unchanged behaviour)
2020-11-30 19:38:23 -08:00

72 lines
3.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: jmp <jasonpenilla2@me.com>
Date: Wed, 18 Nov 2020 20:52:25 -0800
Subject: [PATCH] PaperPR - Projectile load/save limit per chunk
Adds a config option to limit the number of projectiles saved and loaded
to a chunk. Limits are counted per entity type, i.e. a limit of 5 means
that 5 arrows, 5 snowballs, 5 tridents, etc. will be allowed to be
saved/loaded per chunk. The default value of -1 disables the limit.
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 80b0c08cef..f451b0aa68 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -699,4 +699,9 @@ public class PaperWorldConfig {
wanderingTraderSpawnChanceMin = getInt("wandering-trader.spawn-chance-min", wanderingTraderSpawnChanceMin);
wanderingTraderSpawnChanceMax = getInt("wandering-trader.spawn-chance-max", wanderingTraderSpawnChanceMax);
}
+
+ public int projectileSaveLimit = -1;
+ private void projectileSaveLimit() {
+ projectileSaveLimit = getInt("projectile-load-save-per-chunk-limit", projectileSaveLimit);
+ }
}
diff --git a/src/main/java/net/minecraft/server/ChunkRegionLoader.java b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
index 64dd95292f..3628b04fc4 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -525,11 +525,21 @@ public class ChunkRegionLoader {
chunk.d(false);
+ // Paper start
+ final Map<EntityTypes<?>, Integer> savedProjectileCounts = Maps.newHashMap();
for (int j = 0; j < chunk.getEntitySlices().length; ++j) {
Iterator iterator1 = chunk.getEntitySlices()[j].iterator();
while (iterator1.hasNext()) {
Entity entity = (Entity) iterator1.next();
+ if (worldserver.paperConfig.projectileSaveLimit > -1 && (entity instanceof IProjectile || entity instanceof EntityEnderSignal)) {
+ final EntityTypes<?> projectileType = entity.getEntityType();
+ if (savedProjectileCounts.getOrDefault(projectileType, 0) >= worldserver.paperConfig.projectileSaveLimit) {
+ continue;
+ }
+ savedProjectileCounts.merge(projectileType, 1, Integer::sum);
+ }
+ // Paper end
NBTTagCompound nbttagcompound4 = new NBTTagCompound();
// Paper start
if (asyncsavedata == null && !entity.dead && (int) Math.floor(entity.locX()) >> 4 != chunk.getPos().x || (int) Math.floor(entity.locZ()) >> 4 != chunk.getPos().z) {
@@ -660,10 +670,20 @@ public class ChunkRegionLoader {
NBTTagList nbttaglist = nbttagcompound.getList("Entities", 10);
World world = chunk.getWorld();
+ // Paper start
+ final Map<EntityTypes<?>, Integer> loadedProjectileCounts = Maps.newHashMap();
for (int i = 0; i < nbttaglist.size(); ++i) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompound(i);
EntityTypes.a(nbttagcompound1, world, (entity) -> {
+ if (world.paperConfig.projectileSaveLimit > -1 && (entity instanceof IProjectile || entity instanceof EntityEnderSignal)) {
+ final EntityTypes<?> projectileType = entity.getEntityType();
+ if (loadedProjectileCounts.getOrDefault(projectileType, 0) >= world.paperConfig.projectileSaveLimit) {
+ return entity;
+ }
+ loadedProjectileCounts.merge(projectileType, 1, Integer::sum);
+ }
+ // Paper end
chunk.a(entity);
return entity;
});