Add mixin support and example mixin
This commit is contained in:
1 parent
c69b3653f8
commit
f75568214a
4 files changed
+68
-1
No files matched your search
+33
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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": []
|
||||
}
|
||||
Reference in new issue
Block a user