Skip to content

Commit 86c7513

Browse files
committed
add tolerance for waypoint distance & name rendering
1 parent 95d26ac commit 86c7513

File tree

7 files changed

+67
-53
lines changed

7 files changed

+67
-53
lines changed

1.20/src/main/java/io/github/axolotlclient/waypoints/waypoints/WaypointRenderer.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
package io.github.axolotlclient.waypoints.waypoints;
2424

2525
import java.lang.Math;
26+
import java.util.ArrayList;
2627
import java.util.HashSet;
28+
import java.util.List;
2729
import java.util.Set;
28-
import java.util.concurrent.atomic.AtomicReference;
2930

3031
import com.mojang.blaze3d.systems.RenderSystem;
3132
import com.mojang.blaze3d.vertex.PoseStack;
@@ -123,20 +124,21 @@ public void renderWaypoints(GuiGraphics graphics, float delta) {
123124

124125
graphics.pose().pushPose();
125126
graphics.pose().translate(0.0F, 0.0F, -100.0F);
126-
var positionDrawer = new AtomicReference<Runnable>();
127-
for (Waypoint waypoint : AxolotlClientWaypoints.getCurrentWaypoints()) {
127+
var waypoints = AxolotlClientWaypoints.getCurrentWaypoints();
128+
var positionDrawers = new ArrayList<Runnable>(waypoints.size());
129+
for (Waypoint waypoint : waypoints) {
128130
graphics.pose().pushPose();
129-
renderWaypoint(waypoint, graphics, delta, cam, positionDrawer);
131+
renderWaypoint(waypoint, graphics, delta, cam, positionDrawers);
130132
graphics.pose().popPose();
131133
}
132-
if (positionDrawer.get() != null) {
133-
positionDrawer.get().run();
134+
if (!positionDrawers.isEmpty()) {
135+
positionDrawers.forEach(Runnable::run);
134136
}
135137
graphics.pose().popPose();
136138
profiler.pop();
137139
}
138140

139-
private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, float tick, Camera camera, AtomicReference<Runnable> positionDrawn) {
141+
private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, float tick, Camera camera, List<Runnable> positionDrawn) {
140142
var fov = ((GameRendererAccessor) minecraft.gameRenderer).invokeGetFov(camera, tick, false);
141143
var pose = graphics.pose();
142144

@@ -181,14 +183,16 @@ private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, float tick,
181183
} else {
182184
_3dOnScreen = false;
183185
}
184-
if (positionDrawn.get() == null && Math.abs(result.x() - graphics.guiWidth() / 2f) < (_3dOnScreen ? Math.max(projWidth, width) : width) / 2f && Math.abs(result.y() - graphics.guiHeight() / 2f) < (_3dOnScreen ? Math.max(height, projHeight) : height) / 2f) {
186+
boolean displayX = Math.abs(result.x() - graphics.guiWidth() / 2f) < (_3dOnScreen ? Math.max(projWidth, width) : width) / 2f + graphics.guiWidth() / 4f;
187+
boolean displayY = Math.abs(result.y() - graphics.guiHeight() / 2f) < (_3dOnScreen ? Math.max(height, projHeight) : height) / 2f + graphics.guiHeight() / 4f;
188+
if (displayX && displayY) {
185189
pose.pushPose();
186190
pose.translate(0, Math.max(height, projHeight + 4) / 2f + 4, 0);
187191
var pos = pose.last().pose().transformPosition(new Vector3f());
188192
if ((projWidth >= width || projHeight >= height) && _3dOnScreen) {
189-
pos.y = Math.min(pos.y, displayEnd.y()+6);
193+
pos.y = Math.min(pos.y, displayEnd.y() + 6);
190194
}
191-
positionDrawn.set(() -> {
195+
positionDrawn.add(() -> {
192196
var line1 = waypoint.name();
193197
pose.pushPose();
194198
pose.last().pose().translate(pos);

1.21.8/src/main/java/io/github/axolotlclient/waypoints/waypoints/WaypointRenderer.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222

2323
package io.github.axolotlclient.waypoints.waypoints;
2424

25+
import java.util.ArrayList;
2526
import java.util.HashSet;
27+
import java.util.List;
2628
import java.util.Set;
27-
import java.util.concurrent.atomic.AtomicReference;
2829

2930
import com.mojang.blaze3d.ProjectionType;
3031
import com.mojang.blaze3d.framegraph.FrameGraphBuilder;
@@ -146,20 +147,21 @@ public void renderWaypoints(GuiGraphics graphics, DeltaTracker deltaTracker) {
146147
profiler.push("waypoints");
147148

148149
graphics.pose().pushMatrix();
149-
var positionDrawer = new AtomicReference<Runnable>();
150-
for (Waypoint waypoint : AxolotlClientWaypoints.getCurrentWaypoints()) {
150+
var waypoints = AxolotlClientWaypoints.getCurrentWaypoints();
151+
var positionDrawers = new ArrayList<Runnable>(waypoints.size());
152+
for (Waypoint waypoint : waypoints) {
151153
graphics.pose().pushMatrix();
152-
renderWaypoint(waypoint, graphics, deltaTracker, cam, positionDrawer);
154+
renderWaypoint(waypoint, graphics, deltaTracker, cam, positionDrawers);
153155
graphics.pose().popMatrix();
154156
}
155-
if (positionDrawer.get() != null) {
156-
positionDrawer.get().run();
157+
if (!positionDrawers.isEmpty()) {
158+
positionDrawers.forEach(Runnable::run);
157159
}
158160
graphics.pose().popMatrix();
159161
profiler.pop();
160162
}
161163

162-
private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, DeltaTracker tracker, Camera camera, AtomicReference<Runnable> positionDrawn) {
164+
private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, DeltaTracker tracker, Camera camera, List<Runnable> positionDrawers) {
163165
var tick = tracker.getGameTimeDeltaPartialTick(true);
164166
var fov = ((GameRendererAccessor) minecraft.gameRenderer).invokeGetFov(camera, tick, true);
165167
var pose = graphics.pose();
@@ -205,14 +207,17 @@ private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, DeltaTracke
205207
} else {
206208
_3dOnScreen = false;
207209
}
208-
if (positionDrawn.get() == null && Math.abs(result.x() - graphics.guiWidth() / 2f) < (_3dOnScreen ? Math.max(projWidth, width) : width) / 2f && Math.abs(result.y() - graphics.guiHeight() / 2f) < (_3dOnScreen ? Math.max(height, projHeight) : height) / 2f) {
210+
211+
boolean displayX = Math.abs(result.x() - graphics.guiWidth() / 2f) < (_3dOnScreen ? Math.max(projWidth, width) : width) / 2f + graphics.guiWidth() / 4f;
212+
boolean displayY = Math.abs(result.y() - graphics.guiHeight() / 2f) < (_3dOnScreen ? Math.max(height, projHeight) : height) / 2f + graphics.guiHeight() / 4f;
213+
if (displayX && displayY) {
209214
pose.pushMatrix();
210215
pose.translate(0, Math.max(height, projHeight + 4) / 2f + 4);
211216
var pos = pose.transformPosition(new Vector2f());
212217
if ((projWidth >= width || projHeight >= height) && _3dOnScreen) {
213-
pos.y = Math.min(pos.y, displayEnd.y()+6);
218+
pos.y = Math.min(pos.y, displayEnd.y() + 6);
214219
}
215-
positionDrawn.set(() -> {
220+
positionDrawers.add(() -> {
216221
var line1 = waypoint.name();
217222
pose.pushMatrix();
218223
pose.translate(pos);

1.21/src/main/java/io/github/axolotlclient/waypoints/waypoints/WaypointRenderer.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
package io.github.axolotlclient.waypoints.waypoints;
2424

2525
import java.lang.Math;
26+
import java.util.ArrayList;
2627
import java.util.HashSet;
28+
import java.util.List;
2729
import java.util.Set;
28-
import java.util.concurrent.atomic.AtomicReference;
2930

3031
import com.mojang.blaze3d.vertex.PoseStack;
3132
import io.github.axolotlclient.AxolotlClientConfig.api.util.Colors;
@@ -127,20 +128,21 @@ public void renderWaypoints(GuiGraphics graphics, DeltaTracker deltaTracker) {
127128
profiler.push("waypoints");
128129

129130
graphics.pose().pushPose();
130-
var positionDrawer = new AtomicReference<Runnable>();
131-
for (Waypoint waypoint : AxolotlClientWaypoints.getCurrentWaypoints()) {
131+
var waypoints = AxolotlClientWaypoints.getCurrentWaypoints();
132+
var positionDrawers = new ArrayList<Runnable>(waypoints.size());
133+
for (Waypoint waypoint : waypoints) {
132134
graphics.pose().pushPose();
133-
renderWaypoint(waypoint, graphics, deltaTracker, cam, positionDrawer);
135+
renderWaypoint(waypoint, graphics, deltaTracker, cam, positionDrawers);
134136
graphics.pose().popPose();
135137
}
136-
if (positionDrawer.get() != null) {
137-
positionDrawer.get().run();
138+
if (!positionDrawers.isEmpty()) {
139+
positionDrawers.forEach(Runnable::run);
138140
}
139141
graphics.pose().popPose();
140142
profiler.pop();
141143
}
142144

143-
private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, DeltaTracker tracker, Camera camera, AtomicReference<Runnable> positionDrawn) {
145+
private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, DeltaTracker tracker, Camera camera, List<Runnable> positionDrawn) {
144146
var tick = tracker.getGameTimeDeltaPartialTick(true);
145147
var fov = ((GameRendererAccessor) minecraft.gameRenderer).invokeGetFov(camera, tick, false);
146148
var pose = graphics.pose();
@@ -186,14 +188,16 @@ private void renderWaypoint(Waypoint waypoint, GuiGraphics graphics, DeltaTracke
186188
} else {
187189
_3dOnScreen = false;
188190
}
189-
if (positionDrawn.get() == null && Math.abs(result.x() - graphics.guiWidth() / 2f) < (_3dOnScreen ? Math.max(projWidth, width) : width) / 2f && Math.abs(result.y() - graphics.guiHeight() / 2f) < (_3dOnScreen ? Math.max(height, projHeight) : height) / 2f) {
191+
boolean displayX = Math.abs(result.x() - graphics.guiWidth() / 2f) < (_3dOnScreen ? Math.max(projWidth, width) : width) / 2f + graphics.guiWidth() / 4f;
192+
boolean displayY = Math.abs(result.y() - graphics.guiHeight() / 2f) < (_3dOnScreen ? Math.max(height, projHeight) : height) / 2f + graphics.guiHeight() / 4f;
193+
if (displayX && displayY) {
190194
pose.pushPose();
191195
pose.translate(0, Math.max(height, projHeight + 4) / 2f + 4, 0);
192196
var pos = pose.last().pose().transformPosition(new Vector3f());
193197
if ((projWidth >= width || projHeight >= height) && _3dOnScreen) {
194-
pos.y = Math.min(pos.y, displayEnd.y()+6);
198+
pos.y = Math.min(pos.y, displayEnd.y() + 6);
195199
}
196-
positionDrawn.set(() -> {
200+
positionDrawn.add(() -> {
197201
var line1 = waypoint.name();
198202
pose.pushPose();
199203
pose.last().pose().translate(pos);

1.8.9/build.gradle.kts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,15 @@ dependencies {
5656
runtimeOnly("org.lwjgl:lwjgl-nanovg:${lwjglVersion}:natives-macos")
5757
runtimeOnly("org.lwjgl:lwjgl-nanovg:${lwjglVersion}:natives-macos-arm64")
5858

59-
/*include("org.apache.logging.log4j:log4j-slf4j-impl:2.0-beta9") {
60-
exclude(group = "org.apache.logging.log4j", module = "log4j-api")
61-
exclude(group = "org.apache.logging.log4j", module = "log4j-core")
62-
}
63-
implementation(include("org.slf4j:slf4j-api:1.7.36")!!)
64-
localRuntime("org.slf4j:slf4j-jdk14:1.7.36")*/
65-
6659
//compileOnly("org.lwjgl:lwjgl-glfw:${lwjglVersion}")
6760

68-
modCompileOnly("io.github.moehreag:legacy-lwjgl3:${project.property("legacy_lwgjl3")}")
69-
modLocalRuntime("io.github.moehreag:legacy-lwjgl3:${project.property("legacy_lwgjl3")}:all-remapped")
61+
modImplementation("io.github.moehreag:legacy-lwjgl3:${project.property("legacy_lwgjl3")}")
7062

7163
implementation(include("org.joml:joml:1.10.8")!!)
7264
}
7365

7466
configurations.configureEach {
67+
exclude("org.lwjgl.lwjgl")
7568
resolutionStrategy {
7669
dependencySubstitution {
7770
substitute(module("io.netty:netty-all:4.0.23.Final")).using(module("io.netty:netty-all:4.1.9.Final"))

1.8.9/src/main/java/io/github/axolotlclient/waypoints/waypoints/WaypointRenderer.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222

2323
package io.github.axolotlclient.waypoints.waypoints;
2424

25+
import java.util.ArrayList;
2526
import java.util.HashSet;
27+
import java.util.List;
2628
import java.util.Set;
27-
import java.util.concurrent.atomic.AtomicReference;
2829

2930
import com.mojang.blaze3d.platform.GlStateManager;
3031
import com.mojang.blaze3d.vertex.BufferBuilder;
@@ -148,14 +149,15 @@ public void renderWaypoints(float tick) {
148149
var win = new Window(minecraft);
149150

150151
GlStateManager.pushMatrix();
151-
var positionDrawer = new AtomicReference<Runnable>();
152-
for (Waypoint waypoint : AxolotlClientWaypoints.getCurrentWaypoints()) {
152+
var waypoints = AxolotlClientWaypoints.getCurrentWaypoints();
153+
var positionDrawers = new ArrayList<Runnable>(waypoints.size());
154+
for (Waypoint waypoint : waypoints) {
153155
GlStateManager.pushMatrix();
154-
renderWaypoint(waypoint, tick, cam, positionDrawer, win.getWidth(), win.getHeight());
156+
renderWaypoint(waypoint, tick, cam, positionDrawers, win.getWidth(), win.getHeight());
155157
GlStateManager.popMatrix();
156158
}
157-
if (positionDrawer.get() != null) {
158-
positionDrawer.get().run();
159+
if (!positionDrawers.isEmpty()) {
160+
positionDrawers.forEach(Runnable::run);
159161
}
160162
GlStateManager.popMatrix();
161163
profiler.pop();
@@ -166,7 +168,7 @@ private Matrix4f getProjectionMatrix(float fov) {
166168
return matrix4f.perspective(fov * ((float) Math.PI / 180F), (float) this.minecraft.width / (float) this.minecraft.height, 0.05F, minecraft.options.viewDistance * 4);
167169
}
168170

169-
private void renderWaypoint(Waypoint waypoint, float tick, Entity camera, AtomicReference<Runnable> positionDrawn, int guiWidth, int guiHeight) {
171+
private void renderWaypoint(Waypoint waypoint, float tick, Entity camera, List<Runnable> positionDrawn, int guiWidth, int guiHeight) {
170172
var fov = ((GameRendererAccessor) minecraft.gameRenderer).invokeGetFov(tick, false);
171173

172174
var textWidth = minecraft.textRenderer.getWidth(waypoint.display());
@@ -208,16 +210,18 @@ private void renderWaypoint(Waypoint waypoint, float tick, Entity camera, Atomic
208210
} else {
209211
_3dOnScreen = false;
210212
}
211-
if (positionDrawn.get() == null && Math.abs(result.x() - guiWidth / 2f) < (_3dOnScreen ? Math.max(projWidth, width) : width) / 2f && Math.abs(result.y() - guiHeight / 2f) < (_3dOnScreen ? Math.max(height, projHeight) : height) / 2f) {
212-
positionDrawn.set(() -> {
213+
boolean displayX = Math.abs(result.x() - guiWidth / 2f) < (_3dOnScreen ? Math.max(projWidth, width) : width) / 2f + guiWidth / 4f;
214+
boolean displayY = Math.abs(result.y() - guiHeight / 2f) < (_3dOnScreen ? Math.max(height, projHeight) : height) / 2f + guiHeight / 4f;
215+
if (displayX && displayY) {
216+
positionDrawn.add(() -> {
213217
var line1 = waypoint.name();
214218
GlStateManager.pushMatrix();
215219
GlStateManager.translatef(result.x(), result.y(), 0);
216220
GlStateManager.translatef(0, Math.max(height, projHeight + 4) / 2f + 4, 0);
217221
if ((projWidth >= width || projHeight >= height) && _3dOnScreen) {
218-
float y = result.y()+Math.max(height, projHeight + 4) / 2f + 4;
219-
var y2 = Math.min(y, displayEnd.y()+6);
220-
GlStateManager.translatef(0, y2-y, 0);
222+
float y = result.y() + Math.max(height, projHeight + 4) / 2f + 4;
223+
var y2 = Math.min(y, displayEnd.y() + 6);
224+
GlStateManager.translatef(0, y2 - y, 0);
221225
}
222226
int line1W = minecraft.textRenderer.getWidth(line1);
223227
GuiElement.fill(-line1W / 2 - 2, -2, line1W / 2 + 2, minecraft.textRenderer.fontHeight + 2, Colors.GRAY.withAlpha(100).toInt());

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Changelog
22

3+
### 0.0.1-beta.15
4+
5+
- add tolerance for waypoint distance & name rendering, currently 1/4 of the screen size on each side
6+
37
### 0.0.1-beta.14
48

59
- fix water colors for 1.20.1 + 1.21.1

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ org.gradle.parallel=true
66
axolotlclient.modules.all=true
77

88
# Mod Properties
9-
version=0.0.1-beta.14+3.1.5
9+
version=0.0.1-beta.15+3.1.5
1010

1111
maven_group=io.github.axolotlclient.waypoints
1212

@@ -16,7 +16,7 @@ fabric_loader=0.17.2
1616

1717
osl=0.16.3
1818

19-
legacy_lwgjl3=1.2.5+1.8.9
19+
legacy_lwgjl3=1.2.9+1.8.9
2020

2121
config=3.0.19-beta.1
2222
axolotlclient=3.1.5

0 commit comments

Comments
 (0)