Skip to content

Commit

Permalink
Mixin Extras, plus a few bugfixes:
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
AlexIIL committed Dec 7, 2023
1 parent e834b5a commit 50e64d0
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 33 deletions.
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import net.fabricmc.loom.build.nesting.JarNester
import org.slf4j.LoggerFactory

buildscript {
dependencies {
classpath "org.kohsuke:github-api:${project.github_api}"
Expand Down Expand Up @@ -75,6 +78,14 @@ configurations {
implementation {
extendsFrom include
}

development {
transitive = false
}

api {
extendsFrom development
}
}

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

development "io.github.llamalad7:mixinextras-fabric:$mixin_extras"

// also must update in minecraft AND minecraft test
compileOnly "org.quiltmc.chasm:chasm:${project.quilt_chasm}"
compileOnly "org.quiltmc.chasm:chassembly:${project.quilt_chasm}"
Expand Down Expand Up @@ -136,6 +149,7 @@ processResources {
inputs.property "asm_tree", project.asm
inputs.property "asm_util", project.asm
inputs.property "quilt_config", project.quilt_config
inputs.property "mixin_extras", project.mixin_extras

filesMatching("quilt.mod.json") {
expand "version": project.version
Expand All @@ -154,6 +168,7 @@ processResources {
"asm_tree": project.asm,
"asm_util": project.asm,
"quilt_config": project.quilt_config,
"mixin_extras": project.mixin_extras,
)
}
}
Expand Down Expand Up @@ -232,6 +247,10 @@ task fatJar(type: ShadowJar, dependsOn: getSat4jAbout) {
exclude 'sat4j.version'
exclude 'META-INF/maven/org.ow2.sat4j/*/**'

doLast {
JarNester.nestJars(project.configurations.development.files, archiveFile.get().asFile, LoggerFactory.getLogger("JiJ"))
}

outputs.upToDateWhen { false }
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ group = org.quiltmc
description = The mod loading component of Quilt
url = https://github.com/quiltmc/quilt-loader
# Don't forget to change this in QuiltLoaderImpl as well
quilt_loader = 0.22.1-beta.2
quilt_loader = 0.22.1-alexlocal.13

# Fabric & Quilt Libraries
asm = 9.6
Expand All @@ -27,3 +27,4 @@ junit_bom = 5.9.3
proguard_gradle = 7.3.2
github_api = 1.315
flexver = 1.1.0
mixin_extras = 0.3.0
4 changes: 2 additions & 2 deletions minecraft/minecraft-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ repositories {

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


implementation project(":minecraft")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
package net.fabricmc.minecraft.test.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;

import net.minecraft.block.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Fertilizable;
import net.minecraft.block.GrassBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.random.RandomGenerator;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(GrassBlock.class)
public abstract class MixinGrassBlock implements Fertilizable {
@Override
@Overwrite
public boolean canGrow(World world, RandomGenerator random, BlockPos pos, BlockState state) {
public boolean canFertilize(World world, RandomGenerator random, BlockPos pos, BlockState state) {
return false;
}

@WrapOperation(method = "isFertilizable", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldView;getBlockState(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/BlockState;"))
private BlockState testMixinExtras(WorldView instance, BlockPos pos, Operation<BlockState> original, @Local(argsOnly = true) BlockState state) {
if (state == null) {
return Blocks.AIR.getDefaultState();
}

return original.call(instance, pos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

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

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.util.math.MatrixStack;
Expand All @@ -35,8 +36,8 @@ protected MixinGuiMain(Text textComponent_1) {
}

@Inject(method = "render", at = @At("RETURN"))
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta, CallbackInfo info) {
this.textRenderer.draw(matrixStack, "Quilt Test Mod", 2, this.height - 30, -1);
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta, CallbackInfo info) {
graphics.drawShadowedText(textRenderer, "Quilt Test Mod", 2, this.height - 30, -1);
TestMixinGuiHelper.help();
}
}
29 changes: 22 additions & 7 deletions minecraft/minecraft-test/src/test/java/JunitTest.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.llamalad7.mixinextras.MixinExtrasBootstrap;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.quiltmc.loader.api.QuiltLoader;

import net.fabricmc.loader.api.FabricLoader;

import net.minecraft.Bootstrap;
Expand All @@ -7,17 +17,13 @@
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.quiltmc.loader.api.QuiltLoader;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import net.minecraft.util.math.BlockPos;

public class JunitTest {
@BeforeAll
public static void setup() {
System.out.println("Initializing Minecraft");
MixinExtrasBootstrap.init();
SharedConstants.createGameVersion();
Bootstrap.initialize();
System.out.println("Minecraft initialized");
Expand All @@ -35,10 +41,19 @@ public void testItems() {
public void testMixin() {
// MixinGrassBlock sets canGrow to false
GrassBlock grassBlock = (GrassBlock) Blocks.GRASS_BLOCK;
boolean canGrow = grassBlock.canGrow(null, null, null, null);
boolean canGrow = grassBlock.canFertilize(null, null, null, null);
assertFalse(canGrow);
}

@Test
public void testMixinExtras() {
// MixinGrassBlock sets isFertilizable to true
GrassBlock grassBlock = (GrassBlock) Blocks.GRASS_BLOCK;
System.out.println("Grass Block = " + grassBlock);
boolean isFertilizable = grassBlock.isFertilizable(null, BlockPos.ORIGIN, null);
assertTrue(isFertilizable);
}

@Test
@SuppressWarnings("deprecation")
public void testAccessLoader() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@


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

private final MinecraftGameProvider gameProvider;
Expand All @@ -60,7 +61,16 @@ public EntrypointPatch(MinecraftGameProvider gameProvider) {
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/quiltmc/loader/impl/QuiltLoaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public final class QuiltLoaderImpl {

public static final int ASM_VERSION = Opcodes.ASM9;

public static final String VERSION = "0.22.1-beta.2";
public static final String VERSION = "0.22.1-alexlocal.13";
public static final String MOD_ID = "quilt_loader";
public static final String DEFAULT_MODS_DIR = "mods";
public static final String DEFAULT_CACHE_DIR = ".cache";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,11 @@ public int getEqualPathIndex(Path in) {

public Path get(String key) {
for (Path value : values) {
Path compare = value;
if (value instanceof OverlappingPath) {
value = ((OverlappingPath) value).paths[0];
compare = ((OverlappingPath) value).paths[0];
}
if (isEqual(key, value)) {
if (isEqual(key, compare)) {
return value;
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/org/quiltmc/loader/impl/gui/QuiltForkComms.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,17 @@ public static QuiltForkComms connect(File medium, Consumer<LoaderValue> handler)
if (overridePort == null) {
File portFile = new File(medium.toString() + ".port");
File readyFile = new File(medium.toString() + ".ready");
File classpath = new File(medium.toString() + ".cp");
File classpathFile = new File(medium.toString() + ".cp");
if (portFile.exists()) {
portFile.delete();
}
if (readyFile.exists()) {
readyFile.delete();
}
if (classpath.exists()) {
classpath.delete();
if (classpathFile.exists()) {
classpathFile.delete();
}

// Write classpath to file
Files.write(classpath.toPath(), System.getProperty("java.class.path")
.replace(" ", "\" \"")
.getBytes(StandardCharsets.UTF_8));

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

commands.add("--file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void addToClassPath(Path path, String... allowedPrefixes) {

@Override
public void addToClassPath(Path path, ModContainer mod, URL origin, String... allowedPrefixes) {
Log.debug(LogCategory.KNOT, "Adding " + path + " to classpath.");
Log.debug(LogCategory.KNOT, "Adding " + path.getFileSystem() + " " + path + " to classpath.");

try {
URL url = UrlUtil.asUrl(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.quiltmc.loader.api.plugin.solver.LoadOption;
import org.quiltmc.loader.api.plugin.solver.ModLoadOption;
import org.quiltmc.loader.api.plugin.solver.RuleContext;
import org.quiltmc.loader.impl.QuiltLoaderImpl;
import org.quiltmc.loader.impl.filesystem.QuiltJoinedFileSystem;
import org.quiltmc.loader.impl.game.GameProvider;
import org.quiltmc.loader.impl.game.GameProvider.BuiltinMod;
Expand All @@ -78,6 +79,7 @@
public class StandardQuiltPlugin extends BuiltinQuiltPlugin {

public static final boolean DEBUG_PRINT_STATE = Boolean.getBoolean(SystemProperties.DEBUG_MOD_SOLVING);
public static final boolean DISBALE_BUILTIN_MIXIN_EXTRAS = Boolean.getBoolean(SystemProperties.DISABLE_BUILTIN_MIXIN_EXTRAS);

private QuiltOverrides overrides;
private final Map<String, OptionalModIdDefintion> modDefinitions = new HashMap<>();
Expand Down Expand Up @@ -273,6 +275,16 @@ private ModLoadOption[] scan0(Path root, QuiltLoaderIcon fileIcon, ModLocation l
}

PluginGuiTreeNode jarNode = guiNode.addChild(QuiltLoaderText.of(jar), SortOrder.ALPHABETICAL_ORDER);
if (DISBALE_BUILTIN_MIXIN_EXTRAS) {
if (QuiltLoaderImpl.MOD_ID.equals(meta.id())) {
if (inner.toString().startsWith("/META-INF/jars/mixinextras-")) {
Log.info(LogCategory.GENERAL, "Disabling loader's builtin mixin extras library due to command line flag");
jarNode.addChild(QuiltLoaderText.translate("mixin_extras.disabled"));
jarNode.mainIcon(QuiltLoaderGui.iconDisabled());
continue;
}
}
}
context().addFileToScan(inner, jarNode, false);
}

Expand Down Expand Up @@ -379,6 +391,12 @@ public void onLoadOptionAdded(LoadOption option) {
replace(override.fuzzy, override.overrides.breakOverrides, breaks);
}

if (QuiltLoaderImpl.MOD_ID.equals(metadata.id())) {
if (DISBALE_BUILTIN_MIXIN_EXTRAS) {
depends.removeIf(dep -> dep instanceof ModDependency.Only && ((ModDependency.Only) dep).id().id().equals("mixinextras"));
}
}

for (ModDependency dep : depends) {
if (!dep.shouldIgnore()) {
ctx.addRule(createModDepLink(context().manager(), ctx, mod, dep));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private SystemProperties() {}
public static final String DEBUG_DUMP_FILESYSTEM_CONTENTS = "loader.debug.filesystem.dump_contents";
public static final String ALWAYS_DEFER_FILESYSTEM_OPERATIONS = "loader.workaround.defer_all_filesystem_operations";
public static final String DISABLE_QUILT_CLASS_PATH_CUSTOM_TABLE = "loader.quilt_class_path.disable_custom_table";
public static final String DISABLE_BUILTIN_MIXIN_EXTRAS = "loader.disable_builtin_mixin_extras";

// ##############
// # Validation #
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/changelog/0.22.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@ Features:

- Changed the solver pre-processor to include it's state in the crash report when it encounters a contradiction.
- This makes it easy for a loader developer to reproduce the solver state in order to debug it.
- 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 a solver pre-processor bug where chooseBasedOnOnly didn't check for new constants, resulting in later contradictions.
- Fixed QuiltClassPath.getResources not always returning all paths, when multiple mods ship the same file.
1 change: 1 addition & 0 deletions src/main/resources/lang/quilt_loader.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tab.file_list=Files
tab.mod_list=Mods
msg.load_state=Mod loading state (for debugging - this means it worked!)
msg.load_state.warns=Mod loading state (for debugging - this means it worked!)\n%s warnings.
mixin_extras.disabled=Mixin Extras disabled by -Dloader.disable_builtin_mixin_extras=true
# Buttons
button.view_file=View %s
button.edit_file=Edit %s
Expand Down
13 changes: 8 additions & 5 deletions src/main/resources/quilt.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
},
"intermediate_mappings": "net.fabricmc:intermediary",
"provides": [
{
"id": "fabricloader",
"version": "0.14.24"
}
]
{
"id": "fabricloader",
"version": "0.15.0"
}
],
"depends": [
"mixinextras"
]
}
}
Loading

0 comments on commit 50e64d0

Please sign in to comment.