Skip to content

Commit

Permalink
fix serverside crash
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Nov 10, 2024
1 parent b01203e commit 230d0f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
41 changes: 15 additions & 26 deletions src/main/java/com/falsepattern/falsetweaks/FalseTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@
package com.falsepattern.falsetweaks;

import com.falsepattern.falsetweaks.proxy.CommonProxy;
import lombok.val;

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiErrorScreen;
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
Expand All @@ -37,6 +33,7 @@
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.relauncher.FMLLaunchHandler;

@Mod(modid = Tags.MOD_ID,
version = Tags.MOD_VERSION,
Expand All @@ -61,21 +58,21 @@ public void construct(FMLConstructionEvent e) {
proxy.construct(e);
}

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

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
proxy.preInit(e);
if (Loader.isModLoaded("animfix")) {
throw builtinMod("animfix");
builtinMod("animfix");
}
if (Loader.isModLoaded("triangulator")) {
throw builtinMod("triangulator");
builtinMod("triangulator");
}
if (Loader.isModLoaded("DynamicLights")) {
throw new MultiLineLoadingException("Remove the DynamicLights mod and restart the game!\nFalseTweaks has built-in dynamic lights support.");
createSidedException("Remove the DynamicLights mod and restart the game!\nFalseTweaks has built-in dynamic lights support.");
}
}

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

private static class MultiLineLoadingException extends CustomModLoadingErrorDisplayException {
private final String[] lines;
public MultiLineLoadingException(String text) {
lines = text.split("\n");
}

@Override
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {

private static void createSidedException(String text) {
if (FMLLaunchHandler.side().isClient()) {
throw ClientHelper.createException(text);
} else {
throw new Error(text);
}
}

@Override
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) {
int offset = errorScreen.height / 2 - (lines.length * 5);
int x = errorScreen.width / 2;
for (val line: lines) {
errorScreen.drawCenteredString(fontRenderer, line, x, offset, 0xFFFFFF);
offset += 10;
}
private static class ClientHelper {
private static RuntimeException createException(String text) {
return new MultiLineLoadingException(text);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.falsepattern.falsetweaks;

import lombok.val;

import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiErrorScreen;
import cpw.mods.fml.client.CustomModLoadingErrorDisplayException;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
class MultiLineLoadingException extends CustomModLoadingErrorDisplayException {
private final String[] lines;

public MultiLineLoadingException(String text) {
lines = text.split("\n");
}

@Override
public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) {

}

@Override
public void drawScreen(GuiErrorScreen errorScreen, FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) {
int offset = errorScreen.height / 2 - (lines.length * 5);
int x = errorScreen.width / 2;
for (val line : lines) {
errorScreen.drawCenteredString(fontRenderer, line, x, offset, 0xFFFFFF);
offset += 10;
}
}
}

0 comments on commit 230d0f7

Please sign in to comment.