Skip to content

Commit 0c35d94

Browse files
rom1504botgithub-actions[bot]rom1504extremeheatSuperGamerTron
authored
🎈 1.21.9 (#1435)
* Update to version 1.21.9 * Fix branch name in CI workflow for minecraft-data * Update ci.yml * 1.21.9: Add lpvec3 data type (#1453) * Update to version 1.21.10 * Update ci.yml * Update ci.yml * Update packetTest.js types * Handle code_of_conduct packets * Implement lpVec3 * Update ci.yml --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: extremeheat <extreme@protonmail.ch> * optimise lpvec3 * lint * Update lpVec3.js * typo * Update lpVec3.js * Update lpVec3.js * ExplosionParticleEntry --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Romain Beaumont <romain.rom1@gmail.com> Co-authored-by: extremeheat <extreme@protonmail.ch> Co-authored-by: SuperGamerTron <45374546+SuperGamerTron@users.noreply.github.com>
1 parent bf89f7e commit 0c35d94

File tree

8 files changed

+151
-8
lines changed

8 files changed

+151
-8
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111
jobs:
1212
Lint:
1313
runs-on: ubuntu-latest
14-
1514
steps:
1615
- uses: actions/checkout@v2
1716
- name: Use Node.js 22.x

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Parse and serialize minecraft packets, plus authentication and encryption.
1818
1.15 (1.15, 1.15.1, 1.15.2), 1.16 (20w13b, 20w14a, 1.16-rc1, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5),
1919
1.17 (21w07a, 1.17, 1.17.1), 1.18 (1.18, 1.18.1 and 1.18.2),
2020
1.19 (1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4), 1.20 (1.20, 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6),
21-
1.21, 1.21.1, 1.21.3, 1.21.4, 1.21.5, 1.21.6, 1.21.8
21+
1.21, 1.21.1, 1.21.3, 1.21.4, 1.21.5, 1.21.6, 1.21.8, 1.21.9
2222
<!--add_next_version_above-->
2323

2424
* Parses all packets and emits events with packet fields as JavaScript

src/client/play.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ module.exports = function (client, options) {
5656
client.once('select_known_packs', () => {
5757
client.write('select_known_packs', { packs: [] })
5858
})
59+
client.once('code_of_conduct', () => {
60+
client.write('accept_code_of_conduct', {})
61+
})
5962
// Server should send finish_configuration on its own right after sending the client a dimension codec
6063
// for login (that has data about world height, world gen, etc) after getting a login success from client
6164
client.once('finish_configuration', () => {

src/datatypes/compiler-minecraft.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ if (n !== 0) {
7070
return { value: { ${opts.otherwise.name}: set }, size: accSize }
7171
}
7272
`.trim())
73-
}]
73+
}],
74+
lpVec3: ['native', minecraft.lpVec3[0]]
7475
},
7576
Write: {
7677
varlong: ['native', minecraft.varlong[1]],
@@ -135,7 +136,8 @@ if (${baseName} != null) {
135136
}
136137
return offset
137138
`.trim())
138-
}]
139+
}],
140+
lpVec3: ['native', minecraft.lpVec3[1]]
139141
},
140142
SizeOf: {
141143
varlong: ['native', minecraft.varlong[2]],
@@ -194,6 +196,7 @@ if (${baseName} != null) {
194196
}
195197
return size
196198
`.trim())
197-
}]
199+
}],
200+
lpVec3: ['native', minecraft.lpVec3[2]]
198201
}
199202
}

src/datatypes/lpVec3.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
const [readVarInt, writeVarInt, sizeOfVarInt] = require('protodef').types.varint
2+
3+
const DATA_BITS_MASK = 32767
4+
const MAX_QUANTIZED_VALUE = 32766.0
5+
const ABS_MIN_VALUE = 3.051944088384301e-5
6+
const ABS_MAX_VALUE = 1.7179869183e10
7+
8+
function sanitize (value) {
9+
if (isNaN(value)) return 0.0
10+
return Math.max(-ABS_MAX_VALUE, Math.min(value, ABS_MAX_VALUE))
11+
}
12+
13+
function pack (value) {
14+
return Math.round((value * 0.5 + 0.5) * MAX_QUANTIZED_VALUE)
15+
}
16+
17+
function unpack (packed, shift) {
18+
// We use division by power of 2 to simulate a 64-bit right shift
19+
const val = Math.floor(packed / Math.pow(2, shift)) & DATA_BITS_MASK
20+
const clamped = val > 32766 ? 32766 : val
21+
return (clamped * 2.0) / 32766.0 - 1.0
22+
}
23+
24+
function readLpVec3 (buffer, offset) {
25+
const a = buffer[offset]
26+
if (a === 0) {
27+
return { value: { x: 0, y: 0, z: 0 }, size: 1 }
28+
}
29+
30+
const b = buffer[offset + 1]
31+
const c = buffer.readUInt32LE(offset + 2)
32+
33+
// Combine into 48-bit safe integer (up to 2^53 is safe in JS)
34+
const packed = (c * 65536) + (b << 8) + a
35+
36+
let scale = a & 3
37+
let size = 6
38+
39+
if ((a & 4) === 4) {
40+
const { value: varIntVal, size: varIntSize } = readVarInt(buffer, offset + 6)
41+
scale = (varIntVal * 4) + scale
42+
size += varIntSize
43+
}
44+
45+
return {
46+
value: {
47+
x: unpack(packed, 3) * scale,
48+
y: unpack(packed, 18) * scale,
49+
z: unpack(packed, 33) * scale
50+
},
51+
size
52+
}
53+
}
54+
55+
function writeLpVec3 (value, buffer, offset) {
56+
const x = sanitize(value.x)
57+
const y = sanitize(value.y)
58+
const z = sanitize(value.z)
59+
60+
const max = Math.max(Math.abs(x), Math.abs(y), Math.abs(z))
61+
62+
if (max < ABS_MIN_VALUE) {
63+
buffer[offset] = 0
64+
return offset + 1
65+
}
66+
67+
const scale = Math.ceil(max)
68+
const needsContinuation = (scale & 3) !== scale
69+
const scaleByte = needsContinuation ? ((scale & 3) | 4) : (scale & 3)
70+
71+
const pX = pack(x / scale)
72+
const pY = pack(y / scale)
73+
const pZ = pack(z / scale)
74+
75+
// Layout:
76+
// [Z (15)] [Y (15)] [X (15)] [Flags (3)]
77+
78+
// low32 contains Flags(3), X(15), and the first 14 bits of Y (3+15+14 = 32)
79+
const low32 = (scaleByte | (pX << 3) | (pY << 18)) >>> 0
80+
81+
// high16 contains the 15th bit of Y and all 15 bits of Z
82+
const high16 = ((pY >> 14) & 0x01) | (pZ << 1)
83+
84+
buffer.writeUInt32LE(low32, offset)
85+
buffer.writeUInt16LE(high16, offset + 4)
86+
87+
if (needsContinuation) {
88+
return writeVarInt(Math.floor(scale / 4), buffer, offset + 6)
89+
}
90+
91+
return offset + 6
92+
}
93+
94+
function sizeOfLpVec3 (value) {
95+
const max = Math.max(Math.abs(value.x), Math.abs(value.y), Math.abs(value.z))
96+
if (max < ABS_MIN_VALUE) return 1
97+
98+
const scale = Math.ceil(max)
99+
if ((scale & 3) !== scale) {
100+
return 6 + sizeOfVarInt(Math.floor(scale / 4))
101+
}
102+
return 6
103+
}
104+
105+
module.exports = [readLpVec3, writeLpVec3, sizeOfLpVec3]

src/datatypes/minecraft.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ const nbt = require('prismarine-nbt')
44
const UUID = require('uuid-1345')
55
const zlib = require('zlib')
66
const [readVarInt, writeVarInt, sizeOfVarInt] = require('protodef').types.varint
7+
const [readLpVec3, writeLpVec3, sizeOfLpVec3] = require('./lpVec3')
78

89
module.exports = {
910
varlong: [readVarLong, writeVarLong, sizeOfVarLong],
1011
UUID: [readUUID, writeUUID, 16],
1112
compressedNbt: [readCompressedNbt, writeCompressedNbt, sizeOfCompressedNbt],
1213
restBuffer: [readRestBuffer, writeRestBuffer, sizeOfRestBuffer],
1314
entityMetadataLoop: [readEntityMetadata, writeEntityMetadata, sizeOfEntityMetadata],
14-
topBitSetTerminatedArray: [readTopBitSetTerminatedArray, writeTopBitSetTerminatedArray, sizeOfTopBitSetTerminatedArray]
15+
topBitSetTerminatedArray: [readTopBitSetTerminatedArray, writeTopBitSetTerminatedArray, sizeOfTopBitSetTerminatedArray],
16+
lpVec3: [readLpVec3, writeLpVec3, sizeOfLpVec3]
1517
}
1618
const PartialReadError = require('protodef').utils.PartialReadError
1719

src/version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

33
module.exports = {
4-
defaultVersion: '1.21.8',
5-
supportedVersions: ['1.7', '1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2', '1.20.4', '1.20.6', '1.21.1', '1.21.3', '1.21.4', '1.21.5', '1.21.6', '1.21.8']
4+
defaultVersion: '1.21.9',
5+
supportedVersions: ['1.7', '1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20', '1.20.1', '1.20.2', '1.20.4', '1.20.6', '1.21.1', '1.21.3', '1.21.4', '1.21.5', '1.21.6', '1.21.8', '1.21.9']
66
}

test/packetTest.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,37 @@ const values = {
415415
RecipeBookSetting: {
416416
open: false,
417417
filtering: false
418+
},
419+
lpVec3: { x: 0, y: 0, z: 0 },
420+
ExplosionParticleEntry: {
421+
data: { // ExplosionParticleInfo
422+
particle: {
423+
particleId: 0,
424+
data: null
425+
},
426+
speed: 0,
427+
scaling: 0
428+
},
429+
weight: 1
430+
},
431+
DebugSubscriptionDataType: 0,
432+
DebugSubscriptionUpdate: {
433+
type: 0
434+
},
435+
DebugSubscriptionEvent: {
436+
type: 0
437+
},
438+
RespawnData: {
439+
globalPos: {
440+
dimensionName: 'minecraft:overworld',
441+
location: { x: 0, y: 64, z: 0 }
442+
},
443+
yaw: 0,
444+
pitch: 0
445+
},
446+
GlobalPos: {
447+
dimensionName: 'minecraft:overworld',
448+
location: { x: 0, y: 64, z: 0 }
418449
}
419450
}
420451

0 commit comments

Comments
 (0)