Add mixin support and example mixin

This commit is contained in:
BipolarExpedition committed 2026-11-01 20:49:26 -05:00
1 parent c69b3653f8
commit f75568214a
4 files changed
+68 -1

No files matched your search

+21 -1
View File
@@ -1,8 +1,15 @@
buildscript {
repositories {
maven { url = 'https://repo.spongepowered.org/repository/maven-public/' }
}
}
plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.spongepowered.mixin' version '0.7.+'
}
version = mod_version
@@ -15,6 +22,9 @@ base {
// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
minecraft {
// The mappings can be changed at any time and must be in the following format.
@@ -76,6 +86,7 @@ minecraft {
property("mixin.env.remapRefMap", "true")
property("mixin.env.refMapRemappingFile", "${projectDir}/build/createSrgToMcp/output.srg")
args '-mixin.config=contraptionsaresafe.mixins.json'
mods {
"${mod_id}" {
@@ -148,6 +159,8 @@ dependencies {
// The group id is ignored when searching -- in this case, it is "blank"
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
annotationProcessor 'org.spongepowered:mixin:0.8.5:processor'
implementation(fg.deobf("com.simibubi.create:create-${minecraft_version}:${create_version}:slim") { transitive = false })
implementation(fg.deobf("net.createmod.ponder:Ponder-Forge-${minecraft_version}:${ponder_version}"))
compileOnly(fg.deobf("dev.engine-room.flywheel:flywheel-forge-api-${minecraft_version}:${flywheel_version}"))
@@ -190,7 +203,9 @@ tasks.named('jar', Jar).configure {
'Implementation-Title' : project.name,
'Implementation-Version' : project.jar.archiveVersion,
'Implementation-Vendor' : mod_authors,
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"TSRGFx" : "true",
"MixinConfigs" : "contraptionsaresafe.mixins.json"
])
}
@@ -203,6 +218,11 @@ tasks.named('jar', Jar).configure {
// dependsOn 'reobfJar'
// }
mixin {
add sourceSets.main, "contraptionsaresafe.refmap.json"
config "contraptionsaresafe.mixins.json"
}
// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
@@ -0,0 +1,33 @@
package com.bipolarexpedition.java.contraptions_are_safe.mixin;
import com.bipolarexpedition.java.contraptions_are_safe.ContraptionsAreSafe;
import com.simibubi.create.content.contraptions.AbstractContraptionEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
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;
@Mixin(Mob.class)
public class MobTargetingMixin {
@Inject(method = "canAttack(Lnet/minecraft/world/entity/LivingEntity;)Z", at = @At("HEAD"), cancellable = true)
private void preventContraptionTargeting(LivingEntity target, CallbackInfoReturnable<Boolean> cir) {
if (target != null && isOnContraption(target)) {
cir.setReturnValue(false);
}
}
private boolean isOnContraption(Entity entity) {
Entity vehicle = entity.getVehicle();
while (vehicle != null) {
if (vehicle instanceof AbstractContraptionEntity) {
return true;
}
vehicle = vehicle.getVehicle();
}
return false;
}
}
+2
View File
@@ -41,6 +41,8 @@ authors="${mod_authors}" #optional
# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself.
#displayTest="MATCH_VERSION" # if nothing is specified, MATCH_VERSION is the default when clientSideOnly=false, otherwise IGNORE_ALL_VERSION when clientSideOnly=true (#optional)
mixinConfig = "contraptionsaresafe.mixins.json"
# Access Transformers
# Optional, if not specified Forge will attempt to find the default META-INF/accesstransformer.cfg and silently continue if not found. May default to an empty list in a future MC.
# If you specify AT path strings in this list, Forge will attempt to load each of them and throw errors for any that aren't found.
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.bipolarexpedition.java.contraptions_are_safe.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "contraptionsaresafe.refmap.json",
"mixins": [
"MobTargetingMixin"
],
"client": [],
"server": []
}