From 130eb4fea1399dcbd4d2ee08ee51668b95729c32 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 12 May 2023 14:49:00 +0100 Subject: [PATCH] Make bat ponies harder to see --- .../minelittlepony/unicopia/entity/Living.java | 8 ++++++++ .../unicopia/entity/player/Pony.java | 14 ++++++++++++++ .../unicopia/mixin/MixinLivingEntity.java | 2 +- .../unicopia/mixin/MixinTargetPredicate.java | 15 +++++---------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Living.java b/src/main/java/com/minelittlepony/unicopia/entity/Living.java index bb69a035..955f9c2c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Living.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Living.java @@ -212,6 +212,14 @@ public abstract class Living implements Equine, Caste updateDragonBreath(); } + public boolean canBeSeenBy(Entity entity) { + return !isInvisible() + && getSpellSlot() + .get(SpellPredicate.IS_DISGUISE, true) + .filter(spell -> spell.getDisguise().getAppearance() == entity) + .isEmpty(); + } + private void updateDragonBreath() { if (!entity.world.isClient && (entity instanceof PlayerEntity || entity.hasCustomName())) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index bcd1b7da..96995e77 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -40,6 +40,7 @@ import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; @@ -449,6 +450,19 @@ public class Pony extends Living implements Copyable, Update sendCapabilities(); } + @Override + public boolean canBeSeenBy(Entity entity) { + if (entity instanceof HostileEntity && getActualSpecies() == Race.BAT) { + float velocityScale = MathHelper.clamp((float)this.entity.getVelocity().horizontalLength(), 0, 5) / 5F; + float lightScale = asWorld().getLightLevel(getPhysics().getHeadPosition()) / 15F; + + if (((velocityScale + lightScale) / 2F) < 0.8F) { + return false; + } + } + return !super.canBeSeenBy(entity); + } + public Optional> getEntityInArms() { return Living.getOrEmpty(entity.getFirstPassenger()).filter(Living::isBeingCarried); } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java index d3781f50..931de7f8 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java @@ -110,7 +110,7 @@ abstract class MixinLivingEntity extends Entity implements LivingEntityDuck, Equ @Inject(method = "canSee(Lnet/minecraft/entity/Entity;)Z", at = @At("HEAD"), cancellable = true) private void onCanSee(Entity other, CallbackInfoReturnable info) { - if (get().isInvisible()) { + if (!get().canBeSeenBy(other)) { info.setReturnValue(false); } } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinTargetPredicate.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinTargetPredicate.java index 34610cb0..8caf0e28 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinTargetPredicate.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinTargetPredicate.java @@ -7,8 +7,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.minelittlepony.unicopia.ability.magic.SpellPredicate; -import com.minelittlepony.unicopia.entity.Equine; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.LivingEntity; @@ -18,13 +16,10 @@ import net.minecraft.entity.ai.TargetPredicate; abstract class MixinTargetPredicate { @Inject(method = "test", at = @At("HEAD"), cancellable = true) public void onTest(@Nullable LivingEntity baseEntity, LivingEntity targetEntity, CallbackInfoReturnable info) { - Equine eq = Equine.of(targetEntity).orElse(null); - if (eq instanceof Pony) { - ((Pony)eq).getSpellSlot().get(SpellPredicate.IS_DISGUISE, true).ifPresent(spell -> { - if (spell.getDisguise().getAppearance() == baseEntity) { - info.setReturnValue(false); - } - }); - } + Pony.of(targetEntity).ifPresent(pony -> { + if (!pony.canBeSeenBy(baseEntity)) { + info.setReturnValue(false); + } + }); } }