Improve the bat pony stealth checks

This commit is contained in:
Sollace 2023-05-14 19:15:12 +01:00
parent 45c7f8655a
commit e645423a14
2 changed files with 16 additions and 5 deletions

View file

@ -180,7 +180,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
}
}
private double getHorizontalMotion() {
public double getHorizontalMotion() {
return lastVel.horizontalLengthSquared();
}

View file

@ -452,11 +452,22 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
@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 (entity instanceof HostileEntity hostile
&& getActualSpecies() == Race.BAT
&& hostile.getTarget() != this.entity
&& hostile.getAttacker() != this.entity
&& entity.distanceTo(this.entity) > entity.getWidth()) {
if (entity.isSneaking() && entity.distanceTo(this.entity) > 4) {
return false;
}
if (((velocityScale + lightScale) / 2F) < 0.6F) {
float vel = (float)getPhysics().getHorizontalMotion();
float velocityScale = MathHelper.clamp(vel * 15, 0, 1);
int light = asWorld().getLightLevel(getPhysics().getHeadPosition());
float lightScale = light / 15F;
float approachFactor = ((velocityScale + lightScale) / 2F);
if (approachFactor < (entity.isSneaking() ? 0.8F : 0.6F)) {
return false;
}
}