Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.21.4] Revert Registries to Frozen on Disconnect when a connection is present #1934

Open
wants to merge 2 commits into
base: 1.21.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions patches/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -324,22 +324,31 @@
this.level = p_91157_;
this.updateLevelInEngines(p_91157_);
if (!this.isLocalServer) {
@@ -2030,6 +_,7 @@
@@ -2030,13 +_,16 @@
IntegratedServer integratedserver = this.singleplayerServer;
this.singleplayerServer = null;
this.gameRenderer.resetData();
+ net.neoforged.neoforge.client.ClientHooks.firePlayerLogout(this.gameMode, this.player);
this.gameMode = null;
this.narrator.clear();
this.clientLevelTeardownInProgress = true;
@@ -2037,6 +_,7 @@

+ var shouldRevertRegistriesToFrozen = this.getConnection() != null && this.getConnection().getConnection() != null; // Neo: Track whether to revert registries after disconnect
try {
this.updateScreenAndTick(p_320248_);
if (this.level != null) {
+ net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.level.LevelEvent.Unload(this.level));
if (integratedserver != null) {
ProfilerFiller profilerfiller = Profiler.get();
profilerfiller.push("waitForServer");
@@ -2060,6 +_,7 @@
}

SkullBlockEntity.clear();
+ if(shouldRevertRegistriesToFrozen) net.neoforged.neoforge.registries.RegistryManager.revertToFrozen(); // Neo: Revert registries to frozen on disconnect
}

public void clearDownloadedResourcePacks() {
@@ -2197,6 +_,7 @@

private void pickBlock() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@
this.connection.send(p_295097_);
}

@@ -285,6 +_,9 @@
public void onDisconnect(DisconnectionDetails p_350760_) {
this.telemetryManager.onDisconnect();
this.minecraft.disconnect(this.createDisconnectScreen(p_350760_), this.isTransferring);
+ if (!this.connection.isMemoryConnection()) {
+ net.neoforged.neoforge.registries.RegistryManager.revertToFrozen();
+ }
LOGGER.warn("Client disconnected with reason: {}", p_350760_.reason().getString());
}

@@ -409,5 +_,10 @@
@OnlyIn(Dist.CLIENT)
static record PendingRequest(UUID id, URL url, String hash) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import net.neoforged.neoforge.mixins.MappedRegistryAccessor;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import net.neoforged.neoforge.registries.NeoForgeRegistries.Keys;
import net.neoforged.neoforge.registries.RegistryManager;
import net.neoforged.neoforge.server.permission.PermissionAPI;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -123,7 +122,6 @@ public static void expectServerStopped() {
}

public static void handleServerStopped(final MinecraftServer server) {
if (!server.isDedicatedServer()) RegistryManager.revertToFrozen();
NeoForge.EVENT_BUS.post(new ServerStoppedEvent(server));
currentServer = null;
LogicalSidedProvider.setServer(null);
Expand Down