diff --git a/src/main/java/mekanism/client/ApiJarPresentException.java b/src/main/java/mekanism/client/ApiJarPresentException.java new file mode 100644 index 000000000..7c6f51026 --- /dev/null +++ b/src/main/java/mekanism/client/ApiJarPresentException.java @@ -0,0 +1,43 @@ +package mekanism.client; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiErrorScreen; +import net.minecraftforge.fml.client.CustomModLoadingErrorDisplayException; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Copied from EnderCore + */ +public class ApiJarPresentException extends CustomModLoadingErrorDisplayException +{ + private static final long serialVersionUID = 1L; + + private final @Nonnull String[] msgs; + + public ApiJarPresentException(@Nonnull String[] msgs) { + super(msgs[0], new RuntimeException()); + this.msgs = msgs; + } + + @Override + public void initGui(GuiErrorScreen errorScreen, FontRenderer fontRenderer) { + } + + @Override + public void drawScreen(@Nullable GuiErrorScreen errorScreen, @Nullable FontRenderer fontRenderer, int mouseRelX, int mouseRelY, float tickTime) { + if (errorScreen == null || fontRenderer == null) { + return; + } + int y = errorScreen.height / 2 - msgs.length * 5; + for (String msg : msgs) { + if (msg != null) { + errorScreen.drawCenteredString(fontRenderer, msg, errorScreen.width / 2, y, 0xFFFFFF); + y += 10; + } else { + y += 5; + } + } + } +} diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index 9f5e1a532..b41dceee1 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -1150,4 +1150,10 @@ public class ClientProxy extends CommonProxy { return Minecraft.getMinecraft().fontRenderer; } + + @Override + public void throwApiPresentException() + { + throw new ApiJarPresentException(API_PRESENT_MESSAGE); + } } diff --git a/src/main/java/mekanism/common/CommonProxy.java b/src/main/java/mekanism/common/CommonProxy.java index 73a9a3144..ff2ceceea 100644 --- a/src/main/java/mekanism/common/CommonProxy.java +++ b/src/main/java/mekanism/common/CommonProxy.java @@ -708,4 +708,10 @@ public class CommonProxy implements IGuiProvider { return null; } + + protected final String[] API_PRESENT_MESSAGE = {"Mekanism API jar detected (Mekanism--api.jar),", "please delete it from your mods folder and restart the game."}; + + public void throwApiPresentException(){ + throw new RuntimeException(String.join(" ", API_PRESENT_MESSAGE)); + } } diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index 2f13938f2..1287c0e4e 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.UUID; @@ -106,6 +107,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.IRecipe; +import net.minecraft.launchwrapper.Launch; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; @@ -701,6 +703,14 @@ public class Mekanism @EventHandler public void preInit(FMLPreInitializationEvent event) { + //sanity check the api location if not deobf + if (!((Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"))){ + String apiLocation = MekanismAPI.class.getProtectionDomain().getCodeSource().getLocation().toString(); + if (apiLocation.toLowerCase(Locale.ROOT).contains("-api.jar")){ + proxy.throwApiPresentException(); + } + } + File config = event.getSuggestedConfigurationFile(); //Set the mod's configuration