File tree Expand file tree Collapse file tree
src/main/java/com/mitchej123/hodgepodge Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -115,6 +115,11 @@ public static class MemoryLeakFixes {
115115 @ Config .DefaultBoolean (true )
116116 @ Config .RequiresMcRestart
117117 public boolean fixBibliocraftTESRWorldLeak ;
118+
119+ @ Config .Comment ("Fix forge's FakePlayerFactory leaking the world instance" )
120+ @ Config .DefaultBoolean (true )
121+ @ Config .RequiresMcRestart
122+ public boolean fixForgePlayerFactoryLeak ;
118123 }
119124
120125 public static class AllocationFixes {
Original file line number Diff line number Diff line change @@ -1035,6 +1035,10 @@ public enum Mixins implements IMixins {
10351035 .addClientMixins ("forge.MixinAdvancedModelLoader_CacheModels" )
10361036 .setApplyIf (() -> MemoryConfig .allocs .cacheAdvancedModels )
10371037 .setPhase (Phase .EARLY )),
1038+ FIX_FORGE_PLAYER_LEAK (new MixinBuilder ()
1039+ .addCommonMixins ("memory.MixinFakePlayerFactory_FixLeak" )
1040+ .setApplyIf (() -> MemoryConfig .leaks .fixForgePlayerFactoryLeak )
1041+ .setPhase (Phase .EARLY )),
10381042 // endregion
10391043
10401044 // region Ic2 adjustments
Original file line number Diff line number Diff line change 1+ package com .mitchej123 .hodgepodge .mixins .early .memory ;
2+
3+ import net .minecraft .world .WorldServer ;
4+ import net .minecraftforge .common .util .FakePlayer ;
5+ import net .minecraftforge .common .util .FakePlayerFactory ;
6+
7+ import org .spongepowered .asm .mixin .Mixin ;
8+ import org .spongepowered .asm .mixin .Shadow ;
9+ import org .spongepowered .asm .mixin .injection .At ;
10+ import org .spongepowered .asm .mixin .injection .Inject ;
11+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
12+
13+ @ Mixin (value = FakePlayerFactory .class , remap = false )
14+ public class MixinFakePlayerFactory_FixLeak {
15+
16+ @ Shadow
17+ private static FakePlayer MINECRAFT_PLAYER ;
18+
19+ @ Inject (method = "unloadWorld" , at = @ At ("HEAD" ))
20+ private static void clearMinecraftPlayer (WorldServer world , CallbackInfo ci ) {
21+ if (MINECRAFT_PLAYER != null && MINECRAFT_PLAYER .worldObj == world ) {
22+ MINECRAFT_PLAYER = null ;
23+ }
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments