<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Seed Map Dev Notes]]></title><description><![CDATA[Seed Map Dev Notes]]></description><link>https://seedmapdev.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 01:58:38 GMT</lastBuildDate><atom:link href="https://seedmapdev.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Keeping Map State in the URL Hash Without Flooding Browser History]]></title><description><![CDATA[Map apps feel much better when the address bar always describes what you are looking at. Someone can copy the URL, send it to a friend and the friend lands…]]></description><link>https://seedmapdev.hashnode.dev/keeping-map-state-in-the-url-hash-without-flooding-browser-history</link><guid isPermaLink="true">https://seedmapdev.hashnode.dev/keeping-map-state-in-the-url-hash-without-flooding-browser-history</guid><dc:creator><![CDATA[Seed Map]]></dc:creator><pubDate>Fri, 27 Nov 2026 11:35:35 GMT</pubDate><content:encoded><![CDATA[<p>Map apps feel much better when the address bar always describes what you are looking at. Someone can copy the URL, send it to a friend and the friend lands on exactly the same spot, at the same zoom, with the same settings. Here is a small pattern for keeping map state (seed, x, z, zoom, layer) in the URL hash with plain JavaScript, without spamming the browser history.</p>
<h2>What to store</h2>
<p>Keep the URL short and human-readable:</p>
<pre><code>#seed=-4172144997902289642&amp;x=1200&amp;z=-830&amp;zoom=3&amp;layer=structures
</code></pre>
<p>Use the hash rather than query parameters if your map runs entirely in the browser: changing the hash never triggers a page reload or a server request.</p>
<h2>Reading state from the URL</h2>
<pre><code class="language-js">const DEFAULTS = { seed: "0", x: 0, z: 0, zoom: 2, layer: "biomes" };

function readState() {
  const params = new URLSearchParams(location.hash.slice(1));
  const num = (key) =&gt; {
    const raw = params.get(key);
    const v = raw === null ? NaN : Number(raw);
    return Number.isFinite(v) ? v : DEFAULTS[key];
  };
  return {
    seed: params.get("seed") ?? DEFAULTS.seed,   // keep seeds as strings
    x: Math.round(num("x")),
    z: Math.round(num("z")),
    zoom: Math.min(8, Math.max(0, num("zoom"))),
    layer: ["biomes", "structures"].includes(params.get("layer"))
      ? params.get("layer") : DEFAULTS.layer,
  };
}
</code></pre>
<p>Two details matter here. Seeds are 64-bit integers, which do not fit safely in a JavaScript number, so keep them as strings (or BigInt). And always validate: a URL is user input, so clamp numbers and whitelist enum values.</p>
<h2>Writing state without flooding history</h2>
<p>Panning a map fires dozens of events per second. Writing each one with <code>location.hash = ...</code> would add a history entry every time, and the Back button would become useless. Use <code>history.replaceState</code> and debounce it:</p>
<pre><code class="language-js">let pending = null;

function writeState(state) {
  clearTimeout(pending);
  pending = setTimeout(() =&gt; {
    const params = new URLSearchParams({
      seed: state.seed,
      x: String(Math.round(state.x)),
      z: String(Math.round(state.z)),
      zoom: String(state.zoom),
      layer: state.layer,
    });
    history.replaceState(null, "", "#" + params.toString());
  }, 250);
}
</code></pre>
<p>If you do want Back to work for big changes, such as switching seeds, call <code>history.pushState</code> for those events only and keep <code>replaceState</code> for panning and zooming.</p>
<h2>Reacting to manual edits</h2>
<p>Users sometimes edit the hash by hand or paste a new link into the same tab. Listen for it:</p>
<pre><code class="language-js">window.addEventListener("hashchange", () =&gt; {
  const s = readState();
  map.setView(s.x, s.z, s.zoom);
  map.setSeed(s.seed);
  map.setLayer(s.layer);
});
</code></pre>
<p><code>replaceState</code> does not fire <code>hashchange</code>, so your own writes will not loop back into this handler.</p>
<h2>Putting it together</h2>
<pre><code class="language-js">const initial = readState();
map.setSeed(initial.seed);
map.setView(initial.x, initial.z, initial.zoom);
map.setLayer(initial.layer);

