From 3b65283c30c9a8463ddcca724ce64bb19584b584 Mon Sep 17 00:00:00 2001 From: W13R <91822031+W13R@users.noreply.github.com> Date: Sat, 1 Oct 2022 13:56:10 +0200 Subject: [PATCH] Prevent all mobs from targeting the player --- src/main/java/net/w13r/soothed/mixin/ModLivingEntity.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/w13r/soothed/mixin/ModLivingEntity.java b/src/main/java/net/w13r/soothed/mixin/ModLivingEntity.java index 26eaeee..07f3a43 100644 --- a/src/main/java/net/w13r/soothed/mixin/ModLivingEntity.java +++ b/src/main/java/net/w13r/soothed/mixin/ModLivingEntity.java @@ -4,7 +4,6 @@ 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; @@ -20,8 +19,8 @@ public abstract class ModLivingEntity extends Entity { @Inject(method = "canTarget(Lnet/minecraft/entity/LivingEntity;)Z", at = @At("HEAD"), cancellable = true, expect = 1) public void onCanTarget(LivingEntity target, CallbackInfoReturnable 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; + // Can't target if target is a player + boolean readable = true; ci.setReturnValue((!(target instanceof PlayerEntity) || !readable) && target.canTakeDamage()); } }