Skip to content

Commit 93d4f65

Browse files
committed
Mixin Extras, plus a few bugfixes:
- Bumped provided version of Fabric Loader from 0.14.24 to 0.15.0 - Added MixinExtras as a jar-in-jar mod inside of quilt loader. - This is an additional library for creating mixins in more expressive and compatible ways. For example "@WrapOperation" is a more compatible way of doing "@reDIrect", if you don't need to replace the method call in all circumstances. For more information please see the MixinExtras wiki page: https://github.com/LlamaLad7/MixinExtras/wiki - You can use the system property "-Dloader.disable_builtin_mixin_extras=true" to disable loader's builtin version of mixin extras. As such mods that use mixin extras are encouraged to add it as a dependency in their quilt.mod.json to make the crash more obvious when a user has disabled it but a mod requires it. - Re-added a previous fix that was added in 0.18.1-beta.1 and accidently removed in 0.18.1-beta.58: - Changed the entrypoint hook to use the old fabric class when running in versions before 1.17. - This allows NotEnoughCrashes to redirect our entrypoint Bug Fixes: - Fixed QuiltClassPath.getResources not always returning all paths, when multiple mods ship the same file.
1 parent e834b5a commit 93d4f65

File tree

17 files changed

+142
-33
lines changed

17 files changed

+142
-33
lines changed

