working version
This commit is contained in:
parent
1f5c01a3ad
commit
99be3d3d4c
3 changed files with 32 additions and 0 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -24,6 +24,10 @@ bin/
|
|||
.classpath
|
||||
.project
|
||||
|
||||
# Visual Studio probably
|
||||
|
||||
*.vs
|
||||
|
||||
# macos
|
||||
|
||||
*.DS_Store
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package net.fabricmc.example.mixin;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.Difficulty;
|
||||
import net.minecraft.world.World;
|
||||
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(LivingEntity.class)
|
||||
public abstract class ModLivingEntity extends Entity {
|
||||
|
||||
public ModLivingEntity(EntityType<?> type, World world) {
|
||||
super(type, world);
|
||||
}
|
||||
|
||||
@Inject(method = "canTarget(Lnet/minecraft/entity/LivingEntity;)Z", at = @At("HEAD"), cancellable = true, expect = 1)
|
||||
public void onCanTarget(LivingEntity target, CallbackInfoReturnable<Boolean> ci) {
|
||||
// Can't target if target is a player and difficulty is peaceful or easy
|
||||
boolean readable = this.world.getDifficulty() == Difficulty.PEACEFUL || this.world.getDifficulty() == Difficulty.EASY;
|
||||
ci.setReturnValue((!(target instanceof PlayerEntity) || !readable) && target.canTakeDamage());
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
"package": "net.fabricmc.example.mixin",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"mixins": [
|
||||
"ModLivingEntity"
|
||||
],
|
||||
"client": [
|
||||
"ExampleMixin"
|
||||
|
|
Reference in a new issue