204 lines
7.0 KiB
Diff
204 lines
7.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <wangxyper@163.com>
|
|
Date: Mon, 27 Jan 2025 13:01:56 +0800
|
|
Subject: [PATCH] Tick regions api
|
|
|
|
|
|
diff --git a/src/main/java/me/earthme/luminol/api/impl/RegionStatsImpl.java b/src/main/java/me/earthme/luminol/api/impl/RegionStatsImpl.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..30d4e7b6a433974c5047148f35973eb31c82d424
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/earthme/luminol/api/impl/RegionStatsImpl.java
|
|
@@ -0,0 +1,27 @@
|
|
+package me.earthme.luminol.api.impl;
|
|
+
|
|
+import io.papermc.paper.threadedregions.TickRegions;
|
|
+import me.earthme.luminol.api.RegionStats;
|
|
+
|
|
+public class RegionStatsImpl implements RegionStats {
|
|
+ private final TickRegions.RegionStats internal;
|
|
+
|
|
+ public RegionStatsImpl(TickRegions.RegionStats internal) {
|
|
+ this.internal = internal;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getEntityCount() {
|
|
+ return this.internal.getEntityCount();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getPlayerCount() {
|
|
+ return this.internal.getPlayerCount();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public int getChunkCount() {
|
|
+ return this.internal.getChunkCount();
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/me/earthme/luminol/api/impl/ThreadedRegionImpl.java b/src/main/java/me/earthme/luminol/api/impl/ThreadedRegionImpl.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a1380abacf7bc0fe106982d9b4cd7bbc44e4e375
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/earthme/luminol/api/impl/ThreadedRegionImpl.java
|
|
@@ -0,0 +1,47 @@
|
|
+package me.earthme.luminol.api.impl;
|
|
+
|
|
+import io.papermc.paper.threadedregions.ThreadedRegionizer;
|
|
+import io.papermc.paper.threadedregions.TickRegions;
|
|
+import me.earthme.luminol.api.ThreadedRegion;
|
|
+import me.earthme.luminol.api.TickRegionData;
|
|
+import net.minecraft.world.level.ChunkPos;
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.World;
|
|
+
|
|
+import javax.annotation.Nullable;
|
|
+
|
|
+public class ThreadedRegionImpl implements ThreadedRegion {
|
|
+ private final ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> internal;
|
|
+
|
|
+ public ThreadedRegionImpl(ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> internal) {
|
|
+ this.internal = internal;
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public Location getCenterChunkPos() {
|
|
+ final ChunkPos centerChunkPos = this.internal.getCenterChunk();
|
|
+
|
|
+ if (centerChunkPos == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ return new Location(this.internal.regioniser.world.getWorld(), centerChunkPos.getMiddleBlockX(), 0, centerChunkPos.getMiddleBlockZ());
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public double getDeadSectionPercent() {
|
|
+ return this.internal.getDeadSectionPercent();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public TickRegionData getTickRegionData() {
|
|
+ return new TickRegionDataImpl(this.internal.getData());
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ @Override
|
|
+ public World getWorld() {
|
|
+ return this.internal.regioniser.world.getWorld();
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/me/earthme/luminol/api/impl/ThreadedRegionizerImpl.java b/src/main/java/me/earthme/luminol/api/impl/ThreadedRegionizerImpl.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..203ba60216febd8c19315afd89140d5400213f67
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/earthme/luminol/api/impl/ThreadedRegionizerImpl.java
|
|
@@ -0,0 +1,53 @@
|
|
+package me.earthme.luminol.api.impl;
|
|
+
|
|
+import io.papermc.paper.threadedregions.TickRegions;
|
|
+import me.earthme.luminol.api.ThreadedRegion;
|
|
+import me.earthme.luminol.api.ThreadedRegionizer;
|
|
+import net.minecraft.server.level.ServerLevel;
|
|
+
|
|
+import java.util.ArrayList;
|
|
+import java.util.Collection;
|
|
+import java.util.List;
|
|
+
|
|
+public class ThreadedRegionizerImpl implements ThreadedRegionizer {
|
|
+ private final ServerLevel internal;
|
|
+
|
|
+ public ThreadedRegionizerImpl(ServerLevel internal) {
|
|
+ this.internal = internal;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Collection<ThreadedRegion> getAllRegions() {
|
|
+ final List<ThreadedRegion> ret = new ArrayList<>();
|
|
+
|
|
+ this.internal.regioniser.computeForAllRegions(region -> {
|
|
+ final ThreadedRegion wrapped = new ThreadedRegionImpl(region);
|
|
+
|
|
+ ret.add(wrapped);
|
|
+ });
|
|
+
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ThreadedRegion getAtSynchronized(int chunkX, int chunkZ) {
|
|
+ final io.papermc.paper.threadedregions.ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> got = this.internal.regioniser.getRegionAtSynchronised(chunkX, chunkZ);
|
|
+
|
|
+ if (got == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ return new ThreadedRegionImpl(got);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ThreadedRegion getAtUnSynchronized(int chunkX, int chunkZ) {
|
|
+ final io.papermc.paper.threadedregions.ThreadedRegionizer.ThreadedRegion<TickRegions.TickRegionData, TickRegions.TickRegionSectionData> got = this.internal.regioniser.getRegionAtUnsynchronised(chunkX, chunkZ);
|
|
+
|
|
+ if (got == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ return new ThreadedRegionImpl(got);
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/me/earthme/luminol/api/impl/TickRegionDataImpl.java b/src/main/java/me/earthme/luminol/api/impl/TickRegionDataImpl.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..cf51350ccabeda97e9eff41ccd30c58e836fe041
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/earthme/luminol/api/impl/TickRegionDataImpl.java
|
|
@@ -0,0 +1,30 @@
|
|
+package me.earthme.luminol.api.impl;
|
|
+
|
|
+import io.papermc.paper.threadedregions.TickRegions;
|
|
+import me.earthme.luminol.api.RegionStats;
|
|
+import me.earthme.luminol.api.TickRegionData;
|
|
+import org.bukkit.World;
|
|
+
|
|
+public class TickRegionDataImpl implements TickRegionData {
|
|
+ private final TickRegions.TickRegionData internal;
|
|
+
|
|
+ public TickRegionDataImpl(TickRegions.TickRegionData internal) {
|
|
+ this.internal = internal;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public World getWorld() {
|
|
+ return this.internal.world.getWorld();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public long getCurrentTickCount() {
|
|
+ return this.internal.getCurrentTick();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public RegionStats getRegionStats() {
|
|
+ return new RegionStatsImpl(this.internal.getRegionStats());
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
index b88d48b79b97b22adbfb22a3b289237737a5fb5f..e0e283698ff621c4799ce9f50d86e7159cad4265 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -2517,4 +2517,11 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
return this.adventure$pointers;
|
|
}
|
|
// Paper end
|
|
+
|
|
+ // Luminol start - Tick regions api
|
|
+ @Override
|
|
+ public me.earthme.luminol.api.ThreadedRegionizer getThreadedRegionizer() {
|
|
+ return new me.earthme.luminol.api.impl.ThreadedRegionizerImpl(this.world);
|
|
+ }
|
|
+ // Luminol end
|
|
}
|