Skip to content

Commit b95c54a

Browse files
committed
feat: Recursive deploader and mod dep loading
1 parent 6777344 commit b95c54a

File tree

8 files changed

+280
-103
lines changed

8 files changed

+280
-103
lines changed

src/main/java/com/falsepattern/lib/dependencies/DependencyLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void addMavenRepo(String url) {
3939
* @since 0.10.0
4040
*/
4141
public static CompletableFuture<Void> loadLibrariesAsync(Library... libraries) {
42-
return DependencyLoaderImpl.loadLibrariesAsync(libraries);
42+
return DependencyLoaderImpl.loadLibrariesAsync(libraries).thenApply(list -> null);
4343
}
4444

4545
/**

src/main/java/com/falsepattern/lib/internal/Share.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3535
public final class Share {
3636
public static final boolean DEV_ENV = PreShare.devEnv();
37+
public static final boolean CLIENT = PreShare.client();
3738

3839
public static boolean EARLY_INIT_DONE = false;
3940
}

src/main/java/com/falsepattern/lib/internal/asm/CoreLoadingPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
import net.minecraft.launchwrapper.IClassTransformer;
3737
import net.minecraft.launchwrapper.Launch;
3838
import net.minecraft.launchwrapper.LaunchClassLoader;
39+
import cpw.mods.fml.relauncher.FMLLaunchHandler;
3940
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
4041
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
4142
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.Name;
4243
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.SortingIndex;
44+
import cpw.mods.fml.relauncher.Side;
4345

4446
import java.util.List;
4547
import java.util.Map;
@@ -57,6 +59,7 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
5759

5860
static {
5961
PreShare.initDevState(Launch.classLoader.findResource("net/minecraft/world/World.class") != null);
62+
PreShare.initClientState(FMLLaunchHandler.side() == Side.CLIENT);
6063
LetsEncryptHelper.replaceSSLContext();
6164
FPLog.LOG.info("Removing skill issues...");
6265
try {

src/main/java/com/falsepattern/lib/internal/asm/PreShare.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,27 @@
2222

2323
package com.falsepattern.lib.internal.asm;
2424

25-
import lombok.Getter;
26-
2725
public class PreShare {
28-
private static volatile boolean devEnv = false;
29-
private static volatile boolean inited = false;
26+
private static volatile int devEnv = -1;
27+
private static volatile int client = -1;
3028
public static synchronized void initDevState(boolean state) {
31-
if (inited) {
29+
if (devEnv >= 0) {
30+
return;
31+
}
32+
devEnv = state ? 1 : 0;
33+
}
34+
public static synchronized void initClientState(boolean state) {
35+
if (client >= 0) {
3236
return;
3337
}
34-
inited = true;
35-
devEnv = state;
38+
client = state ? 1 : 0;
3639
}
3740

3841
public static synchronized boolean devEnv() {
39-
return devEnv;
42+
return devEnv == 1;
43+
}
44+
45+
public static synchronized boolean client() {
46+
return client == 1;
4047
}
4148
}

src/main/java/com/falsepattern/lib/internal/asm/RFBLoadingPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class RFBLoadingPlugin implements RfbPlugin {
4848
exc.invoke(loader, "com.falsepattern.lib.internal.core.LowLevelCallMultiplexer");
4949
} catch (Exception ignored) {}
5050
PreShare.initDevState(((URLClassLoader)loader).findResource("net/minecraft/world/World.class") != null);
51+
PreShare.initClientState(((URLClassLoader)loader).findResource("net/minecraft/client/Minecraft.class") != null ||
52+
((URLClassLoader)loader).findResource("bao.class") != null);
5153
LetsEncryptHelper.replaceSSLContext();
5254
LowLevelCallMultiplexer.rfbDetected();
5355
DependencyLoaderImpl.executeDependencyLoading();

src/main/java/com/falsepattern/lib/internal/impl/dependencies/DepRoot.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ public class DepRoot {
3737
@Expose
3838
private Integer maxJava;
3939
@Expose
40+
private List<String> bundledArtifacts;
41+
@Expose
4042
private List<String> repositories;
4143
@Expose
4244
private Dependencies dependencies;
45+
@Expose
46+
private Dependencies modDependencies;
4347

4448
@Data
4549
@Accessors(fluent = true)

src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java

Lines changed: 229 additions & 94 deletions
Large diffs are not rendered by default.

src/main/resources/DEPENDENCIES.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ DependencyLoader api. This file needs to reside inside the META-INF directory.
99
"identifier": "falsepatternlib_dependencies",
1010
"minJava": 8,
1111
"maxJava": 8,
12+
"bundledArtifacts": [
13+
"com.example:myjar:1.2.3"
14+
],
1215
"repositories": [
1316
"https://example.com/"
1417
],
@@ -30,6 +33,25 @@ DependencyLoader api. This file needs to reside inside the META-INF directory.
3033
"client": [],
3134
"server": []
3235
}
36+
},
37+
"modDependencies": {
38+
"always": {
39+
"common": [
40+
"com.example:mymod:3.0.0"
41+
],
42+
"client": [],
43+
"server": []
44+
},
45+
"obf": {
46+
"common": [],
47+
"client": [],
48+
"server": []
49+
},
50+
"dev": {
51+
"common": [],
52+
"client": [],
53+
"server": []
54+
}
3355
}
3456
}
3557
```
@@ -45,6 +67,7 @@ Explanation:
4567
for any java versions above or equal minJava.
4668
- If both `minJava` and `maxJava` are unset, dependencies from the file will be loaded regardless of java version.
4769
- If you want to load dependencies for multiple different java ranges, use multiple dependency jsons.
70+
- `bundledArtifacts`: A list of maven artifacts which are "shaded" into this jar without relocation. Useful for recursive deploading of mc mods.
4871
- `repositories`: A list of maven repositories to use when downloading dependencies. These are used in addition to the
4972
default maven repositories. This is just a list of strings, each string being a https repository url.
5073
Additionally, every jar with a dependencies json file inside of it is treated as a "jar in jar" maven repository.
@@ -57,6 +80,8 @@ Explanation:
5780
here.
5881
- The `dev` category gets downloaded only in the dev environment. Usually not needed, as gradle will automatically
5982
download dependencies.
83+
- `modDependencies`: Same as `dependencies`, but files from here get downloaded into `.minecraft/mods/1.7.10`. Useful
84+
if you want to download third party mods as well.
6085

6186
Each of these categories also have 3 more subcategories:
6287

0 commit comments

Comments
 (0)