Files
Purpur/patches/server/0070-PaperPR-Projectile-load-save-limit-per-chunk.patch
jmp 885092f773 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
3148b25b1 [CI-SKIP] [Auto] Rebuild Patches
880a910a9 Properly track block update flags (actually fixes #5038)
ace3146df Fix debug stick update suppression (Fixes #5038)
bb4247f86 Fix dumpitem command not checking sender (#5025)
b72a74e48 nerf nether search radius config (#4781)
2021-01-11 12:48:40 -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 c5495e02c3fe271b26f62ea2ec64e07957edf37e..0ba5734e60467e34c73d4ed92f5a030af9817582 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -761,4 +761,9 @@ public class PaperWorldConfig {
EnumDifficulty.class
);
}
+
+ 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 cba943682f5ee798517bc8c3a098c100e235320b..d5c0b5574f763c7191b03ff0e78e689dad6589ff 100644
--- a/src/main/java/net/minecraft/server/ChunkRegionLoader.java
+++ b/src/main/java/net/minecraft/server/ChunkRegionLoader.java
@@ -529,11 +529,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) {
@@ -664,10 +674,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;
});