diff --git a/mosfet.py b/mosfet.py
index 8b25e10..98ba634 100644
--- a/mosfet.py
+++ b/mosfet.py
@@ -226,6 +226,17 @@ def api_minimap():
lock.release()
ready = any(cell is not None for row in cells for cell in row)
+ path_nodes = []
+ for node in (g.get('path') or ())[:512]:
+ try:
+ if all(hasattr(node, key) for key in ('x', 'z')):
+ path_x, path_z = float(node.x), float(node.z)
+ else:
+ path_x, path_z = float(node[0]), float(node[2])
+ except (IndexError, TypeError, ValueError, AttributeError):
+ continue
+ path_nodes.append({'x': path_x, 'z': path_z})
+
return jsonify(
ready=ready,
center={'x': center_x, 'y': center_y, 'z': center_z},
@@ -234,6 +245,7 @@ def api_minimap():
radius_x=radius_x,
radius_z=radius_z,
cells=cells if ready else [],
+ path=path_nodes,
)
diff --git a/tests/test_web_inventory_api.py b/tests/test_web_inventory_api.py
index 793360e..8c9b271 100644
--- a/tests/test_web_inventory_api.py
+++ b/tests/test_web_inventory_api.py
@@ -35,7 +35,7 @@ class TestWebInventoryAPI(unittest.TestCase):
self.original = {
key: self.g.get(key) for key in
('connected', 'game', 'inv', 'chest_viewers', 'time', 'time_base',
- 'chunks', 'pos', 'yaw')
+ 'chunks', 'pos', 'yaw', 'path')
}
self.game = FakeGame()
self.g.connected = True
@@ -78,6 +78,7 @@ class TestWebInventoryAPI(unittest.TestCase):
self.g.chunks = FakeChunks()
self.g.pos = Munch(x=1.5, y=6.0, z=1.5)
self.g.yaw = 90
+ self.g.path = [(-1, 5, 1), Munch(x=1, y=5, z=1)]
response = self.client.get(
'/api/minimap?radius=4&radius_x=6&radius_z=4')
@@ -87,6 +88,9 @@ class TestWebInventoryAPI(unittest.TestCase):
self.assertTrue(data['ready'])
self.assertEqual(data['center'], {'x': 1, 'y': 6, 'z': 1})
self.assertEqual(data['yaw'], 90)
+ self.assertEqual(data['path'], [
+ {'x': -1.0, 'z': 1.0}, {'x': 1.0, 'z': 1.0},
+ ])
self.assertEqual(data['radius_x'], 6)
self.assertEqual(data['radius_z'], 4)
self.assertEqual(len(data['cells']), 9)
diff --git a/web_interface/build/index.html b/web_interface/build/index.html
index 839586b..6a509f9 100644
--- a/web_interface/build/index.html
+++ b/web_interface/build/index.html
@@ -6,8 +6,8 @@
Mosfet · Minecraft Bot
-
-
+
+
diff --git a/web_interface/public/index.html b/web_interface/public/index.html
index 839586b..6a509f9 100644
--- a/web_interface/public/index.html
+++ b/web_interface/public/index.html
@@ -6,8 +6,8 @@
Mosfet · Minecraft Bot
-
-
+
+
diff --git a/web_interface/src/dashboard.css b/web_interface/src/dashboard.css
index 16000f7..1b4b684 100644
--- a/web_interface/src/dashboard.css
+++ b/web_interface/src/dashboard.css
@@ -138,7 +138,7 @@ h2 { margin: 3px 0 0; font-size: 20px; letter-spacing: -.01em; font-weight: 600;
.side-panel { padding: 14px; }
.minimap-panel { min-width: 0; }
.minimap-panel.is-large { grid-column: 1 / -1; width: 100%; }
-.minimap-canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; margin: 2px auto 0; border: 1px solid #4b5549; border-radius: 2px; background: #111411; image-rendering: pixelated; }
+.minimap-canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; margin: 2px auto 0; border: 1px solid #4b5549; border-radius: 2px; background: #111411; }
.minimap-panel.is-large .minimap-canvas { aspect-ratio: 2 / 1; }
.minimap-caption { min-height: 14px; margin-top: 6px; color: var(--muted); text-align: center; font: 10px var(--mono); }
.minimap-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-top: 8px; }
diff --git a/web_interface/src/dashboard.js b/web_interface/src/dashboard.js
index 393b1af..df2ef9d 100644
--- a/web_interface/src/dashboard.js
+++ b/web_interface/src/dashboard.js
@@ -93,13 +93,6 @@
return '#7a806f';
}
- function shadeMinimapColor(color, amount) {
- const value = Number.parseInt(color.slice(1), 16);
- const channels = [value >> 16, (value >> 8) & 0xff, value & 0xff]
- .map((channel) => Math.max(0, Math.min(255, Math.round(channel * amount))));
- return `rgb(${channels[0]} ${channels[1]} ${channels[2]})`;
- }
-
function drawMinimap(data = lastMinimapData) {
const canvas = $('minimap-canvas');
if (!canvas) return;
@@ -124,6 +117,27 @@
const columns = radiusX * 2 + 1;
const cellWidth = width / columns;
const cellHeight = height / rows;
+ // Rasterize one color per sample before scaling to avoid subpixel cell seams.
+ const raster = document.createElement('canvas');
+ raster.width = columns;
+ raster.height = rows;
+ const rasterContext = raster.getContext('2d');
+ const rasterPixels = rasterContext.createImageData(columns, rows);
+ for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
+ const row = data.cells[rowIndex] || [];
+ for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
+ const surface = row[columnIndex];
+ const color = surface ? minimapBlockColor(surface.block) : '#171b17';
+ const value = Number.parseInt(color.slice(1), 16);
+ const pixel = (rowIndex * columns + columnIndex) * 4;
+ rasterPixels.data[pixel] = value >> 16;
+ rasterPixels.data[pixel + 1] = (value >> 8) & 0xff;
+ rasterPixels.data[pixel + 2] = value & 0xff;
+ rasterPixels.data[pixel + 3] = 255;
+ }
+ }
+ rasterContext.putImageData(rasterPixels, 0, 0);
+
const yaw = Number(data.yaw || 0);
const mapRotation = minimapNorthLocked ? 0 : (180 - yaw) * Math.PI / 180;
context.save();
@@ -132,23 +146,28 @@
context.clip();
context.translate(centerX, centerY);
context.rotate(mapRotation);
- for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
- const row = data.cells[rowIndex] || [];
- for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
- const surface = row[columnIndex];
- const x = -centerX + columnIndex * cellWidth;
- const y = -centerY + rowIndex * cellHeight;
- if (!surface) {
- context.fillStyle = '#171b17';
- } else {
- const heightDelta = Number(surface.y) - Number(data.center?.y || 0);
- const shade = Math.max(0.72, Math.min(1.28, 1 + heightDelta * 0.018));
- context.fillStyle = shadeMinimapColor(
- minimapBlockColor(surface.block), shade);
- }
- context.fillRect(x, y, Math.ceil(cellWidth) + 0.2,
- Math.ceil(cellHeight) + 0.2);
- }
+ context.imageSmoothingEnabled = false;
+ context.drawImage(raster, -centerX, -centerY, width, height);
+
+ const route = Array.isArray(data.path) ? data.path : [];
+ if (route.length) {
+ context.beginPath();
+ route.forEach((point, index) => {
+ const x = (Number(point.x) - data.center.x + radiusX + 0.5) *
+ cellWidth - centerX;
+ const y = (Number(point.z) - data.center.z + radiusZ + 0.5) *
+ cellHeight - centerY;
+ if (index === 0) context.moveTo(x, y);
+ else context.lineTo(x, y);
+ });
+ context.lineCap = 'round';
+ context.lineJoin = 'round';
+ context.strokeStyle = '#17251d';
+ context.lineWidth = 4;
+ context.stroke();
+ context.strokeStyle = '#b7f27d';
+ context.lineWidth = 2;
+ context.stroke();
}
context.restore();
diff --git a/web_interface/src/index.html b/web_interface/src/index.html
index 839586b..6a509f9 100644
--- a/web_interface/src/index.html
+++ b/web_interface/src/index.html
@@ -6,8 +6,8 @@
Mosfet · Minecraft Bot
-
-
+
+