502 lines
23 KiB
Diff
502 lines
23 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
From: MrHua269 <novau233@163.com>
|
||
Date: Sat, 27 Apr 2024 12:36:55 +0000
|
||
Subject: [PATCH] KioCG Chunk API and display of chunkhot in tpsbar
|
||
|
||
|
||
diff --git a/src/main/java/com/kiocg/ChunkHot.java b/src/main/java/com/kiocg/ChunkHot.java
|
||
new file mode 100644
|
||
index 0000000000000000000000000000000000000000..53b4397997bc9b9b9d88e48304b37a2590161906
|
||
--- /dev/null
|
||
+++ b/src/main/java/com/kiocg/ChunkHot.java
|
||
@@ -0,0 +1,90 @@
|
||
+package com.kiocg;
|
||
+
|
||
+import java.util.Arrays;
|
||
+
|
||
+public class ChunkHot {
|
||
+ // 热度统计总区间数量
|
||
+ private static final int TIMES_LENGTH = 10;
|
||
+ // 当前统计区间下标
|
||
+ private int index = -1;
|
||
+
|
||
+ // 热度统计区间
|
||
+ private final long[] times = new long[TIMES_LENGTH];
|
||
+ // 存放临时的区间数值
|
||
+ // 用于修正正在统计的当前区间热度没有计入总值的问题
|
||
+ private long temp;
|
||
+ // 所有区间的热度总值
|
||
+ private long total;
|
||
+
|
||
+ // 用于每个具体统计的计算
|
||
+ private long nanos;
|
||
+ // 当前统计是否进行中
|
||
+ private volatile boolean started = false;
|
||
+
|
||
+ /**
|
||
+ * 更新区间下标
|
||
+ */
|
||
+ public void nextTick() {
|
||
+ this.index = ++this.index % TIMES_LENGTH;
|
||
+ }
|
||
+
|
||
+ /**
|
||
+ * 开始统计一个新区间
|
||
+ */
|
||
+ public void start() {
|
||
+ started = true;
|
||
+ temp = times[this.index];
|
||
+ times[this.index] = 0L;
|
||
+ }
|
||
+
|
||
+ public boolean isStarted(){
|
||
+ return this.started;
|
||
+ }
|
||
+
|
||
+ /**
|
||
+ * 结束当前区间的统计
|
||
+ * 将统计值更新入热度总值
|
||
+ */
|
||
+ public void stop() {
|
||
+ started = false;
|
||
+ total -= temp;
|
||
+ total += times[this.index];
|
||
+ }
|
||
+
|
||
+ /**
|
||
+ * 开始一个具体统计
|
||
+ */
|
||
+ public void startTicking() {
|
||
+ if (!started) return;
|
||
+ nanos = System.nanoTime();
|
||
+ }
|
||
+
|
||
+ /**
|
||
+ * 结束一个具体统计
|
||
+ * 将统计值计入当前热度区间
|
||
+ */
|
||
+ public void stopTickingAndCount() {
|
||
+ if (!started) return;
|
||
+ // 定义一个具体统计的最大值为 1,000,000
|
||
+ // 有时候某个具体统计的计算值会在某1刻飙升,可能是由于保存数据到磁盘?
|
||
+ times[this.index] += Math.min(System.nanoTime() - nanos, 1000000L);
|
||
+ }
|
||
+
|
||
+ /**
|
||
+ * 清空统计 (当区块卸载时)
|
||
+ */
|
||
+ public void clear() {
|
||
+ started = false;
|
||
+ Arrays.fill(times, 0L);
|
||
+ temp = 0L;
|
||
+ total = 0L;
|
||
+ nanos = 0L;
|
||
+ }
|
||
+
|
||
+ /**
|
||
+ * @return 获取区块热度平均值
|
||
+ */
|
||
+ public long getAverage() {
|
||
+ return total / ((long) TIMES_LENGTH * 20L);
|
||
+ }
|
||
+}
|
||
diff --git a/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java b/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
|
||
index aafb2f5052c7c8e5971a47308253badb3027093c..9fe7ac7ba83bbcc9a2a851a5cace47641323f4d2 100644
|
||
--- a/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
|
||
+++ b/src/main/java/me/earthme/luminol/config/modules/misc/TpsBarConfig.java
|
||
@@ -12,11 +12,13 @@ public class TpsBarConfig implements IConfigModule {
|
||
@ConfigInfo(baseName = "enabled")
|
||
public static boolean tpsbarEnabled = false;
|
||
@ConfigInfo(baseName = "format")
|
||
- public static String tpsBarFormat = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms";
|
||
+ public static String tpsBarFormat = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms ChunkHot<yellow>:</yellow> <chunkhot>";
|
||
@ConfigInfo(baseName = "tps_color_list")
|
||
public static List<String> tpsColors = List.of("GREEN","YELLOW","RED","PURPLE");
|
||
@ConfigInfo(baseName = "ping_color_list")
|
||
public static List<String> pingColors = List.of("GREEN","YELLOW","RED","PURPLE");
|
||
+ @ConfigInfo(baseName = "chunkhot_color_list")
|
||
+ public static List<String> chunkHotColors = List.of("GREEN","YELLOW","RED","PURPLE");
|
||
@ConfigInfo(baseName = "update_interval_ticks")
|
||
public static int updateInterval = 15;
|
||
|
||
diff --git a/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java b/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
|
||
index 3f1478dde900d671c4bfa43df80f629519cd602e..7abde30d420ff66026d1dee017c41bc23df22b26 100644
|
||
--- a/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
|
||
+++ b/src/main/java/me/earthme/luminol/functions/GlobalServerTpsBar.java
|
||
@@ -139,7 +139,8 @@ public class GlobalServerTpsBar {
|
||
TpsBarConfig.tpsBarFormat,
|
||
Placeholder.component("tps",getTpsComponent(tps)),
|
||
Placeholder.component("mspt",getMsptComponent(mspt)),
|
||
- Placeholder.component("ping",getPingComponent(player.getPing()))
|
||
+ Placeholder.component("ping",getPingComponent(player.getPing())),
|
||
+ Placeholder.component("chunkhot",getChunkHotComponent(player.getNearbyChunkHot()))
|
||
));
|
||
bar.color(barColorFromTps(tps));
|
||
bar.progress((float) Math.min((float)1,Math.max(mspt / 50,0)));
|
||
@@ -181,6 +182,32 @@ public class GlobalServerTpsBar {
|
||
return MiniMessage.miniMessage().deserialize(replaced,Placeholder.parsed("text", String.format("%.2f", mspt)));
|
||
}
|
||
|
||
+ private static @NotNull Component getChunkHotComponent(long chunkHot){
|
||
+ final BossBar.Color colorBukkit = barColorFromChunkHot(chunkHot);
|
||
+ final String colorString = colorBukkit.name();
|
||
+
|
||
+ final String content = "<%s><text></%s>";
|
||
+ final String replaced = String.format(content,colorString,colorString);
|
||
+
|
||
+ return MiniMessage.miniMessage().deserialize(replaced,Placeholder.parsed("text", String.valueOf(chunkHot)));
|
||
+ }
|
||
+
|
||
+ private static BossBar.Color barColorFromChunkHot(long chunkHot){
|
||
+ if (chunkHot == -1){
|
||
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(3));
|
||
+ }
|
||
+
|
||
+ if (chunkHot <= 300000L){
|
||
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(0));
|
||
+ }
|
||
+
|
||
+ if (chunkHot <= 500000L){
|
||
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(1));
|
||
+ }
|
||
+
|
||
+ return BossBar.Color.valueOf(TpsBarConfig.chunkHotColors.get(2));
|
||
+ }
|
||
+
|
||
private static BossBar.Color barColorFromMspt(double mspt){
|
||
if (mspt == -1){
|
||
return BossBar.Color.valueOf(TpsBarConfig.tpsColors.get(3));
|
||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||
index 6ead4f65a07defbb7778365ce92d891528dc67aa..87664187c073685573cb93bf51ba84ef26e6bd8c 100644
|
||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||
@@ -1697,6 +1697,17 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
}
|
||
// Folia end - region threading
|
||
|
||
+ // KioCG start - ChunkHot
|
||
+ if (region != null && io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() % 20 == 0){
|
||
+ final Iterator<net.minecraft.world.level.chunk.LevelChunk> chunkIterator = region.world.getCurrentWorldData().getChunks().unsafeIterator();
|
||
+ while (chunkIterator.hasNext()){
|
||
+ final net.minecraft.world.level.chunk.LevelChunk targetChunk = chunkIterator.next();
|
||
+
|
||
+ targetChunk.getChunkHot().nextTick();
|
||
+ targetChunk.getChunkHot().start();
|
||
+ }
|
||
+ }
|
||
+ //KioCG end
|
||
// Folia - region threading
|
||
if (region == null) this.tickRateManager.tick(); // Folia - region threading
|
||
this.tickChildren(shouldKeepTicking, region); // Folia - region threading
|
||
@@ -1706,6 +1717,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||
}
|
||
|
||
// Folia - region threading
|
||
+ // KioCG start - ChunkHot
|
||
+ if (region != null && io.papermc.paper.threadedregions.RegionizedServer.getCurrentTick() % 20 == 0){
|
||
+ final Iterator<net.minecraft.world.level.chunk.LevelChunk> chunkIterator = region.world.getCurrentWorldData().getChunks().unsafeIterator();
|
||
+ while (chunkIterator.hasNext()){
|
||
+ final net.minecraft.world.level.chunk.LevelChunk targetChunk = chunkIterator.next();
|
||
+
|
||
+ if (!targetChunk.getChunkHot().isStarted()){
|
||
+ continue;
|
||
+ }
|
||
+
|
||
+ targetChunk.getChunkHot().stop();
|
||
+ }
|
||
+ }
|
||
+ //KioCG end
|
||
// Paper start - Incremental chunk and player saving
|
||
int playerSaveInterval = io.papermc.paper.configuration.GlobalConfiguration.get().playerAutoSave.rate;
|
||
if (playerSaveInterval < 0) {
|
||
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
index 12c46e7a3f6a8675921d95dee97ece4a83252282..573cca66b905c5decb0e59c58cfa861d1788d5d3 100644
|
||
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
@@ -1549,6 +1549,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||
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.sectionX,entity.sectionZ) : null; // KioCG
|
||
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
|
||
// Folia end - timer
|
||
try {
|
||
// Paper end - timings
|
||
@@ -1576,6 +1578,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||
} else { entity.inactiveTick(); } // Paper - EAR 2
|
||
this.getProfiler().pop();
|
||
} finally { timer.stopTiming(); profiler.stopTimer(timerId); } // Paper - timings // Folia - timer
|
||
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
|
||
Iterator iterator = entity.getPassengers().iterator();
|
||
|
||
while (iterator.hasNext()) {
|
||
@@ -1604,6 +1607,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||
final ca.spottedleaf.leafprofiler.RegionizedProfiler.Handle profiler = io.papermc.paper.threadedregions.TickRegionScheduler.getProfiler();
|
||
profiler.startTimer(timerId);
|
||
// Folia end - timer
|
||
+ LevelChunk levelChunk = !(passenger instanceof Player) ? this.getChunkIfLoaded(passenger.blockPosition()) : null; // KioCG
|
||
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
|
||
try {
|
||
// Paper end
|
||
passenger.setOldPosAndRot();
|
||
@@ -1644,6 +1649,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
||
}
|
||
|
||
} finally { timer.stopTiming(); profiler.stopTimer(timerId); }// Paper - EAR2 timings // Folia - timer
|
||
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
|
||
}
|
||
} else {
|
||
passenger.stopRiding();
|
||
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||
index ea3cf67d65155d72a42e39bc45dd0546ae780670..0fa0f7dc32bae5c5c5d3426e28b8156b9305efb2 100644
|
||
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||
@@ -352,6 +352,25 @@ public class ServerPlayer extends Player {
|
||
public boolean handlingMoveEvent = false;
|
||
//Luminol end
|
||
|
||
+ // KioCG start - ChunkHot
|
||
+ private long nearbyChunkHot = 0;
|
||
+
|
||
+ public long getNearbyChunkHot() { return this.nearbyChunkHot; }
|
||
+
|
||
+ private long refreshNearbyChunkHot() {
|
||
+ long total = 0L;
|
||
+ for (int i = this.sectionX - 4; i <= this.sectionX + 4; ++i) {
|
||
+ for (int j = this.sectionZ - 4; j <= this.sectionZ + 4; ++j) {
|
||
+ net.minecraft.world.level.chunk.LevelChunk targetChunk = this.level().getChunkIfLoaded(i, j);
|
||
+ if (targetChunk != null) {
|
||
+ total += targetChunk.getChunkHot().getAverage();
|
||
+ }
|
||
+ }
|
||
+ }
|
||
+ return total;
|
||
+ }
|
||
+ // KioCG end
|
||
+
|
||
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
|
||
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
|
||
this.chatVisibility = ChatVisiblity.FULL;
|
||
@@ -935,6 +954,12 @@ public class ServerPlayer extends Player {
|
||
this.trackEnteredOrExitedLavaOnVehicle();
|
||
this.updatePlayerAttributes();
|
||
this.advancements.flushDirty(this);
|
||
+
|
||
+ // KioCG start - ChunkHot
|
||
+ if (this.tickCount % 20 == 0){
|
||
+ this.nearbyChunkHot = this.refreshNearbyChunkHot();
|
||
+ }
|
||
+ // KioCG end
|
||
}
|
||
|
||
private void updatePlayerAttributes() {
|
||
diff --git a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
|
||
index ee972fa1a2bc023ed18eaceae21c8c8244754e6a..0fe6afb51246701309c88febeb61aaf7561bd954 100644
|
||
--- a/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
|
||
+++ b/src/main/java/net/minecraft/world/entity/AreaEffectCloud.java
|
||
@@ -440,4 +440,11 @@ public class AreaEffectCloud extends Entity implements TraceableEntity {
|
||
public EntityDimensions getDimensions(Pose pose) {
|
||
return EntityDimensions.scalable(this.getRadius() * 2.0F, 0.5F);
|
||
}
|
||
+
|
||
+ // KioCG start
|
||
+ @Override
|
||
+ public boolean shouldTickHot() {
|
||
+ return false;
|
||
+ }
|
||
+ // KioCG end
|
||
}
|
||
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
||
index 99978531e19eb9d5a14354b7e518d609e2389b5a..3baaf0eb1ab26ec269161f9c5f35bfc743e9d98e 100644
|
||
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
||
@@ -6025,4 +6025,6 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
||
return ((net.minecraft.server.level.ServerChunkCache) level.getChunkSource()).isPositionTicking(this);
|
||
}
|
||
// Paper end - Expose entity id counter
|
||
+
|
||
+ public boolean shouldTickHot() { return this.tickCount > 20 * 10 && this.isAlive(); } // KioCG
|
||
}
|
||
diff --git a/src/main/java/net/minecraft/world/entity/LightningBolt.java b/src/main/java/net/minecraft/world/entity/LightningBolt.java
|
||
index 4f701788bd21b61cad251a3a88f9bc416fb99051..86caa40a91ee0385bc32fd19d0fec6bd2f3634d2 100644
|
||
--- a/src/main/java/net/minecraft/world/entity/LightningBolt.java
|
||
+++ b/src/main/java/net/minecraft/world/entity/LightningBolt.java
|
||
@@ -288,4 +288,11 @@ public class LightningBolt extends Entity {
|
||
public Stream<Entity> getHitEntities() {
|
||
return this.hitEntities.stream().filter(Entity::isAlive);
|
||
}
|
||
+
|
||
+ // KioCG start
|
||
+ @Override
|
||
+ public boolean shouldTickHot() {
|
||
+ return false;
|
||
+ }
|
||
+ // KioCG end
|
||
}
|
||
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
|
||
index 4e0335d683334b0c6ee4dbf16d93f4e0392cf8d4..d01a5a920a44b2168247a83aea56f6b0f02ca9f1 100644
|
||
--- a/src/main/java/net/minecraft/world/entity/Mob.java
|
||
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
|
||
@@ -1950,4 +1950,11 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti
|
||
|
||
return itemmonsteregg == null ? null : new ItemStack(itemmonsteregg);
|
||
}
|
||
+
|
||
+ // KioCG start
|
||
+ @Override
|
||
+ public boolean shouldTickHot() {
|
||
+ return super.shouldTickHot() && (!this.removeWhenFarAway(0.0) || this.isPersistenceRequired() || this.requiresCustomPersistence());
|
||
+ }
|
||
+ // KioCG end
|
||
}
|
||
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/TraderLlama.java b/src/main/java/net/minecraft/world/entity/animal/horse/TraderLlama.java
|
||
index bbfc94237bbd546361cc4a7bde773c810e8c5d49..d9f48fe2bcf1a2e317e97046618c056b05643268 100644
|
||
--- a/src/main/java/net/minecraft/world/entity/animal/horse/TraderLlama.java
|
||
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/TraderLlama.java
|
||
@@ -166,4 +166,11 @@ public class TraderLlama extends Llama {
|
||
super.start();
|
||
}
|
||
}
|
||
+
|
||
+ // KioCG start
|
||
+ @Override
|
||
+ public boolean shouldTickHot() {
|
||
+ return super.shouldTickHot() && !this.canDespawn();
|
||
+ }
|
||
+ // KioCG end
|
||
}
|
||
diff --git a/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java b/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
|
||
index 0854e9b7ee2e6b23b6c1ee6a324a5a253c9d4679..26f2e3980cb8ac72db71dd3e91156f16fa9466cf 100644
|
||
--- a/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
|
||
+++ b/src/main/java/net/minecraft/world/entity/npc/WanderingTrader.java
|
||
@@ -326,4 +326,12 @@ public class WanderingTrader extends net.minecraft.world.entity.npc.AbstractVill
|
||
return !pos.closerToCenterThan(this.trader.position(), proximityDistance);
|
||
}
|
||
}
|
||
+
|
||
+
|
||
+ // KioCG start
|
||
+ @Override
|
||
+ public boolean shouldTickHot() {
|
||
+ return false;
|
||
+ }
|
||
+ // KioCG end
|
||
}
|
||
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||
index b0f2e614c90137c526de865bd64469f09b95c964..3d8b55afaced6fbac3bc957ffdc3368252d06b61 100644
|
||
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
||
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||
@@ -2472,4 +2472,12 @@ public abstract class Player extends LivingEntity {
|
||
return this.message;
|
||
}
|
||
}
|
||
+
|
||
+
|
||
+ // KioCG start
|
||
+ @Override
|
||
+ public boolean shouldTickHot() {
|
||
+ return false;
|
||
+ }
|
||
+ // 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 829b63c8a7574d6aefe95b7d190dccc4c6ecf1ba..d9018cc8a1e69efd23d6a0d35a24b75dd0220d20 100644
|
||
--- a/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
||
+++ b/src/main/java/net/minecraft/world/entity/projectile/Projectile.java
|
||
@@ -402,4 +402,11 @@ public abstract class Projectile extends Entity implements TraceableEntity {
|
||
public float getPickRadius() {
|
||
return this.isPickable() ? 1.0F : 0.0F;
|
||
}
|
||
+
|
||
+ // KioCG start
|
||
+ @Override
|
||
+ public boolean shouldTickHot() {
|
||
+ return false;
|
||
+ }
|
||
+ // KioCG end
|
||
}
|
||
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
||
index 5f60010d44f2a3df8645a0e7dafa3f28d882aecf..7592c90fdf35bcaad7ea198f920bcf9e4f35baf5 100644
|
||
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
||
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
||
@@ -94,6 +94,7 @@ public class LevelChunk extends ChunkAccess {
|
||
private final LevelChunkTicks<Block> blockTicks;
|
||
private final LevelChunkTicks<Fluid> fluidTicks;
|
||
public volatile FullChunkStatus chunkStatus = FullChunkStatus.INACCESSIBLE; // Paper - rewrite chunk system
|
||
+ private final com.kiocg.ChunkHot chunkHot = new com.kiocg.ChunkHot(); public com.kiocg.ChunkHot getChunkHot() { return this.chunkHot; } // KioCG
|
||
|
||
public LevelChunk(Level world, ChunkPos pos) {
|
||
this(world, pos, UpgradeData.EMPTY, new LevelChunkTicks<>(), new LevelChunkTicks<>(), 0L, (LevelChunkSection[]) null, (LevelChunk.PostLoadProcessor) null, (BlendingData) null);
|
||
@@ -762,6 +763,7 @@ public class LevelChunk extends ChunkAccess {
|
||
}
|
||
|
||
public void onChunkNotTicking(io.papermc.paper.chunk.system.scheduling.NewChunkHolder chunkHolder) {
|
||
+ this.chunkHot.clear(); // KioCG
|
||
io.papermc.paper.chunk.system.ChunkSystem.onChunkNotTicking(this, chunkHolder.vanillaChunkHolder);
|
||
}
|
||
|
||
@@ -1186,6 +1188,7 @@ public class LevelChunk extends ChunkAccess {
|
||
|
||
gameprofilerfiller.push(this::getType);
|
||
this.blockEntity.tickTimer.startTiming(); // Spigot
|
||
+ LevelChunk.this.chunkHot.startTicking(); // KioCG
|
||
profiler.startTimer(timerId); try { // Folia - profiler
|
||
BlockState iblockdata = LevelChunk.this.getBlockState(blockposition);
|
||
|
||
@@ -1216,6 +1219,7 @@ public class LevelChunk extends ChunkAccess {
|
||
} finally {
|
||
this.blockEntity.tickTimer.stopTiming();
|
||
// Spigot end
|
||
+ LevelChunk.this.chunkHot.stopTickingAndCount(); // KioCG
|
||
}
|
||
}
|
||
}
|
||
diff --git a/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java b/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
|
||
index e679b40b9628b0eb7152978ef641f9c918c4c8b2..bf9ae765242bb61d3e279893b0355d122cb1e985 100644
|
||
--- a/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
|
||
+++ b/src/main/java/net/minecraft/world/level/redstone/NeighborUpdater.java
|
||
@@ -63,7 +63,10 @@ public interface NeighborUpdater {
|
||
}
|
||
}
|
||
// CraftBukkit end
|
||
+ net.minecraft.world.level.chunk.LevelChunk levelChunk = world.getChunkIfLoaded(pos); // KioCG
|
||
+ if (levelChunk != null) levelChunk.getChunkHot().startTicking(); try { // KioCG
|
||
state.handleNeighborChanged(world, pos, sourceBlock, sourcePos, notify);
|
||
+ } finally { if (levelChunk != null) levelChunk.getChunkHot().stopTickingAndCount(); } // KioCG
|
||
// Spigot Start
|
||
} catch (StackOverflowError ex) {
|
||
world.lastPhysicsProblem = new BlockPos(pos);
|
||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
||
index 92f1ea81b5e90529905d9c508aca18c31443ff6a..3b972bf05d9ee79f2cdfc9b5a81692c229a5662e 100644
|
||
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
||
@@ -434,4 +434,12 @@ public class CraftChunk implements Chunk {
|
||
static {
|
||
Arrays.fill(FULL_LIGHT, (byte) 0xFF);
|
||
}
|
||
+
|
||
+ // KioCG start - ChunkHot
|
||
+ @Override
|
||
+ public long getChunkHotAvg() {
|
||
+ final net.minecraft.world.level.chunk.LevelChunk target = this.worldServer.getChunkIfLoaded(this.x,this.z);
|
||
+ return target == null ? -1 : target.getChunkHot().getAverage();
|
||
+ }
|
||
+ // KioCG end
|
||
}
|
||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||
index 2e2c8d6fa55f3b58fb6e48de0c36b22d51b09653..6c8eb658145ad0a15f6e734e0902916ba32e77bb 100644
|
||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||
@@ -3560,4 +3560,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||
public void setSendViewDistance(final int viewDistance) {
|
||
this.getHandle().setSendViewDistance(viewDistance);
|
||
}
|
||
+
|
||
+ // KioCG start - ChunkHot
|
||
+ @Override
|
||
+ public long getNearbyChunkHot() {
|
||
+ return this.getHandle().getNearbyChunkHot();
|
||
+ }
|
||
+ // KioCG end
|
||
}
|