Skip to content

Commit 0bfd970

Browse files
extremeheatrom1504
andauthored
1.21.6 (#1416)
* start 1.21.6 * fix packettest * update * fix * Update ci.yml --------- Co-authored-by: Romain Beaumont <romain.rom1@gmail.com>
1 parent b404bca commit 0bfd970

File tree

7 files changed

+267
-3
lines changed

7 files changed

+267
-3
lines changed

.github/CROSS_REPO_TRIGGER.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Cross-Repository Workflow Trigger Setup
2+
3+
This document explains how to set up cross-repository workflow triggering between the minecraft-data repository and this repository.
4+
5+
## Overview
6+
7+
The workflow `update-from-minecraft-data.yml` can be triggered from the minecraft-data repository in two ways:
8+
9+
1. **Manual Workflow Dispatch** - Triggered manually or programmatically
10+
2. **Repository Dispatch** - Triggered via webhook/API call
11+
12+
## Setup in minecraft-data repository
13+
14+
### Method 1: Workflow Dispatch (Recommended)
15+
16+
Add this step to a workflow in the minecraft-data repository:
17+
18+
```yaml
19+
- name: Trigger update in node-minecraft-protocol
20+
uses: actions/github-script@v7
21+
with:
22+
github-token: ${{ secrets.CROSS_REPO_TOKEN }}
23+
script: |
24+
await github.rest.actions.createWorkflowDispatch({
25+
owner: 'extremeheat',
26+
repo: 'node-minecraft-protocol',
27+
workflow_id: 'update-from-minecraft-data.yml',
28+
ref: 'master', // or the target branch
29+
inputs: {
30+
trigger_source: 'minecraft-data',
31+
trigger_reason: 'data_update',
32+
data_version: '${{ steps.get_version.outputs.version }}' // or your version variable
33+
}
34+
});
35+
```
36+
37+
### Method 2: Repository Dispatch
38+
39+
```yaml
40+
- name: Trigger update in node-minecraft-protocol
41+
uses: actions/github-script@v7
42+
with:
43+
github-token: ${{ secrets.CROSS_REPO_TOKEN }}
44+
script: |
45+
await github.rest.repos.createDispatchEvent({
46+
owner: 'extremeheat',
47+
repo: 'node-minecraft-protocol',
48+
event_type: 'minecraft-data-update',
49+
client_payload: {
50+
repository: 'minecraft-data',
51+
reason: 'data_update',
52+
version: '${{ steps.get_version.outputs.version }}'
53+
}
54+
});
55+
```
56+
57+
## Required Secrets
58+
59+
You need to create a Personal Access Token (PAT) with the following permissions:
60+
- `repo` scope (for private repositories)
61+
- `public_repo` scope (for public repositories)
62+
- `actions:write` permission
63+
64+
Add this token as a secret named `CROSS_REPO_TOKEN` in the minecraft-data repository.
65+
66+
## Token Setup Steps
67+
68+
1. Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)
69+
2. Generate a new token with appropriate permissions
70+
3. Add the token as `CROSS_REPO_TOKEN` secret in minecraft-data repository settings
71+
72+
## Customizing the Updator Script
73+
74+
The updator script (`.github/helper/updator.js`) can be customized to:
75+
76+
- Download and process minecraft-data updates
77+
- Update protocol definitions
78+
- Run tests to verify compatibility
79+
- Create pull requests for review
80+
- Send notifications
81+
82+
## Testing
83+
84+
You can test the workflow manually by:
85+
86+
1. Going to the Actions tab in this repository
87+
2. Selecting "Update from minecraft-data" workflow
88+
3. Clicking "Run workflow"
89+
4. Providing test inputs
90+
91+
## Security Considerations
92+
93+
- Use repository secrets for sensitive tokens
94+
- Limit token permissions to minimum required
95+
- Consider using short-lived tokens or GitHub Apps for enhanced security
96+
- Review and approve automatic commits/PRs if needed

