Skip to content

Commit

Permalink
Fix dimension bugs in the map view (#1606)
Browse files Browse the repository at this point in the history
* Only draw player if they are in the current dimension

* Update the map view immediately on switching dimensions
  • Loading branch information
NotStirred authored Jul 22, 2023
1 parent a77df36 commit 0f4aec6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions chunky/src/java/se/llbit/chunky/map/WorldMapLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public void setDimension(int value) {
// switching and it would probably be much better to just create a fresh
// world instance to load.
loadWorld(world.getWorldDirectory());
viewUpdated(mapView.getMapView()); // update visible chunks immediately
}
}

Expand Down
22 changes: 12 additions & 10 deletions chunky/src/java/se/llbit/chunky/ui/ChunkMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,18 @@ private void drawPlayers(GraphicsContext gc) {
World world = mapLoader.getWorld();
double blockScale = mapView.scale / 16.;
for (PlayerEntityData player : world.getPlayerPositions()) {
int px = (int) QuickMath.floor(player.x * blockScale);
int py = (int) QuickMath.floor(player.y);
int pz = (int) QuickMath.floor(player.z * blockScale);
int ppx = px - (int) QuickMath.floor(mapView.x0 * mapView.scale);
int ppy = pz - (int) QuickMath.floor(mapView.z0 * mapView.scale);
int pw = (int) QuickMath.max(16, QuickMath.min(32, blockScale * 4));
ppx = Math.min(mapView.width - pw, Math.max(0, ppx - pw / 2));
ppy = Math.min(mapView.height - pw, Math.max(0, ppy - pw / 2));

gc.drawImage(Icon.player.fxImage(), ppx, ppy, pw, pw);
if (player.dimension == world.currentDimension()) {
int px = (int) QuickMath.floor(player.x * blockScale);
int py = (int) QuickMath.floor(player.y);
int pz = (int) QuickMath.floor(player.z * blockScale);
int ppx = px - (int) QuickMath.floor(mapView.x0 * mapView.scale);
int ppy = pz - (int) QuickMath.floor(mapView.z0 * mapView.scale);
int pw = (int) QuickMath.max(16, QuickMath.min(32, blockScale * 4));
ppx = Math.min(mapView.width - pw, Math.max(0, ppx - pw / 2));
ppy = Math.min(mapView.height - pw, Math.max(0, ppy - pw / 2));

gc.drawImage(Icon.player.fxImage(), ppx, ppy, pw, pw);
}
}
}

Expand Down

0 comments on commit 0f4aec6

Please sign in to comment.