From 995c204338cd601e118396d4b4ef8feb6e759037 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 8 Feb 2014 22:37:40 -0500 Subject: [PATCH] Fix failing to load a world with missing mod blocks and items. There will be a way to force worlds to load when stuff is missing, but for right now, it will fail as this is "world safe". --- .../net/minecraft/client/Minecraft.java.patch | 32 +++++--- .../server/MinecraftServer.java.patch | 31 +++++--- .../cpw/mods/fml/client/FMLClientHandler.java | 73 ++++++++++++++++++- .../cpw/mods/fml/common/FMLCommonHandler.java | 11 ++- .../cpw/mods/fml/common/IFMLSidedHandler.java | 4 + .../cpw/mods/fml/server/FMLServerHandler.java | 11 +++ 6 files changed, 142 insertions(+), 20 deletions(-) diff --git a/patches/minecraft/net/minecraft/client/Minecraft.java.patch b/patches/minecraft/net/minecraft/client/Minecraft.java.patch index 276b54667e..00d133e9ba 100644 --- a/patches/minecraft/net/minecraft/client/Minecraft.java.patch +++ b/patches/minecraft/net/minecraft/client/Minecraft.java.patch @@ -19,7 +19,21 @@ @SideOnly(Side.CLIENT) public class Minecraft implements IPlayerUsage { -@@ -448,7 +453,7 @@ +@@ -323,8 +328,11 @@ + + public void func_71404_a(CrashReport p_71404_1_) + { +- this.field_71434_R = true; +- this.field_71433_S = p_71404_1_; ++ if (!FMLClientHandler.instance().handlingCrash(p_71404_1_)) ++ { ++ this.field_71434_R = true; ++ this.field_71433_S = p_71404_1_; ++ } + } + + public void func_71377_b(CrashReport p_71377_1_) +@@ -448,7 +456,7 @@ this.field_110451_am = new SimpleReloadableResourceManager(this.field_110452_an); this.field_135017_as = new LanguageManager(this.field_110452_an, this.field_71474_y.field_74363_ab); this.field_110451_am.func_110542_a(this.field_135017_as); @@ -28,7 +42,7 @@ this.field_71446_o = new TextureManager(this.field_110451_am); this.field_110451_am.func_110542_a(this.field_71446_o); this.field_147127_av = new SoundHandler(this.field_110451_am, this.field_71474_y); -@@ -508,12 +513,13 @@ +@@ -508,12 +516,13 @@ this.field_71446_o.func_130088_a(TextureMap.field_110576_c, new TextureMap(1, "textures/items")); GL11.glViewport(0, 0, this.field_71443_c, this.field_71440_d); this.field_71452_i = new EffectRenderer(this.field_71441_e, this.field_71446_o); @@ -43,7 +57,7 @@ } else { -@@ -527,6 +533,7 @@ +@@ -527,6 +536,7 @@ this.func_71352_k(); } @@ -51,7 +65,7 @@ Display.setVSyncEnabled(this.field_71474_y.field_74352_v); } -@@ -916,9 +923,11 @@ +@@ -916,9 +926,11 @@ if (!this.field_71454_w) { @@ -63,7 +77,7 @@ } GL11.glFlush(); -@@ -1496,6 +1505,8 @@ +@@ -1496,6 +1508,8 @@ --this.field_71467_ac; } @@ -72,7 +86,7 @@ this.field_71424_I.func_76320_a("gui"); if (!this.field_71445_n) -@@ -1646,6 +1657,7 @@ +@@ -1646,6 +1660,7 @@ this.field_71462_r.func_146274_d(); } } @@ -80,7 +94,7 @@ } if (this.field_71429_W > 0) -@@ -1787,6 +1799,7 @@ +@@ -1787,6 +1802,7 @@ } } } @@ -88,7 +102,7 @@ } } -@@ -1978,12 +1991,15 @@ +@@ -1978,12 +1994,15 @@ this.field_71453_ak.func_74428_b(); } @@ -104,7 +118,7 @@ this.func_71403_a((WorldClient)null); System.gc(); ISaveHandler isavehandler = this.field_71469_aa.func_75804_a(p_71371_1_, false); -@@ -2094,6 +2110,7 @@ +@@ -2094,6 +2113,7 @@ this.field_110448_aq.func_148529_f(); this.func_71351_a((ServerData)null); this.field_71455_al = false; diff --git a/patches/minecraft/net/minecraft/server/MinecraftServer.java.patch b/patches/minecraft/net/minecraft/server/MinecraftServer.java.patch index 0f078b31ba..50652e5ec4 100644 --- a/patches/minecraft/net/minecraft/server/MinecraftServer.java.patch +++ b/patches/minecraft/net/minecraft/server/MinecraftServer.java.patch @@ -1,15 +1,17 @@ --- ../src-base/minecraft/net/minecraft/server/MinecraftServer.java +++ ../src-work/minecraft/net/minecraft/server/MinecraftServer.java -@@ -4,6 +4,8 @@ +@@ -4,6 +4,10 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftSessionService; import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; + +import cpw.mods.fml.common.FMLCommonHandler; ++import cpw.mods.fml.common.Loader; ++import cpw.mods.fml.common.LoaderState; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import io.netty.buffer.ByteBuf; -@@ -385,6 +387,7 @@ +@@ -385,6 +389,7 @@ { if (this.func_71197_b()) { @@ -17,7 +19,7 @@ long i = func_130071_aq(); long l = 0L; this.field_147147_p.func_151315_a(new ChatComponentText(this.field_71286_C)); -@@ -429,6 +432,7 @@ +@@ -429,6 +434,7 @@ Thread.sleep(1L); this.field_71296_Q = true; } @@ -25,7 +27,18 @@ } else { -@@ -475,6 +479,8 @@ +@@ -466,7 +472,10 @@ + { + try + { ++ if (Loader.instance().hasReachedState(LoaderState.SERVER_STARTED)) ++ { + this.func_71260_j(); ++ } + this.field_71316_v = true; + } + catch (Throwable throwable) +@@ -475,6 +484,8 @@ } finally { @@ -34,7 +47,7 @@ this.func_71240_o(); } } -@@ -517,6 +523,7 @@ +@@ -517,6 +528,7 @@ { long i = System.nanoTime(); AxisAlignedBB.func_72332_a().func_72298_a(); @@ -42,7 +55,7 @@ ++this.field_71315_w; if (this.field_71295_T) -@@ -570,6 +577,7 @@ +@@ -570,6 +582,7 @@ this.field_71304_b.func_76319_b(); this.field_71304_b.func_76319_b(); @@ -50,7 +63,7 @@ } public void func_71190_q() -@@ -597,6 +605,7 @@ +@@ -597,6 +610,7 @@ } this.field_71304_b.func_76320_a("tick"); @@ -58,7 +71,7 @@ CrashReport crashreport; try -@@ -621,6 +630,7 @@ +@@ -621,6 +635,7 @@ throw new ReportedException(crashreport); } @@ -66,7 +79,7 @@ this.field_71304_b.func_76319_b(); this.field_71304_b.func_76320_a("tracker"); worldserver.func_73039_n().func_72788_a(); -@@ -699,7 +709,7 @@ +@@ -699,7 +714,7 @@ public String getServerModName() { diff --git a/src/main/java/cpw/mods/fml/client/FMLClientHandler.java b/src/main/java/cpw/mods/fml/client/FMLClientHandler.java index 6e8fec0d1e..5831280f3a 100644 --- a/src/main/java/cpw/mods/fml/client/FMLClientHandler.java +++ b/src/main/java/cpw/mods/fml/client/FMLClientHandler.java @@ -21,7 +21,9 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityClientPlayerMP; @@ -69,6 +71,7 @@ import cpw.mods.fml.client.registry.RenderingRegistry; import cpw.mods.fml.common.DummyModContainer; import cpw.mods.fml.common.DuplicateModsFoundException; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.FMLContainer; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.IFMLSidedHandler; import cpw.mods.fml.common.Loader; @@ -78,6 +81,7 @@ import cpw.mods.fml.common.MissingModsException; import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.ModMetadata; import cpw.mods.fml.common.ObfuscationReflectionHelper; +import cpw.mods.fml.common.WorldAccessContainer; import cpw.mods.fml.common.WrongMinecraftVersionException; import cpw.mods.fml.common.event.FMLMissingMappingsEvent; import cpw.mods.fml.common.event.FMLMissingMappingsEvent.Action; @@ -596,16 +600,35 @@ public class FMLClientHandler implements IFMLSidedHandler } } + private CountDownLatch gameReleaseLatch; + private Thread clientWaiter; + private GameRegistryException gre; + public void launchIntegratedServerCallback(String dirName, String saveName) { try { - client.func_71371_a(dirName, saveName, (WorldSettings)null); + try + { + Thread.interrupted(); + gameReleaseLatch = new CountDownLatch(1); + clientWaiter = Thread.currentThread(); + client.func_71371_a(dirName, saveName, (WorldSettings)null); + System.out.printf("POKEE %b\n", Thread.currentThread().isInterrupted()); + gameReleaseLatch.await(); + } + catch (InterruptedException ie) + { + Thread.interrupted(); + throw gre; + } } catch (GameRegistryException gre) { + client.func_71403_a(null); showGuiScreen(new GuiModItemsMissing(gre.getItems(), gre.getMessage())); } + Thread.interrupted(); } public void showInGameModOptions(GuiIngameMenu guiIngameMenu) @@ -801,4 +824,52 @@ public class FMLClientHandler implements IFMLSidedHandler { return defaultMissingAction; } + + @Override + public void serverLoadedSuccessfully() + { + if (gameReleaseLatch!=null) + { + gameReleaseLatch.countDown(); + } + } + + @Override + public void failedServerLoading(RuntimeException ex, WorldAccessContainer wac) + { + if (wac instanceof FMLContainer && ex instanceof GameRegistryException) + { + try + { + gre = (GameRegistryException) ex; + Executors.newSingleThreadExecutor().submit(new Callable() + { + @Override + public Void call() throws Exception + { + System.err.println("POKE"); + clientWaiter.interrupt(); + Thread.sleep(50); + System.err.println("POKE"); + clientWaiter.interrupt(); + Thread.sleep(50); + System.err.println("POKE"); + clientWaiter.interrupt(); + return null; + } + + }); + + } + catch (Throwable t) + { + FMLLog.log(Level.ERROR, t, "stuff"); + } + } + } + + public boolean handlingCrash(CrashReport report) + { + return report.func_71505_b() instanceof GameRegistryException; + } } diff --git a/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java b/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java index 17bc4f7575..7327528761 100644 --- a/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java +++ b/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java @@ -266,6 +266,7 @@ public class FMLCommonHandler public boolean handleServerStarting(MinecraftServer server) { + sidedDelegate.serverLoadedSuccessfully(); return Loader.instance().serverStarting(server); } @@ -380,7 +381,15 @@ public class FMLCommonHandler WorldAccessContainer wac = ((InjectedModContainer)mc).getWrappedWorldAccessContainer(); if (wac != null) { - wac.readData(handler, worldInfo, additionalProperties, tagCompound.func_74775_l(mc.getModId())); + try + { + wac.readData(handler, worldInfo, additionalProperties, tagCompound.func_74775_l(mc.getModId())); + } + catch (RuntimeException ex) + { + sidedDelegate.failedServerLoading(ex, wac); + throw ex; + } } } } diff --git a/src/main/java/cpw/mods/fml/common/IFMLSidedHandler.java b/src/main/java/cpw/mods/fml/common/IFMLSidedHandler.java index ee7c3199ee..a3bbdff912 100644 --- a/src/main/java/cpw/mods/fml/common/IFMLSidedHandler.java +++ b/src/main/java/cpw/mods/fml/common/IFMLSidedHandler.java @@ -57,4 +57,8 @@ public interface IFMLSidedHandler void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set channelSet, String channel, Side side); FMLMissingMappingsEvent.Action getDefaultMissingAction(); + + void serverLoadedSuccessfully(); + + void failedServerLoading(RuntimeException ex, WorldAccessContainer wac); } diff --git a/src/main/java/cpw/mods/fml/server/FMLServerHandler.java b/src/main/java/cpw/mods/fml/server/FMLServerHandler.java index 552921fa74..4ac7f18ea2 100644 --- a/src/main/java/cpw/mods/fml/server/FMLServerHandler.java +++ b/src/main/java/cpw/mods/fml/server/FMLServerHandler.java @@ -23,6 +23,7 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.IFMLSidedHandler; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; +import cpw.mods.fml.common.WorldAccessContainer; import cpw.mods.fml.common.event.FMLMissingMappingsEvent; import cpw.mods.fml.common.eventhandler.EventBus; import cpw.mods.fml.common.network.FMLNetworkEvent; @@ -185,4 +186,14 @@ public class FMLServerHandler implements IFMLSidedHandler { return FMLMissingMappingsEvent.Action.valueOf(System.getProperty("fml.missingBlockAction", "FAIL")); } + @Override + public void serverLoadedSuccessfully() + { + + } + @Override + public void failedServerLoading(RuntimeException ex, WorldAccessContainer wac) + { + + } }