Skip to content

Commit d2506b1

Browse files
committed
Only draw direction arrow when it's within bounds of the seed map
1 parent 22dee92 commit d2506b1

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/main/java/dev/xpple/seedmapper/seedmap/SeedMapScreen.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import net.minecraft.world.phys.Vec2;
8282
import org.jetbrains.annotations.Nullable;
8383
import org.joml.Matrix3x2f;
84+
import org.joml.Vector2f;
8485

8586
import java.lang.foreign.Arena;
8687
import java.lang.foreign.MemoryLayout;
@@ -98,6 +99,7 @@
9899
import java.util.function.IntSupplier;
99100
import java.util.function.ToIntBiFunction;
100101
import java.util.stream.IntStream;
102+
import java.util.stream.Stream;
101103

102104
import static dev.xpple.seedmapper.util.ChatBuilder.*;
103105

@@ -466,19 +468,25 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
466468
int playerMaxY = playerMinY + 20;
467469
if (playerMinX >= HORIZONTAL_PADDING && playerMaxX <= HORIZONTAL_PADDING + this.seedMapWidth && playerMinY >= VERTICAL_PADDING && playerMaxY <= VERTICAL_PADDING + this.seedMapHeight) {
468470
PlayerFaceRenderer.draw(guiGraphics, this.minecraft.player.getSkin(), playerMinX, playerMinY, 20);
469-
}
470471

471-
// draw player direction arrow
472-
guiGraphics.pose().pushMatrix();
473-
guiGraphics.pose() // transformations are applied in reverse order
474-
.translate(10, 10)
475-
.translate(playerMinX, playerMinY)
476-
.rotate((float) (Math.toRadians(this.playerRotation.y) + Math.PI))
477-
.translate(-10, -10)
478-
.translate(0, -30)
479-
;
480-
drawIcon(guiGraphics, DIRECTION_ARROW_TEXTURE, 0, 0, 20, 20, 0xFF_FFFFFF);
481-
guiGraphics.pose().popMatrix();
472+
// draw player direction arrow
473+
guiGraphics.pose().pushMatrix();
474+
Matrix3x2f transform = guiGraphics.pose() // transformations are applied in reverse order
475+
.translate(10, 10)
476+
.translate(playerMinX, playerMinY)
477+
.rotate((float) (Math.toRadians(this.playerRotation.y) + Math.PI))
478+
.translate(-10, -10)
479+
.translate(0, -30)
480+
;
481+
boolean withinBounds = Stream.of(new Vector2f(20, 0), new Vector2f(20, 20), new Vector2f(0, 20), new Vector2f(0, 0))
482+
.map(transform::transformPosition)
483+
.allMatch(v -> v.x >= HORIZONTAL_PADDING && v.x <= HORIZONTAL_PADDING + this.seedMapWidth &&
484+
v.y >= VERTICAL_PADDING && v.y <= VERTICAL_PADDING + this.seedMapHeight);
485+
if (withinBounds) {
486+
drawIcon(guiGraphics, DIRECTION_ARROW_TEXTURE, 0, 0, 20, 20, 0xFF_FFFFFF);
487+
}
488+
guiGraphics.pose().popMatrix();
489+
}
482490
}
483491

484492
// calculate spawn point

0 commit comments

Comments
 (0)