diff --git a/common/src/main/java/galena/blissful/index/BlissfulEffects.java b/common/src/main/java/galena/blissful/index/BlissfulEffects.java index a730cb2..ca5ea0c 100644 --- a/common/src/main/java/galena/blissful/index/BlissfulEffects.java +++ b/common/src/main/java/galena/blissful/index/BlissfulEffects.java @@ -9,6 +9,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; public class BlissfulEffects { @@ -20,9 +22,11 @@ public class BlissfulEffects { .generic("peace", Registries.MOB_EFFECT, PeaceEffect::new) .register(); - //public static final RegistryEntry PEACE_POTION = REGISTRATE - // .generic("peace", Registries.POTION, () -> new Potion(new MobEffectInstance(PEACE.get()))) - // .register(); + public static boolean arePeaceful(Entity target, LivingEntity attacker) { + if (!(target instanceof LivingEntity living)) return false; + var effect = BlissfulEffects.PEACE.get(); + return attacker.hasEffect(effect) || living.hasEffect(effect); + } public static void register() { // loads this class diff --git a/common/src/main/java/galena/blissful/mixins/EntityMixin.java b/common/src/main/java/galena/blissful/mixins/EntityMixin.java index ac8c07c..ce5b6d8 100644 --- a/common/src/main/java/galena/blissful/mixins/EntityMixin.java +++ b/common/src/main/java/galena/blissful/mixins/EntityMixin.java @@ -5,6 +5,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; @@ -15,7 +16,7 @@ public abstract class EntityMixin { public boolean canAttack(Entity instance, DamageSource damageSource) { return (instance instanceof LivingEntity && damageSource.getEntity() instanceof LivingEntity attacker - && attacker.hasEffect(BlissfulEffects.PEACE.get()) + && BlissfulEffects.arePeaceful(instance, attacker) ) || instance.isInvulnerable(); } diff --git a/common/src/main/java/galena/blissful/mixins/LivingEntityMixin.java b/common/src/main/java/galena/blissful/mixins/LivingEntityMixin.java index 8a0e427..7a18dac 100644 --- a/common/src/main/java/galena/blissful/mixins/LivingEntityMixin.java +++ b/common/src/main/java/galena/blissful/mixins/LivingEntityMixin.java @@ -15,7 +15,7 @@ public void canAttack(LivingEntity target, CallbackInfoReturnable cir) @SuppressWarnings("DataFlowIssue") var self = (LivingEntity) (Object) (this); - if(self.hasEffect(BlissfulEffects.PEACE.get())) { + if(BlissfulEffects.arePeaceful(self, target)) { cir.setReturnValue(false); } }