diff --git a/patches/minecraft/net/minecraft/client/Minecraft.java.patch b/patches/minecraft/net/minecraft/client/Minecraft.java.patch index 97b770da1..8a471ad36 100644 --- a/patches/minecraft/net/minecraft/client/Minecraft.java.patch +++ b/patches/minecraft/net/minecraft/client/Minecraft.java.patch @@ -1,6 +1,14 @@ --- a/net/minecraft/client/Minecraft.java +++ b/net/minecraft/client/Minecraft.java -@@ -314,7 +314,7 @@ +@@ -297,6 +297,7 @@ + public Minecraft(GameConfiguration p_i45547_1_) { + this.field_195556_O = p_i45547_1_.field_178743_b; + field_71432_P = this; ++ net.minecraftforge.client.ForgeHooksClient.invalidateLog4jThreadCache(); + this.field_71412_D = p_i45547_1_.field_178744_c.field_178760_a; + this.field_110446_Y = p_i45547_1_.field_178744_c.field_178759_c; + this.field_130070_K = p_i45547_1_.field_178744_c.field_178758_b; +@@ -314,7 +315,7 @@ supplier = p_211818_2_; } @@ -9,7 +17,7 @@ }); this.field_110448_aq.func_198982_a(this.field_195554_ax); this.field_110448_aq.func_198982_a(new FolderPackFinder(this.field_130070_K)); -@@ -322,7 +322,6 @@ +@@ -322,7 +323,6 @@ this.field_152355_az = (new YggdrasilAuthenticationService(this.field_110453_aa, UUID.randomUUID().toString())).createMinecraftSessionService(); this.field_71449_j = p_i45547_1_.field_178745_a.field_178752_a; field_147123_G.info("Setting user: {}", (Object)this.field_71449_j.func_111285_a()); @@ -17,7 +25,7 @@ this.field_71459_aj = p_i45547_1_.field_178741_d.field_178756_a; this.field_147129_ai = func_147122_X(); this.field_71437_Z = null; -@@ -409,9 +408,11 @@ +@@ -409,9 +409,11 @@ this.field_135017_as = new LanguageManager(this.field_71474_y.field_74363_ab); this.field_110451_am.func_199006_a(this.field_135017_as); this.field_71474_y.func_198017_a(this.field_110448_aq); @@ -29,7 +37,7 @@ this.field_195558_d.func_198098_h(); this.func_147108_a(new GuiScreenLoading()); this.func_195547_ap(); -@@ -429,6 +430,8 @@ +@@ -429,6 +431,8 @@ this.field_110451_am.func_199006_a(new GrassColorReloadListener()); this.field_110451_am.func_199006_a(new FoliageColorReloadListener()); @@ -38,7 +46,7 @@ this.field_195558_d.func_198076_a("Startup"); GlStateManager.func_179098_w(); GlStateManager.func_179103_j(7425); -@@ -442,19 +445,24 @@ +@@ -442,19 +446,24 @@ GlStateManager.func_179096_D(); GlStateManager.func_179128_n(5888); this.field_195558_d.func_198076_a("Post startup"); @@ -63,7 +71,7 @@ this.field_71460_t = new GameRenderer(this, this.field_110451_am); this.field_110451_am.func_199006_a(this.field_71460_t); this.field_175618_aM = new BlockRendererDispatcher(this.field_175617_aL.func_174954_c(), this.field_184127_aH); -@@ -465,7 +473,10 @@ +@@ -465,7 +474,10 @@ this.field_110451_am.func_199006_a(this.field_193995_ae); GlStateManager.func_179083_b(0, 0, this.field_195558_d.func_198109_k(), this.field_195558_d.func_198091_l()); this.field_71452_i = new ParticleManager(this.field_71441_e, this.field_71446_o); @@ -75,7 +83,7 @@ if (this.field_71475_ae != null) { this.func_147108_a(new GuiConnecting(new GuiMainMenu(), this, this.field_71475_ae, this.field_71477_af)); } else { -@@ -474,6 +485,7 @@ +@@ -474,6 +486,7 @@ this.field_184132_p = new DebugRenderer(this); GLFW.glfwSetErrorCallback(this::func_195545_a).free(); @@ -83,7 +91,7 @@ if (this.field_71474_y.field_74353_u && !this.field_195558_d.func_198113_j()) { this.field_195558_d.func_198077_g(); } -@@ -489,7 +501,7 @@ +@@ -489,7 +502,7 @@ }); List list = Lists.newArrayList(); GLFWErrorCallback glfwerrorcallback = GLFW.glfwSetErrorCallback((p_211100_1_, p_211100_2_) -> { @@ -92,7 +100,7 @@ }); if (!GLFW.glfwInit()) { throw new IllegalStateException("Failed to initialize GLFW, errors: " + Joiner.on(",").join(list)); -@@ -599,7 +611,7 @@ +@@ -599,7 +612,7 @@ Bootstrap.func_179870_a(p_71377_1_.func_71502_e()); if (p_71377_1_.func_71497_f() != null) { Bootstrap.func_179870_a("#@!@# Game crashed! Crash report saved to: #@!@# " + p_71377_1_.func_71497_f()); @@ -101,7 +109,7 @@ } else if (p_71377_1_.func_147149_a(file2)) { Bootstrap.func_179870_a("#@!@# Game crashed! Crash report saved to: #@!@# " + file2.getAbsolutePath()); System.exit(-1); -@@ -614,6 +626,7 @@ +@@ -614,6 +627,7 @@ return this.field_71474_y.field_211842_aO; } @@ -109,7 +117,7 @@ public void func_110436_a() { this.field_110448_aq.func_198983_a(); List list = this.field_110448_aq.func_198980_d().stream().map(ResourcePackInfo::func_195796_e).collect(Collectors.toList()); -@@ -668,16 +681,20 @@ +@@ -668,16 +682,20 @@ } public void func_147108_a(@Nullable GuiScreen p_147108_1_) { @@ -134,7 +142,7 @@ if (p_147108_1_ instanceof GuiMainMenu || p_147108_1_ instanceof GuiMultiplayer) { this.field_71474_y.field_74330_P = false; this.field_71456_v.func_146158_b().func_146231_a(true); -@@ -761,7 +778,7 @@ +@@ -761,7 +779,7 @@ GLFW.glfwPollEvents(); long i1 = Util.func_211178_c() - l; this.field_71424_I.func_76318_c("sound"); @@ -143,7 +151,7 @@ this.field_71424_I.func_76319_b(); this.field_71424_I.func_76320_a("render"); GlStateManager.func_179094_E(); -@@ -771,11 +788,13 @@ +@@ -771,11 +789,13 @@ GlStateManager.func_179098_w(); this.field_71424_I.func_76319_b(); if (!this.field_71454_w) { @@ -157,7 +165,7 @@ } this.field_71424_I.func_76319_b(); -@@ -994,8 +1013,8 @@ +@@ -994,8 +1014,8 @@ if (this.field_71429_W <= 0 && !this.field_71439_g.func_184587_cr()) { if (p_147115_1_ && this.field_71476_x != null && this.field_71476_x.field_72313_a == RayTraceResult.Type.BLOCK) { BlockPos blockpos = this.field_71476_x.func_178782_a(); @@ -168,7 +176,7 @@ this.field_71439_g.func_184609_a(EnumHand.MAIN_HAND); } -@@ -1020,7 +1039,7 @@ +@@ -1020,7 +1040,7 @@ break; case BLOCK: BlockPos blockpos = this.field_71476_x.func_178782_a(); @@ -177,7 +185,7 @@ this.field_71442_b.func_180511_b(blockpos, this.field_71476_x.field_178784_b); break; } -@@ -1030,6 +1049,7 @@ +@@ -1030,6 +1050,7 @@ } this.field_71439_g.func_184821_cY(); @@ -185,7 +193,7 @@ } this.field_71439_g.func_184609_a(EnumHand.MAIN_HAND); -@@ -1060,7 +1080,7 @@ +@@ -1060,7 +1081,7 @@ break; case BLOCK: BlockPos blockpos = this.field_71476_x.func_178782_a(); @@ -194,7 +202,7 @@ int i = itemstack.func_190916_E(); EnumActionResult enumactionresult = this.field_71442_b.func_187099_a(this.field_71439_g, this.field_71441_e, blockpos, this.field_71476_x.field_178784_b, this.field_71476_x.field_72307_f, enumhand); if (enumactionresult == EnumActionResult.SUCCESS) { -@@ -1079,6 +1099,9 @@ +@@ -1079,6 +1100,9 @@ } } @@ -204,7 +212,7 @@ if (!itemstack.func_190926_b() && this.field_71442_b.func_187101_a(this.field_71439_g, this.field_71441_e, enumhand) == EnumActionResult.SUCCESS) { this.field_71460_t.field_78516_c.func_187460_a(enumhand); return; -@@ -1098,6 +1121,8 @@ +@@ -1098,6 +1122,8 @@ --this.field_71467_ac; } @@ -213,7 +221,7 @@ this.field_71424_I.func_76320_a("gui"); if (!this.field_71445_n) { this.field_71456_v.func_73831_a(); -@@ -1220,6 +1245,8 @@ +@@ -1220,6 +1246,8 @@ this.field_71424_I.func_76318_c("keyboard"); this.field_195559_v.func_204870_b(); this.field_71424_I.func_76319_b(); @@ -222,7 +230,7 @@ } private void func_184117_aA() { -@@ -1378,6 +1405,14 @@ +@@ -1378,6 +1406,14 @@ guiscreenworking.func_200209_c(new TextComponentString("")); } @@ -237,7 +245,7 @@ this.func_195542_b(false); try { -@@ -1397,7 +1432,12 @@ +@@ -1397,7 +1433,12 @@ networkmanager.func_150719_a(new NetHandlerLoginClient(networkmanager, this, (GuiScreen)null, (p_209507_0_) -> { })); networkmanager.func_179290_a(new CPacketHandshake(socketaddress.toString(), 0, EnumConnectionState.LOGIN)); @@ -251,7 +259,7 @@ this.field_71453_ak = networkmanager; } -@@ -1411,6 +1451,7 @@ +@@ -1411,6 +1452,7 @@ } public void func_205055_a(@Nullable WorldClient p_205055_1_, GuiScreen p_205055_2_) { @@ -259,7 +267,7 @@ if (p_205055_1_ == null) { NetHandlerPlayClient nethandlerplayclient = this.func_147114_u(); if (nethandlerplayclient != null) { -@@ -1447,6 +1488,7 @@ +@@ -1447,6 +1489,7 @@ } TileEntityRendererDispatcher.field_147556_a.func_147543_a(p_205055_1_); @@ -267,7 +275,7 @@ if (p_205055_1_ != null) { if (!this.field_71455_al) { AuthenticationService authenticationservice = new YggdrasilAuthenticationService(this.field_110453_aa, UUID.randomUUID().toString()); -@@ -1493,6 +1535,7 @@ +@@ -1493,6 +1536,7 @@ EntityPlayerSP entityplayersp = this.field_71439_g; this.field_71439_g = this.field_71442_b.func_199681_a(this.field_71441_e, this.field_71439_g == null ? new StatisticsManager() : this.field_71439_g.func_146107_m(), this.field_71439_g == null ? new RecipeBookClient(new RecipeManager()) : this.field_71439_g.func_199507_B()); this.field_71439_g.func_184212_Q().func_187218_a(entityplayersp.func_184212_Q().func_187231_c()); @@ -275,7 +283,7 @@ this.field_71439_g.field_71093_bK = p_212315_1_; this.field_175622_Z = this.field_71439_g; this.field_71439_g.func_70065_x(); -@@ -1532,110 +1575,8 @@ +@@ -1532,110 +1576,8 @@ private void func_147112_ai() { if (this.field_71476_x != null && this.field_71476_x.field_72313_a != RayTraceResult.Type.MISS) { @@ -388,7 +396,7 @@ } } -@@ -1712,6 +1653,7 @@ +@@ -1712,6 +1654,7 @@ return field_71432_P; } @@ -396,7 +404,7 @@ public ListenableFuture func_175603_A() { return this.func_152344_a(this::func_110436_a); } -@@ -1871,6 +1813,8 @@ +@@ -1871,6 +1814,8 @@ } public MusicTicker.MusicType func_147109_W() { @@ -405,7 +413,7 @@ if (this.field_71462_r instanceof GuiWinGame) { return MusicTicker.MusicType.CREDITS; } else if (this.field_71439_g == null) { -@@ -2010,4 +1954,12 @@ +@@ -2010,4 +1955,12 @@ public FontResourceManager func_211500_ak() { return this.field_211501_aD; } diff --git a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java index 86d50a85b..e0c209fa5 100644 --- a/src/main/java/net/minecraftforge/client/ForgeHooksClient.java +++ b/src/main/java/net/minecraftforge/client/ForgeHooksClient.java @@ -26,6 +26,7 @@ import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL20.*; import java.io.File; +import java.lang.reflect.Field; import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.util.Map; @@ -43,6 +44,8 @@ import net.minecraftforge.client.event.RecipesUpdatedEvent; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.async.ThreadNameCachingStrategy; +import org.apache.logging.log4j.core.impl.ReusableLogEventFactory; import org.lwjgl.BufferUtils; import net.minecraft.block.state.IBlockState; @@ -815,4 +818,23 @@ public class ForgeHooksClient Event event = new RecipesUpdatedEvent(); MinecraftForge.EVENT_BUS.post(event); } + + // Resets cached thread fields in ThreadNameCachingStrategy and ReusableLogEventFactory to be repopulated during their next access. + // This serves a workaround for no built-in method of triggering this type of refresh as brought up by LOG4J2-2178. + public static void invalidateLog4jThreadCache() + { + try + { + Field nameField = ThreadNameCachingStrategy.class.getDeclaredField("THREADLOCAL_NAME"); + Field logEventField = ReusableLogEventFactory.class.getDeclaredField("mutableLogEventThreadLocal"); + nameField.setAccessible(true); + logEventField.setAccessible(true); + ((ThreadLocal) nameField.get(null)).set(null); + ((ThreadLocal) logEventField.get(null)).set(null); + } + catch (ReflectiveOperationException | NoClassDefFoundError e) + { + LOGGER.error("Unable to invalidate log4j thread cache, thread fields in logs may be inaccurate", e); + } + } }