Skip to content

Commit

Permalink
rework peace effect
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Sep 27, 2023
1 parent 0fc8727 commit 0421562
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
10 changes: 7 additions & 3 deletions common/src/main/java/galena/blissful/index/BlissfulEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -20,9 +22,11 @@ public class BlissfulEffects {
.generic("peace", Registries.MOB_EFFECT, PeaceEffect::new)
.register();

//public static final RegistryEntry<Potion> 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
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/java/galena/blissful/mixins/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void canAttack(LivingEntity target, CallbackInfoReturnable<Boolean> cir)
@SuppressWarnings("DataFlowIssue")
var self = (LivingEntity) (Object) (this);

if(self.hasEffect(BlissfulEffects.PEACE.get())) {
if(BlissfulEffects.arePeaceful(self, target)) {
cir.setReturnValue(false);
}
}
Expand Down

0 comments on commit 0421562

Please sign in to comment.