Skip to content

Commit 47cfdd4

Browse files
committed
Update 1.2.34
1 parent aa2cc7a commit 47cfdd4

File tree

60 files changed

+437
-1542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+437
-1542
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ please keep that in mind when messing with mixins plugins.
5353

5454
## Lua mods
5555

56-
If you are too lazy to learn java you can just use put `.lua` files in your `mods` folder
56+
If you are too lazy to learn java you can just use put `.lua` files in your `mods` folder,
57+
while the lua API is a lot more limited than the java one, it should be enough to allow
58+
you to customize your server to your likings without putting too much effort.
5759

5860
```lua
5961
-- modId: lua_example
@@ -73,4 +75,4 @@ mod.onNetworkPlayerJoined = function(player)
7375
end
7476
```
7577

76-
Note: You can use the [`luajava`](https://github.com/luaj/luaj#user-content-luajava) extension from [LuaJ](https://github.com/luaj/luaj)
78+
Note: You can also use the [`luajava`](https://github.com/luaj/luaj#user-content-luajava) extension from [LuaJ](https://github.com/luaj/luaj)

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ subprojects {
3030
includeGroup "org.spongepowered"
3131
}
3232
}
33+
maven {
34+
name = 'Fabric'
35+
url 'https://maven.fabricmc.net/'
36+
content {
37+
includeGroup "net.fabricmc"
38+
}
39+
}
3340
maven {
3441
url 'https://cdn.fox2code.com/maven'
3542
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package com.fox2code.foxloader.client.mixins;
22

33
import com.fox2code.foxloader.loader.ModLoader;
4+
import com.fox2code.foxloader.loader.lua.LuaObjectHolder;
45
import com.fox2code.foxloader.network.NetworkPlayer;
56
import com.fox2code.foxloader.registry.RegisteredEntity;
67
import net.minecraft.src.game.entity.Entity;
78
import net.minecraft.src.game.entity.player.EntityPlayer;
9+
import org.luaj.vm2.LuaValue;
810
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.Unique;
912
import org.spongepowered.asm.mixin.injection.At;
1013
import org.spongepowered.asm.mixin.injection.Inject;
1114
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1215

16+
import java.lang.ref.WeakReference;
17+
1318
@Mixin(EntityPlayer.class)
14-
public class MixinEntityPlayer {
19+
public class MixinEntityPlayer implements LuaObjectHolder {
1520
@Inject(method = "useCurrentItemOnEntity", at = @At("HEAD"), cancellable = true)
1621
public void onUseCurrentItemOnEntity(Entity var1, CallbackInfo ci) {
1722
if (!(this instanceof NetworkPlayer)) return;
@@ -31,4 +36,18 @@ public void onAttackTargetEntityWithCurrentItem(Entity var1, CallbackInfo ci) {
3136
ci.cancel();
3237
}
3338
}
39+
40+
// Lua object holder
41+
@Unique
42+
private WeakReference<LuaValue> foxLoader$LuaObject;
43+
44+
@Override
45+
public WeakReference<LuaValue> foxLoader$getLuaObject() {
46+
return this.foxLoader$LuaObject;
47+
}
48+
49+
@Override
50+
public void foxLoader$setLuaObject(WeakReference<LuaValue> foxLoader$LuaObject) {
51+
this.foxLoader$LuaObject = foxLoader$LuaObject;
52+
}
3453
}

common/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ group 'com.fox2code'
77
version project['foxloader.version']
88

99
dependencies {
10-
// TODO Don't forget to update DependencyHelper
10+
// TODO: Don't forget to update DependencyHelper
1111
api 'org.ow2.asm:asm-util:9.6'
1212
api 'org.ow2.asm:asm-commons:9.6'
1313
api 'org.semver4j:semver4j:5.2.2'
14-
api 'org.spongepowered:mixin:0.8.5'
14+
// api 'org.spongepowered:mixin:0.8.5'
15+
api 'net.fabricmc:sponge-mixin:0.12.5+mixin.0.8.5'
1516
api 'io.github.llamalad7:mixinextras-common:0.3.2'
1617
api 'com.github.bawnorton.mixinsquared:mixinsquared-common:0.1.1'
18+
api 'it.unimi.dsi:fastutil-core:8.5.12'
1719
api 'org.luaj:luaj-jse:3.0.1'
1820

1921
// Mixin dependencies
@@ -22,13 +24,16 @@ dependencies {
2224
api 'org.apache.commons:commons-lang3:3.3.2'
2325

2426
// Dev annotations
25-
api 'org.jetbrains:annotations:13.0'
27+
api 'org.jetbrains:annotations:24.1.0'
2628

2729
// Unpick transformer helper
2830
compileOnly('org.lwjgl.lwjgl:lwjgl:2.9.3') {
2931
transitive = false
3032
}
3133

34+
// Do not expose JFallback API to mods
35+
implementation("com.fox2code:JFallback:0.0.1")
36+
3237
// Do no expose spark APIs to mods
3338
implementation(project['spark.dependency'] as String)
3439
}

common/generate.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
3030
final String FOXLOADER_TRANSFORMER_VERSION =
3131
project['foxloader.lastReIndevTransformerChanges']
3232
final String FOXLOADER_VERSION = project['foxloader.version']
33+
final String VINEFLOWER_DEPENDENCY = project['vineflower.dependency']
3334
final String SPARK_DEPENDENCY = project['spark.dependency']
3435
final String SPARK_VERSION = project['spark.version']
3536
final String REINDEV_VERSION = project['reindev.version']
@@ -49,6 +50,7 @@ static void generateBuildConfig0(File buildConfigSrc, Project project) {
4950
" public static final String FOXLOADER_TRANSFORMER_VERSION = \"" +
5051
FOXLOADER_TRANSFORMER_VERSION + "\";")
5152
printStream.println(" public static final String FOXLOADER_VERSION = \"" + FOXLOADER_VERSION + "\";")
53+
printStream.println(" public static final String VINEFLOWER_DEPENDENCY = \"" + VINEFLOWER_DEPENDENCY + "\";")
5254
printStream.println(" public static final String SPARK_DEPENDENCY = \"" + SPARK_DEPENDENCY + "\";")
5355
printStream.println(" public static final String SPARK_VERSION = \"" + SPARK_VERSION + "\";")
5456
printStream.println(" public static final String REINDEV_VERSION = \"" + REINDEV_VERSION + "\";")

common/src/main/java/com/fox2code/foxloader/commands/WorldReplace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void onExecute(String[] args, NetworkPlayer commandExecutor) {
7777
final int maxY = networkPlayerController.getMaxY();
7878
final int minZ = networkPlayerController.getMinZ();
7979
final int maxZ = networkPlayerController.getMaxZ();
80-
final long blockChanged = ((maxX - (long) minX) + 1) * ((maxX - minX) + 1) * ((maxX - minX) + 1);
80+
final long blockChanged = ((maxX - (long) minX) + 1) * ((maxY - minY) + 1) * ((maxZ - minZ) + 1);
8181
if (blockChanged > 1000000000) {
8282
commandExecutor.displayChatMessage(gameRegistry.translateKeyFormat(
8383
"command.error.changing-too-many-blocks", Long.toString(blockChanged)));

common/src/main/java/com/fox2code/foxloader/commands/WorldSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void onExecute(String[] args, NetworkPlayer commandExecutor) {
5656
final int maxY = networkPlayerController.getMaxY();
5757
final int minZ = networkPlayerController.getMinZ();
5858
final int maxZ = networkPlayerController.getMaxZ();
59-
final long blockChanged = ((maxX - (long) minX) + 1) * ((maxX - minX) + 1) * ((maxX - minX) + 1);
59+
final long blockChanged = ((maxX - (long) minX) + 1) * ((maxY - minY) + 1) * ((maxZ - minZ) + 1);
6060
if (blockChanged > 1000000000) {
6161
commandExecutor.displayChatMessage(gameRegistry.translateKeyFormat(
6262
"command.error.changing-too-many-blocks", Long.toString(blockChanged)));

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@
1111
import java.net.*;
1212
import java.nio.file.Files;
1313
import java.security.NoSuchAlgorithmException;
14+
import java.util.function.Consumer;
1415
import java.util.jar.JarFile;
1516

1617
public class DependencyHelper {
1718
public static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2";
1819
public static final String SPONGE_POWERED = "https://repo.spongepowered.org/maven";
20+
public static final String FABRIC_MC = "https://maven.fabricmc.net/";
1921
public static final String JITPACK = "https://jitpack.io";
2022
public static final String MODRINTH = "https://api.modrinth.com/maven";
23+
public static final String FOX2CODE = "https://cdn.fox2code.com/maven";
2124

2225
public static final Dependency GSON_DEPENDENCY = // Used by installer.
2326
new Dependency("com.google.code.gson:gson:2.10.1", MAVEN_CENTRAL, "com.google.gson.Gson");
2427

2528
// Extra dependencies not included in ReIndev
29+
public static final Dependency jFallback =
30+
new Dependency("com.fox2code:JFallback:0.0.1", FOX2CODE, "com.fox2code.jfallback.JFallbackClassVisitor");
31+
2632
public static final Dependency[] commonDependencies = new Dependency[]{
2733
new Dependency("org.ow2.asm:asm:9.6", MAVEN_CENTRAL, "org.objectweb.asm.ClassVisitor"),
2834
new Dependency("org.ow2.asm:asm-tree:9.6", MAVEN_CENTRAL, "org.objectweb.asm.tree.ClassNode"),
@@ -33,17 +39,22 @@ GSON_DEPENDENCY, new Dependency("com.google.guava:guava:21.0", MAVEN_CENTRAL, "c
3339
new Dependency("org.semver4j:semver4j:5.2.2", MAVEN_CENTRAL, "org.semver4j.Semver"),
3440
new Dependency("org.apache.commons:commons-lang3:3.3.2", MAVEN_CENTRAL, "org.apache.commons.lang3.tuple.Pair"),
3541
new Dependency("org.luaj:luaj-jse:3.0.1", MAVEN_CENTRAL, "org.luaj.vm2.Globals"),
36-
new Dependency("org.spongepowered:mixin:0.8.5", SPONGE_POWERED, "org.spongepowered.asm.mixin.Mixins"),
42+
// new Dependency("org.spongepowered:mixin:0.8.5", SPONGE_POWERED, "org.spongepowered.asm.mixin.Mixins"),
43+
new Dependency("net.fabricmc:sponge-mixin:0.12.5+mixin.0.8.5", FABRIC_MC, "org.spongepowered.asm.mixin.Mixins"),
3744
new Dependency("io.github.llamalad7:mixinextras-common:0.3.2",
3845
MAVEN_CENTRAL, "com.llamalad7.mixinextras.MixinExtrasBootstrap"),
3946
new Dependency("com.github.bawnorton.mixinsquared:mixinsquared-common:0.1.1",
4047
JITPACK, "com.bawnorton.mixinsquared.MixinSquaredBootstrap",
4148
"https://github.com/Bawnorton/MixinSquared/releases/download/0.1.1/mixinsquared-common-0.1.1.jar"),
49+
jFallback, // jFallback have special handling in dev plugin
4250
};
4351

4452
public static final Dependency sparkDependency =
4553
new Dependency(BuildConfig.SPARK_DEPENDENCY, MODRINTH, "me.lucko.spark.common.SparkPlugin");
4654

55+
public static final Dependency vineFlower = new Dependency(
56+
BuildConfig.VINEFLOWER_DEPENDENCY, MAVEN_CENTRAL, "org.jetbrains.java.decompiler.main.Fernflower");
57+
4758
public static final Dependency[] clientDependencies = new Dependency[]{
4859
new Dependency("net.silveros:reindev:" + BuildConfig.REINDEV_VERSION,
4960
BuildConfig.CLIENT_URL, "net.minecraft.src.client.MinecraftImpl",
@@ -253,6 +264,10 @@ static void addToClassPath(final File library) {
253264
}
254265
}
255266

267+
public static File loadDependencyAsFile(Dependency dependency) {
268+
return loadDependencyImpl(dependency, false, true);
269+
}
270+
256271
public static void loadDependencySelf(Dependency dependency) {
257272
if (FoxLauncher.foxClassLoader != null)
258273
throw new IllegalStateException("FoxClassLoader already initialized!");
@@ -261,7 +276,7 @@ public static void loadDependencySelf(Dependency dependency) {
261276
return; // Great news, we already have the library loaded!
262277
}
263278
if (mcLibraries == null) setMCLibraryRoot();
264-
File file = loadDependencyImpl(dependency, false, true);
279+
File file = loadDependencyAsFile(dependency);
265280
if (file == null) {
266281
// If null it means it's already in class path.
267282
return;

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

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@
88
import java.io.InputStream;
99
import java.net.*;
1010
import java.nio.file.Files;
11-
import java.security.CodeSigner;
12-
import java.security.CodeSource;
11+
import java.security.*;
1312
import java.util.*;
1413

1514
public final class FoxClassLoader extends URLClassLoader {
1615
private static final String CLASS_TO_DUMP = System.getProperty("foxloader.dump-class");
1716
private static final String MIXIN_CONFIG = "org.spongepowered.asm.mixin.transformer.MixinConfig";
18-
private static final String MIXIN_PRE_PROCESSOR = "org.spongepowered.asm.mixin.transformer.MixinPreProcessorStandard";
17+
private static final CodeSigner[] NO_CodeSigners = new CodeSigner[0];
1918
private static final URL[] NO_URLs = new URL[0];
19+
static URL earlyMinecraftURL;
20+
21+
static {
22+
ClassLoader.registerAsParallelCapable();
23+
}
24+
25+
private final HashMap<String, CodeSource> codeSourceCache;
2026
private final LinkedList<String> exclusions;
2127
private final LinkedList<ClassTransformer> classTransformers;
2228
private final LinkedList<ClassGenerator> classGenerators;
@@ -28,10 +34,10 @@ public final class FoxClassLoader extends URLClassLoader {
2834
private boolean didPrintedTransformFail = false;
2935
private boolean patchedExclusiveSource = false;
3036
private URL minecraftURL;
31-
static URL earlyMinecraftURL;
3237

3338
FoxClassLoader() {
34-
super(new URL[0], FoxClassLoader.class.getClassLoader());
39+
super(NO_URLs, FoxClassLoader.class.getClassLoader());
40+
this.codeSourceCache = new HashMap<>();
3541
this.exclusions = new LinkedList<>();
3642
this.classTransformers = new LinkedList<>();
3743
this.classGenerators = new LinkedList<>();
@@ -53,22 +59,28 @@ protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundE
5359
}
5460
c = findLoadedClass(name);
5561
if (c == null) {
56-
c = findClassImpl(name, null);
62+
synchronized (getClassLoadingLock(name)) {
63+
c = findClassImpl(name, null);
64+
}
5765
}
5866
} else if ((name.startsWith("com.fox2code.foxloader.") &&
5967
!name.startsWith("com.fox2code.foxloader.launcher.")) ||
6068
// Check mixins to fix them in development environment.
6169
isSpecialClassName(name)) {
6270
c = findLoadedClass(name);
6371
if (c == null) {
64-
c = findClassImpl(name, null);
72+
synchronized (getClassLoadingLock(name)) {
73+
c = findClassImpl(name, null);
74+
}
6575
}
6676
} else {
6777
c = findLoadedClass(name);
6878
if (c == null) {
6979
URL resource = findResource(name.replace('.', '/') + ".class");
7080
if (resource != null) {
71-
c = findClassImpl(name, resource);
81+
synchronized (getClassLoadingLock(name)) {
82+
c = findClassImpl(name, resource);
83+
}
7284
} else try {
7385
c = super.loadClass(name, false);
7486
} catch (SecurityException securityException) {
@@ -140,6 +152,7 @@ private Class<?> findClassImpl(String name, URL resource) throws ClassNotFoundEx
140152
bytes = buffer.toByteArray();
141153
}
142154
String tmpName = name.replace('/','.');
155+
// We need to apply some patches to mixins to make them actually work.
143156
if (wrappedExtensions != null && !isTransformExclude(tmpName)) {
144157
for (ClassTransformer classTransformer : classTransformers) {
145158
if (classTransformer == generator) continue;
@@ -159,18 +172,10 @@ private Class<?> findClassImpl(String name, URL resource) throws ClassNotFoundEx
159172
Files.write(new File(FoxLauncher.gameDir, "compute_fail.class").toPath(), bytes);
160173
throw new ClassTransformException("Can't compute frames for "+name, e);
161174
}
162-
} else switch (name) {
163-
// We need to apply some patches to mixins to make them actually work.
164-
case MIXIN_CONFIG:
165-
if (wrappedExtensions == null)
166-
throw new ClassTransformException("wrappedExtensions not initialized yet");
167-
bytes = wrappedExtensions.patchMixinConfig(bytes);
168-
break;
169-
case MIXIN_PRE_PROCESSOR:
170-
if (wrappedExtensions == null)
171-
throw new ClassTransformException("wrappedExtensions not initialized yet");
172-
bytes = wrappedExtensions.patchMixinPreProcessorStandard(bytes);
173-
break;
175+
} else if (name.equals(MIXIN_CONFIG)) {
176+
if (wrappedExtensions == null)
177+
throw new ClassTransformException("wrappedExtensions not initialized yet");
178+
bytes = wrappedExtensions.patchMixinConfig(bytes);
174179
}
175180

176181
URL url = null;
@@ -186,8 +191,7 @@ private Class<?> findClassImpl(String name, URL resource) throws ClassNotFoundEx
186191
new Throwable("Dumped " + CLASS_TO_DUMP + " with source " + url +
187192
" from " + loaderType + " loader").printStackTrace();
188193
}
189-
clas = defineClass(name,bytes,0,bytes.length, url == null ?
190-
null : new CodeSource(url, new CodeSigner[]{}));
194+
clas = defineClass(name,bytes,0,bytes.length, codeSourceFromURL(url));
191195
return clas;
192196
} catch (ClassFormatError ioe) {
193197
if (bytes != null) try {
@@ -202,6 +206,12 @@ private Class<?> findClassImpl(String name, URL resource) throws ClassNotFoundEx
202206
}
203207
}
204208

209+
private CodeSource codeSourceFromURL(final URL url) {
210+
if (url == null) return null;
211+
return this.codeSourceCache.computeIfAbsent(url.toString(),
212+
k -> new CodeSource(url, NO_CodeSigners));
213+
}
214+
205215
@Override
206216
public URL getResource(String name) {
207217
// Don't allow mods from adding classes in net.minecraft.
@@ -376,10 +386,6 @@ public boolean isAllowLoadingGame() {
376386
return allowLoadingGame;
377387
}
378388

379-
static {
380-
ClassLoader.registerAsParallelCapable();
381-
}
382-
383389
public boolean isTransformExclude(String className) {
384390
for (String excl:exclusions) {
385391
if (className.startsWith(excl)) {
@@ -400,7 +406,10 @@ public static boolean isSpecialClassName(String cls) {
400406
return cls.startsWith("com.llamalad7.mixinextras.") ||
401407
cls.startsWith("com.bawnorton.mixinsquared.") ||
402408
cls.startsWith("org.spongepowered.") ||
403-
cls.startsWith("org.objectweb.asm.");
409+
cls.startsWith("org.objectweb.asm.") ||
410+
// Special case for JFallback
411+
cls.startsWith("com.fox2code.jfallback.") ||
412+
cls.startsWith("jfallback.");
404413
}
405414

406415
public static boolean isGameClassName(String cls) {
@@ -439,7 +448,5 @@ public static abstract class WrappedExtensions {
439448
public abstract byte[] computeFrames(byte[] classData);
440449

441450
public abstract byte[] patchMixinConfig(byte[] classData);
442-
443-
public abstract byte[] patchMixinPreProcessorStandard(byte[] classData);
444451
}
445452
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ static void initForClientFromArgs(String[] args) {
100100
foxClassLoader.addTransformerExclusion("org.spongepowered.tools.");
101101
foxClassLoader.addTransformerExclusion("com.llamalad7.mixinextras.");
102102
foxClassLoader.addTransformerExclusion("com.bawnorton.mixinsquared.");
103+
foxClassLoader.addTransformerExclusion("com.fox2code.jfallback.");
103104
foxClassLoader.addTransformerExclusion("com.fox2code.foxloader.loader.");
104105
installLoggerHelper(true); // Install special logger before libraries loading
105106
DependencyHelper.loadDependencies(true);
@@ -147,6 +148,7 @@ static void initForServerFromArgs(String[] args) {
147148
foxClassLoader.addTransformerExclusion("org.spongepowered.tools.");
148149
foxClassLoader.addTransformerExclusion("com.llamalad7.mixinextras.");
149150
foxClassLoader.addTransformerExclusion("com.bawnorton.mixinsquared.");
151+
foxClassLoader.addTransformerExclusion("com.fox2code.jfallback.");
150152
foxClassLoader.addTransformerExclusion("com.fox2code.foxloader.loader.");
151153
installLoggerHelper(false); // Install special logger before libraries loading
152154
DependencyHelper.loadDependencies(false);

0 commit comments

Comments
 (0)