Skip to content

Commit

Permalink
Fix Xaero's map issues: (#25)
Browse files Browse the repository at this point in the history
- Now works with (and requires) a newer version of Xaero's maps
- Refactor out a very volatile local capture so I don't have to constantly update it
- Fix waypoints not appearing when ore veins/TC nodes are activated
- Remove some warning suppressions that were apparently unneeded
  • Loading branch information
kumquat-ir authored Jan 4, 2023
1 parent 07de40d commit 29f5d04
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 43 deletions.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
compileOnly('com.github.GTNewHorizons:GalacticGregGT5:1.0.8:dev') {transitive = false}
compileOnly('com.github.GTNewHorizons:bartworks:0.5.82:dev') {transitive = false}

compileOnly(deobf('https://media.forgecdn.net/files/3630/490/Xaeros_Minimap_21.10.20_Forge_1.7.10.jar'))
compileOnly(deobf('https://media.forgecdn.net/files/3599/504/XaerosWorldMap_1.14.1.13_Forge_1.7.10.jar'))
compileOnly(deobf('https://media.forgecdn.net/files/4127/308/Xaeros_Minimap_21.10.30_Forge_1.7.10.jar'))
compileOnly(deobf('https://media.forgecdn.net/files/4127/328/XaerosWorldMap_1.14.1.22_Forge_1.7.10.jar'))
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'))
}
4 changes: 4 additions & 0 deletions src/main/java/com/sinthoras/visualprospecting/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static boolean isXaerosWorldMapInstalled() {
return Loader.isModLoaded("XaeroWorldMap");
}

public static boolean isXaerosMinimapInstalled() {
return Loader.isModLoaded("XaeroMinimap");
}