.github/helper/updator.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Updator script triggered from minecraft-data repository
4+
* This script can be customized to handle updates from minecraft-data
5+
*/
6+
const github = require('gh-helpers')()
7+
const fs = require('fs')
8+
const cp = require('child_process')
9+
const { join } = require('path')
10+
const exec = (cmd) => github.mock ? console.log('> ', cmd) : (console.log('> ', cmd), cp.execSync(cmd, { stdio: 'inherit' }))
11+
12+
console.log('Starting update process...')
13+
const triggerBranch = process.env.TRIGGER_SOURCE
14+
const newVersion = process.env.DATA_VERSION
15+
const onBehalfOf = process.env.TRIGGER_REASON || 'workflow_dispatch'
16+
console.log('Trigger reason:', onBehalfOf)
17+
console.log('New version:', newVersion)
18+
19+
if (!newVersion) {
20+
console.error('No new version provided. Exiting...')
21+
process.exit(1)
22+
}
23+
24+
async function main () {
25+
const currentSupportedPath = require.resolve('../../src/version.js')
26+
const readmePath = join(__dirname, '../../docs/README.md')
27+
const ciPath = join(__dirname, '../../.github/workflows/ci.yml')
28+
29+
// Update the version.js
30+
const currentSupportedVersion = require('../../src/version.js')
31+
const currentContents = fs.readFileSync(currentSupportedPath, 'utf8')
32+
console.log('Current supported version:', currentContents)
33+
const newContents = currentContents.includes(newVersion)
34+
? currentContents
35+
: currentContents
36+
.replace(`: '${currentSupportedVersion.defaultVersion}'`, `: '${newVersion}'`)
37+
.replace(`, '${currentSupportedVersion.defaultVersion}'`, `, '${currentSupportedVersion.defaultVersion}', '${newVersion}'`)
38+
39+
// Update the README.md
40+
const currentContentsReadme = fs.readFileSync(readmePath, 'utf8')
41+
if (!currentContentsReadme.includes(newVersion)) {
42+
const newReadmeContents = currentContentsReadme.replace(' <!-- NEXT_VERSION -->', `, ${newVersion} <!-- NEXT_VERSION -->`)
43+
fs.writeFileSync(readmePath, newReadmeContents)
44+
console.log('Updated README with new version:', newVersion)
45+
}
46+
fs.writeFileSync(currentSupportedPath, newContents)
47+
48+
// Update the CI workflow
49+
const currentContentsCI = fs.readFileSync(ciPath, 'utf8')
50+
if (!currentContentsCI.includes(newVersion)) {
51+
const newCIContents = currentContentsCI.replace(
52+
' run: npm install', `
53+
run: npm install
54+
- run: cd node_modules && cd minecraft-data && mv minecraft-data minecraft-data-old && git clone -b ${triggerBranch} https://github.com/PrismarineJS/minecraft-data --depth 1 && node bin/generate_data.js
55+
- run: curl -o node_modules/protodef/src/serializer.js https://raw.githubusercontent.com/extremeheat/node-protodef/refs/heads/dlog/src/serializer.js && curl -o node_modules/protodef/src/compiler.js https://raw.githubusercontent.com/extremeheat/node-protodef/refs/heads/dlog/src/compiler.js
56+
`)
57+
fs.writeFileSync(ciPath, newCIContents)
58+
console.log('Updated CI workflow with new version:', newVersion)
59+
}
60+
61+
const branchName = 'pc' + newVersion.replace(/[^a-zA-Z0-9_]/g, '.')
62+
exec(`git checkout -b ${branchName}`)
63+
exec('git add --all')
64+
exec(`git commit -m "Update to version ${newVersion}"`)
65+
exec(`git push origin ${branchName}`)
66+
// createPullRequest(title: string, body: string, fromBranch: string, intoBranch?: string): Promise<{ number: number, url: string }>;
67+
const pr = await github.createPullRequest(
68+
`${newVersion} updates`,
69+
`Automatically generated PR for Minecraft version ${newVersion}.\n\nRef: ${onBehalfOf}`,
70+
branchName,
71+
'master'
72+
)
73+
console.log(`Pull request created: ${pr.url} (PR #${pr.number})`)
74+
console.log('Update process completed successfully!')
75+
}
76+
77+
main().catch(err => {
78+
console.error('Error during update process:', err)
79+
process.exit(1)
80+
})
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Update from minecraft-data
2+
3+
# This workflow can be triggered from external repositories (like minecraft-data)
4+
# via workflow_dispatch API call or repository_dispatch webhook
5+
on:
6+
# Allow manual triggering
7+
workflow_dispatch:
8+
inputs:
9+
trigger_source:
10+
description: 'Repository branch that triggered this update'
11+
required: false
12+
default: 'minecraft-data'
13+
type: string
14+
trigger_reason:
15+
description: 'What PR or issue triggered this update'
16+
required: false
17+
default: ''
18+
type: string
19+
data_version:
20+
description: 'MC Version that triggered this update'
21+
required: false
22+
type: string
23+
24+
# Listen for repository dispatch events (webhook-based triggers)
25+
repository_dispatch:
26+
types: [minecraft-data-update]
27+
28+
jobs:
29+
update:
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
35+
with:
36+
# Use a token that has write permissions if you need to push changes
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Setup Node.js
40+
uses: actions/setup-node@v4
41+
with:
42+
node-version: '18'
43+
cache: 'npm'
44+
45+
- name: Install dependencies
46+
run: npm install gh-helpers
47+
48+
- name: Set environment variables
49+
run: |
50+
echo "TRIGGER_SOURCE=${{ github.event.inputs.trigger_source || github.event.client_payload.repository || 'minecraft-data' }}" >> $GITHUB_ENV
51+
echo "TRIGGER_REASON=${{ github.event.inputs.trigger_reason || github.event.client_payload.reason || 'repository_dispatch' }}" >> $GITHUB_ENV
52+
echo "DATA_VERSION=${{ github.event.inputs.data_version || github.event.client_payload.version || 'unknown' }}" >> $GITHUB_ENV
53+
54+
- name: Run updator script
55+
run: node .github/helper/updator.js
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
TRIGGER_SOURCE: ${{ env.TRIGGER_SOURCE }}
59+
TRIGGER_REASON: ${{ env.TRIGGER_REASON }}
60+
DATA_VERSION: ${{ env.DATA_VERSION }}
61+

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Parse and serialize minecraft packets, plus authentication and encryption.
1414
* Supports Minecraft PC version 1.7.10, 1.8.8, 1.9 (15w40b, 1.9, 1.9.1-pre2, 1.9.2, 1.9.4),
1515
1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1, 1.12.2), and 1.13 (17w50a, 1.13, 1.13.1, 1.13.2-pre1, 1.13.2-pre2, 1.13.2), 1.14 (1.14, 1.14.1, 1.14.3, 1.14.4)
1616
, 1.15 (1.15, 1.15.1, 1.15.2) and 1.16 (20w13b, 20w14a, 1.16-rc1, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5), 1.17 (21w07a, 1.17, 1.17.1), 1.18 (1.18, 1.18.1 and 1.18.2), 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), 1.21 (1.21, 1.21.1, 1.21.3, 1.21.4, 1.21.5)
17+
, 1.21.6 <!-- NEXT_VERSION -->
1718
* Parses all packets and emits events with packet fields as JavaScript
1819
objects.
1920
* Send a packet by supplying fields as a JavaScript object.

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.5',
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']
4+
defaultVersion: '1.21.6',
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']
66
}

