mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Make bat ponies harder to see
This commit is contained in:
parent
81c7f8c25c
commit
130eb4fea1
4 changed files with 28 additions and 11 deletions
|
@ -212,6 +212,14 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, 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())) {
|
||||
|
||||
|
|
|
@ -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<PlayerEntity> implements Copyable<Pony>, 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<Living<?>> getEntityInArms() {
|
||||
return Living.getOrEmpty(entity.getFirstPassenger()).filter(Living::isBeingCarried);
|
||||
}
|
||||
|
|
|
@ -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<Boolean> info) {
|
||||
if (get().isInvisible()) {
|
||||
if (!get().canBeSeenBy(other)) {
|
||||
info.setReturnValue(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Boolean> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue