Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include MixinExtras #854

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "3d3389039b962720c8a106f0121cb155",
"sha1": "dddf5b2c5e6066552017d1d13b58ac0b7faecbb4",
"sha256": "e91a44d50ca874a3836c49fd9c6fd211283f1e420c8f38932fe10fa9b63cbb3d",
"sha512": "1d183a2e715d37d5ac5db1fbce5eeb5e227d1d93beaf0ed50dc4ceb3fefcd1315d9bc29ca977a696a506b944dfb903591ba430be4d07446b64b720134fec6b37",
"size": 169340
}
]
},
"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": "3d3389039b962720c8a106f0121cb155",
"sha1": "dddf5b2c5e6066552017d1d13b58ac0b7faecbb4",
"sha256": "e91a44d50ca874a3836c49fd9c6fd211283f1e420c8f38932fe10fa9b63cbb3d",
"sha512": "1d183a2e715d37d5ac5db1fbce5eeb5e227d1d93beaf0ed50dc4ceb3fefcd1315d9bc29ca977a696a506b944dfb903591ba430be4d07446b64b720134fec6b37",
"size": 169340
}
]
},
"mainClass": "net.minecraft.launchwrapper.Launch",
Expand Down