44import cc .polyfrost .oneconfig .events .event .RenderEvent ;
55import cc .polyfrost .oneconfig .events .event .Stage ;
66import cc .polyfrost .oneconfig .utils .gui .GuiUtils ;
7+ import net .minecraft .client .multiplayer .WorldClient ;
8+ import net .minecraft .client .network .NetHandlerPlayClient ;
9+ import net .minecraft .client .renderer .EntityRenderer ;
10+ import net .minecraft .util .ChatComponentText ;
711import org .polyfrost .crashpatch .config .CrashPatchConfig ;
812import org .polyfrost .crashpatch .crashes .StateManager ;
913import org .polyfrost .crashpatch .gui .CrashGui ;
4852
4953import java .awt .*;
5054import java .util .Objects ;
55+ import java .util .Queue ;
56+ import java .util .concurrent .FutureTask ;
5157
5258@ Mixin (value = Minecraft .class , priority = -9000 )
5359public abstract class MixinMinecraft implements MinecraftHook {
@@ -121,6 +127,13 @@ public abstract class MixinMinecraft implements MinecraftHook {
121127
122128 @ Shadow public abstract void displayCrashReport (CrashReport crashReportIn );
123129 @ Shadow private int leftClickCounter ;
130+
131+ @ Shadow public abstract NetHandlerPlayClient getNetHandler ();
132+
133+ @ Shadow public abstract void loadWorld (WorldClient worldClientIn );
134+
135+ @ Shadow public EntityRenderer entityRenderer ;
136+ @ Shadow @ Final private Queue <FutureTask <?>> scheduledTasks ;
124137 @ Unique
125138 private int crashpatch$clientCrashCount = 0 ;
126139 @ Unique
@@ -198,7 +211,7 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
198211 crashpatch$letDie = true ;
199212 }
200213 if ((crashpatch$clientCrashCount >= CrashPatchConfig .INSTANCE .getCrashLimit () || crashpatch$serverCrashCount >= CrashPatchConfig .INSTANCE .getCrashLimit ())) {
201- logger .error ("Crash limit reached, exiting" );
214+ logger .error ("Crash limit reached, exiting game " );
202215 crashpatch$letDie = true ;
203216 }
204217 displayCrashReport (report );
@@ -208,7 +221,6 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
208221 // Reset hasCrashed, debugCrashKeyPressTime, and crashIntegratedServerNextTick
209222 hasCrashed = false ;
210223 debugCrashKeyPressTime = -1 ;
211- // crashIntegratedServerNextTick = false;
212224
213225 // Vanilla does this when switching to main menu but not our custom crash screen
214226 // nor the out of memory screen (see https://bugs.mojang.com/browse/MC-128953)
@@ -247,20 +259,21 @@ private void onGUIDisplay(GuiScreen i, CallbackInfo ci) {
247259
248260 StateManager .INSTANCE .resetStates ();
249261
250- /*/
251- if (getNetHandler() != null) {
252- getNetHandler().getNetworkManager().closeChannel(new ChatComponentText("[CrashPatch] Client crashed"));
253- }
254- loadWorld(null);
255-
256- if (entityRenderer.isShaderActive()) {
257- entityRenderer.stopUseShader();
258- }
262+ if (crashpatch$clientCrashCount >= CrashPatchConfig .INSTANCE .getLeaveLimit () || crashpatch$serverCrashCount >= CrashPatchConfig .INSTANCE .getLeaveLimit ()) {
263+ logger .error ("Crash limit reached, exiting world" );
264+ CrashGui .Companion .setLeaveWorldCrash$CrashPatch_1_8_9_forge (true );
265+ if (getNetHandler () != null ) {
266+ getNetHandler ().getNetworkManager ().closeChannel (new ChatComponentText ("[CrashPatch] Client crashed" ));
267+ }
268+ loadWorld (null );
259269
260- scheduledTasks.clear(); // TODO: Figure out why this isn't necessary for vanilla disconnect
270+ if (entityRenderer .isShaderActive ()) {
271+ entityRenderer .stopUseShader ();
272+ }
261273
274+ scheduledTasks .clear (); // TODO: Figure out why this isn't necessary for vanilla disconnect
275+ }
262276
263- */
264277 crashpatch$resetState ();
265278
266279 if (originalMemoryReserveSize != -1 ) {
0 commit comments