1 parent
ba9070eddd
commit
f04d2c3260
3 files changed
+31
-11
No files matched your search
@@ -105,13 +105,20 @@ public class WorldServerMixin {
|
||||
IRequest request;
|
||||
while ((request = RequestManager.pollRequest()) != null) {
|
||||
IRequest current = request;
|
||||
EXECUTOR.submit(() -> {
|
||||
try {
|
||||
current.handle(mcServer);
|
||||
} catch (Exception e) {
|
||||
Loon.LOGGER.error("Failed to handle request: {}, {}", current.getClass().getSimpleName(), e);
|
||||
}
|
||||
});
|
||||
if (current.requireTickThread()) {
|
||||
runRequest(current);
|
||||
} else {
|
||||
EXECUTOR.submit(() -> runRequest(current));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private void runRequest(IRequest request) {
|
||||
try {
|
||||
request.handle(mcServer);
|
||||
} catch (Exception e) {
|
||||
Loon.LOGGER.error("Failed to handle request: {}, {}", request.getClass().getSimpleName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public record ChunkMapRequest(int xStart, int xEnd, int zStart, int zEnd) implements IRequest {
|
||||
private static final boolean REQUIRE_TICK_THREAD = false;
|
||||
|
||||
@Override
|
||||
public void handle(MinecraftServer server) {
|
||||
World world = server.getDimensionWorld(0);
|
||||
@@ -72,10 +74,11 @@ public record ChunkMapRequest(int xStart, int xEnd, int zStart, int zEnd) implem
|
||||
|
||||
Chunk resolveChunk(World world, ChunkProvider provider, ChunkLoader loader, int x, int z)
|
||||
{
|
||||
ChunkPos chunkPos = new ChunkPos(x, z);
|
||||
|
||||
if (provider.isChunkLoaded(chunkPos))
|
||||
return world.getChunk(chunkPos);
|
||||
if (REQUIRE_TICK_THREAD) {
|
||||
ChunkPos chunkPos = new ChunkPos(x, z);
|
||||
if (provider.isChunkLoaded(chunkPos))
|
||||
return world.getChunk(chunkPos);
|
||||
}
|
||||
|
||||
if (loader == null || !loader.chunkExists(world, x, z))
|
||||
return null;
|
||||
@@ -86,4 +89,10 @@ public record ChunkMapRequest(int xStart, int xEnd, int zStart, int zEnd) implem
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireTickThread()
|
||||
{
|
||||
return REQUIRE_TICK_THREAD;
|
||||
}
|
||||
}
|
||||
@@ -6,4 +6,8 @@ import net.minecraft.server.entity.player.PlayerServer;
|
||||
public interface IRequest
|
||||
{
|
||||
void handle(MinecraftServer server);
|
||||
default boolean requireTickThread()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user