From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 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 b29604f06a07e8946c542db4f3dd9c44084e1392..4aaecc2da66004a6c71f0b80fdfeb31bf1506824 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -1665,7 +1665,46 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 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 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 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 5871d2e7a8c24281c93c11e7935f32666b6cb539..606faf38b90ce1f9867da8f94383ad0a6d927dd5 100644 --- a/net/minecraft/server/dedicated/DedicatedServer.java +++ b/net/minecraft/server/dedicated/DedicatedServer.java @@ -720,6 +720,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface @Override public void stopServer() { + me.earthme.luminol.functions.bars.GlobalServerBarManager.cancelAll(); // Luminol - turn off all bars 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 0f62eb1483838bb1c01d908c095ad76ef999040d..886299f6a69e57286b6acbee416b552163f2c5b2 100644 --- a/net/minecraft/server/level/ServerPlayer.java +++ b/net/minecraft/server/level/ServerPlayer.java @@ -429,7 +429,9 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc public boolean isRealPlayer; // Paper public @Nullable com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent 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(); @@ -963,8 +965,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 01b34ee5da7d0db4bc1cd47e2fbe94423da200fd..7d026161ef0290405bdf86b4e5d6b6f0ca5f6556 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -6207,4 +6207,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 975e0ccd6aac36457c26522a5dd1a256f78500c0..e748b581b135ca80103e4e16707b10d1529ef3e2 100644 --- a/net/minecraft/world/entity/Mob.java +++ b/net/minecraft/world/entity/Mob.java @@ -1631,4 +1631,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 6de2b7702b07edd89784a5554fee4f7a75c521f8..2842314c712449625e9275aff7707c916c3ea767 100644 --- a/net/minecraft/world/entity/player/Player.java +++ b/net/minecraft/world/entity/player/Player.java @@ -1492,6 +1492,13 @@ public abstract class Player extends LivingEntity { return true; } + // KioCG start + @Override + public boolean shouldTickHot() { + return false; + } + // KioCG end + public Either 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 3e1c8d9f8c246765cb9026b2560c30917585b363..2d5ba788d48ea2cb7f78c3119013c2d73c90f106 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 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();