Skip to content

Commit caf216a

Browse files
committed
Added Old/New Chunks to World Map
1 parent cae291a commit caf216a

6 files changed

Lines changed: 126 additions & 3 deletions

File tree

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"workbench.colorCustomizations": {
3+
"titleBar.activeBackground": "#FFFF00",
4+
"titleBar.activeForeground": "#000000",
5+
"titleBar.inactiveBackground": "#FFFF00CC",
6+
"titleBar.inactiveForeground": "#000000CC"
7+
}
8+
}

common/src/main/java/com/mamiyaotaru/voxelmap/gui/overridden/EnumOptionsMinimap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public enum EnumOptionsMinimap {
8282
SHOW_DISTANT_WAYPOINTS("options.worldmap.showDistantWaypoints", Type.BOOLEAN),
8383
WORLDMAP_SHOW_WAYPOINTS_IN_PERFORMANCE_MODE("options.worldmap.showWaypointsInPerformanceMode", Type.BOOLEAN),
8484
WORLDMAP_LITERAL_LINE_MODE("options.worldmap.literalLineMode", Type.BOOLEAN),
85+
WORLDMAP_SHOW_NEW_OLD_CHUNKS("options.worldmap.showNewOldChunks", Type.BOOLEAN),
8586
MIN_ZOOM("options.worldmap.minZoom", Type.FLOAT),
8687
MAX_ZOOM("options.worldmap.maxZoom", Type.FLOAT),
8788
WORLDMAP_PERFORMANCE_MODE_THRESHOLD("options.worldmap.performanceModeThreshold", Type.FLOAT),

common/src/main/java/com/mamiyaotaru/voxelmap/persistent/GuiPersistentMap.java

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mamiyaotaru.voxelmap.persistent;
22

33
import com.mamiyaotaru.voxelmap.MapSettingsManager;
4+
import com.mamiyaotaru.voxelmap.NewerNewChunksManager;
45
import com.mamiyaotaru.voxelmap.RadarSettingsManager;
56
import com.mamiyaotaru.voxelmap.VoxelConstants;
67
import com.mamiyaotaru.voxelmap.WaypointManager;
@@ -850,6 +851,7 @@ public void extractRenderState(GuiGraphicsExtractor graphics, int mouseX, int mo
850851
}
851852
}
852853
drawExploredChunkLinesWorldMap(graphics, exploredLeftRegion, exploredRightRegion, exploredTopRegion, exploredBottomRegion);
854+
drawNewOldChunkOverlayWorldMap(graphics, exploredLeftRegion, exploredRightRegion, exploredTopRegion, exploredBottomRegion);
853855

854856
if (!farZoomPerformanceMode && mapOptions.worldBorder) {
855857
WorldBorder worldBorder = minecraft.level.getWorldBorder();
@@ -1297,6 +1299,111 @@ private void drawExploredChunkLinesWorldMap(GuiGraphicsExtractor graphics, int l
12971299
}
12981300
}
12991301

