From 7d73904a8d28488e9c172d4464b39db5fc8721af Mon Sep 17 00:00:00 2001 From: Kevin Murphy Date: Fri, 14 Feb 2025 00:13:03 -0800 Subject: [PATCH 1/2] Fix issues with scaling when mapScale != guiScale. --- .../sisby/antique_atlas/gui/AtlasScreen.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java b/src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java index bfe82e67..1d2a4543 100644 --- a/src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java +++ b/src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java @@ -249,6 +249,10 @@ private int getMapScale() { }; } + private float getEffectiveScale(){ + return (float)(mapScale/MinecraftClient.getInstance().getWindow().getScaleFactor()); + } + public AtlasScreen prepareToOpen() { MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.ITEM_BOOK_PAGE_TURN, 1.0F)); @@ -389,7 +393,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { } private double getPixelsPerBlock() { - return ((double) mapScale / MinecraftClient.getInstance().getWindow().getScaleFactor()) * ((double) tilePixels) / ((double) tileChunks * 16.0); + return (double) getEffectiveScale() * ((double) tilePixels) / ((double) tileChunks * 16.0); } @Override @@ -501,7 +505,7 @@ private double getTargetPositionY() { private void updateScaleBookmark() { int tileSizeBlocks = (tileChunks * 16 * 16) / tilePixels; int defaultTileSizeBlocks = 16; - int rulerSizeBlocks = (tileSizeBlocks * (int) MinecraftClient.getInstance().getWindow().getScaleFactor()) / mapScale; + int rulerSizeBlocks = (int)(tileSizeBlocks * getEffectiveScale()); resetScaleBookmark.setLabel(Text.literal( rulerSizeBlocks == 16 | rulerSizeBlocks >= 32 ? "%dc".formatted(rulerSizeBlocks / 16) : "%db".formatted(rulerSizeBlocks)).formatted( tileSizeBlocks < defaultTileSizeBlocks ? Formatting.DARK_RED : tileSizeBlocks == defaultTileSizeBlocks ? Formatting.BLACK : Formatting.DARK_BLUE @@ -601,7 +605,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float par3) { context.getMatrices().push(); context.getMatrices().translate(getGuiX(), getGuiY(), 0); - float markerScale = (float) (((double) tilePixels * mapScale / (guiScale * 16.0))); + float markerScale = (float) ((double) tilePixels * (getEffectiveScale() * 16.0)); Map friends = SurveyorClient.getFriends(); @@ -660,7 +664,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float par3) { if (playerSummary != null) orderedFriends.put(SurveyorClient.getClientUuid(), playerSummary); orderedFriends.forEach((uuid, friend) -> { if (state.is(HIDING_MARKERS) && (!playerBookmark.isSelected() || friend != playerSummary)) return; - renderPlayer(context, friend, 1, hoveredFriend == friend && markerModal.getParent() == null, friend == playerSummary); + renderPlayer(context, friend, (float)(mapScale/guiScale), hoveredFriend == friend && markerModal.getParent() == null, friend == playerSummary); }); context.getMatrices().pop(); @@ -701,9 +705,10 @@ public void render(DrawContext context, int mouseX, int mouseY, float par3) { } public static void renderTiles(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int mapX, int mapY, int mapWidth, int mapHeight, double mapStartScreenX, double mapStartScreenY, double mapScale, int pixelsPerTile, double guiScale, int light, TileRenderIterator tiles) { + float effectiveScale = (float)(mapScale/guiScale); matrices.push(); matrices.translate(mapStartScreenX, mapStartScreenY, 0); - matrices.scale((float) (mapScale / guiScale), (float) (mapScale / guiScale), 1.0F); + matrices.scale(effectiveScale, effectiveScale, 1.0F); Map> tileTextures = new Reference2ObjectArrayMap<>(); for (SubTileQuartet subTiles : tiles) { @@ -719,7 +724,7 @@ public static void renderTiles(MatrixStack matrices, VertexConsumerProvider vert int drawX = subtile.x * subTilePixels; int drawY = subtile.y * subTilePixels; // a non-scope bounds check allows subtile-level accuracy, and keeps border tiling accurate. - if (drawX * (guiScale / mapScale) > mapX + mapWidth - mapStartScreenX || drawY * (guiScale / mapScale) > mapY + mapHeight - mapStartScreenY || (drawX + subTilePixels) * (guiScale / mapScale) < mapX - mapStartScreenX || (drawY + subTilePixels) * (guiScale / mapScale) < mapY - mapStartScreenY) continue; + if (drawX * effectiveScale > mapX + mapWidth - mapStartScreenX || drawY * effectiveScale > mapY + mapHeight - mapStartScreenY || (drawX + subTilePixels) * effectiveScale < mapX - mapStartScreenX || (drawY + subTilePixels) * effectiveScale < mapY - mapStartScreenY) continue; batcher.add(drawX, drawY, subTilePixels, subTilePixels, subtile.getTextureU() * 8, subtile.getTextureV() * 8, 8, 8, 0xFFFFFFFF); } } From 75cdad4cfbc7e4796208671d877c7afb68c24c95 Mon Sep 17 00:00:00 2001 From: Kevin Murphy Date: Fri, 14 Feb 2025 01:29:43 -0800 Subject: [PATCH 2/2] Oops, markerScale is different. Reverting that change. --- src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java b/src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java index 1d2a4543..593abb12 100644 --- a/src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java +++ b/src/main/java/folk/sisby/antique_atlas/gui/AtlasScreen.java @@ -605,7 +605,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float par3) { context.getMatrices().push(); context.getMatrices().translate(getGuiX(), getGuiY(), 0); - float markerScale = (float) ((double) tilePixels * (getEffectiveScale() * 16.0)); + float markerScale = (float) (((double) tilePixels * mapScale / (guiScale * 16.0))); Map friends = SurveyorClient.getFriends();