Skip to content

Commit d00fd81

Browse files
committed
Minimap
1 parent f93a37b commit d00fd81

File tree

7 files changed

+289
-17
lines changed

7 files changed

+289
-17
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Around your player icon in the SeedMap there will be a little arrow showing you
2929

3030
![Arrow](https://i.imgur.com/pkodE8d.png)
3131

32+
### Seed Map Minimap
33+
Run ```/sm:minimap``` to open a live SeedMap minimap in the top-left corner of the HUD (use ```/sm:minimap on``` or ```/sm:minimap off``` to explicitly control it). The overlay renders the same features you selected on the main map and tracks your current position. Adjust its placement with ```/sm:config SeedMapMinimapOffsetX``` and ```/sm:config SeedMapMinimapOffsetY```, and resize it with ```/sm:config SeedMapMinimapWidth``` / ```SeedMapMinimapHeight``` to cover other minimaps if needed.
34+
3235
### Memory Handling
3336
Added a config option ```/sm:config ClearSeedMapCachesOnClose``` to clear tiles, per‑world locations and any other relevant caches. When enabled, this prevents FPS dips from garbage collection on large caches after zooming out far and then closing the map. Opening the map again will result it in being loaded like its the first time, at smaller zoom levels this isn't a problem.
3437

src/main/java/dev/xpple/seedmapper/SeedMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import dev.xpple.seedmapper.command.commands.HighlightCommand;
1313
import dev.xpple.seedmapper.command.commands.EspConfigCommand;
1414
import dev.xpple.seedmapper.command.commands.LocateCommand;
15+
import dev.xpple.seedmapper.command.commands.MinimapCommand;
1516
import dev.xpple.seedmapper.command.commands.SampleCommand;
1617
import dev.xpple.seedmapper.command.commands.SeedMapCommand;
1718
import dev.xpple.seedmapper.command.commands.SourceCommand;
@@ -21,6 +22,7 @@
2122
import dev.xpple.seedmapper.config.SeedResolutionAdapter;
2223
import dev.xpple.seedmapper.render.RenderManager;
2324
import dev.xpple.seedmapper.seedmap.MapFeature;
25+
import dev.xpple.seedmapper.seedmap.SeedMapMinimapManager;
2426
import dev.xpple.seedmapper.util.SeedDatabaseHelper;
2527
import dev.xpple.simplewaypoints.api.SimpleWaypointsAPI;
2628
import net.fabricmc.api.ClientModInitializer;
@@ -89,6 +91,7 @@ public void onInitializeClient() {
8991

9092
ClientCommandRegistrationCallback.EVENT.register(SeedMapper::registerCommands);
9193
RenderManager.registerEvents();
94+
SeedMapMinimapManager.registerHud();
9295
}
9396

9497
private static void registerCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandBuildContext context) {
@@ -101,6 +104,7 @@ private static void registerCommands(CommandDispatcher<FabricClientCommandSource
101104
ClearCommand.register(dispatcher);
102105
StopTaskCommand.register(dispatcher);
103106
SeedMapCommand.register(dispatcher);
107+
MinimapCommand.register(dispatcher);
104108
DiscordCommand.register(dispatcher);
105109
SampleCommand.register(dispatcher);
106110
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package dev.xpple.seedmapper.command.commands;
2+
3+
import com.mojang.brigadier.Command;
4+
import com.mojang.brigadier.CommandDispatcher;
5+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
6+
import dev.xpple.seedmapper.command.CustomClientCommandSource;
7+
import dev.xpple.seedmapper.seedmap.SeedMapMinimapManager;
8+
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
9+
import net.minecraft.core.BlockPos;
10+
11+
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
12+
13+
public class MinimapCommand {
14+
15+
public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
16+
dispatcher.register(literal("sm:minimap")
17+
.executes(ctx -> toggle(CustomClientCommandSource.of(ctx.getSource())))
18+
.then(literal("on").executes(ctx -> enable(CustomClientCommandSource.of(ctx.getSource()))))
19+
.then(literal("off").executes(ctx -> disable(CustomClientCommandSource.of(ctx.getSource())))));
20+
}
21+
22+
private static int toggle(CustomClientCommandSource source) throws CommandSyntaxException {
23+
long seed = source.getSeed().getSecond();
24+
int dimension = source.getDimension();
25+
int version = source.getVersion();
26+
BlockPos playerPos = BlockPos.containing(source.getPosition());
27+
source.getClient().schedule(() -> SeedMapMinimapManager.toggle(seed, dimension, version, playerPos));
28+
return Command.SINGLE_SUCCESS;
29+
}
30+
31+
private static int enable(CustomClientCommandSource source) throws CommandSyntaxException {
32+
long seed = source.getSeed().getSecond();
33+
int dimension = source.getDimension();
34+
int version = source.getVersion();
35+
BlockPos playerPos = BlockPos.containing(source.getPosition());
36+
source.getClient().schedule(() -> SeedMapMinimapManager.show(seed, dimension, version, playerPos));
37+
return Command.SINGLE_SUCCESS;
38+
}
39+
40+
private static int disable(CustomClientCommandSource source) {
41+
source.getClient().schedule(SeedMapMinimapManager::hide);
42+
return Command.SINGLE_SUCCESS;
43+
}
44+
}

src/main/java/dev/xpple/seedmapper/config/Configs.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,34 @@ private static void setPixelsPerBiome(double pixelsPerBiome) {
6363
PixelsPerBiome = Math.clamp(pixelsPerBiome, SeedMapScreen.MIN_PIXELS_PER_BIOME, SeedMapScreen.MAX_PIXELS_PER_BIOME);
6464
}
6565

66+
@Config(setter = @Config.Setter("setMinimapOffsetX"))
67+
public static int SeedMapMinimapOffsetX = 5;
68+
69+
private static void setMinimapOffsetX(int offsetX) {
70+
SeedMapMinimapOffsetX = Math.max(0, offsetX);
71+
}
72+
73+
@Config(setter = @Config.Setter("setMinimapOffsetY"))
74+
public static int SeedMapMinimapOffsetY = 5;
75+
76+
private static void setMinimapOffsetY(int offsetY) {
77+
SeedMapMinimapOffsetY = Math.max(0, offsetY);
78+
}
79+
80+
@Config(setter = @Config.Setter("setMinimapWidth"))
81+
public static int SeedMapMinimapWidth = 205;
82+
83+
private static void setMinimapWidth(int width) {
84+
SeedMapMinimapWidth = Math.clamp(width, 64, 512);
85+
}
86+
87+
@Config(setter = @Config.Setter("setMinimapHeight"))
88+
public static int SeedMapMinimapHeight = 205;
89+
90+
private static void setMinimapHeight(int height) {
91+
SeedMapMinimapHeight = Math.clamp(height, 64, 512);
92+
}
93+
6694
@Config(comment = "getPlayerDirectionArrowComment")
6795
public static boolean ShowPlayerDirectionArrow = true;
6896

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package dev.xpple.seedmapper.seedmap;
2+
3+
import dev.xpple.seedmapper.config.Configs;
4+
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
5+
import net.minecraft.client.DeltaTracker;
6+
import net.minecraft.client.Minecraft;
7+
import net.minecraft.client.gui.GuiGraphics;
8+
import net.minecraft.client.player.LocalPlayer;
9+
import net.minecraft.core.BlockPos;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
public final class SeedMapMinimapManager {
13+
private static final SeedMapMinimapManager INSTANCE = new SeedMapMinimapManager();
14+
15+
private @Nullable SeedMapMinimapScreen minimapScreen;
16+
17+
private SeedMapMinimapManager() {
18+
}
19+
20+
public static void registerHud() {
21+
HudRenderCallback.EVENT.register((guiGraphics, deltaTracker) -> INSTANCE.render(guiGraphics, deltaTracker));
22+
}
23+
24+
public static boolean isVisible() {
25+
return INSTANCE.minimapScreen != null;
26+
}
27+
28+
public static void show(long seed, int dimension, int version, BlockPos pos) {
29+
INSTANCE.enable(seed, dimension, version, pos);
30+
}
31+
32+
public static void hide() {
33+
INSTANCE.disable();
34+
}
35+
36+
public static void toggle(long seed, int dimension, int version, BlockPos pos) {
37+
if (INSTANCE.minimapScreen != null) {
38+
INSTANCE.disable();
39+
return;
40+
}
41+
INSTANCE.enable(seed, dimension, version, pos);
42+
}
43+
44+
public static void disableMinimap() {
45+
INSTANCE.disable();
46+
}
47+
48+
private void enable(long seed, int dimension, int version, BlockPos pos) {
49+
this.disable();
50+
this.minimapScreen = new SeedMapMinimapScreen(seed, dimension, version, pos);
51+
}
52+
53+
private void disable() {
54+
if (this.minimapScreen != null) {
55+
if (this.minimapScreen.isInitialized()) {
56+
this.minimapScreen.onClose();
57+
}
58+
this.minimapScreen = null;
59+
}
60+
}
61+
62+
private void render(GuiGraphics guiGraphics, DeltaTracker deltaTracker) {
63+
if (this.minimapScreen == null) {
64+
return;
65+
}
66+
Minecraft minecraft = Minecraft.getInstance();
67+
LocalPlayer player = minecraft.player;
68+
if (player == null || minecraft.level == null) {
69+
this.disable();
70+
return;
71+
}
72+
73+
int minimapWidth = Math.max(64, Configs.SeedMapMinimapWidth);
74+
int minimapHeight = Math.max(64, Configs.SeedMapMinimapHeight);
75+
this.minimapScreen.initForOverlay(minecraft, minimapWidth, minimapHeight);
76+
this.minimapScreen.focusOn(player.blockPosition());
77+
78+
int offsetX = Configs.SeedMapMinimapOffsetX;
79+
int offsetY = Configs.SeedMapMinimapOffsetY;
80+
int translateX = offsetX - SeedMapScreen.horizontalPadding();
81+
int translateY = offsetY - SeedMapScreen.verticalPadding();
82+
float partialTick = deltaTracker.getGameTimeDeltaPartialTick(false);
83+
guiGraphics.pose().pushMatrix();
84+
guiGraphics.pose().translate((float) translateX, (float) translateY);
85+
this.minimapScreen.renderToHud(guiGraphics, partialTick);
86+
guiGraphics.pose().popMatrix();
87+
}
88+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package dev.xpple.seedmapper.seedmap;
2+
3+
import dev.xpple.seedmapper.util.QuartPos2;
4+
import dev.xpple.seedmapper.util.QuartPos2f;
5+
import net.minecraft.client.Minecraft;
6+
import net.minecraft.client.gui.GuiGraphics;
7+
import net.minecraft.core.BlockPos;
8+
9+
public class SeedMapMinimapScreen extends SeedMapScreen {
10+
11+
private boolean initialized = false;
12+
private int cachedWidth = -1;
13+
private int cachedHeight = -1;
14+
15+
public SeedMapMinimapScreen(long seed, int dimension, int version, BlockPos playerPos) {
16+
super(seed, dimension, version, playerPos);
17+
}
18+
19+
public void initForOverlay(Minecraft minecraft, int width, int height) {
20+
if (this.initialized && width == this.cachedWidth && height == this.cachedHeight) {
21+
return;
22+
}
23+
this.init(minecraft, width, height);
24+
this.initialized = true;
25+
this.cachedWidth = width;
26+
this.cachedHeight = height;
27+
}
28+
29+
public void renderToHud(GuiGraphics guiGraphics, float partialTick) {
30+
this.renderSeedMap(guiGraphics, Integer.MIN_VALUE, Integer.MIN_VALUE, partialTick);
31+
}
32+
33+
public void focusOn(BlockPos pos) {
34+
this.updatePlayerPosition(pos);
35+
this.moveCenter(QuartPos2f.fromQuartPos(QuartPos2.fromBlockPos(pos)));
36+
}
37+
38+
public boolean isInitialized() {
39+
return this.initialized;
40+
}
41+
42+
@Override
43+
protected boolean showCoordinateOverlay() {
44+
return false;
45+
}
46+
47+
@Override
48+
protected boolean showFeatureToggleTooltips() {
49+
return false;
50+
}
51+
52+
@Override
53+
protected boolean showSeedLabel() {
54+
return false;
55+
}
56+
}

0 commit comments

Comments
 (0)