Skip to content

Commit

Permalink
Include MixinExtras (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
LlamaLad7 authored Nov 28, 2023
1 parent b82625c commit 11ce0e4
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
build:
strategy:
matrix:
java: [11-jdk, 16-jdk, 17-jdk, 21-jdk]
java: [17-jdk, 21-jdk]
runs-on: ubuntu-22.04
container:
image: eclipse-temurin:${{ matrix.java }}
Expand Down
13 changes: 13 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:1.135'
Expand Down Expand Up @@ -73,9 +76,13 @@ configurations {
transitive = false
extendsFrom installer
}
development {
transitive = false
}

api {
extendsFrom installer
extendsFrom development
}
}

Expand Down Expand Up @@ -110,6 +117,8 @@ dependencies {
transitive = false
}

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

testCompileOnly 'org.jetbrains:annotations:23.0.0'

// Unit testing for mod metadata
Expand Down Expand Up @@ -199,6 +208,10 @@ task fatJar(type: ShadowJar, dependsOn: getSat4jAbout) {
exclude 'META-INF/*.RSA'
exclude 'META-INF/*.SF'

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

outputs.upToDateWhen { false }
}

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ url = https://github.com/FabricMC/fabric-loader

asm_version = 9.6
mixin_version = 0.12.5+mixin.0.8.5
mixin_extras_version = 0.3.0
4 changes: 2 additions & 2 deletions gradle/installer-json.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import groovy.json.JsonOutput

tasks.register("generateInstallerJson", GenerateInstallerJsonTask) {
configurations = [ common: "installer" ]
configurations = [ common: "installer", development: "development" ]
outputFile = file("src/main/resources/fabric-installer.json")
options = [
mainClasses: [
Expand All @@ -12,7 +12,7 @@ tasks.register("generateInstallerJson", GenerateInstallerJsonTask) {
}

tasks.register("generateLaunchWrapperInstallerJson", GenerateInstallerJsonTask) {
configurations = [ common: "installerLaunchWrapper" ]
configurations = [ common: "installerLaunchWrapper", development: "development" ]
outputFile = file("src/main/resources/fabric-installer.launchwrapper.json")
options = [
mainClass: "net.minecraft.launchwrapper.Launch",
Expand Down
2 changes: 2 additions & 0 deletions minecraft/minecraft-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apply plugin: "fabric-loom"
loom {
runConfigs.configureEach {
ideConfigGenerated = true
property("fabric.debug.replaceVersion", "fabricloader:$version")
}
}

Expand Down Expand Up @@ -35,6 +36,7 @@ dependencies {
exclude module: 'launchwrapper'
exclude module: 'guava'
}
annotationProcessor "io.github.llamalad7:mixinextras-fabric:$mixin_extras_version"

testImplementation project(":junit")
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,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 org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.block.Blocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.GrassBlock;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;

@Mixin(GrassBlock.class)
public class MixinGrassBlock {
@Inject(method = "canGrow", at = @At("HEAD"), cancellable = true)
public void canGrow(World world, Random random, BlockPos pos, BlockState state, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(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 @@ -18,6 +18,7 @@

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 org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -29,6 +30,7 @@
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;

import net.fabricmc.loader.api.FabricLoader;

Expand All @@ -55,6 +57,14 @@ public void testMixin() {
assertFalse(canGrow);
}

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

@Test
public void testAccessLoader() {
FabricLoader.getInstance().getAllMods();
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/fabric-installer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@

],
"development": [

{
"name": "io.github.llamalad7:mixinextras-fabric:0.3.0",
"url": "https://maven.fabricmc.net/",
"md5": "b8627d24b59a04d4b23576ce2fe5b22a",
"sha1": "46c525ed982e80bcced01f7dc1dd99b738f08f79",
"sha256": "bccb03e951ff722a8f03179521a0813bf282e58d02fa77420d62ed630e7e2b0b",
"sha512": "4e08cf603df8ac02d3ed571657dd8bd7d704040698766020eedc4a8806edf8ad6006c206c976fe7fbe97271d0a1d0d729f7cb2e8d14544e8838c274d8b5d9f0b",
"size": 169320
}
]
},
"mainClasses": {
Expand Down
10 changes: 9 additions & 1 deletion src/main/resources/fabric-installer.launchwrapper.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@

],
"development": [

{
"name": "io.github.llamalad7:mixinextras-fabric:0.3.0",
"url": "https://maven.fabricmc.net/",
"md5": "b8627d24b59a04d4b23576ce2fe5b22a",
"sha1": "46c525ed982e80bcced01f7dc1dd99b738f08f79",
"sha256": "bccb03e951ff722a8f03179521a0813bf282e58d02fa77420d62ed630e7e2b0b",
"sha512": "4e08cf603df8ac02d3ed571657dd8bd7d704040698766020eedc4a8806edf8ad6006c206c976fe7fbe97271d0a1d0d729f7cb2e8d14544e8838c274d8b5d9f0b",
"size": 169320
}
]
},
"mainClass": "net.minecraft.launchwrapper.Launch",
Expand Down

0 comments on commit 11ce0e4

Please sign in to comment.