1302+
private void drawNewOldChunkOverlayWorldMap(GuiGraphicsExtractor graphics, int leftRegion, int rightRegion, int topRegion, int bottomRegion) {
1303+
if (!options.showNewOldChunks || !radarOptions.showNewerNewChunks) {
1304+
return;
1305+
}
1306+
1307+
int minChunkX = leftRegion * 16;
1308+
int maxChunkX = rightRegion * 16 + 15;
1309+
int minChunkZ = topRegion * 16;
1310+
int maxChunkZ = bottomRegion * 16 + 15;
1311+
int centerChunkX = (minChunkX + maxChunkX) >> 1;
1312+
int centerChunkZ = (minChunkZ + maxChunkZ) >> 1;
1313+
int radius = Math.max(maxChunkX - centerChunkX, maxChunkZ - centerChunkZ) + 2;
1314+
1315+
boolean farZoomPerformanceMode = isFarZoomPerformanceMode();
1316+
boolean mapInMotion = currentDragging
1317+
|| Math.abs(this.deltaX) > 0.01F
1318+
|| Math.abs(this.deltaY) > 0.01F
1319+
|| this.zoom != this.zoomGoal;
1320+
1321+
NewerNewChunksManager manager = VoxelConstants.getVoxelMapInstance().getNewerNewChunksManager();
1322+
List<ChunkPos> oldChunks = new ArrayList<>(manager.getOldChunksInRange(centerChunkX, centerChunkZ, radius));
1323+
List<ChunkPos> newChunks = new ArrayList<>(manager.getNewChunksInRange(centerChunkX, centerChunkZ, radius));
1324+
1325+
int oldAlpha = Mth.clamp((int) Math.round((radarOptions.newerNewChunksOldOpacity / 100.0D) * 255.0D), 0, 255);
1326+
int newAlpha = Mth.clamp((int) Math.round((radarOptions.newerNewChunksNewOpacity / 100.0D) * 255.0D), 0, 255);
1327+
if (oldAlpha <= 0 && newAlpha <= 0) {
1328+
return;
1329+
}
1330+
1331+
int oldColor = (oldAlpha << 24) | (radarOptions.getNewerNewChunksOldColorRgb() & 0x00FFFFFF);
1332+
int newColor = (newAlpha << 24) | (radarOptions.getNewerNewChunksNewColorRgb() & 0x00FFFFFF);
1333+
1334+
int cellChunkSize = 1;
1335+
if (this.mapToGui < 0.03F) {
1336+
cellChunkSize = mapInMotion ? 8 : 6;
1337+
} else if (this.mapToGui < 0.06F) {
1338+
cellChunkSize = mapInMotion ? 6 : 4;
1339+
} else if (this.mapToGui < 0.10F) {
1340+
cellChunkSize = mapInMotion ? 4 : 3;
1341+
} else if (this.mapToGui < 0.18F) {
1342+
cellChunkSize = mapInMotion ? 3 : 2;
1343+
}
1344+
1345+
int maxDraw = Integer.MAX_VALUE;
1346+
if (farZoomPerformanceMode) {
1347+
maxDraw = mapInMotion ? 2200 : 4500;
1348+
} else if (this.mapToGui < 0.06F) {
1349+
maxDraw = mapInMotion ? 900 : 2000;
1350+
} else if (this.mapToGui < 0.10F) {
1351+
maxDraw = mapInMotion ? 1500 : 2800;
1352+
}
1353+
1354+
int drawn = 0;
1355+
drawn = drawChunkSquaresWorldMap(graphics, oldChunks, minChunkX, maxChunkX, minChunkZ, maxChunkZ, oldColor, cellChunkSize, maxDraw, drawn);
1356+
drawChunkSquaresWorldMap(graphics, newChunks, minChunkX, maxChunkX, minChunkZ, maxChunkZ, newColor, cellChunkSize, maxDraw, drawn);
1357+
}
1358+
1359+
private int drawChunkSquaresWorldMap(GuiGraphicsExtractor graphics, List<ChunkPos> chunks, int minChunkX, int maxChunkX, int minChunkZ, int maxChunkZ, int color, int cellChunkSize, int maxDraw, int startDrawn) {
1360+
int drawn = startDrawn;
1361+
if (cellChunkSize > 1) {
1362+
java.util.HashSet<Long> cells = new java.util.HashSet<>();
1363+
for (ChunkPos chunk : chunks) {
1364+
int chunkX = chunk.x();
1365+
int chunkZ = chunk.z();
1366+
if (chunkX < minChunkX || chunkX > maxChunkX || chunkZ < minChunkZ || chunkZ > maxChunkZ) {
1367+
continue;
1368+
}
1369+
int cellX = Math.floorDiv(chunkX, cellChunkSize);
1370+
int cellZ = Math.floorDiv(chunkZ, cellChunkSize);
1371+
cells.add(chunkKey(cellX, cellZ));
1372+
}
1373+
1374+
float worldCellSize = 16.0F * cellChunkSize;
1375+
for (long key : cells) {
1376+
if (drawn >= maxDraw) {
1377+
break;
1378+
}
1379+
int cellX = (int) (key >> 32);
1380+
int cellZ = (int) key;
1381+
float minX = cellX * worldCellSize;
1382+
float minZ = cellZ * worldCellSize;
1383+
VoxelMapGuiGraphics.fillGradient(graphics, minX, minZ, minX + worldCellSize, minZ + worldCellSize, color, color, color, color);
1384+
drawn++;
1385+
}
1386+
return drawn;
1387+
}
1388+
1389+
for (ChunkPos chunk : chunks) {
1390+
if (drawn >= maxDraw) {
1391+
break;
1392+
}
1393+
int chunkX = chunk.x();
1394+
int chunkZ = chunk.z();
1395+
if (chunkX < minChunkX || chunkX > maxChunkX || chunkZ < minChunkZ || chunkZ > maxChunkZ) {
1396+
continue;
1397+
}
1398+
1399+
float minX = chunk.getMinBlockX();
1400+
float minZ = chunk.getMinBlockZ();
1401+
VoxelMapGuiGraphics.fillGradient(graphics, minX, minZ, minX + 16.0F, minZ + 16.0F, color, color, color, color);
1402+
drawn++;
1403+
}
1404+
return drawn;
1405+
}
1406+
13001407
private long chunkKey(int x, int z) {
13011408
return (((long) x) << 32) ^ (z & 0xFFFFFFFFL);
13021409
}

