Skip to content

Commit

Permalink
Only run discard checks of projectile chunk-loading optimization on t…
Browse files Browse the repository at this point in the history
…ick regions
  • Loading branch information
MrHua269 committed Jul 29, 2024
1 parent 0e04930 commit fefc53d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ index 0000000000000000000000000000000000000000..12683ec5a5102e45b6171fea0b833ba5
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
index a8d2f7a9d0bcb6db0b38ac30b098d59951053b47..77eee09a301a838f21834319d4962eba1c8dcbed 100644
index a8d2f7a9d0bcb6db0b38ac30b098d59951053b47..1d62c164cf891a183ff3b5cfb8f88fd9508f4e12 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -46,6 +46,36 @@ public abstract class Projectile extends Entity implements TraceableEntity {
@@ -46,6 +46,38 @@ public abstract class Projectile extends Entity implements TraceableEntity {
super(type, world);
}

Expand All @@ -47,23 +47,25 @@ index a8d2f7a9d0bcb6db0b38ac30b098d59951053b47..77eee09a301a838f21834319d4962eba
+ private int loadedLifetime = 0;
+ @Override
+ public void setPos(double x, double y, double z) {
+ long currentTick = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion().getData().getCurrentTick();
+ if (loadedTick != currentTick) {
+ loadedTick = currentTick;
+ loadedThisTick = 0;
+ }
+ int previousX = Mth.floor(this.getX()) >> 4, previousZ = Mth.floor(this.getZ()) >> 4;
+ int newX = Mth.floor(x) >> 4, newZ = Mth.floor(z) >> 4;
+ if (previousX != newX || previousZ != newZ) {
+ boolean isLoaded = ((net.minecraft.server.level.ServerChunkCache) this.level().getChunkSource()).getChunkAtIfLoadedMainThread(newX, newZ) != null;
+ if (!isLoaded) {
+ if (Projectile.loadedThisTick > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerTick) {
+ if (++this.loadedLifetime > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerProjectile) {
+ this.discard();
+ if (io.papermc.paper.util.TickThread.isTickThreadFor(this)){
+ long currentTick = io.papermc.paper.threadedregions.TickRegionScheduler.getCurrentRegion().getData().getCurrentTick();
+ if (loadedTick != currentTick) {
+ loadedTick = currentTick;
+ loadedThisTick = 0;
+ }
+ int previousX = Mth.floor(this.getX()) >> 4, previousZ = Mth.floor(this.getZ()) >> 4;
+ int newX = Mth.floor(x) >> 4, newZ = Mth.floor(z) >> 4;
+ if ((previousX != newX || previousZ != newZ) && io.papermc.paper.util.TickThread.isTickThreadFor(((ServerLevel) this.level()), newX, newZ)) {
+ boolean isLoaded = ((net.minecraft.server.level.ServerChunkCache) this.level().getChunkSource()).getChunkAtIfLoadedMainThread(newX, newZ) != null;
+ if (!isLoaded) {
+ if (Projectile.loadedThisTick > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerTick) {
+ if (++this.loadedLifetime > me.earthme.luminol.config.modules.optimizations.ProjectileChunkReduceConfig.maxProjectileLoadsPerProjectile) {
+ this.discard();
+ }
+ return;
+ }
+ return;
+ Projectile.loadedThisTick++;
+ }
+ Projectile.loadedThisTick++;
+ }
+ }
+ super.setPos(x, y, z);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ index b0f2e614c90137c526de865bd64469f09b95c964..3d8b55afaced6fbac3bc957ffdc33682
+ // KioCG end
}
diff --git a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
index 77eee09a301a838f21834319d4962eba1c8dcbed..cd133931de618e5d8ed5062f8ebfde9d8a9e799c 100644
index 1d62c164cf891a183ff3b5cfb8f88fd9508f4e12..c2976e61f6d8840c8811e10d6097051bd50654df 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
@@ -400,4 +400,11 @@ public abstract class Projectile extends Entity implements TraceableEntity {
@@ -402,4 +402,11 @@ public abstract class Projectile extends Entity implements TraceableEntity {
public float getPickRadius() {
return this.isPickable() ? 1.0F : 0.0F;
}
Expand Down

0 comments on commit fefc53d

Please sign in to comment.