diff options
7 files changed, 204 insertions, 27 deletions
diff --git a/build.gradle.kts b/build.gradle.kts index 1e0f4873..409a8d51 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -17,7 +17,11 @@ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. */ + +import net.fabricmc.loom.task.RemapJarTask import java.io.ByteArrayOutputStream +import java.nio.file.FileSystems +import java.nio.file.Files import java.nio.charset.StandardCharsets import java.util.* @@ -98,15 +102,20 @@ repositories { maven("https://jitpack.io") } +val shadowImplementation by configurations.creating { + configurations.implementation.get().extendsFrom(this) +} + dependencies { minecraft("com.mojang:minecraft:1.8.9") mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") - implementation("org.spongepowered:mixin:0.7.11-SNAPSHOT") + shadowImplementation("org.spongepowered:mixin:0.7.11-SNAPSHOT") { + isTransitive = false // Dependencies of mixin are already bundled by minecraft + } annotationProcessor("org.spongepowered:mixin:0.8.4-SNAPSHOT") - implementation("com.fasterxml.jackson.core:jackson-core:2.13.1") - implementation("info.bliki.wiki:bliki-core:3.1.0") + shadowImplementation("info.bliki.wiki:bliki-core:3.1.0") testImplementation("org.junit.jupiter:junit-jupiter:5.8.2") testAnnotationProcessor("org.spongepowered:mixin:0.8.4-SNAPSHOT") // modImplementation("io.github.notenoughupdates:MoulConfig:0.0.1") @@ -138,6 +147,7 @@ tasks.withType(Jar::class) { this["MixinConfigs"] = "mixins.notenoughupdates.json" this["FMLCorePluginContainsFMLMod"] = "true" this["ForceLoadAsMod"] = "true" + this["Manifest-Version"] = "1.0" } } @@ -145,41 +155,26 @@ val remapJar by tasks.named<net.fabricmc.loom.task.RemapJarTask>("remapJar") { archiveClassifier.set("dep") from(tasks.shadowJar) input.set(tasks.shadowJar.get().archiveFile) + doLast { + println("Jar name: ${archiveFile.get().asFile}") + } } tasks.shadowJar { archiveClassifier.set("dep-dev") - exclude( - "module-info.class", "LICENSE.txt" - ) + configurations = listOf(shadowImplementation) + exclude("**/module-info.class", "LICENSE.txt") dependencies { - include(dependency("org.spongepowered:mixin")) - - include(dependency("commons-io:commons-io")) - include(dependency("org.apache.commons:commons-lang3")) - include(dependency("com.fasterxml.jackson.core:jackson-databind:2.10.2")) - include(dependency("com.fasterxml.jackson.core:jackson-annotations:2.10.2")) - include(dependency("com.fasterxml.jackson.core:jackson-core:2.10.2")) - - include(dependency("info.bliki.wiki:bliki-core:3.1.0")) - include(dependency("org.slf4j:slf4j-api:1.7.18")) - include(dependency("org.luaj:luaj-jse:3.0.1")) + exclude { + it.moduleGroup.startsWith("org.apache.") || it.moduleName in + listOf("logback-classic", "commons-logging", "commons-codec", "logback-core") + } } fun relocate(name: String) = relocate(name, "io.github.moulberry.notenoughupdates.deps.$name") - relocate("com.fasterxml.jackson") - relocate("org.eclipse") - relocate("org.slf4j") } tasks.assemble.get().dependsOn(remapJar) -tasks.remapJar{ - - doLast{ - println("Jar name :" + archiveFileName.get()) - } -} - val generateBuildFlags by tasks.creating { outputs.upToDateWhen { false } val t = layout.buildDirectory.file("buildflags.properties") diff --git a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java new file mode 100644 index 00000000..8e0f24b9 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/EnvironmentScan.java @@ -0,0 +1,85 @@ +package io.github.moulberry.notenoughupdates.envcheck; + +import javax.swing.*; +import java.lang.reflect.Field; +import java.util.Objects; + +public class EnvironmentScan { + + static Class<?> tryGetClass(String name) { + try { + return Class.forName(name); + } catch (ClassNotFoundException e) { + return null; + } + } + + static Object tryGetField(Class<?> clazz, Object inst, String name) { + if (clazz == null) return null; + try { + Field declaredField = clazz.getDeclaredField(name); + return declaredField.get(inst); + } catch (NoSuchFieldException | IllegalAccessException ignored) { + } + return null; + } + + + static boolean isAtLeast(Object left, int right) { + if (left instanceof Integer) { + return (Integer) left >= right; + } + return false; + } + + static boolean shouldCheckOnce = true; + + static void checkEnvironmentOnce() { + if (shouldCheckOnce) checkEnvironment(); + } + + + static void checkEnvironment() { + shouldCheckOnce = false; + checkForgeEnvironment(); + } + + static void checkForgeEnvironment() { + Class<?> forgeVersion = tryGetClass("net.minecraftforge.common.ForgeVersion"); + if (forgeVersion == null + || !Objects.equals(tryGetField(forgeVersion, null, "majorVersion"), 11) + || !Objects.equals(tryGetField(forgeVersion, null, "minorVersion"), 15) + || !isAtLeast(tryGetField(forgeVersion, null, "revisionVersion"), 1) + || !Objects.equals(tryGetField(forgeVersion, null, "mcVersion"), "1.8.9") + ) { + + System.out.printf("Forge Version : %s%nMajor : %s%nMinor : %s%nRevision : %s%nMinecraft : %s%n", + forgeVersion, + tryGetField(forgeVersion, null, "majorVersion"), + tryGetField(forgeVersion, null, "minorVersion"), + tryGetField(forgeVersion, null, "revisionVersion"), + tryGetField(forgeVersion, null, "mcVersion") + ); + missingOrOutdatedForgeError(); + } + } + + static void missingOrOutdatedForgeError() { + showErrorMessage( + "You just launched NotEnoughUpdates with the wrong (or no) modloader installed.", + "", + "NotEnoughUpdates only works in Minecraft 1.8.9, with Forge 11.15.1+", + "Please relaunch NotEnoughUpdates in the correct environment.", + "If you are using Minecraft 1.8.9 with Forge 11.15.1+ installed, please contact support.", + "Click OK to launch anyways." + ); + } + + + public static void showErrorMessage(String... messages) { + String message = String.join("\n", messages); + JOptionPane.showMessageDialog( + null, message, "NotEnoughUpdates - Problematic System Configuration", JOptionPane.ERROR_MESSAGE + ); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/FabricEntrypoint.java b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/FabricEntrypoint.java new file mode 100644 index 00000000..4a70fca3 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/FabricEntrypoint.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.envcheck; + +public class FabricEntrypoint { + static { + EnvironmentScan.checkForgeEnvironment(); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java new file mode 100644 index 00000000..44e24ff4 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/envcheck/NEUMixinConfigPlugin.java @@ -0,0 +1,46 @@ +package io.github.moulberry.notenoughupdates.envcheck; + +import org.spongepowered.asm.lib.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; + +public class NEUMixinConfigPlugin implements IMixinConfigPlugin { + + static { + EnvironmentScan.checkEnvironmentOnce(); + } + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + return true; + } + + @Override + public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { + } + + @Override + public List<String> getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 index 00000000..281faf65 --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,14 @@ +# This mods.toml is loaded by forge 1.13-1.19 and is only here to make forge display an error message +modLoader = "javafml" +loaderVersion = "[12,)" +license = "LGPL" + +[[mods]] +modId="notenoughupdateserrordisplay" +version="99.99" +displayName="NotEnoughUpdates (1.8.9)" +description=''' +This mod description is only here to warn you about using the wrong version of Minecraft and Forge. +''' + + diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..8dd63bf3 --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,10 @@ +{ + "id": "notenoughupdates", + "version": "9999.0", + "schemaVersion": 1, + "entrypoints": { + "main": [ + "io.github.moulberry.notenoughupdates.envcheck.FabricEntrypoint" + ] + } +} diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json index 8b1d4559..ed1ba55a 100644 --- a/src/main/resources/mixins.notenoughupdates.json +++ b/src/main/resources/mixins.notenoughupdates.json @@ -2,6 +2,7 @@ "package": "io.github.moulberry.notenoughupdates.mixins", "refmap": "mixins.notenoughupdates.refmap.json", "minVersion": "0.7", + "plugin": "io.github.moulberry.notenoughupdates.envcheck.NEUMixinConfigPlugin", "compatibilityLevel": "JAVA_8", "mixins": [ "AccessorEntityAgeable", |