common/src/main/java/com/mamiyaotaru/voxelmap/persistent/GuiPersistentMapOptions.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ public GuiPersistentMapOptions(Screen parent) {
6060
public void init() {
6161
optionSections.clear();
6262

63-
addSection("Map Display", 0, 1);
63+
addSection("Map Display", 0, 2);
6464
addMappedOption(EnumOptionsMinimap.SHOW_WORLDMAP_COORDS, 0, 0);
6565
addMappedOption(EnumOptionsMinimap.SHOW_WORLDMAP_PLAYER_DIRECTION_ARROW, 0, 1);
6666
addMappedOption(EnumOptionsMinimap.WORLDMAP_LITERAL_LINE_MODE, 1, 0);
6767
addMappedOption(EnumOptionsMinimap.CONFIRM_WAYPOINT_DELETE, 1, 1);
68+
addMappedOption(EnumOptionsMinimap.WORLDMAP_SHOW_NEW_OLD_CHUNKS, 2, -1);
6869

6970
addSection("Waypoints", 3, 4);
7071
addMappedOption(EnumOptionsMinimap.SHOW_WAYPOINTS, 3, 0);
@@ -98,12 +99,12 @@ public void init() {
9899
}));
99100
refreshExploredChunkButtons();
100101

101-
addSection("Zoom & Performance", 9, 11);
102+
addSection("Zoom & Performance", 9, 12);
102103
addMappedOption(EnumOptionsMinimap.MIN_ZOOM, 9, 0);
103104
addMappedOption(EnumOptionsMinimap.MAX_ZOOM, 9, 1);
104105
addMappedOption(EnumOptionsMinimap.WORLDMAP_PERFORMANCE_MODE_THRESHOLD, 10, 0);
105106
addMappedOption(EnumOptionsMinimap.WORLDMAP_CHUNK_LINE_THICKNESS, 10, 1);
106-
addMappedOption(EnumOptionsMinimap.CACHE_SIZE, 11, -1);
107+
addMappedOption(EnumOptionsMinimap.CACHE_SIZE, 12, -1);
107108

108109
this.addRenderableWidget(new Button.Builder(Component.translatable("gui.done"), buttonx -> this.onClose()).bounds(this.getWidth() / 2 - 100, this.getHeight() - 26, 200, 20).build());
109110

