Skip to content

Commit 18ad917

Browse files
committed
Update 1.2.20
1 parent e6f179e commit 18ad917

File tree

18 files changed

+183
-113
lines changed

18 files changed

+183
-113
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ You can [join the official ReIndev Discord here](https://discord.gg/38Vfes6NpR)
88

99
A feature missing to make your mod? [Just open an issue!](https://github.com/Fox2Code/FoxLoader/issues)
1010

11+
## Installation
12+
13+
For client side installation, just run the jar file.
14+
Either by double clicking on it, or running `java -jar FoxLoader.jar`
15+
16+
To run FoxLoader as a server just run `java -jar FoxLoader.jar --server`
17+
1118
## Documentation
1219

1320
For mixins usage check here: https://github.com/2xsaiko/mixin-cheatsheet

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ subprojects {
3434
}
3535

3636
java {
37-
sourceCompatibility = JavaVersion.VERSION_1_8
38-
targetCompatibility = JavaVersion.VERSION_1_8
37+
toolchain {
38+
languageVersion = JavaLanguageVersion.of(8)
39+
}
3940

4041
withSourcesJar()
4142
}

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinEntity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fox2code.foxloader.registry.RegisteredEntity;
44
import com.fox2code.foxloader.registry.RegisteredWorld;
55
import net.minecraft.src.game.entity.Entity;
6-
import net.minecraft.src.game.entity.other.EntityItem;
76
import net.minecraft.src.game.level.World;
87
import org.spongepowered.asm.mixin.Mixin;
98
import org.spongepowered.asm.mixin.Shadow;

common/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ version project['foxloader.version']
44

55
dependencies {
66
// TODO Don't forget to update DependencyHelper
7-
api 'org.ow2.asm:asm-util:9.5'
8-
api 'org.ow2.asm:asm-commons:9.5'
9-
api 'org.semver4j:semver4j:4.3.0'
7+
api 'org.ow2.asm:asm-util:9.6'
8+
api 'org.ow2.asm:asm-commons:9.6'
9+
api 'org.semver4j:semver4j:5.2.2'
1010
api 'org.spongepowered:mixin:0.8.5'
11-
api 'com.github.LlamaLad7.MixinExtras:mixinextras-common:0.2.0-beta.9'
11+
api 'com.github.LlamaLad7.MixinExtras:mixinextras-common:0.2.0'
1212
api 'org.luaj:luaj-jse:3.0.1'
1313

1414
// Mixin dependencies
15-
api 'com.google.code.gson:gson:2.2.4'
15+
api 'com.google.code.gson:gson:2.10.1'
1616
api 'com.google.guava:guava:21.0'
1717
api 'org.apache.commons:commons-lang3:3.3.2'
1818

common/src/main/java/com/fox2code/foxloader/launcher/DependencyHelper.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,24 @@ public class DependencyHelper {
1717
public static final String MODRINTH = "https://api.modrinth.com/maven";
1818

1919
public static final Dependency GSON_DEPENDENCY = // Used by installer.
20-
new Dependency("com.google.code.gson:gson:2.2.4", MAVEN_CENTRAL, "com.google.gson.Gson");
20+
new Dependency("com.google.code.gson:gson:2.10.1", MAVEN_CENTRAL, "com.google.gson.Gson");
2121

2222
// Extra dependencies not included in ReIndev
2323
public static final Dependency[] commonDependencies = new Dependency[]{
24-
new Dependency("org.ow2.asm:asm:9.5", MAVEN_CENTRAL, "org.objectweb.asm.ClassVisitor"),
25-
new Dependency("org.ow2.asm:asm-tree:9.5", MAVEN_CENTRAL, "org.objectweb.asm.tree.ClassNode"),
26-
new Dependency("org.ow2.asm:asm-analysis:9.5", MAVEN_CENTRAL, "org.objectweb.asm.tree.analysis.Analyzer"),
27-
new Dependency("org.ow2.asm:asm-commons:9.5", MAVEN_CENTRAL, "org.objectweb.asm.commons.InstructionAdapter"),
28-
new Dependency("org.ow2.asm:asm-util:9.5", MAVEN_CENTRAL, "org.objectweb.asm.util.CheckClassAdapter"),
24+
new Dependency("org.ow2.asm:asm:9.6", MAVEN_CENTRAL, "org.objectweb.asm.ClassVisitor"),
25+
new Dependency("org.ow2.asm:asm-tree:9.6", MAVEN_CENTRAL, "org.objectweb.asm.tree.ClassNode"),
26+
new Dependency("org.ow2.asm:asm-analysis:9.6", MAVEN_CENTRAL, "org.objectweb.asm.tree.analysis.Analyzer"),
27+
new Dependency("org.ow2.asm:asm-commons:9.6", MAVEN_CENTRAL, "org.objectweb.asm.commons.InstructionAdapter"),
28+
new Dependency("org.ow2.asm:asm-util:9.6", MAVEN_CENTRAL, "org.objectweb.asm.util.CheckClassAdapter"),
2929
GSON_DEPENDENCY, new Dependency("com.google.guava:guava:21.0", MAVEN_CENTRAL, "com.google.common.io.Files"),
30-
new Dependency("org.semver4j:semver4j:4.3.0", MAVEN_CENTRAL, "org.semver4j.Semver"),
30+
new Dependency("org.semver4j:semver4j:5.2.2", MAVEN_CENTRAL, "org.semver4j.Semver"),
3131
new Dependency("org.apache.commons:commons-lang3:3.3.2", MAVEN_CENTRAL, "org.apache.commons.lang3.tuple.Pair"),
3232
new Dependency("org.luaj:luaj-jse:3.0.1", MAVEN_CENTRAL, "org.luaj.vm2.Globals"),
3333
new Dependency("org.spongepowered:mixin:0.8.5", SPONGE_POWERED, "org.spongepowered.asm.mixin.Mixins"),
34-
new Dependency("com.github.LlamaLad7.MixinExtras:mixinextras-common:0.2.0-beta.9",
34+
new Dependency("com.github.LlamaLad7.MixinExtras:mixinextras-common:0.2.0",
3535
JITPACK, "com.llamalad7.mixinextras.MixinExtrasBootstrap",
3636
// Need fallback URL cause JitPack links can ded at any time
37-
"https://github.com/LlamaLad7/MixinExtras/releases/download/0.2.0-beta.9/mixinextras-common-0.2.0-beta.9.jar"),
37+
"https://github.com/LlamaLad7/MixinExtras/releases/download/0.2.0/mixinextras-common-0.2.0.jar"),
3838
};
3939

4040
public static final Dependency sparkDependency =
@@ -285,7 +285,7 @@ private static String fixUpPath(String path) {
285285
}
286286

287287
public static boolean hasClass(String cls) {
288-
return FoxLauncher.getFoxClassLoader().getResource(cls.replace('.', '/') + ".class") != null;
288+
return FoxLauncher.getFoxClassLoader().isClassInClassPath(cls);
289289
}
290290

291291
private static String resolvePostURL(String string) {

common/src/main/java/com/fox2code/foxloader/launcher/FoxClassLoader.java

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public final class FoxClassLoader extends URLClassLoader {
1818
private final LinkedList<String> exclusions;
1919
private final LinkedList<ClassTransformer> classTransformers;
2020
private final HashMap<String, byte[]> injectedClasses;
21-
private URLClassLoader minecraftExclusiveSource;
21+
private URLClassLoader gameExclusiveSource;
2222
private boolean allowLoadingGame;
2323
private WrappedExtensions wrappedExtensions;
2424
private ArrayList<URL> coreMods;
@@ -39,30 +39,25 @@ public final class FoxClassLoader extends URLClassLoader {
3939

4040
@Override
4141
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
42-
if (name.startsWith("net.minecraft.") ||
43-
name.startsWith("paulscode.sound.") ||
44-
name.startsWith("com.jcraft.")) {
42+
Class<?> c;
43+
if (isGameClassName(name)) {
4544
if (!allowLoadingGame) {
4645
throw new ClassNotFoundException("Cannot load \"" + name + "\" during pre init");
4746
}
48-
Class<?> c = findLoadedClass(name);
47+
c = findLoadedClass(name);
4948
if (c == null) {
5049
c = findClassImpl(name, null);
5150
}
52-
return c;
5351
} else if ((name.startsWith("com.fox2code.foxloader.") &&
5452
!name.startsWith("com.fox2code.foxloader.launcher.")) ||
5553
// Check mixins to fix them in development environment.
56-
name.startsWith("com.llamalad7.mixinextras.") ||
57-
name.startsWith("org.spongepowered.") ||
58-
name.startsWith("org.objectweb.asm.")) {
59-
Class<?> c = findLoadedClass(name);
54+
isSpecialClassName(name)) {
55+
c = findLoadedClass(name);
6056
if (c == null) {
6157
c = findClassImpl(name, null);
6258
}
63-
return c;
6459
} else {
65-
Class<?> c = findLoadedClass(name);
60+
c = findLoadedClass(name);
6661
if (c == null) {
6762
URL resource = findResource(name.replace('.', '/') + ".class");
6863
if (resource != null) {
@@ -73,8 +68,11 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
7368
throw new ClassNotFoundException(name, securityException);
7469
}
7570
}
76-
return c;
7771
}
72+
if (resolve) {
73+
resolveClass(c);
74+
}
75+
return c;
7876
}
7977

8078
@Override
@@ -94,12 +92,10 @@ private Class<?> findClassImpl(String name, URL resource) throws ClassNotFoundEx
9492
ClassLoader resourceClassLoader;
9593
if (name.startsWith("com.fox2code.foxloader.")) {
9694
resourceClassLoader = getParent();
97-
} else if ((name.startsWith("net.minecraft.") ||
98-
name.startsWith("paulscode.sound.") ||
99-
name.startsWith("com.jcraft."))) {
95+
} else if (isGameClassName(name)) {
10096
resourceClassLoader = // Do not allow mods to act as jar mods blindly.
101-
minecraftExclusiveSource != null ?
102-
minecraftExclusiveSource : getParent();
97+
gameExclusiveSource != null ?
98+
gameExclusiveSource : getParent();
10399
} else {
104100
resourceClassLoader = this;
105101
}
@@ -191,8 +187,8 @@ public URL getResource(String name) {
191187
if ((name.startsWith("net/minecraft/") &&
192188
name.endsWith(".class")) ||
193189
name.equals("font.txt")) {
194-
if (minecraftExclusiveSource != null) {
195-
return minecraftExclusiveSource.findResource(name);
190+
if (gameExclusiveSource != null) {
191+
return gameExclusiveSource.findResource(name);
196192
} else {
197193
return this.getParent().getResource(name);
198194
}
@@ -202,8 +198,8 @@ public URL getResource(String name) {
202198
}
203199
URL resource = this.findResource(name);
204200
if (resource != null) return resource;
205-
if (minecraftExclusiveSource != null) {
206-
resource = minecraftExclusiveSource.findResource(name);
201+
if (gameExclusiveSource != null) {
202+
resource = gameExclusiveSource.findResource(name);
207203
if (resource != null) return resource;
208204
}
209205
return this.getParent().getResource(name);
@@ -213,6 +209,22 @@ public boolean isClassLoaded(String className) {
213209
return this.findLoadedClass(className) != null;
214210
}
215211

212+
public boolean isClassInClassPath(String className) {
213+
final String path = className.replace('.', '/') + ".class";
214+
215+
if (className.startsWith("com.fox2code.foxloader.")) {
216+
return this.getParent().getResource(path) != null;
217+
} else if (isGameClassName(className)) {
218+
if (gameExclusiveSource != null)
219+
return gameExclusiveSource.getResource(path) != null;
220+
return this.findResource(path) != null;
221+
} else if (isSpecialClassName(className)) {
222+
return this.findResource(path) != null;
223+
} else {
224+
return this.getResource(path) != null;
225+
}
226+
}
227+
216228
public void addClassTransformers(ClassTransformer classTransformer) {
217229
String pkg = classTransformer.getClass().getPackage().getName();
218230
if (!isTransformExclude(pkg)) {
@@ -250,13 +262,13 @@ public void addCoreModURL(URL url) {
250262
public void setMinecraftURL(URL url) {
251263
if (allowLoadingGame)
252264
throw new IllegalStateException("Minecraft jar already loaded!");
253-
minecraftExclusiveSource = new URLClassLoader(makeURLClassPathForSource(url), null);
265+
gameExclusiveSource = new URLClassLoader(makeURLClassPathForSource(url), null);
254266
}
255267

256268
public void setPatchedMinecraftURL(URL url) {
257269
if (allowLoadingGame)
258270
throw new IllegalStateException("Minecraft jar already loaded!");
259-
minecraftExclusiveSource = new URLClassLoader(new URL[]{url}, null);
271+
gameExclusiveSource = new URLClassLoader(new URL[]{url}, null);
260272
}
261273

262274
public URL[] makeURLClassPathForSource(URL source) {
@@ -314,6 +326,20 @@ public void installWrappedExtensions(WrappedExtensions wrappedExtensions) {
314326
this.wrappedExtensions = Objects.requireNonNull(wrappedExtensions);
315327
}
316328

329+
public static boolean isSpecialClassName(String cls) {
330+
// Check mixins to fix them in development environment.
331+
return cls.startsWith("com.llamalad7.mixinextras.") ||
332+
cls.startsWith("org.spongepowered.") ||
333+
cls.startsWith("org.objectweb.asm.");
334+
}
335+
336+
public static boolean isGameClassName(String cls) {
337+
// Allow game pre-transforming
338+
return cls.startsWith("net.minecraft.") ||
339+
cls.startsWith("paulscode.sound.") ||
340+
cls.startsWith("com.jcraft.");
341+
}
342+
317343
private static class ClassTransformException extends Exception {
318344
public ClassTransformException(String message) {
319345
super(message);

common/src/main/java/com/fox2code/foxloader/loader/PreLoader.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ public class PreLoader {
6363
// secondary pre patched jar, so in DEV_MODE ignoreMinecraft
6464
// is false and only mods and none of FoxLoader pre-patches
6565
// are loaded at runtime.
66-
if (ignoreMinecraft && (
67-
className.startsWith("net.minecraft.") ||
68-
className.startsWith("paulscode.sound.") ||
69-
className.startsWith("com.jcraft."))) {
66+
if (ignoreMinecraft && FoxClassLoader.isGameClassName(className)) {
7067
return bytes;
7168
}
7269
ClassReader classReader = new ClassReader(bytes);

common/src/main/java/com/fox2code/foxloader/network/NetworkPlayer.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.fox2code.foxloader.network;
22

33
import com.fox2code.foxloader.loader.ModContainer;
4+
import com.fox2code.foxloader.registry.RegisteredCommandSender;
45
import com.fox2code.foxloader.registry.RegisteredEntityLiving;
56

6-
public interface NetworkPlayer extends RegisteredEntityLiving {
7+
public interface NetworkPlayer extends RegisteredEntityLiving, RegisteredCommandSender {
78
/**
89
* Just empty byte array to reduce allocations.
910
*/
@@ -20,11 +21,6 @@ public interface NetworkPlayer extends RegisteredEntityLiving {
2021
*/
2122
default void sendNetworkData(ModContainer modContainer, byte[] data) { throw new RuntimeException(); }
2223

23-
/**
24-
* Send/Display chat message to the user screen.
25-
*/
26-
default void displayChatMessage(String chatMessage) { throw new RuntimeException(); }
27-
2824
/**
2925
* @return if the remote party has the mod loader,
3026
* always return true for a single player world.
@@ -36,13 +32,6 @@ public interface NetworkPlayer extends RegisteredEntityLiving {
3632
*/
3733
default String getPlayerName() { throw new RuntimeException(); }
3834

39-
/**
40-
* @return if the player as operator permission.
41-
*
42-
* Always false client-side when connected to a server.
43-
*/
44-
default boolean isOperator() { throw new RuntimeException(); }
45-
4635
/**
4736
* Will kick the player.
4837
*

common/src/main/java/com/fox2code/foxloader/registry/CommandCompat.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static void registerClientCommand(CommandCompat commandCompat) {
2525
private final boolean opOnly;
2626
private final boolean isHidden;
2727
private final String[] aliases;
28+
private final boolean supportConsole;
2829

2930
public CommandCompat(String name) {
3031
this(name, true, false, NO_ALIASES);
@@ -35,35 +36,67 @@ public CommandCompat(String name, boolean opOnly) {
3536
}
3637

3738
public CommandCompat(String name, boolean opOnly, boolean isHidden, String[] aliases) {
39+
this(name, opOnly, isHidden, aliases, null);
40+
}
41+
42+
public CommandCompat(String name, boolean opOnly, boolean isHidden, String[] aliases, boolean supportConsole) {
43+
this(name, opOnly, isHidden, aliases, (Boolean) supportConsole);
44+
}
45+
46+
private CommandCompat(String name, boolean opOnly, boolean isHidden, String[] aliases, Boolean supportConsole) {
3847
this.name = name;
3948
this.opOnly = opOnly;
4049
this.isHidden = isHidden;
4150
this.aliases = aliases == null ?
4251
NO_ALIASES : aliases;
52+
if (supportConsole == null) {
53+
try { // Auto-detect support if not explicitly defined.
54+
supportConsole = this.getClass().getMethod("onExecute",
55+
String[].class, RegisteredCommandSender.class)
56+
.getDeclaringClass() != CommandCompat.class;
57+
} catch (Throwable ignored) {}
58+
}
59+
this.supportConsole = supportConsole == Boolean.TRUE;
4360
}
4461

45-
public String getName() {
62+
public final String getName() {
4663
return this.name;
4764
}
4865

49-
public boolean isOpOnly() {
66+
public final boolean isOpOnly() {
5067
return this.opOnly;
5168
}
5269

53-
public boolean isHidden() {
70+
public final boolean isHidden() {
5471
return this.isHidden;
5572
}
5673

57-
public String[] getAliases() {
74+
public final String[] getAliases() {
5875
return this.aliases;
5976
}
6077

61-
public void onExecute(String[] args, NetworkPlayer commandExecutor) {}
78+
public final boolean supportConsole() {
79+
return this.supportConsole;
80+
}
6281

63-
public void printHelpInformation(NetworkPlayer commandExecutor) {
82+
public void onExecute(String[] args, RegisteredCommandSender commandSender) {
83+
if (!this.supportConsole) {
84+
if (commandSender instanceof NetworkPlayer) {
85+
this.onExecute(args, (NetworkPlayer) commandSender);
86+
} else {
87+
commandSender.displayChatMessage("This command can only be executed by a player!");
88+
}
89+
}
90+
}
6491

92+
public void onExecute(String[] args, NetworkPlayer commandExecutor) {
93+
if (this.supportConsole) {
94+
this.onExecute(args, (RegisteredCommandSender) commandExecutor);
95+
}
6596
}
6697

98+
public void printHelpInformation(NetworkPlayer commandExecutor) {}
99+
67100
public String commandSyntax() {
68101
return this.name;
69102
}

0 commit comments

Comments
 (0)