public static boolean isVoxelMapInstalled() {
try {
// If a LiteLoader mod is present cannot be checked by calling Loader#isModLoaded.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.sinthoras.visualprospecting.integration.model;

import static com.sinthoras.visualprospecting.Utils.isTCNodeTrackerInstalled;
import static com.sinthoras.visualprospecting.Utils.*;

import com.sinthoras.visualprospecting.Config;
import com.sinthoras.visualprospecting.integration.model.buttons.*;
import com.sinthoras.visualprospecting.integration.model.layers.*;
import com.sinthoras.visualprospecting.integration.tcnodetracker.NTNodeTrackerWaypointManager;
import com.sinthoras.visualprospecting.integration.xaerominimap.XaeroMiniMapState;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -33,5 +34,10 @@ public MapState() {
buttons.add(DirtyChunkButtonManager.instance);
layers.add(DirtyChunkLayerManager.instance);
}

if (isXaerosMinimapInstalled()) {
// need to classload XaeroMiniMapState in order for its waypoint manager to get registered
XaeroMiniMapState.instance.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import net.minecraft.client.gui.GuiScreen;

public abstract class InteractableLayerRenderer extends LayerRenderer {
private double mouseXForRender;
private double mouseYForRender;
private double mouseX;
private double mouseY;
protected WaypointProviderManager manager;
protected InteractableRenderStep hovered;

Expand All @@ -23,12 +23,12 @@ public InteractableLayerRenderer(WaypointProviderManager manager) {
protected abstract List<? extends InteractableRenderStep> generateRenderSteps(
List<? extends ILocationProvider> visibleElements);

public void updateHovered(double mouseX, double mouseY, double cameraX, double cameraZ, double scale) {
mouseXForRender = mouseX - cameraX;
mouseYForRender = mouseY - cameraZ;
public void updateHovered(double mouseX, double mouseY, double scale) {
this.mouseX = mouseX;
this.mouseY = mouseY;
for (RenderStep step : renderStepsReversed) {
if (step instanceof InteractableRenderStep
&& ((InteractableRenderStep) step).isMouseOver(mouseXForRender, mouseYForRender, scale)) {
&& ((InteractableRenderStep) step).isMouseOver(mouseX, mouseY, scale)) {
hovered = (InteractableRenderStep) step;
return;
}
Expand All @@ -38,7 +38,7 @@ public void updateHovered(double mouseX, double mouseY, double cameraX, double c

public void drawTooltip(GuiScreen gui, double scale, int scaleAdj) {
if (hovered != null) {
hovered.drawTooltip(gui, mouseXForRender, mouseYForRender, scale, scaleAdj);
hovered.drawTooltip(gui, mouseX, mouseY, scale, scaleAdj);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@SuppressWarnings("UnusedMixin")
@Mixin(value = ForgeHooksClient.class, remap = false)
public class ForgeHooksClientMixin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import xaero.common.minimap.render.MinimapRenderer;
import xaero.common.settings.ModSettings;

@SuppressWarnings("UnusedMixin")
@Mixin(value = MinimapRenderer.class, remap = false)
public class MinimapRendererMixin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.Entity;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -29,7 +29,6 @@
import xaero.map.gui.ScreenBase;
import xaero.map.misc.Misc;

@SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference", "UnusedMixin"})
@Mixin(value = GuiMap.class, remap = false)
public abstract class GuiMapMixin extends ScreenBase {

Expand Down Expand Up @@ -63,7 +62,7 @@ protected GuiMapMixin(GuiScreen parent, GuiScreen escape) {

@Inject(method = "<init>", at = @At("RETURN"))
private void injectConstruct(
GuiScreen parent, GuiScreen escape, MapProcessor mapProcessor, EntityPlayer player, CallbackInfo ci) {
GuiScreen parent, GuiScreen escape, MapProcessor mapProcessor, Entity player, CallbackInfo ci) {
MapState.instance.layers.forEach(LayerManager::onOpenMap);
}

Expand All @@ -74,44 +73,22 @@ private void injectConstruct(
method = "func_73863_a",
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glPushMatrix()V", ordinal = 1),
locals = LocalCapture.CAPTURE_FAILEXCEPTION)
// why is this method so long. this isnt even 1/5 of the way through and look at how many locals there are already
private void injectPreRender(
int scaledMouseX,
int scaledMouseY,
float partialTicks,
CallbackInfo ci,
Minecraft mc,
long startTime,
long passed,
double passedScrolls,
int direction,
Object var12,
boolean mapLoaded,
boolean noWorldMapEffect,
int mouseXPos,
int mouseYPos,
double scaleMultiplier,
double oldMousePosZ,
double preScale,
double fboScale,
double secondaryScale,
double mousePosX,
double mousePosZ,
int mouseFromCentreX,
int mouseFromCentreY,
double oldMousePosX,
int textureLevel,
int leveledRegionShift) {
int scaledMouseX, int scaledMouseY, float partialTicks, CallbackInfo ci, Minecraft mc) {
// snap the camera to whole pixel values. works around a rendering issue but causes another when framerate is
// uncapped
if (mc.gameSettings.limitFramerate < 255 || mc.gameSettings.enableVsync) {
cameraX = Math.round(cameraX * scale) / scale;
cameraZ = Math.round(cameraZ * scale) / scale;
}

// there's some nice local variables for exactly this but the local table for this function is hell
double mousePosX = (double) ((int) Misc.getMouseX(mc) - mc.displayWidth / 2) / this.scale;
double mousePosZ = (double) ((int) Misc.getMouseY(mc) - mc.displayHeight / 2) / this.scale;

for (LayerRenderer layer : XaeroWorldMapState.instance.renderers) {
if (layer instanceof InteractableLayerRenderer) {
((InteractableLayerRenderer) layer).updateHovered(mousePosX, mousePosZ, cameraX, cameraZ, scale);
((InteractableLayerRenderer) layer).updateHovered(mousePosX, mousePosZ, scale);
}
}
}
Expand Down

0 comments on commit 29f5d04

Please sign in to comment.