common/src/main/java/com/mamiyaotaru/voxelmap/persistent/PersistentMapSettingsManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class PersistentMapSettingsManager implements ISubSettingsManager {
4141
public boolean showWaypoints = true;
4242
public boolean showWaypointNames = true;
4343
public boolean showDistantWaypoints = true;
44+
public boolean showNewOldChunks = false;
4445

4546
@Override
4647
public void loadAll(File settingsFile) {
@@ -59,6 +60,7 @@ public void loadAll(File settingsFile) {
5960
case "Worldmap Chunk Line Thickness" -> chunkLineThickness = Float.parseFloat(curLine[1]);
6061
case "Worldmap Show Waypoints In Performance Mode" -> showWaypointsInPerformanceMode = Boolean.parseBoolean(curLine[1]);
6162
case "Worldmap Literal Line Mode" -> literalLineMode = Boolean.parseBoolean(curLine[1]);
63+
case "Worldmap Show New Old Chunks" -> showNewOldChunks = Boolean.parseBoolean(curLine[1]);
6264
case "Show Worldmap Coordinates" -> showCoordinates = Boolean.parseBoolean(curLine[1]);
6365
case "Show Worldmap Player Direction Arrow" -> showPlayerDirectionArrow = Boolean.parseBoolean(curLine[1]);
6466
case "Show Worldmap Waypoints" -> showWaypoints = Boolean.parseBoolean(curLine[1]);
@@ -109,6 +111,7 @@ public void saveAll(PrintWriter out) {
109111
out.println("Worldmap Chunk Line Thickness:" + chunkLineThickness);
110112
out.println("Worldmap Show Waypoints In Performance Mode:" + showWaypointsInPerformanceMode);
111113
out.println("Worldmap Literal Line Mode:" + literalLineMode);
114+
out.println("Worldmap Show New Old Chunks:" + showNewOldChunks);
112115
out.println("Show Worldmap Coordinates:" + showCoordinates);
113116
out.println("Show Worldmap Player Direction Arrow:" + showPlayerDirectionArrow);
114117
out.println("Show Worldmap Waypoints:" + showWaypoints);
@@ -155,6 +158,7 @@ public boolean getBooleanValue(EnumOptionsMinimap option) {
155158
case SHOW_DISTANT_WAYPOINTS -> showDistantWaypoints && VoxelConstants.getVoxelMapInstance().getMapOptions().waypointsAllowed;
156159
case WORLDMAP_SHOW_WAYPOINTS_IN_PERFORMANCE_MODE -> showWaypointsInPerformanceMode;
157160
case WORLDMAP_LITERAL_LINE_MODE -> literalLineMode;
161+
case WORLDMAP_SHOW_NEW_OLD_CHUNKS -> showNewOldChunks;
158162

159163
default -> throw new IllegalArgumentException("Invalid boolean value! Add code to handle EnumOptionMinimap: " + option.getName());
160164
};
@@ -170,6 +174,7 @@ public void toggleBooleanValue(EnumOptionsMinimap option) {
170174
case SHOW_DISTANT_WAYPOINTS -> showDistantWaypoints = !showDistantWaypoints;
171175
case WORLDMAP_SHOW_WAYPOINTS_IN_PERFORMANCE_MODE -> showWaypointsInPerformanceMode = !showWaypointsInPerformanceMode;
172176
case WORLDMAP_LITERAL_LINE_MODE -> literalLineMode = !literalLineMode;
177+
case WORLDMAP_SHOW_NEW_OLD_CHUNKS -> showNewOldChunks = !showNewOldChunks;
173178

174179
default -> throw new IllegalArgumentException("Invalid boolean value! Add code to handle EnumOptionMinimap: " + option.getName());
175180
}

common/src/main/resources/assets/voxelmap/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@
247247
"options.worldmap.showDistantWaypoints": "Show Distant Waypoints",
248248
"options.worldmap.showWaypointsInPerformanceMode": "Waypoints In Performance Mode",
249249
"options.worldmap.literalLineMode": "Solid Chunk Line Mode",
250+
"options.worldmap.showNewOldChunks": "Show New/Old Chunks",
250251
"options.worldmap.minZoom": "Min Zoom",
251252
"options.worldmap.maxZoom": "Max Zoom",
252253
"options.worldmap.performanceModeThreshold": "Perf Mode Threshold",

0 commit comments

Comments
 (0)