Skip to content

Commit a0fc890

Browse files
committed
feat: Support some more versions
1 parent cd11767 commit a0fc890

File tree

20 files changed

+452
-132
lines changed

20 files changed

+452
-132
lines changed

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tasks.withType<JavaCompile> {
2727

2828
tasks.withType<ProcessResources> {
2929
inputs.property("version", project.version)
30-
filesMatching(listOf("fabric.mod.json", "quilt.mod.json", "META-INF/mods.toml")) {
30+
filesMatching(listOf("fabric.mod.json", "quilt.mod.json", "META-INF/mods.toml", "mcmod.info")) {
3131
expand("version" to project.version)
3232
}
3333
}
@@ -42,6 +42,9 @@ tasks.withType<Jar> {
4242
"Implementation-Title" to "Ksyxis",
4343
"Implementation-Version" to project.version,
4444
"Implementation-Vendor" to "VidTu",
45+
"FMLCorePlugin" to "ru.vidtu.ksyxis.KsyxisLegacyForge",
46+
"FMLCorePluginContainsFMLMod" to "true",
47+
"ForceLoadAsMod" to "true",
4548
"MixinConfigs" to "ksyxis.mixins.json"
4649
)
4750
}

loaders/src/main/java/net/fabricmc/api/ModInitializer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package net.fabricmc.api;
1818

1919
/**
20-
* A mod initializer.
20+
* Emulated entrypoint interface of the Fabric mod.
2121
*
22-
* <p>In {@code fabric.mod.json}, the entrypoint is defined with {@code main} key.</p>
22+
* @author VidTu
23+
* @author FabricMC
2324
*/
2425
@FunctionalInterface
2526
public interface ModInitializer {
2627
/**
27-
* Runs the mod initializer.
28+
* Runs the entrypoint.
2829
*/
2930
void onInitialize();
3031
}

loaders/src/main/java/net/minecraftforge/fml/common/Mod.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@
1111
import java.lang.annotation.Target;
1212

1313
/**
14-
* This defines a Mod to FML.
15-
* Any class found with this annotation applied will be loaded as a Mod. The instance that is loaded will
16-
* represent the mod to other Mods in the system. It will be sent various subclasses of {@code ModLifecycleEvent}
17-
* at pre-defined times during the loading of the game.
14+
* Emulated annotation of the Forge mod.
15+
*
16+
* @author VidTu
17+
* @author MinecraftForge
1818
*/
1919
@Retention(RetentionPolicy.RUNTIME)
2020
@Target(ElementType.TYPE)
2121
public @interface Mod {
22+
// Java annotations will simply ignore unneeded things.
23+
2224
/**
23-
* The unique mod identifier for this mod.
24-
* <b>Required to be lowercased in the english locale for compatibility. Will be truncated to 64 characters long.</b>
25-
* <p>
26-
* This will be used to identify your mod for third parties (other mods), it will be used to identify your mod for registries such as block and item registries.
27-
* By default, you will have a resource domain that matches the modid. All these uses require that constraints are imposed on the format of the modid.
25+
* Gets the mod ID for modern (1.13+) Forge.
26+
*
27+
* @return Modern mod ID
2828
*/
2929
String value();
30+
31+
/**
32+
* Gets the mod ID for legacy (1.12) Forge.
33+
*
34+
* @return Legacy mod ID
35+
*/
36+
String modid();
3037
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
package net.minecraftforge.fml.relauncher;
7+
8+
import java.util.Map;
9+
10+
/**
11+
* Emulated interface of the legacy (1.12) Forge coremod.
12+
*
13+
* @author VidTu
14+
* @author MinecraftForge
15+
*/
16+
public interface IFMLLoadingPlugin {
17+
String getAccessTransformerClass();
18+
19+
String[] getASMTransformerClass();
20+
21+
String getModContainerClass();
22+
23+
String getSetupClass();
24+
25+
void injectData(Map<String, Object> data);
26+
}

loaders/src/main/java/net/neoforged/fml/common/Mod.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@
1111
import java.lang.annotation.Target;
1212

1313
/**
14-
* This defines a Mod to FML.
15-
* Any class found with this annotation applied will be loaded as a Mod. The instance that is loaded will
16-
* represent the mod to other Mods in the system. It will be sent various subclasses of {@code ModLifecycleEvent}
17-
* at pre-defined times during the loading of the game.
14+
* Emulated annotation of the NeoForge mod.
15+
*
16+
* @author VidTu
17+
* @author MinecraftForge
18+
* @author NeoForged
1819
*/
1920
@Retention(RetentionPolicy.RUNTIME)
2021
@Target(ElementType.TYPE)
2122
public @interface Mod {
2223
/**
23-
* The unique mod identifier for this mod.
24-
* <b>Required to be lowercased in the english locale for compatibility. Will be truncated to 64 characters long.</b>
25-
* <p>
26-
* This will be used to identify your mod for third parties (other mods), it will be used to identify your mod for registries such as block and item registries.
27-
* By default, you will have a resource domain that matches the modid. All these uses require that constraints are imposed on the format of the modid.
24+
* Gets the mod ID for modern (1.13+) Forge.
25+
*
26+
* @return Modern mod ID
2827
*/
2928
String value();
3029
}

loaders/src/main/java/org/quiltmc/loader/api/ModContainer.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717

1818
package org.quiltmc.loader.api;
1919

20+
/**
21+
* Emulated QuiltMC mod container.
22+
*
23+
* @author VidTu
24+
* @author FabricMC
25+
* @author QuiltMC
26+
*/
2027
public interface ModContainer {
2128
// Ksyxis: Dummy class
2229
}

loaders/src/main/java/org/quiltmc/qsl/base/api/entrypoint/ModInitializer.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,16 @@
1919
import org.quiltmc.loader.api.ModContainer;
2020

2121
/**
22-
* A mod initializer.
23-
* <p>
24-
* In {@code quilt.mod.json}, the entrypoint is defined with {@value #ENTRYPOINT_KEY} key.
22+
* Emulated entrypoint interface of the Quilt mod.
23+
*
24+
* @author VidTu
25+
* @author FabricMC
2526
*/
2627
public interface ModInitializer {
2728
/**
28-
* Represents the key which this entrypoint is defined with, whose value is {@value}.
29-
*/
30-
String ENTRYPOINT_KEY = "init";
31-
32-
/**
33-
* Runs the mod initializer.
29+
* Runs the entrypoint.
3430
*
35-
* @param mod the mod which is initialized
31+
* @param mod Virtual mod container, do not use
3632
*/
3733
void onInitialize(ModContainer mod);
3834
}

src/main/java/ru/vidtu/ksyxis/Ksyxis.java

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
import org.apache.logging.log4j.LogManager;
2828
import org.apache.logging.log4j.Logger;
29+
import org.spongepowered.asm.launch.MixinBootstrap;
30+
import org.spongepowered.asm.mixin.Mixins;
31+
import org.spongepowered.asm.mixin.Mixin;
2932

3033
import java.lang.reflect.Method;
3134

@@ -41,9 +44,14 @@ public final class Ksyxis {
4144
private static final Logger LOG = LogManager.getLogger("Ksyxis");
4245

4346
/**
44-
* Mixin error message.
47+
* Mixin absent error message.
4548
*/
46-
private static final String MIXIN_ERROR = "Ksyxis: No Mixin found. If you're using old (1.15.2 or older) Forge, please install a Mixin loader, for example MixinBootstrap, MixinBooter, UniMixins, or any other if you find. If you're using new (1.16 or newer) Forge, any Fabric, any Quilt, or any NeoForge, then something went wrong and you should report it on GitHub. If you don't want any hassles and just want to load the game without solving anything, delete the Ksyxis mod.";
49+
private static final String MIXIN_ABSENT = "Ksyxis: No Mixin found. If you're using old (1.15.2 or older) Forge, please install a Mixin loader, for example MixinBootstrap, MixinBooter, UniMixins, or any other if you find. If you're using new (1.16 or newer) Forge, any Fabric, any Quilt, or any NeoForge, then something went wrong and you should report it on GitHub. If you don't want any hassles and just want to load the game without solving anything, delete the Ksyxis mod.";
50+
51+
/**
52+
* Mixin inject error message.
53+
*/
54+
private static final String MIXIN_INJECT = "Ksyxis: Unable to inject the Ksyxis configuration. It's probably a bug or something, you should report it on GitHub. If you don't want any hassles and just want to load the game without solving anything, delete the Ksyxis mod.";
4755

4856
/**
4957
* An instance of this class cannot be created.
@@ -55,41 +63,58 @@ private Ksyxis() {
5563
}
5664

5765
/**
58-
* Checks the mixin presence and logs the info on startup.
66+
* Initializer for super ancient loaders.
5967
*/
60-
public static void init() {
61-
// Check for Mixin.
68+
public static void legacyInit() {
69+
// Verify Mixin.
70+
verifyMixins();
71+
6272
try {
63-
Class.forName("org.spongepowered.asm.mixin.Mixin");
73+
// Bootstrap Mixin.
74+
MixinBootstrap.init();
75+
76+
// Add the config.
77+
Mixins.addConfiguration("ksyxis.mixins.json");
6478
} catch (Throwable t) {
6579
// Log.
66-
LOG.error(MIXIN_ERROR, t);
80+
LOG.error(MIXIN_INJECT, t);
6781

6882
// Try to display LWJGL3 message box from TinyFD.
6983
try {
7084
Class<?> tinyFd = Class.forName("org.lwjgl.util.tinyfd.TinyFileDialogs");
7185
Method tinyFdMessageBox = tinyFd.getMethod("tinyfd_messageBox", CharSequence.class, CharSequence.class, CharSequence.class, CharSequence.class, boolean.class);
72-
tinyFdMessageBox.invoke(null, "Minecraft | Ksyxis Mod", MIXIN_ERROR, "ok", "error", false);
86+
tinyFdMessageBox.invoke(null, "Minecraft | Ksyxis Mod", MIXIN_INJECT, "ok", "error", false);
7387
} catch (Throwable th) {
7488
t.addSuppressed(th);
7589
}
7690

7791
// Try to display LWJGL2 alert from Sys.
7892
try {
79-
Class<?> tinyFd = Class.forName("org.lwjgl.Sys");
80-
Method tinyFdMessageBox = tinyFd.getMethod("alert", String.class, String.class);
81-
tinyFdMessageBox.invoke(null, "Minecraft | Ksyxis Mod", MIXIN_ERROR);
93+
Class<?> sys = Class.forName("org.lwjgl.Sys");
94+
Method sysAlert = sys.getMethod("alert", String.class, String.class);
95+
sysAlert.invoke(null, "Minecraft | Ksyxis Mod", MIXIN_INJECT);
8296
} catch (Throwable th) {
8397
t.addSuppressed(th);
8498
}
8599

86100
// Log again. (with suppressed errors)
87-
LOG.error(MIXIN_ERROR, t);
101+
LOG.error(MIXIN_INJECT, t);
88102

89103
// Throw.
90-
throw new RuntimeException(MIXIN_ERROR, t);
104+
throw new RuntimeException(MIXIN_INJECT, t);
91105
}
92106

107+
// Log the info.
108+
LOG.info("Ksyxis feels the passing of time, because it had to manually inject Mixin configuration. Hey, it's okay, it'll still will speedup your world loading and still may break everything...");
109+
}
110+
111+
/**
112+
* Checks the mixin presence and logs the info on startup.
113+
*/
114+
public static void init() {
115+
// Verify Mixin.
116+
verifyMixins();
117+
93118
// Log the info.
94119
LOG.info("Ksyxis will speedup your world loading, but may break everything :P");
95120
}
@@ -100,4 +125,47 @@ public static void init() {
100125
public static void world() {
101126
LOG.info("Hey. This is Ksyxis. We will now load the world and will try to do it quickly. If the game is not responding after this, it's probably us to blame. (Or delete for good)");
102127
}
128+
129+
/**
130+
* Verifies the {@link Mixin} presence.
131+
*
132+
* @throws RuntimeException If {@link Mixin} class can't be found
133+
*/
134+
private static void verifyMixins() {
135+
// Check for Mixin.
136+
try {
137+
// Try to load the class.
138+
Class.forName("org.spongepowered.asm.mixin.Mixin");
139+
140+
// Class found.
141+
LOG.info("Ksyxis found Mixin library.");
142+
} catch (Throwable t) {
143+
// Log.
144+
LOG.error(MIXIN_ABSENT, t);
145+
146+
// Try to display LWJGL3 message box from TinyFD.
147+
try {
148+
Class<?> tinyFd = Class.forName("org.lwjgl.util.tinyfd.TinyFileDialogs");
149+
Method tinyFdMessageBox = tinyFd.getMethod("tinyfd_messageBox", CharSequence.class, CharSequence.class, CharSequence.class, CharSequence.class, boolean.class);
150+
tinyFdMessageBox.invoke(null, "Minecraft | Ksyxis Mod", MIXIN_ABSENT, "ok", "error", false);
151+
} catch (Throwable th) {
152+
t.addSuppressed(th);
153+
}
154+
155+
// Try to display LWJGL2 alert from Sys.
156+
try {
157+
Class<?> sys = Class.forName("org.lwjgl.Sys");
158+
Method sysAlert = sys.getMethod("alert", String.class, String.class);
159+
sysAlert.invoke(null, "Minecraft | Ksyxis Mod", MIXIN_ABSENT);
160+
} catch (Throwable th) {
161+
t.addSuppressed(th);
162+
}
163+
164+
// Log again. (with suppressed errors)
165+
LOG.error(MIXIN_ABSENT, t);
166+
167+
// Throw.
168+
throw new RuntimeException(MIXIN_ABSENT, t);
169+
}
170+
}
103171
}

src/main/java/ru/vidtu/ksyxis/KsyxisFabric.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@
3333
*/
3434
public final class KsyxisFabric implements ModInitializer {
3535
/**
36-
* Calls {@link Ksyxis#init()} to log info. (from Fabric)
36+
* Calls {@link Ksyxis#init()}.
37+
*/
38+
public KsyxisFabric() {
39+
Ksyxis.init();
40+
}
41+
42+
/**
43+
* Does nothing.
3744
*/
3845
@Override
3946
public void onInitialize() {
40-
Ksyxis.init();
47+
// NO-OP
4148
}
4249
}

src/main/java/ru/vidtu/ksyxis/KsyxisForge.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131
*
3232
* @author VidTu
3333
*/
34-
@Mod("ksyxis")
34+
@Mod(value = "ksyxis", modid = "ksyxis")
3535
public final class KsyxisForge {
3636
/**
37-
* Calls {@link Ksyxis#init()} to log info. (from Forge)
37+
* Calls {@link Ksyxis#init()}.
3838
*/
3939
public KsyxisForge() {
4040
Ksyxis.init();

0 commit comments

Comments
 (0)