Files
Purpur/patches/server/0073-PaperPR-Projectile-load-save-limit-per-chunk.patch
jmp 7ed791400e Updated Upstream (Paper)
Upstream has released updates that appears to apply and compile correctly

Paper Changes:
cc001a73b Climbing should not bypass cramming gamerule
b9930b39d Add legacy plugin count to metrics
4729e6b90 Add more lightning API
5e220bcb5 [ci skip] add stale bot configuration
2a44498a5 Add PlayerItemCooldownEvent
fd33bcee1 Add LivingEntity#clearActiveItem
a99e0ca05 Fix Player spawnParticle x/y/z precision loss
2020-12-02 14:35:13 -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 5596d9f425..5ffc5af1de 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -704,4 +704,9 @@ public class PaperWorldConfig {
private void fixClimbingBypassingCrammingRule() {
fixClimbingBypassingCrammingRule = getBoolean("fix-climbing-bypassing-cramming-rule", fixClimbingBypassingCrammingRule);
}
+
+ 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;
});