@zardoy/flying-squid 0.0.126 → 0.0.127

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.
@@ -659,6 +659,26 @@ const player = function (player, serv, settings) {
659
659
  });
660
660
  }
661
661
  };
662
+ /**
663
+ * Light arrays of the 1.18+ chunk packet in the vanilla byte order (nibbles, low nibble first). prismarine-chunk's dumpLight() writes every
664
+ * section with BitArray.writeBuffer (big-endian longs) while loadParsedLight() on the client reads vanilla bytes, so light reached the client
665
+ * scrambled inside every 16 cells along x (only 1/8 of the cells kept their value). The BitArray's Uint32Array already holds the vanilla layout
666
+ * on little-endian hosts: its bytes are copied as they are (also cheaper than the encoder).
667
+ */
668
+ const LITTLE_ENDIAN = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
669
+ const packetLightArrays = (chunk, dumped) => {
670
+ if (!LITTLE_ENDIAN || !chunk.skyLightSections || !chunk.blockLightSections)
671
+ return { skyLight: dumped.skyLight, blockLight: dumped.blockLight };
672
+ const bytes = (sections, mask) => {
673
+ const out = [];
674
+ sections.forEach((section, index) => {
675
+ if (section !== null && mask.get(index))
676
+ out.push(new Uint8Array(section.data.buffer, section.data.byteOffset, section.data.byteLength).slice());
677
+ });
678
+ return out;
679
+ };
680
+ return { skyLight: bytes(chunk.skyLightSections, chunk.skyLightMask), blockLight: bytes(chunk.blockLightSections, chunk.blockLightMask) };
681
+ };
662
682
  player.sendChunk = async (chunkX, chunkZ, column) => {
663
683
  await player.behavior('sendChunk', {
664
684
  x: chunkX,
@@ -668,7 +688,7 @@ const player = function (player, serv, settings) {
668
688
  serv._finishPlayerChunkLoading(chunkX, chunkZ, player);
669
689
  const newLightsFormat = serv.supportFeature('newLightingDataFormat');
670
690
  const dumpedLights = chunk.dumpLight();
671
- const newLightsData = newLightsFormat ? { skyLight: dumpedLights.skyLight, blockLight: dumpedLights.blockLight } : undefined;
691
+ const newLightsData = newLightsFormat ? packetLightArrays(chunk, dumpedLights) : undefined;
672
692
  const chunkBuffer = chunk.dump();
673
693
  const bitMap = chunk.getMask();
674
694
  player._client.write('map_chunk', {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zardoy/flying-squid",
3
3
  "description": "A minecraft server written in TS",
4
- "version": "0.0.126",
4
+ "version": "0.0.127",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "bin": "dist/app.js",