Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with Xaero's minimap and the layers not being scaled correctly #49

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ src/main/resources/mixins.*.json
*.bat
*.DS_Store
!gradlew.bat
layout.json
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ dependencies {

devOnlyNonPublishable('com.github.GTNewHorizons:TCNodeTracker:1.3.0:dev')

compileOnly(deobfCurse('xaeros-minimap-263420:4905582'))
compileOnly(deobfCurse('xaeros-world-map-317780:4905612'))
compileOnly(deobfCurse('xaeros-minimap-263420:5060684'))
compileOnly(deobfCurse('xaeros-world-map-317780:5060733'))
compileOnly(deobf('https://media.forgecdn.net/files/2462/146/mod_voxelMap_1.7.0b_for_1.7.10.litemod', 'mod_voxelMap_1.7.0b_for_1.7.10.jar'))

// For debugging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
Expand Down Expand Up @@ -139,6 +140,39 @@ public static void drawSimpleLabel(GuiScreen gui, String text, double textX, dou
GL11.glPopMatrix();
}

public static void drawLabel(String text, double textX, double textY, int fontColor, int bgColor, boolean centered,
double fontScale) {
final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;

GL11.glPushMatrix();

if (fontScale != 1.0) {
textX /= fontScale;
textY /= fontScale;
GL11.glScaled(fontScale, fontScale, 0);
}
double dTextX = textX - (double) (int) textX;
double dTextY = textY - (double) (int) textY;
double textWidth = fontRenderer.getStringWidth(text);
double xOffsetL = centered ? -textWidth / 2.0 - 2 : -2;
double xOffsetR = centered ? textWidth / 2.0 + 2 : textWidth + 2;
GL11.glTranslated(dTextX, dTextY, 0.0);
drawGradientRect(
(int) textX + xOffsetL,
(int) textY - 2,
(int) textX + xOffsetR,
(int) textY + fontRenderer.FONT_HEIGHT + 2,
0,
bgColor,
bgColor);
fontRenderer.drawStringWithShadow(
text,
(centered ? (int) (textX - textWidth / 2.0) : (int) textX),
(int) textY,
fontColor);
GL11.glPopMatrix();
}

public static void drawSimpleTooltip(GuiScreen gui, List<String> text, double x, double y, int fontColor,
int bgColor) {
if (text.isEmpty()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.annotation.Nullable;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.init.Blocks;
Expand All @@ -25,7 +26,7 @@ public class OreVeinRenderStep implements InteractableRenderStep {
private final OreVeinLocation oreVeinLocation;
private final ResourceLocation depletedTextureLocation = new ResourceLocation(Tags.MODID, "textures/depleted.png");
private final IIcon blockStoneIcon = Blocks.stone.getIcon(0, 0);
private final double iconSize = 32;
private double iconSize;
private double iconX;
private double iconY;

Expand All @@ -35,6 +36,7 @@ public OreVeinRenderStep(OreVeinLocation veinPosition) {

@Override
public void draw(@Nullable GuiScreen gui, double cameraX, double cameraZ, double scale) {
iconSize = 10 * scale;
final double iconSizeHalf = iconSize / 2;
final double scaleForGui = Math.max(1, scale);
iconX = (oreVeinLocation.getBlockX() - 0.5 - cameraX) * scaleForGui - iconSizeHalf;
Expand Down Expand Up @@ -75,18 +77,17 @@ public void draw(@Nullable GuiScreen gui, double cameraX, double cameraZ, double
}
}

if (gui != null && scale >= Utils.journeyMapScaleToLinear(Config.minZoomLevelForOreLabel)
&& !oreVeinLocation.isDepleted()) {
if (scale >= Utils.journeyMapScaleToLinear(Config.minZoomLevelForOreLabel) && !oreVeinLocation.isDepleted()) {
final int fontColor = oreVeinLocation.drawSearchHighlight() ? 0xFFFFFFFF : 0xFF7F7F7F;
String text = I18n.format(oreVeinLocation.getName());
DrawUtils.drawSimpleLabel(
gui,
DrawUtils.drawLabel(
text,
0,
-iconSizeHalf - gui.mc.fontRenderer.FONT_HEIGHT - 5,
-iconSizeHalf - Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT - 5,
fontColor,
0xB4000000,
true);
true,
1.6);
}

if (oreVeinLocation.isActiveAsWaypoint()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ public class MinimapRendererMixin {
}

if (stencilEnabled) {
double mapZoom = zoom * (double) minimapScale / 2.0;
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_STENCIL_TEST);
GL11.glRotated(Math.toDegrees(angle) - 90, 0.0, 0.0, 1.0);
GL11.glScaled(zoom, zoom, 0);
GL11.glScaled(mapZoom, mapZoom, 0);
GL11.glStencilFunc(GL11.GL_EQUAL, 1, 1);
for (LayerRenderer renderer : XaeroWorldMapState.instance.renderers) {
if (renderer.isLayerActive()) {
for (RenderStep renderStep : renderer.getRenderSteps()) {
renderStep.draw(null, playerX, playerZ, scale);
renderStep.draw(null, playerX, playerZ, mapZoom);
}
}
}
Expand Down