Skip to content

Commit

Permalink
Better EntityLiving|EntityPlayer::hasLineOfSight + Fix out of sight bug
Browse files Browse the repository at this point in the history
  • Loading branch information
iamnoksio authored Jul 31, 2024
1 parent 9d67bd9 commit fca7f1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,8 @@ public void receive(Entity entity, int i) {
}

public boolean hasLineOfSight(Entity entity) {
return this.world.a(Vec3D.a(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ), Vec3D.a(entity.locX, entity.locY + (double) entity.getHeadHeight(), entity.locZ)) == null;
final Vec3D vec = new Vec3D(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ);
return this.world.rayTrace(vec, new Vec3D(entity.locX, entity.locY + (double) this.getHeadHeight(), entity.locZ)) == null;
}

public Vec3D ag() {
Expand Down
15 changes: 15 additions & 0 deletions nPaper-Server/src/main/java/net/minecraft/server/EntityPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,21 @@ public void setPlayerWeather(WeatherType type, boolean plugin) {
}
}

// Rinny - fix out of sight bug https://user-images.githubusercontent.com/127549897/224417820-bcf20d93-cb31-447e-9c55-5b0e513fb4b8.mp4
@Override
public boolean hasLineOfSight(Entity entity) {
final Vec3D vec = new Vec3D(this.locX, this.locY + (double) this.getHeadHeight(), this.locZ);
final double entityHeadHeight = entity.getHeadHeight();

for (int i = 1; i <= 3; i++) {
double targetY = entity.locY + (entityHeadHeight / 3) * i;
if (this.world.rayTrace(vec, new Vec3D(entity.locX, targetY, entity.locZ)) == null) {
return true;
}
}
return false;
}

public void resetPlayerWeather() {
this.weather = null;
this.setPlayerWeather(this.world.getWorldData().hasStorm() ? WeatherType.DOWNFALL : WeatherType.CLEAR, false);
Expand Down

0 comments on commit fca7f1e

Please sign in to comment.