map.on("move", () =&gt; writeState(map.getState()));
</code></pre>
<p>That is all it takes for every view to be shareable. If you want to explore a seed rather than build a map, <a href="https://minecraftseedmap.org/">Minecraft Seed Map</a> shows biomes and structures for any seed in the browser.</p>
]]></content:encoded></item><item><title><![CDATA[Predicting Minecraft Structure Positions with Region Math in JavaScript]]></title><description><![CDATA[Minecraft does not scatter structures completely at random. In Java Edition, most structures use a "random spread" placement: the world is divided into…]]></description><link>https://seedmapdev.hashnode.dev/predicting-minecraft-structure-positions-with-region-math-in-javascript</link><guid isPermaLink="true">https://seedmapdev.hashnode.dev/predicting-minecraft-structure-positions-with-region-math-in-javascript</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[GameDev]]></category><dc:creator><![CDATA[Seed Map]]></dc:creator><pubDate>Thu, 26 Nov 2026 14:11:57 GMT</pubDate><content:encoded><![CDATA[<p>Minecraft does not scatter structures completely at random. In Java Edition, most structures use a "random spread" placement: the world is divided into square regions, and each region gets at most one attempt at that structure. Once you understand this, you can predict where a structure <em>can</em> appear without generating any terrain. This post walks through the idea and a small JavaScript implementation.</p>
<h2>Spacing, separation and salt</h2>
<p>Each structure set has three numbers:</p>
<table>
<thead>
<tr>
<th>Structure</th>
<th>Spacing (chunks)</th>
<th>Separation (chunks)</th>
<th>Salt</th>
</tr>
</thead>
<tbody><tr>
<td>Village</td>
<td>34</td>
<td>8</td>
<td>10387312</td>
</tr>
<tr>
<td>Desert pyramid</td>
<td>32</td>
<td>8</td>
<td>14357617</td>
</tr>
<tr>
<td>Pillager outpost</td>
<td>32</td>
<td>8</td>
<td>165745296</td>
</tr>
<tr>
<td>Woodland mansion</td>
<td>80</td>
<td>20</td>
<td>10387319</td>
</tr>
</tbody></table>
<ul>
<li><strong>Spacing</strong> is the size of a region, in chunks.</li>
<li><strong>Separation</strong> is the minimum gap. The attempt is placed somewhere in the first <code>spacing - separation</code> chunks of the region, so two neighbouring attempts are never closer than <code>separation</code> chunks.</li>
<li><strong>Salt</strong> makes each structure type use a different random sequence, so villages and pyramids do not always land on the same chunk.</li>
</ul>
<p>These values come from the vanilla data files and can change between versions, so always check them against the version you target.</p>
<h2>A Java-compatible random generator</h2>
<p>The game uses <code>java.util.Random</code>, a 48-bit linear congruential generator. JavaScript numbers cannot hold 64-bit products exactly, so use <code>BigInt</code>:</p>
<pre><code class="language-js">const MULT = 0x5DEECE66Dn;
const MASK = (1n &lt;&lt; 48n) - 1n;

class JavaRandom {
  constructor(seed) { this.seed = (BigInt(seed) ^ MULT) &amp; MASK; }

  next(bits) {
    this.seed = (this.seed * MULT + 0xBn) &amp; MASK;
    return Number(BigInt.asIntN(32, this.seed &gt;&gt; BigInt(48 - bits)));
  }

  nextInt(bound) {
    if ((bound &amp; -bound) === bound) {
      return Number((BigInt(bound) * BigInt(this.next(31))) &gt;&gt; 31n);
    }
    let bits, val;
    do {
      bits = this.next(31);
      val = bits % bound;
    } while (((bits - val + (bound - 1)) | 0) &lt; 0);
    return val;
  }
}
</code></pre>
<p>The <code>| 0</code> in the loop reproduces Java's 32-bit integer overflow check, which rejects a small biased range of values.</p>
<h2>Finding the candidate chunk for a region</h2>
<pre><code class="language-js">function regionSeed(worldSeed, regionX, regionZ, salt) {
  return BigInt.asIntN(64,
    BigInt(regionX) * 341873128712n +
    BigInt(regionZ) * 132897987541n +
    BigInt(worldSeed) + BigInt(salt));
}

function candidateChunk(worldSeed, regionX, regionZ, { spacing, separation, salt, triangular = false }) {
  const rng = new JavaRandom(regionSeed(worldSeed, regionX, regionZ, salt));
  const range = spacing - separation;
  const pick = () =&gt; triangular
    ? Math.floor((rng.nextInt(range) + rng.nextInt(range)) / 2)
    : rng.nextInt(range);
  const offX = pick();
  const offZ = pick();
  return { chunkX: regionX * spacing + offX, chunkZ: regionZ * spacing + offZ };
}
</code></pre>
<p>Woodland mansions use the triangular spread (two random numbers averaged), which pulls attempts towards the middle of each region. Most other structures use the linear version.</p>
<h2>Turning a block position into nearby candidates</h2>
<pre><code class="language-js">const floorDiv = (a, b) =&gt; Math.floor(a / b);

