@jsprismarine/spawning 0.23.0-unstable-20261121073620 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @jsprismarine/spawning
2
2
 
3
- ## 0.23.0-unstable-20261121073620
3
+ ## 0.23.0
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -9,11 +9,11 @@
9
9
  ### Patch Changes
10
10
 
11
11
  - [#3241](https://github.com/JSPrismarine/JSPrismarine/pull/3241) [`b41035b`](https://github.com/JSPrismarine/JSPrismarine/commit/b41035be9b61570008b3405aa169418b19081915) Thanks [@filiphsps](https://github.com/filiphsps)! - Errors carry a stable code and a link to their entry in the error reference at https://jsprismarine.dev/errors/, from their catalog in `@jsprismarine/errors`. Messages are unchanged.
12
- - Updated dependencies [[`60edd7a`](https://github.com/JSPrismarine/JSPrismarine/commit/60edd7a1234650367fe5c2406ee402641be33ed9), [`bf419b8`](https://github.com/JSPrismarine/JSPrismarine/commit/bf419b82bfea52c095ca09b02c1c4ac955ac1d0a), [`c8e1685`](https://github.com/JSPrismarine/JSPrismarine/commit/c8e1685ae8316255d39674af9d00ac8d778f674d), [`af89e9c`](https://github.com/JSPrismarine/JSPrismarine/commit/af89e9cadd3cfd2f6652e79ada341e12ac5f66c8), [`e304e99`](https://github.com/JSPrismarine/JSPrismarine/commit/e304e993f54ce5c92e7d4103008076e0d767c0b0), [`b41035b`](https://github.com/JSPrismarine/JSPrismarine/commit/b41035be9b61570008b3405aa169418b19081915), [`b41035b`](https://github.com/JSPrismarine/JSPrismarine/commit/b41035be9b61570008b3405aa169418b19081915), [`4bda824`](https://github.com/JSPrismarine/JSPrismarine/commit/4bda8241a8631da2d205133c85fd361871d6cf61), [`7e2e6f3`](https://github.com/JSPrismarine/JSPrismarine/commit/7e2e6f3cff1f20a11a3f59aac94c68a33fa71a35), [`3e71a8d`](https://github.com/JSPrismarine/JSPrismarine/commit/3e71a8dd75bd0a97e0f8587666f60f160844ff0b), [`586269e`](https://github.com/JSPrismarine/JSPrismarine/commit/586269e324cddfe57caf4206f387895cda6d479f), [`5d2fb0e`](https://github.com/JSPrismarine/JSPrismarine/commit/5d2fb0eb3730e59260a09e60c130e57e5fdb099c), [`936970c`](https://github.com/JSPrismarine/JSPrismarine/commit/936970c04f98b392e4b753f3c89224da3d03cb49), [`57caf26`](https://github.com/JSPrismarine/JSPrismarine/commit/57caf2632f92e5da55ce6eedc4eb0be3d66190d4), [`4b590cf`](https://github.com/JSPrismarine/JSPrismarine/commit/4b590cf6c529d17d8df20d8eab9b2157dc213a19), [`349a814`](https://github.com/JSPrismarine/JSPrismarine/commit/349a81448bfc8be2f901efe14527b8c9334f11eb), [`8876fae`](https://github.com/JSPrismarine/JSPrismarine/commit/8876faec0d0cbd4232446e5081338461e420450e), [`4e02e0b`](https://github.com/JSPrismarine/JSPrismarine/commit/4e02e0b72800bca87529013b34712be0df006874), [`56200a6`](https://github.com/JSPrismarine/JSPrismarine/commit/56200a61535d916f0c41a11d077752b194e4c08b), [`c500335`](https://github.com/JSPrismarine/JSPrismarine/commit/c5003358e3a7199593c6ddcdbe4bdf63f8c29fac), [`c500335`](https://github.com/JSPrismarine/JSPrismarine/commit/c5003358e3a7199593c6ddcdbe4bdf63f8c29fac), [`c500335`](https://github.com/JSPrismarine/JSPrismarine/commit/c5003358e3a7199593c6ddcdbe4bdf63f8c29fac), [`104bb4d`](https://github.com/JSPrismarine/JSPrismarine/commit/104bb4d4a3dbf7654c19294b4a1d66724d591ad3), [`6787fdd`](https://github.com/JSPrismarine/JSPrismarine/commit/6787fdd6ff50c80110f4951a0cea51214611eea0), [`3bb64da`](https://github.com/JSPrismarine/JSPrismarine/commit/3bb64dae3e3ea4e01bca0de55cdedfd678c9c3bf), [`e090dd7`](https://github.com/JSPrismarine/JSPrismarine/commit/e090dd75379edbfc415d84925e48af29aaa4864e), [`d1ad4e7`](https://github.com/JSPrismarine/JSPrismarine/commit/d1ad4e793e464ea4dc828c2c5467f6a4f4450802), [`6e758f9`](https://github.com/JSPrismarine/JSPrismarine/commit/6e758f9de80c357c12d992bf473f1bdac86fb274), [`93a1b61`](https://github.com/JSPrismarine/JSPrismarine/commit/93a1b610493f401c4ac62881f70b3dee8c882f33), [`e1c982e`](https://github.com/JSPrismarine/JSPrismarine/commit/e1c982eeed0dfd682b5680c45c69159e21fd9ec0), [`9579362`](https://github.com/JSPrismarine/JSPrismarine/commit/9579362b4070e246d6300d2f4e2dca2ab4715124), [`f18ef7c`](https://github.com/JSPrismarine/JSPrismarine/commit/f18ef7c595f58a267b5371baab96390d0282616d), [`cf88d2f`](https://github.com/JSPrismarine/JSPrismarine/commit/cf88d2f8c2184bd4e116db888d4528fa27f5338d), [`d6c69e4`](https://github.com/JSPrismarine/JSPrismarine/commit/d6c69e43051eb091f0b4a17c0f33799f5944caf3), [`0792e2a`](https://github.com/JSPrismarine/JSPrismarine/commit/0792e2a7e6e5e98729b80df412262fd549ea3cb9), [`1c3be54`](https://github.com/JSPrismarine/JSPrismarine/commit/1c3be5465a2865072ac0f16b4848ee0cd9b6b13a), [`db04d85`](https://github.com/JSPrismarine/JSPrismarine/commit/db04d8520c1d43b88196c14229f36f5c8e71f3c1)]:
13
- - @jsprismarine/errors@0.23.0-unstable-20261121073620
14
- - @jsprismarine/packs@0.23.0-unstable-20261121073620
15
- - @jsprismarine/entities@0.23.0-unstable-20261121073620
16
- - @jsprismarine/predicates@0.23.0-unstable-20261121073620
12
+ - Updated dependencies [[`60edd7a`](https://github.com/JSPrismarine/JSPrismarine/commit/60edd7a1234650367fe5c2406ee402641be33ed9), [`bf419b8`](https://github.com/JSPrismarine/JSPrismarine/commit/bf419b82bfea52c095ca09b02c1c4ac955ac1d0a), [`c8e1685`](https://github.com/JSPrismarine/JSPrismarine/commit/c8e1685ae8316255d39674af9d00ac8d778f674d), [`af89e9c`](https://github.com/JSPrismarine/JSPrismarine/commit/af89e9cadd3cfd2f6652e79ada341e12ac5f66c8), [`e304e99`](https://github.com/JSPrismarine/JSPrismarine/commit/e304e993f54ce5c92e7d4103008076e0d767c0b0), [`b41035b`](https://github.com/JSPrismarine/JSPrismarine/commit/b41035be9b61570008b3405aa169418b19081915), [`b41035b`](https://github.com/JSPrismarine/JSPrismarine/commit/b41035be9b61570008b3405aa169418b19081915), [`4bda824`](https://github.com/JSPrismarine/JSPrismarine/commit/4bda8241a8631da2d205133c85fd361871d6cf61), [`7e2e6f3`](https://github.com/JSPrismarine/JSPrismarine/commit/7e2e6f3cff1f20a11a3f59aac94c68a33fa71a35), [`3e71a8d`](https://github.com/JSPrismarine/JSPrismarine/commit/3e71a8dd75bd0a97e0f8587666f60f160844ff0b), [`586269e`](https://github.com/JSPrismarine/JSPrismarine/commit/586269e324cddfe57caf4206f387895cda6d479f), [`5d2fb0e`](https://github.com/JSPrismarine/JSPrismarine/commit/5d2fb0eb3730e59260a09e60c130e57e5fdb099c), [`936970c`](https://github.com/JSPrismarine/JSPrismarine/commit/936970c04f98b392e4b753f3c89224da3d03cb49), [`57caf26`](https://github.com/JSPrismarine/JSPrismarine/commit/57caf2632f92e5da55ce6eedc4eb0be3d66190d4), [`4b590cf`](https://github.com/JSPrismarine/JSPrismarine/commit/4b590cf6c529d17d8df20d8eab9b2157dc213a19), [`349a814`](https://github.com/JSPrismarine/JSPrismarine/commit/349a81448bfc8be2f901efe14527b8c9334f11eb), [`4e02e0b`](https://github.com/JSPrismarine/JSPrismarine/commit/4e02e0b72800bca87529013b34712be0df006874), [`56200a6`](https://github.com/JSPrismarine/JSPrismarine/commit/56200a61535d916f0c41a11d077752b194e4c08b), [`c500335`](https://github.com/JSPrismarine/JSPrismarine/commit/c5003358e3a7199593c6ddcdbe4bdf63f8c29fac), [`c500335`](https://github.com/JSPrismarine/JSPrismarine/commit/c5003358e3a7199593c6ddcdbe4bdf63f8c29fac), [`c500335`](https://github.com/JSPrismarine/JSPrismarine/commit/c5003358e3a7199593c6ddcdbe4bdf63f8c29fac), [`104bb4d`](https://github.com/JSPrismarine/JSPrismarine/commit/104bb4d4a3dbf7654c19294b4a1d66724d591ad3), [`6787fdd`](https://github.com/JSPrismarine/JSPrismarine/commit/6787fdd6ff50c80110f4951a0cea51214611eea0), [`3bb64da`](https://github.com/JSPrismarine/JSPrismarine/commit/3bb64dae3e3ea4e01bca0de55cdedfd678c9c3bf), [`e090dd7`](https://github.com/JSPrismarine/JSPrismarine/commit/e090dd75379edbfc415d84925e48af29aaa4864e), [`d1ad4e7`](https://github.com/JSPrismarine/JSPrismarine/commit/d1ad4e793e464ea4dc828c2c5467f6a4f4450802), [`6e758f9`](https://github.com/JSPrismarine/JSPrismarine/commit/6e758f9de80c357c12d992bf473f1bdac86fb274), [`93a1b61`](https://github.com/JSPrismarine/JSPrismarine/commit/93a1b610493f401c4ac62881f70b3dee8c882f33), [`e1c982e`](https://github.com/JSPrismarine/JSPrismarine/commit/e1c982eeed0dfd682b5680c45c69159e21fd9ec0), [`9579362`](https://github.com/JSPrismarine/JSPrismarine/commit/9579362b4070e246d6300d2f4e2dca2ab4715124), [`f18ef7c`](https://github.com/JSPrismarine/JSPrismarine/commit/f18ef7c595f58a267b5371baab96390d0282616d), [`cf88d2f`](https://github.com/JSPrismarine/JSPrismarine/commit/cf88d2f8c2184bd4e116db888d4528fa27f5338d), [`d6c69e4`](https://github.com/JSPrismarine/JSPrismarine/commit/d6c69e43051eb091f0b4a17c0f33799f5944caf3), [`0792e2a`](https://github.com/JSPrismarine/JSPrismarine/commit/0792e2a7e6e5e98729b80df412262fd549ea3cb9), [`1c3be54`](https://github.com/JSPrismarine/JSPrismarine/commit/1c3be5465a2865072ac0f16b4848ee0cd9b6b13a), [`db04d85`](https://github.com/JSPrismarine/JSPrismarine/commit/db04d8520c1d43b88196c14229f36f5c8e71f3c1)]:
13
+ - @jsprismarine/errors@0.23.0
14
+ - @jsprismarine/packs@0.23.0
15
+ - @jsprismarine/entities@0.23.0
16
+ - @jsprismarine/predicates@0.23.0
17
17
 
18
18
  ## 0.22.0
19
19
 
@@ -78,7 +78,7 @@ export declare const slimeSpawnRule: EngineSpawnRule;
78
78
  /**
79
79
  * Every engine rule vanilla needs, keyed by the entity it gates.
80
80
  *
81
- * {@link import('./spawner').Spawner} applies these by default. A host that
81
+ * {@link Spawner} applies these by default. A host that
82
82
  * wants a different set passes its own map, and a host that wants none passes
83
83
  * an empty one.
84
84
  */
@@ -128,7 +128,7 @@ var slimeSpawnRule = (at, { world, random }) => {
128
128
  /**
129
129
  * Every engine rule vanilla needs, keyed by the entity it gates.
130
130
  *
131
- * {@link import('./spawner').Spawner} applies these by default. A host that
131
+ * {@link Spawner} applies these by default. A host that
132
132
  * wants a different set passes its own map, and a host that wants none passes
133
133
  * an empty one.
134
134
  */
@@ -1 +1 @@
1
- {"version":3,"file":"engineRules.js","names":[],"sources":["../src/engineRules.ts"],"sourcesContent":["import type { RandomSource } from '@jsprismarine/predicates';\n\nimport type { SpawnPosition, SpawnWorld } from './world';\n\n/**\n * The spawn conditions Bedrock keeps in engine code rather than in\n * `spawn_rules/*.json`.\n *\n * The 24-component grammar cannot express a hash of the chunk coordinates or a\n * draw against the moon phase, so Mojang writes those in C++ and leaves the\n * JSON file as the coarse gate in front of them. `spawn_rules/slime.json` is\n * the clearest case: it carries no brightness filter, no height filter and a\n * weight of 100, which on its own lets a slime spawn in any `monster` biome in\n * daylight and fill the monster pool to its cap. The real rule is the function\n * at virtual address `0xbb80040` of BDS 1.26.51.1's `bedrock_server`, which\n * this module reimplements.\n *\n * A rule here runs after the JSON conditions pass and before the weighted\n * draw, so the file still decides the biomes, the difficulty and the weight,\n * and the code decides what the file cannot say.\n */\n\n/** What an engine rule reads besides the position it is deciding. */\nexport interface EngineSpawnContext {\n readonly world: SpawnWorld;\n /** The spawner's own source, so one seed still reproduces one set of spawns. */\n readonly random: RandomSource;\n}\n\n/**\n * One entity's engine-side spawn condition.\n *\n * @returns Whether the entity may spawn at the position, with the entity's\n * `spawn_rules/*.json` conditions already satisfied.\n */\nexport type EngineSpawnRule = (at: SpawnPosition, context: EngineSpawnContext) => boolean;\n\n/** How far into the state a twist step reads its second word. */\nconst TWISTER_OFFSET = 397;\n\n/** The multiplier of the twister's seeding recurrence, Matsumoto and Nishimura's 1812433253. */\nconst TWISTER_SEED_MULTIPLIER = 0x6c078965;\n\n/** The twist step's tempering matrix. */\nconst TWISTER_MATRIX = 0x9908b0df;\n\n/**\n * The first 32-bit draw of a Mersenne twister seeded with one value.\n *\n * Only the first draw exists because that is all the slime chunk rule takes.\n * The twist of word zero reads words zero, one and {@link TWISTER_OFFSET}, so\n * the seeding recurrence stops one word past the offset rather than filling\n * all 624 words of a full state. Bedrock's own copy stops in the same place.\n */\nconst firstTwisterDraw = (seed: number): number => {\n const state = new Uint32Array(TWISTER_OFFSET + 2);\n state[0] = seed;\n for (let index = 1; index < state.length; index += 1) {\n const previous = state[index - 1]!;\n state[index] = (Math.imul(TWISTER_SEED_MULTIPLIER, previous ^ (previous >>> 30)) + index) >>> 0;\n }\n\n const mixed = (state[0]! & 0x80000000) | (state[1]! & 0x7fffffff);\n let draw = state[TWISTER_OFFSET]! ^ (mixed >>> 1) ^ ((mixed & 1) === 0 ? 0 : TWISTER_MATRIX);\n\n draw ^= draw >>> 11;\n draw ^= (draw << 7) & 0x9d2c5680;\n draw ^= (draw << 15) & 0xefc60000;\n draw ^= draw >>> 18;\n return draw >>> 0;\n};\n\n/**\n * The multiplier Bedrock hashes a chunk's X coordinate by. It is the engine's\n * general-purpose hash multiplier rather than anything about slimes.\n */\nconst SLIME_CHUNK_MULTIPLIER = 0x1f1f1f1f;\n\n/** One chunk in ten holds slimes, which is the divisor of the draw. */\nconst SLIME_CHUNK_IN = 10;\n\n/** How many answers {@link isSlimeChunk} keeps before it starts over. */\nconst SLIME_CHUNK_MEMO_LIMIT = 4096;\n\nconst slimeChunkMemo = new Map<number, boolean>();\n\n/**\n * Whether a chunk is a slime chunk.\n *\n * Bedrock seeds a Mersenne twister with `chunkX * 0x1f1f1f1f ^ chunkZ` and\n * takes its first draw modulo ten. The world seed is not part of it, which is\n * why a Bedrock slime farm sits at the same chunk coordinates in every world\n * and why Java's seeded formula is the wrong answer here.\n *\n * @param chunkX - The chunk's X coordinate, which is a block X shifted right by four.\n * @param chunkZ - The chunk's Z coordinate.\n */\nexport const isSlimeChunk = (chunkX: number, chunkZ: number): boolean => {\n const seed = (Math.imul(chunkX, SLIME_CHUNK_MULTIPLIER) ^ chunkZ) >>> 0;\n const known = slimeChunkMemo.get(seed);\n if (known !== undefined) return known;\n\n const answer = firstTwisterDraw(seed) % SLIME_CHUNK_IN === 0;\n if (slimeChunkMemo.size >= SLIME_CHUNK_MEMO_LIMIT) slimeChunkMemo.clear();\n slimeChunkMemo.set(seed, answer);\n return answer;\n};\n\n/** How many ticks one Minecraft day lasts. */\nconst DAY_TICKS = 24000;\n\n/**\n * How bright the moon is at each of its eight phases, starting at the full\n * moon. The swamp branch of the slime rule draws against this number, so a\n * swamp spawns no slimes at all on a new moon.\n */\nexport const MOON_BRIGHTNESS: readonly number[] = [1, 0.75, 0.5, 0.25, 0, 0.25, 0.5, 0.75];\n\n/**\n * The moon phase at one world time.\n *\n * @param time - The world's age in ticks, which is never negative on a running server.\n * @returns A phase from 0, the full moon, to 7.\n */\nexport const moonPhase = (time: number): number => Math.abs(Math.trunc(time / DAY_TICKS)) % MOON_BRIGHTNESS.length;\n\n/** The highest Y at which the slime chunk branch applies. */\nconst SLIME_CHUNK_CEILING = 38;\n\n/** The lowest Y of the swamp branch's band. */\nconst SLIME_SWAMP_FLOOR = 50;\n\n/** The highest Y of the swamp branch's band. */\nconst SLIME_SWAMP_CEILING = 68;\n\n/**\n * The light a swamp slime tolerates, before the extra draw.\n *\n * It is an early exit rather than a second condition: the draw it guards is\n * over `[0, 8)`, so a light above seven already fails it.\n */\nconst SLIME_SWAMP_LIGHT_CEILING = 7;\n\n/** The width of the draw the swamp branch compares the light against. */\nconst SLIME_SWAMP_LIGHT_DRAW = 8;\n\n/**\n * The biome tag the swamp branch reads. Three vanilla biomes carry it:\n * `swampland`, `swampland_mutated` and `mangrove_swamp`.\n */\nexport const SLIME_SURFACE_BIOME_TAG = 'spawns_slimes_on_surface';\n\n/**\n * Where a slime may spawn, which `spawn_rules/slime.json` does not say.\n *\n * Two branches, as Bedrock writes them. At Y 38 and below the position has to\n * be in a slime chunk and nothing else is asked, which is why a slime farm is\n * dug out rather than lit up. Above that the position has to be in a swamp\n * between Y 50 and Y 68, dark enough, and lucky against the moon phase.\n * Everything in between, and every lit surface, spawns no slimes at all.\n *\n * The one divergence from the Bedrock function is the position the biome tag\n * is read at. Bedrock reads it one block higher than the spawn position; this\n * reads it at the spawn position, because a biome boundary is the only place\n * the two can differ and neither answer is more correct there.\n */\nexport const slimeSpawnRule: EngineSpawnRule = (at, { world, random }) => {\n if (at.y <= SLIME_CHUNK_CEILING) return isSlimeChunk(at.x >> 4, at.z >> 4);\n\n if (at.y < SLIME_SWAMP_FLOOR || at.y > SLIME_SWAMP_CEILING) return false;\n\n const light = world.light(at);\n if (light > SLIME_SWAMP_LIGHT_CEILING) return false;\n if (light > random.nextInt(SLIME_SWAMP_LIGHT_DRAW)) return false;\n\n if (random.nextFloat() >= MOON_BRIGHTNESS[moonPhase(world.age())]!) return false;\n\n return world.biomeTags(at).includes(SLIME_SURFACE_BIOME_TAG);\n};\n\n/**\n * Every engine rule vanilla needs, keyed by the entity it gates.\n *\n * {@link import('./spawner').Spawner} applies these by default. A host that\n * wants a different set passes its own map, and a host that wants none passes\n * an empty one.\n */\nexport const VANILLA_ENGINE_SPAWN_RULES: ReadonlyMap<string, EngineSpawnRule> = new Map([\n ['minecraft:slime', slimeSpawnRule]\n]);\n"],"mappings":";;AAsCA,IAAM,iBAAiB;;AAGvB,IAAM,0BAA0B;;AAGhC,IAAM,iBAAiB;;;;;;;;;AAUvB,IAAM,oBAAoB,SAAyB;CAC/C,MAAM,wBAAQ,IAAI,YAAY,GAAkB;CAChD,MAAM,KAAK;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a;CACtE,IAAI,GAAG,KAAK,qBAAqB,OAAO,aAAa,GAAG,KAAK,GAAG,GAAG,KAAK,CAAC;CAEzE,IAAI,GAAG,IAAI,qBAAqB,GAAG,IAAI,qBAAqB,OAAO;CAEnE,MAAM,QAAQ,MAAM,MAAM,EAAE;CAC5B,IAAI,QAAQ,2BAA2B,OAAO;CAC9C,IAAI,QAAQ,OAAO,QAAQ,sBAAsB,GAAG,OAAO;CAE3D,IAAI,OAAO,UAAU,KAAK,gBAAgB,UAAU,MAAM,IAAI,CAAC,IAAK,OAAO;CAE3E,OAAO,MAAM,UAAU,EAAE,CAAC,CAAC,SAAS,uBAAuB;AAC/D;;;;;;;;AASA,IAAa,6CAAmE,IAAI,IAAI,CACpF,CAAC,mBAAmB,cAAc,CACtC,CAAC"}
1
+ {"version":3,"file":"engineRules.js","names":[],"sources":["../src/engineRules.ts"],"sourcesContent":["import type { RandomSource } from '@jsprismarine/predicates';\n\nimport type { SpawnPosition, SpawnWorld } from './world';\n\n/**\n * The spawn conditions Bedrock keeps in engine code rather than in\n * `spawn_rules/*.json`.\n *\n * The 24-component grammar cannot express a hash of the chunk coordinates or a\n * draw against the moon phase, so Mojang writes those in C++ and leaves the\n * JSON file as the coarse gate in front of them. `spawn_rules/slime.json` is\n * the clearest case: it carries no brightness filter, no height filter and a\n * weight of 100, which on its own lets a slime spawn in any `monster` biome in\n * daylight and fill the monster pool to its cap. The real rule is the function\n * at virtual address `0xbb80040` of BDS 1.26.51.1's `bedrock_server`, which\n * this module reimplements.\n *\n * A rule here runs after the JSON conditions pass and before the weighted\n * draw, so the file still decides the biomes, the difficulty and the weight,\n * and the code decides what the file cannot say.\n */\n\n/** What an engine rule reads besides the position it is deciding. */\nexport interface EngineSpawnContext {\n readonly world: SpawnWorld;\n /** The spawner's own source, so one seed still reproduces one set of spawns. */\n readonly random: RandomSource;\n}\n\n/**\n * One entity's engine-side spawn condition.\n *\n * @returns Whether the entity may spawn at the position, with the entity's\n * `spawn_rules/*.json` conditions already satisfied.\n */\nexport type EngineSpawnRule = (at: SpawnPosition, context: EngineSpawnContext) => boolean;\n\n/** How far into the state a twist step reads its second word. */\nconst TWISTER_OFFSET = 397;\n\n/** The multiplier of the twister's seeding recurrence, Matsumoto and Nishimura's 1812433253. */\nconst TWISTER_SEED_MULTIPLIER = 0x6c078965;\n\n/** The twist step's tempering matrix. */\nconst TWISTER_MATRIX = 0x9908b0df;\n\n/**\n * The first 32-bit draw of a Mersenne twister seeded with one value.\n *\n * Only the first draw exists because that is all the slime chunk rule takes.\n * The twist of word zero reads words zero, one and {@link TWISTER_OFFSET}, so\n * the seeding recurrence stops one word past the offset rather than filling\n * all 624 words of a full state. Bedrock's own copy stops in the same place.\n */\nconst firstTwisterDraw = (seed: number): number => {\n const state = new Uint32Array(TWISTER_OFFSET + 2);\n state[0] = seed;\n for (let index = 1; index < state.length; index += 1) {\n const previous = state[index - 1]!;\n state[index] = (Math.imul(TWISTER_SEED_MULTIPLIER, previous ^ (previous >>> 30)) + index) >>> 0;\n }\n\n const mixed = (state[0]! & 0x80000000) | (state[1]! & 0x7fffffff);\n let draw = state[TWISTER_OFFSET]! ^ (mixed >>> 1) ^ ((mixed & 1) === 0 ? 0 : TWISTER_MATRIX);\n\n draw ^= draw >>> 11;\n draw ^= (draw << 7) & 0x9d2c5680;\n draw ^= (draw << 15) & 0xefc60000;\n draw ^= draw >>> 18;\n return draw >>> 0;\n};\n\n/**\n * The multiplier Bedrock hashes a chunk's X coordinate by. It is the engine's\n * general-purpose hash multiplier rather than anything about slimes.\n */\nconst SLIME_CHUNK_MULTIPLIER = 0x1f1f1f1f;\n\n/** One chunk in ten holds slimes, which is the divisor of the draw. */\nconst SLIME_CHUNK_IN = 10;\n\n/** How many answers {@link isSlimeChunk} keeps before it starts over. */\nconst SLIME_CHUNK_MEMO_LIMIT = 4096;\n\nconst slimeChunkMemo = new Map<number, boolean>();\n\n/**\n * Whether a chunk is a slime chunk.\n *\n * Bedrock seeds a Mersenne twister with `chunkX * 0x1f1f1f1f ^ chunkZ` and\n * takes its first draw modulo ten. The world seed is not part of it, which is\n * why a Bedrock slime farm sits at the same chunk coordinates in every world\n * and why Java's seeded formula is the wrong answer here.\n *\n * @param chunkX - The chunk's X coordinate, which is a block X shifted right by four.\n * @param chunkZ - The chunk's Z coordinate.\n */\nexport const isSlimeChunk = (chunkX: number, chunkZ: number): boolean => {\n const seed = (Math.imul(chunkX, SLIME_CHUNK_MULTIPLIER) ^ chunkZ) >>> 0;\n const known = slimeChunkMemo.get(seed);\n if (known !== undefined) return known;\n\n const answer = firstTwisterDraw(seed) % SLIME_CHUNK_IN === 0;\n if (slimeChunkMemo.size >= SLIME_CHUNK_MEMO_LIMIT) slimeChunkMemo.clear();\n slimeChunkMemo.set(seed, answer);\n return answer;\n};\n\n/** How many ticks one Minecraft day lasts. */\nconst DAY_TICKS = 24000;\n\n/**\n * How bright the moon is at each of its eight phases, starting at the full\n * moon. The swamp branch of the slime rule draws against this number, so a\n * swamp spawns no slimes at all on a new moon.\n */\nexport const MOON_BRIGHTNESS: readonly number[] = [1, 0.75, 0.5, 0.25, 0, 0.25, 0.5, 0.75];\n\n/**\n * The moon phase at one world time.\n *\n * @param time - The world's age in ticks, which is never negative on a running server.\n * @returns A phase from 0, the full moon, to 7.\n */\nexport const moonPhase = (time: number): number => Math.abs(Math.trunc(time / DAY_TICKS)) % MOON_BRIGHTNESS.length;\n\n/** The highest Y at which the slime chunk branch applies. */\nconst SLIME_CHUNK_CEILING = 38;\n\n/** The lowest Y of the swamp branch's band. */\nconst SLIME_SWAMP_FLOOR = 50;\n\n/** The highest Y of the swamp branch's band. */\nconst SLIME_SWAMP_CEILING = 68;\n\n/**\n * The light a swamp slime tolerates, before the extra draw.\n *\n * It is an early exit rather than a second condition: the draw it guards is\n * over `[0, 8)`, so a light above seven already fails it.\n */\nconst SLIME_SWAMP_LIGHT_CEILING = 7;\n\n/** The width of the draw the swamp branch compares the light against. */\nconst SLIME_SWAMP_LIGHT_DRAW = 8;\n\n/**\n * The biome tag the swamp branch reads. Three vanilla biomes carry it:\n * `swampland`, `swampland_mutated` and `mangrove_swamp`.\n */\nexport const SLIME_SURFACE_BIOME_TAG = 'spawns_slimes_on_surface';\n\n/**\n * Where a slime may spawn, which `spawn_rules/slime.json` does not say.\n *\n * Two branches, as Bedrock writes them. At Y 38 and below the position has to\n * be in a slime chunk and nothing else is asked, which is why a slime farm is\n * dug out rather than lit up. Above that the position has to be in a swamp\n * between Y 50 and Y 68, dark enough, and lucky against the moon phase.\n * Everything in between, and every lit surface, spawns no slimes at all.\n *\n * The one divergence from the Bedrock function is the position the biome tag\n * is read at. Bedrock reads it one block higher than the spawn position; this\n * reads it at the spawn position, because a biome boundary is the only place\n * the two can differ and neither answer is more correct there.\n */\nexport const slimeSpawnRule: EngineSpawnRule = (at, { world, random }) => {\n if (at.y <= SLIME_CHUNK_CEILING) return isSlimeChunk(at.x >> 4, at.z >> 4);\n\n if (at.y < SLIME_SWAMP_FLOOR || at.y > SLIME_SWAMP_CEILING) return false;\n\n const light = world.light(at);\n if (light > SLIME_SWAMP_LIGHT_CEILING) return false;\n if (light > random.nextInt(SLIME_SWAMP_LIGHT_DRAW)) return false;\n\n if (random.nextFloat() >= MOON_BRIGHTNESS[moonPhase(world.age())]!) return false;\n\n return world.biomeTags(at).includes(SLIME_SURFACE_BIOME_TAG);\n};\n\n/**\n * Every engine rule vanilla needs, keyed by the entity it gates.\n *\n * {@link Spawner} applies these by default. A host that\n * wants a different set passes its own map, and a host that wants none passes\n * an empty one.\n */\nexport const VANILLA_ENGINE_SPAWN_RULES: ReadonlyMap<string, EngineSpawnRule> = new Map([\n ['minecraft:slime', slimeSpawnRule]\n]);\n"],"mappings":";;AAsCA,IAAM,iBAAiB;;AAGvB,IAAM,0BAA0B;;AAGhC,IAAM,iBAAiB;;;;;;;;;AAUvB,IAAM,oBAAoB,SAAyB;CAC/C,MAAM,wBAAQ,IAAI,YAAY,GAAkB;CAChD,MAAM,KAAK;CACX,KAA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IAAI,GAAG,KAAK,qBAAqB,OAAO,aAAa,GAAG,KAAK,GAAG,GAAG,KAAK,CAAC;CAEzE,IAAI,GAAG,IAAI,qBAAqB,GAAG,IAAI,qBAAqB,OAAO;CAEnE,MAAM,QAAQ,MAAM,MAAM,EAAE;CAC5B,IAAI,QAAQ,2BAA2B,OAAO;CAC9C,IAAI,QAAQ,OAAO,QAAQ,sBAAsB,GAAG,OAAO;CAE3D,IAAI,OAAO,UAAU,KAAK,gBAAgB,UAAU,MAAM,IAAI,CAAC,IAAK,OAAO;CAE3E,OAAO,MAAM,UAAU,EAAE,CAAC,CAAC,SAAS,uBAAuB;AAC/D;;;;;;;;AASA,IAAa,6CAAmE,IAAI,IAAI,CACpF,CAAC,mBAAmB,cAAc,CACtC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsprismarine/spawning",
3
- "version": "0.23.0-unstable-20261121073620",
3
+ "version": "0.23.0",
4
4
  "description": "Bedrock spawn rules: the 24-component grammar, the condition evaluator, population pools and the spawn loop.",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -46,10 +46,10 @@
46
46
  },
47
47
  "homepage": "https://github.com/JSPrismarine/JSPrismarine/tree/master/packages/spawning",
48
48
  "dependencies": {
49
- "@jsprismarine/entities": "0.23.0-unstable-20261121073620",
50
- "@jsprismarine/errors": "0.23.0-unstable-20261121073620",
51
- "@jsprismarine/packs": "0.23.0-unstable-20261121073620",
52
- "@jsprismarine/predicates": "0.23.0-unstable-20261121073620"
49
+ "@jsprismarine/entities": "0.23.0",
50
+ "@jsprismarine/errors": "0.23.0",
51
+ "@jsprismarine/packs": "0.23.0",
52
+ "@jsprismarine/predicates": "0.23.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "26.6.6",