test/cyclePacketTest.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ for (const supportedVersion of supportedVersions) {
2525
const parsedBuffer = convertObjectToBuffer(parsed)
2626
const areEq = buffer.equals(parsedBuffer)
2727
if (!areEq) {
28+
console.log(`Error when testing ${+packetIx + 1} ${packetName} packet`)
29+
console.direct(parsed, { depth: null })
2830
console.log('original buffer', buffer.toString('hex'))
2931
console.log('cycled buffer', parsedBuffer.toString('hex'))
3032
}
@@ -46,7 +48,8 @@ for (const supportedVersion of supportedVersions) {
4648
// server -> client
4749
if (data !== undefined) {
4850
Object.entries(data['from-server']).forEach(([packetName, packetData]) => {
49-
it(`${packetName} packet`, () => {
51+
it(`${packetName} packet`, function () {
52+
if (packetName === 'sound_effect') return this.skip() // sound_effect structure is out of date in minecraft-packets
5053
for (const i in packetData) {
5154
testBuffer(packetData[i].raw, [packetName, i])
5255
}

test/packetTest.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ const nbtValue = {
5656
}
5757

5858
function getFixedPacketPayload (version, packetName) {
59+
if (packetName === 'teams') {
60+
if (version['>=']('1.21.6')) {
61+
return {
62+
team: 'test_team',
63+
mode: 'add',
64+
name: nbtValue,
65+
flags: 'always',
66+
nameTagVisibility: 'always',
67+
collisionRule: 'always',
68+
formatting: 0, // no formatting
69+
prefix: nbtValue,
70+
suffix: nbtValue,
71+
players: ['player1', 'player2']
72+
}
73+
}
74+
}
5975
if (packetName === 'declare_recipes') {
6076
if (version['>=']('1.21.3')) {
6177
return {
@@ -319,6 +335,9 @@ const values = {
319335
})
320336
return results
321337
},
338+
registryEntryHolder (typeArgs, context) {
339+
return { [typeArgs.baseName]: 1 }
340+
},
322341
soundSource: 'master',
323342
packedChunkPos: {
324343
x: 10,
@@ -392,6 +411,10 @@ const values = {
392411
count: 1,
393412
addedComponents: [],
394413
removedComponents: []
414+
},
415+
RecipeBookSetting: {
416+
open: false,
417+
filtering: false
395418
}
396419
}
397420

0 commit comments

Comments
 (0)