refactor: extract a network service interface for minecraft to depend on

This commit is contained in:
MatthewBeshay
2026-04-08 23:03:54 +10:00
parent 03618ed156
commit b3d6e7151b
21 changed files with 191 additions and 106 deletions

View File

@@ -15,7 +15,7 @@
#include "ClientConnection.h"
#include "app/common/Audio/SoundEngine.h"
#include "minecraft/Console_Debug_enum.h"
#include "app/common/Network/GameNetworkManager.h"
#include "minecraft/network/INetworkService.h"
#include "MultiPlayerChunkCache.h"
#include "MultiPlayerLocalPlayer.h"
#include "java/JavaMath.h"
@@ -104,13 +104,13 @@ MultiPlayerLevel::~MultiPlayerLevel() {
}
void MultiPlayerLevel::unshareChunkAt(int x, int z) {
if (g_NetworkManager.IsHost()) {
if (NetworkService.IsHost()) {
Level::getChunkAt(x, z)->stopSharingTilesAndData();
}
}
void MultiPlayerLevel::shareChunkAt(int x, int z) {
if (g_NetworkManager.IsHost()) {
if (NetworkService.IsHost()) {
Level::getChunkAt(x, z)->startSharingTilesAndData();
}
}
@@ -193,12 +193,12 @@ void MultiPlayerLevel::tick() {
// chunks become unshared over time.
int ls = dimension->getXZSize();
if (g_NetworkManager.IsHost()) {
if (NetworkService.IsHost()) {
if (Level::reallyHasChunk(unshareCheckX - (ls / 2),
unshareCheckZ - (ls / 2))) {
LevelChunk* lc = Level::getChunk(unshareCheckX - (ls / 2),
unshareCheckZ - (ls / 2));
if (g_NetworkManager.IsHost()) {
if (NetworkService.IsHost()) {
lc->startSharingTilesAndData(1000 * 60 * 2);
}
}
@@ -611,8 +611,8 @@ bool MultiPlayerLevel::doSetTileAndData(int x, int y, int z, int tile,
// don't change things as the host might have been sharing data and so set
// it already, but the renderer won't know to update
if ((Level::setTileAndData(x, y, z, tile, data, Tile::UPDATE_ALL) ||
g_NetworkManager.IsHost())) {
if (g_NetworkManager.IsHost() && visuallyImportant) {
NetworkService.IsHost())) {
if (NetworkService.IsHost() && visuallyImportant) {
// 4J Stu - This got removed from the tileUpdated function in TU14.
// Adding it back here as we need it to handle the cases where the
// chunk data is shared so the normal paths never call this