Skip to content

Commit ab71de6

Browse files
committed
Re-tidied optimizations from Pufferfish and fixed unsafe teleportation
1 parent 7bba041 commit ab71de6

File tree

31 files changed

+213
-746
lines changed

31 files changed

+213
-746
lines changed

patches/server/0005-Add-config-for-unsafe-teleportation.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ index 0000000000000000000000000000000000000000..ea374875f529b30db17e8b8cb07b99a6
3131
+ }
3232
+}
3333
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
34-
index 7a102b4e90fbc09b8653e5b566299efe24a04cf6..de5263b0261ed2f8f97b9525936be8067ddb79b2 100644
34+
index 7a102b4e90fbc09b8653e5b566299efe24a04cf6..2a5db8f4ad54b772a0a8bce429fff8b539db81ed 100644
3535
--- a/src/main/java/net/minecraft/world/entity/Entity.java
3636
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
3737
@@ -4142,6 +4142,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
3838

3939
public boolean endPortalLogicAsync(BlockPos portalPos) {
4040
ca.spottedleaf.moonrise.common.util.TickThread.ensureTickThread(this, "Cannot portal entity async");
41-
+ if (!me.earthme.luminol.config.modules.fixes.UnsafeTeleportationConfig.enabled && !(this instanceof Player)) return false; // Luminol - Unsafe teleportation
41+
+ if (me.earthme.luminol.config.modules.fixes.UnsafeTeleportationConfig.enabled && !(this instanceof Player)) return false; // Luminol - Unsafe teleportation
4242

4343
ServerLevel destination = this.getServer().getLevel(this.level().getTypeKey() == net.minecraft.world.level.dimension.LevelStem.END ? Level.OVERWORLD : Level.END);
4444
if (destination == null) {

patches/server/0024-Pufferfish-Make-EntityCollisionContext-a-live-repres.patch renamed to patches/server/0023-Pufferfish-Make-EntityCollisionContext-a-live-repres.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2-
From: MrHua269 <wangxyper@163.com>
3-
Date: Mon, 29 Jul 2024 19:53:42 +0800
2+
From: Paul Sauve <paul@technove.co>
3+
Date: Sun, 9 May 2021 18:35:05 -0500
44
Subject: [PATCH] Pufferfish Make EntityCollisionContext a live representation
55

66

patches/server/0025-Pufferfish-Improve-fluid-direction-caching.patch renamed to patches/server/0024-Pufferfish-Improve-fluid-direction-caching.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2-
From: MrHua269 <wangxyper@163.com>
3-
Date: Wed, 31 Jul 2024 12:52:54 +0800
2+
From: Paul Sauve <paul@technove.co>
3+
Date: Wed, 14 Apr 2021 22:58:15 -0500
44
Subject: [PATCH] Pufferfish Improve fluid direction caching
55

66

Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2-
From: MrHua269 <wangxyper@163.com>
3-
Date: Wed, 31 Jul 2024 12:47:11 +0800
2+
From: Paul Sauve <paul@technove.co>
3+
Date: Mon, 26 Apr 2021 10:52:56 -0500
44
Subject: [PATCH] Pufferfish Cache climbing check for activation
55

66

7-
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
8-
index fe3aeadd4357cc0b28ac9cfc21f0f1100d22d3a0..c1881c4a590a64950679bdac452960ed8d394f89 100644
9-
--- a/src/main/java/net/minecraft/world/entity/Entity.java
10-
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
11-
@@ -315,7 +315,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
12-
public double yo;
13-
public double zo;
14-
private Vec3 position;
15-
- private BlockPos blockPosition;
16-
+ public BlockPos blockPosition; // Pufferfish - private->public
17-
private ChunkPos chunkPosition;
18-
private Vec3 deltaMovement;
19-
private float yRot;
207
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
21-
index 8ccc18881d047e2b06ab3494a25f27e209931413..f3c442976dd358958053ba71a433d7f104559857 100644
8+
index 8ccc18881d047e2b06ab3494a25f27e209931413..30bd7101cca4a93df592f0e3c0dd4aac0f347d07 100644
229
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
2310
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
24-
@@ -2084,6 +2084,20 @@ public abstract class LivingEntity extends Entity implements Attackable {
11+
@@ -157,7 +157,6 @@ import org.bukkit.event.entity.EntityTeleportEvent;
12+
import org.bukkit.event.player.PlayerItemConsumeEvent;
13+
// CraftBukkit end
14+
15+
-import co.aikar.timings.MinecraftTimings; // Paper
16+
17+
public abstract class LivingEntity extends Entity implements Attackable {
18+
19+
@@ -2084,6 +2083,20 @@ public abstract class LivingEntity extends Entity implements Attackable {
2520
return this.lastClimbablePos;
2621
}
2722

@@ -43,15 +38,15 @@ index 8ccc18881d047e2b06ab3494a25f27e209931413..f3c442976dd358958053ba71a433d7f1
4338
if (this.isSpectator()) {
4439
return false;
4540
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
46-
index 91c63c3dceddf09018d3651f4c11bf521eb53ecf..3918fcfbb85cf0be523b3c723d9861aa5bca6d8c 100644
41+
index 91c63c3dceddf09018d3651f4c11bf521eb53ecf..96103d7c380e095c06876da00bd4132ae9598671 100644
4742
--- a/src/main/java/org/spigotmc/ActivationRange.java
4843
+++ b/src/main/java/org/spigotmc/ActivationRange.java
4944
@@ -307,7 +307,7 @@ public class ActivationRange
5045
if ( entity instanceof LivingEntity )
5146
{
5247
LivingEntity living = (LivingEntity) entity;
5348
- if ( living.onClimbable() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 || living.isFreezing()) // Paper
54-
+ if ( living.onClimableCached() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 || living.isFreezing()) // Paper // Pufferfish - use cached
49+
+ if ( living.onClimableCached() || living.jumping || living.hurtTime > 0 || living.activeEffects.size() > 0 || living.isFreezing() ) // Paper // Pufferfish - use cached
5550
{
5651
return 1; // Paper
5752
}

patches/server/0028-Pufferfish-Reduce-chunk-loading-lookups.patch renamed to patches/server/0026-Pufferfish-Reduce-chunk-loading-lookups.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2-
From: MrHua269 <wangxyper@163.com>
3-
Date: Wed, 31 Jul 2024 13:10:34 +0800
2+
From: Paul Sauve <paul@technove.co>
3+
Date: Thu, 4 Feb 2021 23:33:52 -0600
44
Subject: [PATCH] Pufferfish Reduce chunk loading & lookups
55

66

patches/server/0032-Pufferfish-Skip-cloning-loot-parameters.patch renamed to patches/server/0029-Pufferfish-Skip-cloning-loot-parameters.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2-
From: MrHua269 <wangxyper@163.com>
3-
Date: Mon, 29 Jul 2024 20:12:08 +0800
2+
From: Paul <paul@technove.co>
3+
Date: Tue, 29 Jun 2021 02:24:23 -0500
44
Subject: [PATCH] Pufferfish Skip cloning loot parameters
55

66

patches/server/0030-Pufferfish-Reduce-entity-fluid-lookups-if-no-fluids.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ index 0000000000000000000000000000000000000000..0523b3da3fb254bce1998bae6410c632
3131
+ }
3232
+}
3333
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
34-
index c1881c4a590a64950679bdac452960ed8d394f89..8b00f2bdb6f053842844b945d65d1150f596714c 100644
34+
index 39e96b21e77607782da13b4c74c65d8a68af2433..32f027b67b9bd18e486eb321d8874a1e523c1a00 100644
3535
--- a/src/main/java/net/minecraft/world/entity/Entity.java
3636
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
3737
@@ -5259,9 +5259,14 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -73,8 +73,8 @@ index c1881c4a590a64950679bdac452960ed8d394f89..8b00f2bdb6f053842844b945d65d1150
7373
+ BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
7474
+
7575
+ // Pufferfish start - based off CollisionUtil.getCollisionsForBlocksOrWorldBorder
76-
+ final int minSection = io.papermc.paper.util.WorldUtil.getMinSection(this.level());
77-
+ final int maxSection = io.papermc.paper.util.WorldUtil.getMaxSection(this.level());
76+
+ final int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(this.level());
77+
+ final int maxSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMaxSection(this.level());
7878
+ final int minBlock = minSection << 4;
7979
+ final int maxBlock = (maxSection << 4) | 15;
8080
+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: MrHua269 <novau233@163.com>
3+
Date: Wed, 7 Feb 2024 05:45:24 +0000
4+
Subject: [PATCH] Pufferfish Reduce projectile chunk loading
5+
6+
7+
diff --git a/src/main/java/me/earthme/luminol/config/modules/optimizations/ProjectileChunkReduceConfig.java b/src/main/java/me/earthme/luminol/config/modules/optimizations/ProjectileChunkReduceConfig.java
8+
new file mode 100644
9+
index 0000000000000000000000000000000000000000..12683ec5a5102e45b6171fea0b833ba57e5e188c
10+
--- /dev/null
11+
+++ b/src/main/java/me/earthme/luminol/config/modules/optimizations/ProjectileChunkReduceConfig.java
12+
@@ -0,0 +1,22 @@
13+
+package me.earthme.luminol.config.modules.optimizations;
14+
+
15+
+import me.earthme.luminol.config.ConfigInfo;
16+
+import me.earthme.luminol.config.EnumConfigCategory;
17+
+import me.earthme.luminol.config.IConfigModule;
18+
+
19+
+public class ProjectileChunkReduceConfig implements IConfigModule {
20+
+ @ConfigInfo(baseName = "max-loads-per-tick")
21+
+ public static int maxProjectileLoadsPerTick;
22+
+ @ConfigInfo(baseName = "max-loads-per-projectile")
23+
+ public static int maxProjectileLoadsPerProjectile;
24+
+
25+
+ @Override
26+
+ public EnumConfigCategory getCategory() {
27+
+ return EnumConfigCategory.OPTIMIZATIONS;
28+
+ }
29+
+
30+
+ @Override
31+
+ public String getBaseName() {
32+
+ return "projectile";
33+
+ }
34+
+}
35+
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
36+
index c7a59234fb1fdc09745b62039011d0d2f7cd3fb6..bc944fec524d79fd6e5fc01a808e4d13153afc05 100644
37+
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
38+
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
39+
@@ -52,6 +52,40 @@ public abstract class Projectile extends Entity implements TraceableEntity {
40+
super(type, world);
41+
}
42+
43+
+ // Pufferfish start
44+
+ private static final java.lang.ThreadLocal<Long> loadedThisTick = java.lang.ThreadLocal.withInitial(() -> 0L);
45+
+ private static final java.lang.ThreadLocal<Long> loadedTick = java.lang.ThreadLocal.withInitial(() -> 0L);
46+
+
47+
+ private int loadedLifetime = 0;
48+
+ @Override
49+
+ public void setPos(double x, double y, double z) {
50+
+ if (io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion() != null && ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(this)){
51+
+ long currentTick = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion().getData().getCurrentTick();
52+
+
53+
+ if (loadedTick.get() != currentTick) {
54+
+ loadedTick = currentTick;
55+
+ loadedThisTick.set(0L);
56+
+ }
57+
+
58+
+ int previousX = Mth.floor(this.getX()) >> 4, previousZ = Mth.floor(this.getZ()) >> 4;
59+
+ int newX = Mth.floor(x) >> 4, newZ = Mth.floor(z) >> 4;
60+
+ if ((previousX != newX || previousZ != newZ) && ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(this.level(), newX, newZ)) {
61+
+ boolean isLoaded = ((net.minecraft.server.level.ServerChunkCache) this.level().getChunkSource()).getChunkAtIfCachedImmediately(newX, newZ) != null;
62+
+ if (!isLoaded) {
63+
+ if (Projectile.loadedThisTick.get() > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerTick) {
64+
+ if (++this.loadedLifetime > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerProjectile) {
65+
+ this.discard();
66+
+ }
67+
+ return;
68+
+ }
69+
+ Projectile.loadedThisTick.set(Projectile.loadedThisTick.get() + 1);
70+
+ }
71+
+ }
72+
+ }
73+
+ super.setPos(x, y, z);
74+
+ }
75+
+ // Pufferfish end
76+
+
77+
public void setOwner(@Nullable Entity entity) {
78+
if (entity != null) {
79+
this.ownerUUID = entity.getUUID();

patches/server/0033-Pufferfish-Entity-TTL.patch renamed to patches/server/0032-Pufferfish-Entity-TTL.patch

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ index 0000000000000000000000000000000000000000..15697d69659b6e1e776acf5094684b5f
4949
+ }
5050
+}
5151
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
52-
index 79b39562632a2e4dedfaa72db14c63d325e3eb4b..47cfeef4d40ff9c99280d925eacb64d243f6ed8b 100644
52+
index 32f027b67b9bd18e486eb321d8874a1e523c1a00..c808b59b0461ccd78fa57932f51bbb268c1d965f 100644
5353
--- a/src/main/java/net/minecraft/world/entity/Entity.java
5454
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
5555
@@ -857,6 +857,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -65,17 +65,6 @@ index 79b39562632a2e4dedfaa72db14c63d325e3eb4b..47cfeef4d40ff9c99280d925eacb64d2
6565
this.baseTick();
6666
}
6767

68-
@@ -5359,8 +5365,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
69-
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
70-
71-
// Pufferfish start - based off CollisionUtil.getCollisionsForBlocksOrWorldBorder
72-
- final int minSection = io.papermc.paper.util.WorldUtil.getMinSection(this.level());
73-
- final int maxSection = io.papermc.paper.util.WorldUtil.getMaxSection(this.level());
74-
+ final int minSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMinSection(this.level());
75-
+ final int maxSection = ca.spottedleaf.moonrise.common.util.WorldUtil.getMaxSection(this.level());
76-
final int minBlock = minSection << 4;
77-
final int maxBlock = (maxSection << 4) | 15;
78-
7968
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
8069
index c74a01a8551457507441d266b6923b4248560abf..293ec464b1cb4db1734d0c059e59f60bfeb2b7eb 100644
8170
--- a/src/main/java/net/minecraft/world/entity/EntityType.java

0 commit comments

Comments
 (0)