function nearbyCandidates(worldSeed, blockX, blockZ, cfg, radius = 1) {
  const rx = floorDiv(floorDiv(blockX, 16), cfg.spacing);
  const rz = floorDiv(floorDiv(blockZ, 16), cfg.spacing);
  const out = [];
  for (let dx = -radius; dx &lt;= radius; dx++) {
    for (let dz = -radius; dz &lt;= radius; dz++) {
      const c = candidateChunk(worldSeed, rx + dx, rz + dz, cfg);
      out.push({ x: c.chunkX * 16 + 8, z: c.chunkZ * 16 + 8 });
    }
  }
  return out.sort((a, b) =&gt;
    Math.hypot(a.x - blockX, a.z - blockZ) - Math.hypot(b.x - blockX, b.z - blockZ));
}
</code></pre>
<p>Use <code>Math.floor</code> rather than <code>Math.trunc</code> or bit shifts on the division: negative coordinates must round down, or every region west or north of the origin will be off by one.</p>
<h2>The catch: candidates are not structures</h2>
<p>A candidate chunk is only an <em>attempt</em>. The structure is generated only if the biome at that spot allows it (a mansion needs a dark forest, a desert pyramid needs a desert) and, for some structures, if other checks pass. Villages and outposts also interact: an outpost will not generate too close to a village. So a full finder has to run the biome generator too, and that is the expensive part.</p>
<p>That is why it is easier to check results on a finished tool. For example, you can <a href="https://minecraftseedmap.org/structures/woodland_mansion">locate a Woodland Mansion on the seed map</a> and compare the markers with the candidate chunks your code produces for the same seed and version. If your candidates line up with real mansions in dark forests, your random generator and region maths are correct.</p>
<h2>Where to go next</h2>
<ul>
<li>Add a biome lookup (or a lookup against exported biome data) to filter candidates.</li>
<li>Cache region results: the same region is queried over and over while a user pans a map.</li>
<li>Handle concentric-ring placement separately. Strongholds do not use random spread at all; they are placed in rings around the origin.</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Converting Minecraft Coordinates in JavaScript: Overworld, Nether and Chunks]]></title><description><![CDATA[Minecraft coordinates look simple, but a few details trip people up: floor division with negative numbers, the 8:1 Nether ratio, and chunk/region math…]]></description><link>https://seedmapdev.hashnode.dev/converting-minecraft-coordinates-in-javascript-overworld-nether-and-chunks</link><guid isPermaLink="true">https://seedmapdev.hashnode.dev/converting-minecraft-coordinates-in-javascript-overworld-nether-and-chunks</guid><dc:creator><![CDATA[Seed Map]]></dc:creator><pubDate>Tue, 24 Nov 2026 09:36:07 GMT</pubDate><content:encoded><![CDATA[<p>Minecraft coordinates look simple, but a few details trip people up: floor division with negative numbers, the 8:1 Nether ratio, and chunk/region math. Here is a small, tested set of JavaScript helpers.</p>
<h2>Floor division done right</h2>
<p>JavaScript's <code>Math.trunc</code> and the <code>|0</code> trick round toward zero, which is wrong for negative coordinates. Minecraft uses floor division.</p>
<pre><code class="language-javascript">const floorDiv = (a, b) =&gt; Math.floor(a / b);

floorDiv(-1, 16);  // -1 (correct)
(-1 / 16) | 0;     //  0 (wrong)
</code></pre>
<h2>Overworld and Nether</h2>
<pre><code class="language-javascript">function toNether({ x, y, z }) {
  return { x: floorDiv(x, 8), y, z: floorDiv(z, 8) };
}

function toOverworld({ x, y, z }) {
  return { x: x * 8, y, z: z * 8 };
}

toNether({ x: 2400, y: 70, z: -1601 }); // { x: 300, y: 70, z: -201 }
</code></pre>
<p>Y is not scaled. Portals search a 16-block radius in the Nether (128 in the Overworld), which is why portals built too close together link unpredictably.</p>
<h2>Block to chunk and region</h2>
<pre><code class="language-javascript">const blockToChunk = (x, z) =&gt; ({ cx: x &gt;&gt; 4, cz: z &gt;&gt; 4 });
const chunkToRegion = (cx, cz) =&gt; ({ rx: cx &gt;&gt; 5, rz: cz &gt;&gt; 5 });

blockToChunk(-1, 17);     // { cx: -1, cz: 1 }
chunkToRegion(-1, 1);     // { rx: -1, rz: 0 } -&gt; file r.-1.0.mca
</code></pre>
<p>Bit shifts are arithmetic for 32-bit ints in JS, so <code>&gt;&gt; 4</code> is a correct floor division by 16 for negative numbers within the world border.</p>
<h2>Chunk bounds</h2>
<pre><code class="language-javascript">function chunkBounds(cx, cz) {
  return {
    minX: cx * 16, maxX: cx * 16 + 15,
    minZ: cz * 16, maxZ: cz * 16 + 15,
  };
}
</code></pre>
<p>Handy for slime chunk checks, farm placement and spawn-chunk planning.</p>
<h2>Quick tests</h2>
<pre><code class="language-javascript">console.assert(toNether({ x: -9, y: 0, z: 0 }).x === -2);
console.assert(blockToChunk(15, 16).cz === 1);
console.assert(chunkToRegion(31, 32).rz === 1);
</code></pre>
<h2>When you do not want to code it</h2>
<p>For quick lookups while playing, a <a href="https://minecraftseedmap.org/tools/coordinate-converter">Minecraft coordinate converter</a> handles Overworld/Nether and chunk conversions without opening a console.</p>
<p>These few helpers cover most map tools, portal planners and world-editing scripts you will write.</p>
]]></content:encoded></item></channel></rss>