342 lines
18 KiB
Diff
342 lines
18 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <wangxyper@163.com>
|
|
Date: Sun, 12 Jan 2025 10:27:31 +0800
|
|
Subject: [PATCH] Add tpsbar with chunkhot membar and regionbar
|
|
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/paper/util/BaseChunkSystemHooks.java b/ca/spottedleaf/moonrise/paper/util/BaseChunkSystemHooks.java
|
|
index bd3ce123652af11974be4cbf8d2e96f1b2ee0a68..5f26fd89704aa3fd9c37a1d68a7c4c65ce1e7a5d 100644
|
|
--- a/ca/spottedleaf/moonrise/paper/util/BaseChunkSystemHooks.java
|
|
+++ b/ca/spottedleaf/moonrise/paper/util/BaseChunkSystemHooks.java
|
|
@@ -131,6 +131,7 @@ public abstract class BaseChunkSystemHooks implements ca.spottedleaf.moonrise.co
|
|
|
|
@Override
|
|
public void onChunkNotTicking(final LevelChunk chunk, final ChunkHolder holder) {
|
|
+ chunk.getChunkHot().clear(); // KioCG
|
|
chunk.getLevel().getCurrentWorldData().removeTickingChunk(chunk); // Folia - region threading
|
|
}
|
|
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index 8502fdb94142cf12b8d9d4900d8a2440051051ae..d824b49b98266539258a83f9a36f73c5961a1588 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -1664,7 +1664,46 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
// Folia end - region threading
|
|
//this.tickCount++; // Folia - region threading
|
|
//this.tickRateManager.tick(); // Folia - region threading
|
|
+ // KioCG start - ChunkHot
|
|
+ final ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<net.minecraft.world.level.chunk.LevelChunk> chunks = new ca.spottedleaf.moonrise.common.list.IteratorSafeOrderedReferenceSet<>();
|
|
+ if (region != null){
|
|
+ for (net.minecraft.world.level.chunk.LevelChunk chunk : region.world.getCurrentWorldData().getTickingChunks()) {
|
|
+ /* wait for rewrite - temporarily crash fix
|
|
+ for (net.minecraft.server.level.ServerChunkCache.ChunkAndHolder chunkAndHolder : region.world.getCurrentWorldData().getTickingChunks()){
|
|
+ final net.minecraft.world.level.chunk.LevelChunk chunk = chunkAndHolder.chunk();
|
|
+ */
|
|
+ if (!ca.spottedleaf.moonrise.common.util.TickThread.isTickThreadFor(region.world, chunk.locX, chunk.locZ)){
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ chunks.add(chunk);
|
|
+ }
|
|
+ }
|
|
+ if (region != null && io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() % 20 == 0){
|
|
+ final java.util.Iterator<net.minecraft.world.level.chunk.LevelChunk> chunkIterator = chunks.unsafeIterator();
|
|
+ while (chunkIterator.hasNext()){
|
|
+ final net.minecraft.world.level.chunk.LevelChunk targetChunk = chunkIterator.next();
|
|
+
|
|
+ targetChunk.getChunkHot().nextTick();
|
|
+ targetChunk.getChunkHot().start();
|
|
+ }
|
|
+ }
|
|
+ //KioCG end
|
|
this.tickChildren(hasTimeLeft, region); // Folia - region threading
|
|
+ // KioCG start - ChunkHot
|
|
+ if (region != null && io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() % 20 == 0){
|
|
+ final java.util.Iterator<net.minecraft.world.level.chunk.LevelChunk> chunkIterator = chunks.unsafeIterator();
|
|
+ while (chunkIterator.hasNext()){
|
|
+ final net.minecraft.world.level.chunk.LevelChunk targetChunk = chunkIterator.next();
|
|
+
|
|
+ if (!targetChunk.getChunkHot().isStarted()){
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ targetChunk.getChunkHot().stop();
|
|
+ }
|
|
+ }
|
|
+ //KioCG end
|
|
if (false && nanos - this.lastServerStatus >= STATUS_EXPIRE_TIME_NANOS) { // Folia - region threading
|
|
this.lastServerStatus = nanos;
|
|
this.status = this.buildServerStatus();
|
|
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index 61d63e5668e110e9c0b891959bf4cd7c91e54645..f07d3009caf964b8e1b5328bb3e28866e0c41955 100644
|
|
--- a/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -721,6 +721,9 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
|
|
@Override
|
|
public void stopServer() {
|
|
+ me.earthme.luminol.functions.GlobalServerTpsBar.cancelBarUpdateTask(); //Luminol - Tpsbar
|
|
+ me.earthme.luminol.functions.GlobalServerMemoryBar.cancelBarUpdateTask(); //Luminol - Memory bar
|
|
+ me.earthme.luminol.functions.GlobalServerRegionBar.cancelBarUpdateTask(); //Luminol - Region bar
|
|
super.stopServer();
|
|
//Util.shutdownExecutors(); // Paper - Improved watchdog support; moved into super
|
|
SkullBlockEntity.clear();
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index 5e3be75b27ed609be005e8169dc84c125518253e..00482efc8e736e73ad136105ad7b9dd2cafd581f 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1350,6 +1350,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
final int timerId = isActive ? entity.getType().tickTimerId : entity.getType().inactiveTickTimerId;
|
|
final ca.spottedleaf.leafprofiler.RegionizedProfiler.Handle profiler = io.papermc.paper.threadedregions.TickRegionScheduler.getProfiler();
|
|
profiler.startTimer(timerId);
|
|
+ LevelChunk levelChunk = entity.shouldTickHot() ? this.getChunkIfLoaded(entity.moonrise$getSectionX(),entity.moonrise$getSectionZ()) : null; // KioCG
|
|
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
|
|
try {
|
|
// Folia end - profiler
|
|
if (isActive) { // Paper - EAR 2
|
|
@@ -1367,6 +1369,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
} else {entity.inactiveTick();} // Paper - EAR 2
|
|
profilerFiller.pop();
|
|
} finally { profiler.stopTimer(timerId); } // Folia - profiler
|
|
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
|
|
|
|
for (Entity entity1 : entity.getPassengers()) {
|
|
this.tickPassenger(entity, entity1, isActive); // Paper - EAR 2
|
|
@@ -1386,6 +1389,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
final int timerId = isActive ? passengerEntity.getType().tickTimerId : passengerEntity.getType().inactiveTickTimerId;
|
|
final ca.spottedleaf.leafprofiler.RegionizedProfiler.Handle profiler = io.papermc.paper.threadedregions.TickRegionScheduler.getProfiler();
|
|
profiler.startTimer(timerId);
|
|
+ LevelChunk levelChunk = !(passengerEntity instanceof Player) ? this.getChunkIfLoaded(passengerEntity.blockPosition()) : null; // KioCG
|
|
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
|
|
try {
|
|
// Folia end - profiler
|
|
passengerEntity.setOldPosAndRot();
|
|
@@ -1420,6 +1425,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
this.tickPassenger(passengerEntity, entity, isActive); // Paper - EAR 2
|
|
}
|
|
} finally { profiler.stopTimer(timerId); } // Folia - profiler
|
|
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
|
|
}
|
|
}
|
|
|
|
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
|
|
index 5e7a9be34bec7eefbb46db1409bfd90351866ec2..4e3c545f6121d3846d81d776c29edc42d6204f5c 100644
|
|
--- a/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -431,7 +431,9 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
public @Nullable com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
|
|
public @Nullable String clientBrandName = null; // Paper - Brand support
|
|
public @Nullable org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
|
|
-
|
|
+ public volatile boolean isTpsBarVisible = false; //Luminol - Tps bar
|
|
+ public volatile boolean isMemBarVisible = false; //Luminol - Memory bar
|
|
+ public volatile boolean isRegionBarVisible = false; //Luminol - Region bar
|
|
// Paper start - rewrite chunk system
|
|
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
|
|
private final ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.ViewDistanceHolder viewDistanceHolder = new ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.ViewDistanceHolder();
|
|
@@ -1025,8 +1027,35 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
|
|
this.trackEnteredOrExitedLavaOnVehicle();
|
|
this.updatePlayerAttributes();
|
|
this.advancements.flushDirty(this, true);
|
|
+
|
|
+ // KioCG start - ChunkHot
|
|
+ if (this.tickCount % 20 == 0){
|
|
+ this.nearbyChunkHot = this.refreshNearbyChunkHot();
|
|
+ }
|
|
+ // KioCG end
|
|
}
|
|
|
|
+ // KioCG start - ChunkHot
|
|
+ private volatile long nearbyChunkHot = 0;
|
|
+
|
|
+ public long getNearbyChunkHot() { return this.nearbyChunkHot; }
|
|
+
|
|
+ private long refreshNearbyChunkHot() {
|
|
+ long total = 0L;
|
|
+ int searchRadius = ((ServerLevel) this.level()).moonrise$getViewDistanceHolder().getViewDistances().tickViewDistance();
|
|
+ for (int i = this.moonrise$getSectionX() - searchRadius; i <= this.moonrise$getSectionX() + searchRadius; ++i) {
|
|
+ for (int j = this.moonrise$getSectionZ() - searchRadius; j <= this.moonrise$getSectionZ() + searchRadius; ++j) {
|
|
+ net.minecraft.world.level.chunk.LevelChunk targetChunk = this.level().getChunkIfLoaded(i, j);
|
|
+ if (targetChunk != null) {
|
|
+ total += targetChunk.getChunkHot().getAverage();
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ return total;
|
|
+ }
|
|
+ // KioCG end
|
|
+
|
|
+
|
|
private void updatePlayerAttributes() {
|
|
AttributeInstance attribute = this.getAttribute(Attributes.BLOCK_INTERACTION_RANGE);
|
|
if (attribute != null) {
|
|
diff --git a/net/minecraft/world/entity/AreaEffectCloud.java b/net/minecraft/world/entity/AreaEffectCloud.java
|
|
index ec20a5a6d7c8f65abda528fec36bec7bc71117f6..b971cd61db1cfa05b8f2fd6c8a2dac2e27851288 100644
|
|
--- a/net/minecraft/world/entity/AreaEffectCloud.java
|
|
+++ b/net/minecraft/world/entity/AreaEffectCloud.java
|
|
@@ -423,4 +423,11 @@ public class AreaEffectCloud extends Entity implements TraceableEntity {
|
|
return super.applyImplicitComponent(component, value);
|
|
}
|
|
}
|
|
+
|
|
+ // KioCG start
|
|
+ @Override
|
|
+ public boolean shouldTickHot() {
|
|
+ return false;
|
|
+ }
|
|
+ // KioCG end
|
|
}
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 49c76f150c913fdc21d0e253b78625e273f69a22..f5f03801da03089ea1d22de1012d90a2b7b17322 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -6218,4 +6218,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
return ((ServerLevel) this.level()).isPositionEntityTicking(this.blockPosition());
|
|
}
|
|
// Paper end - Expose entity id counter
|
|
+
|
|
+ public boolean shouldTickHot() { return this.tickCount > 20 * 10 && this.isAlive(); } // KioCG
|
|
}
|
|
diff --git a/net/minecraft/world/entity/LightningBolt.java b/net/minecraft/world/entity/LightningBolt.java
|
|
index b091a382624140acb3f3f82647bdd592b7ee1f95..81b4e418687536b54f4ee8bd131185a8547ae651 100644
|
|
--- a/net/minecraft/world/entity/LightningBolt.java
|
|
+++ b/net/minecraft/world/entity/LightningBolt.java
|
|
@@ -288,4 +288,11 @@ public class LightningBolt extends Entity {
|
|
public final boolean hurtServer(ServerLevel level, DamageSource damageSource, float amount) {
|
|
return false;
|
|
}
|
|
+
|
|
+ // KioCG start
|
|
+ @Override
|
|
+ public boolean shouldTickHot() {
|
|
+ return false;
|
|
+ }
|
|
+ // KioCG end
|
|
}
|
|
diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
|
|
index 1240fb5394b1475c8e95a0e65bd03f2d15565d6f..d9ee3b56db44687cfcc6a75f44a1abbcc8ef95a9 100644
|
|
--- a/net/minecraft/world/entity/Mob.java
|
|
+++ b/net/minecraft/world/entity/Mob.java
|
|
@@ -1618,4 +1618,11 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
this.getNavigation().updatePathfinderMaxVisitedNodes();
|
|
}
|
|
}
|
|
+
|
|
+ // KioCG start
|
|
+ @Override
|
|
+ public boolean shouldTickHot() {
|
|
+ return super.shouldTickHot() && (!this.removeWhenFarAway(0.0) || this.isPersistenceRequired() || this.requiresCustomPersistence());
|
|
+ }
|
|
+ // KioCG end
|
|
}
|
|
diff --git a/net/minecraft/world/entity/animal/horse/TraderLlama.java b/net/minecraft/world/entity/animal/horse/TraderLlama.java
|
|
index 2cd1b988f44caf271a7d2dfccf118be53b77caba..d829b230ab366922697061bdbb9a4f1cdc00744f 100644
|
|
--- a/net/minecraft/world/entity/animal/horse/TraderLlama.java
|
|
+++ b/net/minecraft/world/entity/animal/horse/TraderLlama.java
|
|
@@ -157,4 +157,11 @@ public class TraderLlama extends Llama {
|
|
super.start();
|
|
}
|
|
}
|
|
+
|
|
+ // KioCG start
|
|
+ @Override
|
|
+ public boolean shouldTickHot() {
|
|
+ return super.shouldTickHot() && !this.canDespawn();
|
|
+ }
|
|
+ // KioCG end
|
|
}
|
|
diff --git a/net/minecraft/world/entity/npc/WanderingTrader.java b/net/minecraft/world/entity/npc/WanderingTrader.java
|
|
index c2573946dd1244eb5d1ef2be7823211064daa80d..7e9662bf7c17b2f5eda2ff88970a23e4fb09456a 100644
|
|
--- a/net/minecraft/world/entity/npc/WanderingTrader.java
|
|
+++ b/net/minecraft/world/entity/npc/WanderingTrader.java
|
|
@@ -278,4 +278,11 @@ public class WanderingTrader extends net.minecraft.world.entity.npc.AbstractVill
|
|
return !pos.closerToCenterThan(this.trader.position(), distance);
|
|
}
|
|
}
|
|
+
|
|
+ // KioCG start
|
|
+ @Override
|
|
+ public boolean shouldTickHot() {
|
|
+ return false;
|
|
+ }
|
|
+ // KioCG end
|
|
}
|
|
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
|
|
index 73d1557f2d7d60a9a2ad2c3f710b0969c4c5cf40..47f62fbe97c559c25ad2bc67c18f2025c78e2c69 100644
|
|
--- a/net/minecraft/world/entity/player/Player.java
|
|
+++ b/net/minecraft/world/entity/player/Player.java
|
|
@@ -1493,6 +1493,13 @@ public abstract class Player extends LivingEntity {
|
|
return true;
|
|
}
|
|
|
|
+ // KioCG start
|
|
+ @Override
|
|
+ public boolean shouldTickHot() {
|
|
+ return false;
|
|
+ }
|
|
+ // KioCG end
|
|
+
|
|
public Either<Player.BedSleepingProblem, Unit> startSleepInBed(BlockPos bedPos) {
|
|
// CraftBukkit start
|
|
return this.startSleepInBed(bedPos, false);
|
|
diff --git a/net/minecraft/world/entity/projectile/Projectile.java b/net/minecraft/world/entity/projectile/Projectile.java
|
|
index b6cdd02ead8ecc38afd4e76fa0c19a9433550b1d..71c1473e470db82dffcf6be4b4ded61564577e92 100644
|
|
--- a/net/minecraft/world/entity/projectile/Projectile.java
|
|
+++ b/net/minecraft/world/entity/projectile/Projectile.java
|
|
@@ -488,4 +488,11 @@ public abstract class Projectile extends Entity implements TraceableEntity {
|
|
public interface ProjectileFactory<T extends Projectile> {
|
|
T create(ServerLevel level, LivingEntity owner, ItemStack spawnedFrom);
|
|
}
|
|
+
|
|
+ // KioCG start
|
|
+ @Override
|
|
+ public boolean shouldTickHot() {
|
|
+ return false;
|
|
+ }
|
|
+ // KioCG end
|
|
}
|
|
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
index e74ea44096e071878372c5b8889f45cd2bd4ae23..7add73f2dd957374661affebfa2b0102d99363f8 100644
|
|
--- a/net/minecraft/world/level/chunk/LevelChunk.java
|
|
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
|
|
@@ -106,6 +106,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
|
|
// Paper start - rewrite chunk system
|
|
private boolean postProcessingDone;
|
|
private ca.spottedleaf.moonrise.patches.chunk_system.scheduling.NewChunkHolder chunkAndHolder;
|
|
+ private final com.kiocg.ChunkHot chunkHot = new com.kiocg.ChunkHot(); public com.kiocg.ChunkHot getChunkHot() { return this.chunkHot; } // KioCG
|
|
|
|
@Override
|
|
public final boolean moonrise$isPostProcessingDone() {
|
|
@@ -937,6 +938,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
|
|
try {
|
|
ProfilerFiller profilerFiller = Profiler.get();
|
|
profilerFiller.push(this::getType);
|
|
+ LevelChunk.this.chunkHot.startTicking(); // KioCG
|
|
profiler.startTimer(timerId); try { // Folia - profiler
|
|
BlockState blockState = LevelChunk.this.getBlockState(blockPos);
|
|
if (this.blockEntity.getType().isValid(blockState)) {
|
|
@@ -951,7 +953,7 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p
|
|
}
|
|
// Paper end - Remove the Block Entity if it's invalid
|
|
}
|
|
- } finally { profiler.stopTimer(timerId); } // Folia - profiler
|
|
+ } finally { profiler.stopTimer(timerId); LevelChunk.this.chunkHot.stopTickingAndCount(); } // Folia - profiler // KioCG
|
|
|
|
profilerFiller.pop();
|
|
} catch (Throwable var5) {
|
|
diff --git a/net/minecraft/world/level/redstone/NeighborUpdater.java b/net/minecraft/world/level/redstone/NeighborUpdater.java
|
|
index 332b33a004ab11150cca0cc2cefc26d0286648f5..714e291b17856aacdac7db992fc18e6ae662f659 100644
|
|
--- a/net/minecraft/world/level/redstone/NeighborUpdater.java
|
|
+++ b/net/minecraft/world/level/redstone/NeighborUpdater.java
|
|
@@ -57,7 +57,10 @@ public interface NeighborUpdater {
|
|
return;
|
|
}
|
|
// CraftBukkit end
|
|
+ net.minecraft.world.level.chunk.LevelChunk levelChunk = level.getChunkIfLoaded(pos); // KioCG
|
|
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
|
|
state.handleNeighborChanged(level, pos, neighborBlock, orientation, movedByPiston);
|
|
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
|
|
// Spigot start
|
|
} catch (StackOverflowError ex) {
|
|
level.lastPhysicsProblem = pos.immutable();
|