build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import net.fabricmc.loom.build.nesting.JarNester
2+
import org.slf4j.LoggerFactory
3+
14
buildscript {
25
dependencies {
36
classpath "org.kohsuke:github-api:${project.github_api}"
@@ -75,6 +78,14 @@ configurations {
7578
implementation {
7679
extendsFrom include
7780
}
81+
82+
development {
83+
transitive = false
84+
}
85+
86+
api {
87+
extendsFrom development
88+
}
7889
}
7990

8091
dependencies {
@@ -100,6 +111,8 @@ dependencies {
100111
include "com.electronwill.night-config:toml:${project.night_config}"
101112
api "org.quiltmc:quilt-config:${project.quilt_config}"
102113

114+
development "io.github.llamalad7:mixinextras-fabric:$mixin_extras"
115+
103116
// also must update in minecraft AND minecraft test
104117
compileOnly "org.quiltmc.chasm:chasm:${project.quilt_chasm}"
105118
compileOnly "org.quiltmc.chasm:chassembly:${project.quilt_chasm}"
@@ -136,6 +149,7 @@ processResources {
136149
inputs.property "asm_tree", project.asm
137150
inputs.property "asm_util", project.asm
138151
inputs.property "quilt_config", project.quilt_config
152+
inputs.property "mixin_extras", project.mixin_extras
139153

140154
filesMatching("quilt.mod.json") {
141155
expand "version": project.version
@@ -154,6 +168,7 @@ processResources {
154168
"asm_tree": project.asm,
155169
"asm_util": project.asm,
156170
"quilt_config": project.quilt_config,
171+
"mixin_extras": project.mixin_extras,
157172
)
158173
}
159174
}
@@ -232,6 +247,10 @@ task fatJar(type: ShadowJar, dependsOn: getSat4jAbout) {
232247
exclude 'sat4j.version'
233248
exclude 'META-INF/maven/org.ow2.sat4j/*/**'
234249

250+
doLast {
251+
JarNester.nestJars(project.configurations.development.files, archiveFile.get().asFile, LoggerFactory.getLogger("JiJ"))
252+
}
253+
235254
outputs.upToDateWhen { false }
236255
}
237256

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ group = org.quiltmc
55
description = The mod loading component of Quilt
66
url = https://github.com/quiltmc/quilt-loader
77
# Don't forget to change this in QuiltLoaderImpl as well
8-
quilt_loader = 0.22.1-beta.2
8+
quilt_loader = 0.22.1-beta.3
99

1010
# Fabric & Quilt Libraries
1111
asm = 9.6
@@ -27,3 +27,4 @@ junit_bom = 5.9.3
2727
proguard_gradle = 7.3.2
2828
github_api = 1.315
2929
flexver = 1.1.0
30+
mixin_extras = 0.3.0

minecraft/minecraft-test/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ repositories {
1515

1616
dependencies {
1717
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
18-
minecraft "com.mojang:minecraft:23w12a"
19-
mappings "org.quiltmc:quilt-mappings:23w12a+build.1:intermediary-v2"
18+
minecraft "com.mojang:minecraft:1.20.2"
19+
mappings "org.quiltmc:quilt-mappings:1.20.2+build.1:intermediary-v2"
2020

2121

2222
implementation project(":minecraft")
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
package net.fabricmc.minecraft.test.mixin;
22

3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import com.llamalad7.mixinextras.sugar.Local;
6+
7+
import net.minecraft.block.Blocks;
38
import net.minecraft.block.BlockState;
49
import net.minecraft.block.Fertilizable;
510
import net.minecraft.block.GrassBlock;
611
import net.minecraft.util.math.BlockPos;
712
import net.minecraft.util.random.RandomGenerator;
813
import net.minecraft.world.World;
14+
import net.minecraft.world.WorldView;
915
import org.spongepowered.asm.mixin.Mixin;
1016
import org.spongepowered.asm.mixin.Overwrite;
17+
import org.spongepowered.asm.mixin.injection.At;
1118

1219
@Mixin(GrassBlock.class)
1320
public abstract class MixinGrassBlock implements Fertilizable {
1421
@Override
1522
@Overwrite
16-
public boolean canGrow(World world, RandomGenerator random, BlockPos pos, BlockState state) {
23+
public boolean canFertilize(World world, RandomGenerator random, BlockPos pos, BlockState state) {
1724
return false;
1825
}
26+
27+
@WrapOperation(method = "isFertilizable", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldView;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"))
28+
private BlockState testMixinExtras(WorldView instance, BlockPos pos, Operation<BlockState> original, @Local(argsOnly = true) BlockState state) {
29+
if (state == null) {
30+
return Blocks.AIR.getDefaultState();
31+
}
32+
33+
return original.call(instance, pos);
34+
}
1935
}

minecraft/minecraft-test/src/main/java/net/fabricmc/minecraft/test/mixin/MixinGuiMain.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import net.fabricmc.minecraft.test.server_only.TestMixinGuiHelper;
2525

26+
import net.minecraft.client.gui.GuiGraphics;
2627
import net.minecraft.client.gui.screen.Screen;
2728
import net.minecraft.client.gui.screen.TitleScreen;
2829
import net.minecraft.client.util.math.MatrixStack;
@@ -35,8 +36,8 @@ protected MixinGuiMain(Text textComponent_1) {
3536
}
3637

3738
@Inject(method = "render", at = @At("RETURN"))
38-
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta, CallbackInfo info) {
39-
this.textRenderer.draw(matrixStack, "Quilt Test Mod", 2, this.height - 30, -1);
39+
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo info) {
40+
graphics.drawShadowedText(textRenderer, "Quilt Test Mod", 2, this.height - 30, -1);
4041
TestMixinGuiHelper.help();
4142
}
4243
}

minecraft/minecraft-test/src/test/java/JunitTest.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
import static org.junit.jupiter.api.Assertions.assertFalse;
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
4+
5+
import com.llamalad7.mixinextras.MixinExtrasBootstrap;
6+
7+
import org.junit.jupiter.api.BeforeAll;
8+
import org.junit.jupiter.api.Test;
9+
import org.quiltmc.loader.api.QuiltLoader;
10+
111
import net.fabricmc.loader.api.FabricLoader;
212

313
import net.minecraft.Bootstrap;
@@ -7,17 +17,13 @@
717
import net.minecraft.item.Items;
818
import net.minecraft.registry.Registries;
919
import net.minecraft.util.Identifier;
10-
import org.junit.jupiter.api.BeforeAll;
11-
import org.junit.jupiter.api.Test;
12-
import org.quiltmc.loader.api.QuiltLoader;
13-
14-
import static org.junit.jupiter.api.Assertions.assertEquals;
15-
import static org.junit.jupiter.api.Assertions.assertFalse;
20+
import net.minecraft.util.math.BlockPos;
1621

1722
public class JunitTest {
1823
@BeforeAll
1924
public static void setup() {
2025
System.out.println("Initializing Minecraft");
26+
MixinExtrasBootstrap.init();
2127
SharedConstants.createGameVersion();
2228
Bootstrap.initialize();
2329
System.out.println("Minecraft initialized");
@@ -35,10 +41,19 @@ public void testItems() {
3541
public void testMixin() {
3642
// MixinGrassBlock sets canGrow to false
3743
GrassBlock grassBlock = (GrassBlock) Blocks.GRASS_BLOCK;
38-
boolean canGrow = grassBlock.canGrow(null, null, null, null);
44+
boolean canGrow = grassBlock.canFertilize(null, null, null, null);
3945
assertFalse(canGrow);
4046
}
4147

48+
@Test
49+
public void testMixinExtras() {
50+
// MixinGrassBlock sets isFertilizable to true
51+
GrassBlock grassBlock = (GrassBlock) Blocks.GRASS_BLOCK;
52+
System.out.println("Grass Block = " + grassBlock);
53+
boolean isFertilizable = grassBlock.isFertilizable(null, BlockPos.ORIGIN, null);
54+
assertTrue(isFertilizable);
55+
}
56+
4257
@Test
4358
@SuppressWarnings("deprecation")
4459
public void testAccessLoader() {

minecraft/src/main/java/org/quiltmc/loader/impl/game/minecraft/patch/EntrypointPatch.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252

5353
public class EntrypointPatch extends GamePatch {
54+
/* QUILT */private static final VersionPredicate BEFORE_1_17 = createVersionPredicate("<=1.17");
5455
private static final VersionPredicate VERSION_1_19_4 = createVersionPredicate(">=1.19.4-");
5556

5657
private final MinecraftGameProvider gameProvider;
@@ -60,7 +61,16 @@ public EntrypointPatch(MinecraftGameProvider gameProvider) {
6061
}
6162

6263
private void finishEntrypoint(EnvType type, ListIterator<AbstractInsnNode> it) {
63-
String methodName = String.format("start%s", type == EnvType.CLIENT ? "Client" : "Server");
64+
String sideName = type == EnvType.CLIENT ? "Client" : "Server";
65+
/* START OF QUILT */
66+
// Compatibility for older fabric mods which redirect our start hook
67+
if (BEFORE_1_17.test(getGameVersion())) {
68+
String internalName = "net/fabricmc/loader/entrypoint/minecraft/hooks/Entrypoint" + sideName;
69+
it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, internalName, "start", "(Ljava/io/File;Ljava/lang/Object;)V", false));
70+
return;
71+
}
72+
/* END OF QUILT */
73+
String methodName = String.format("start%s", sideName);
6474
it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Hooks.INTERNAL_NAME, methodName, "(Ljava/io/File;Ljava/lang/Object;)V", false));
6575
}
6676

src/main/java/org/quiltmc/loader/impl/QuiltLoaderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public final class QuiltLoaderImpl {
129129

130130
public static final int ASM_VERSION = Opcodes.ASM9;
131131

132-
public static final String VERSION = "0.22.1-beta.2";
132+
public static final String VERSION = "0.22.1-beta.3";
133133
public static final String MOD_ID = "quilt_loader";
134134
public static final String DEFAULT_MODS_DIR = "mods";
135135
public static final String DEFAULT_CACHE_DIR = ".cache";

src/main/java/org/quiltmc/loader/impl/filesystem/QuiltClassPath.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,11 @@ public int getEqualPathIndex(Path in) {
702702

703703
public Path get(String key) {
704704
for (Path value : values) {
705+
Path compare = value;
705706
if (value instanceof OverlappingPath) {
706-
value = ((OverlappingPath) value).paths[0];
707+
compare = ((OverlappingPath) value).paths[0];
707708
}
708-
if (isEqual(key, value)) {
709+
if (isEqual(key, compare)) {
709710
return value;
710711
}
711712
}

src/main/java/org/quiltmc/loader/impl/gui/QuiltForkComms.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,17 @@ public static QuiltForkComms connect(File medium, Consumer<LoaderValue> handler)
8484
if (overridePort == null) {
8585
File portFile = new File(medium.toString() + ".port");
8686
File readyFile = new File(medium.toString() + ".ready");
87-
File classpath = new File(medium.toString() + ".cp");
87+
File classpathFile = new File(medium.toString() + ".cp");
8888
if (portFile.exists()) {
8989
portFile.delete();
9090
}
9191
if (readyFile.exists()) {
9292
readyFile.delete();
9393
}
94-
if (classpath.exists()) {
95-
classpath.delete();
94+
if (classpathFile.exists()) {
95+
classpathFile.delete();
9696
}
9797

98-
// Write classpath to file
99-
Files.write(classpath.toPath(), System.getProperty("java.class.path")
100-
.replace(" ", "\" \"")
101-
.getBytes(StandardCharsets.UTF_8));
102-
10398
List<String> commands = new ArrayList<>();
10499
commands.add(System.getProperty("java.home") + File.separator + "bin" + File.separator + "java");
105100
// GC chosen to minimise real memory usage, and maximise returning memory to the OS
@@ -109,7 +104,15 @@ public static QuiltForkComms connect(File medium, Consumer<LoaderValue> handler)
109104
commands.add("-XX:MaxHeapFreeRatio=10");
110105
commands.add("-XX:MinHeapFreeRatio=2");
111106
commands.add("-cp");
112-
commands.add("@" + classpath.toString());
107+
String classpath = System.getProperty("java.class.path").replace(" ", "\" \"");
108+
if (System.getProperty("java.version").startsWith("1.")) {
109+
// Java 8 and below doesn't support @-file expansion
110+
// I'm not sure exactly which version added @-file expansion, but it works in java 11
111+
commands.add(classpath);
112+
} else {
113+
Files.write(classpathFile.toPath(), classpath.getBytes(StandardCharsets.UTF_8));
114+
commands.add("@" + classpathFile.toString());
115+
}
113116
commands.add(QuiltForkServerMain.class.getName());
114117

115118
commands.add("--file");

0 commit comments

Comments
 (0)