Skip to content

Commit 230d0f7

Browse files
committed
fix serverside crash
1 parent b01203e commit 230d0f7

2 files changed

Lines changed: 48 additions & 26 deletions

File tree

src/main/java/com/falsepattern/falsetweaks/FalseTweaks.java

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
package com.falsepattern.falsetweaks;
2525

2626
import com.falsepattern.falsetweaks.proxy.CommonProxy;
27-
import lombok.val;
2827

29-
import net.minecraft.client.gui.FontRenderer;
30-
import net.minecraft.client.gui.GuiErrorScreen;
31-
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
3228
import cpw.mods.fml.common.Loader;
3329
import cpw.mods.fml.common.Mod;
3430
import cpw.mods.fml.common.SidedProxy;
@@ -37,6 +33,7 @@
3733
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
3834
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
3935
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
36+
import cpw.mods.fml.relauncher.FMLLaunchHandler;
4037

4138
@Mod(modid = Tags.MOD_ID,
4239
version = Tags.MOD_VERSION,
@@ -61,21 +58,21 @@ public void construct(FMLConstructionEvent e) {
6158
proxy.construct(e);
6259
}
6360

64-
private static CustomModLoadingErrorDisplayException builtinMod(String modname) {
65-
return new MultiLineLoadingException("Remove " + modname + " from your mods directory.\nIt has been merged into FalseTweaks!");
61+
private static void builtinMod(String modname) {
62+
createSidedException("Remove " + modname + " from your mods directory.\nIt has been merged into FalseTweaks!");
6663
}
6764

6865
@Mod.EventHandler
6966
public void preInit(FMLPreInitializationEvent e) {
7067
proxy.preInit(e);
7168
if (Loader.isModLoaded("animfix")) {
72-
throw builtinMod("animfix");
69+
builtinMod("animfix");
7370
}
7471
if (Loader.isModLoaded("triangulator")) {
75-
throw builtinMod("triangulator");
72+
builtinMod("triangulator");
7673
}
7774
if (Loader.isModLoaded("DynamicLights")) {
78-
throw new MultiLineLoadingException("Remove the DynamicLights mod and restart the game!\nFalseTweaks has built-in dynamic lights support.");
75+
createSidedException("Remove the DynamicLights mod and restart the game!\nFalseTweaks has built-in dynamic lights support.");
7976
}
8077
}
8178

@@ -94,25 +91,17 @@ public void loadComplete(FMLLoadCompleteEvent e) {
9491
proxy.loadComplete(e);
9592
}
9693

97-
private static class MultiLineLoadingException extends CustomModLoadingErrorDisplayException {
98-
private final String[] lines;
99-
public MultiLineLoadingException(String text) {
100-
lines = text.split("\n");
101-
}
102-
103-
@Override
104-
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
105-
94+
private static void createSidedException(String text) {
95+
if (FMLLaunchHandler.side().isClient()) {
96+
throw ClientHelper.createException(text);
97+
} else {
98+
throw new Error(text);
10699
}
100+
}
107101

108-
@Override
109-
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) {
110-
int offset = errorScreen.height / 2 - (lines.length * 5);
111-
int x = errorScreen.width / 2;
112-
for (val line: lines) {
113-
errorScreen.drawCenteredString(fontRenderer, line, x, offset, 0xFFFFFF);
114-
offset += 10;
115-
}
102+
private static class ClientHelper {
103+
private static RuntimeException createException(String text) {
104+
return new MultiLineLoadingException(text);
116105
}
117106
}
118107
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.falsepattern.falsetweaks;
2+
3+
import lombok.val;
4+
5+
import net.minecraft.client.gui.FontRenderer;
6+
import net.minecraft.client.gui.GuiErrorScreen;
7+
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
8+
import cpw.mods.fml.relauncher.Side;
9+
import cpw.mods.fml.relauncher.SideOnly;
10+
11+
@SideOnly(Side.CLIENT)
12+
class MultiLineLoadingException extends CustomModLoadingErrorDisplayException {
13+
private final String[] lines;
14+
15+
public MultiLineLoadingException(String text) {
16+
lines = text.split("\n");
17+
}
18+
19+
@Override
20+
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {
21+
22+
}
23+
24+
@Override
25+
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) {
26+
int offset = errorScreen.height / 2 - (lines.length * 5);
27+
int x = errorScreen.width / 2;
28+
for (val line : lines) {
29+
errorScreen.drawCenteredString(fontRenderer, line, x, offset, 0xFFFFFF);
30+
offset += 10;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)