Skip to content

Commit 0c09bb1

Browse files
committed
Use PrismarineJS docs for bedrock
1 parent 6baa587 commit 0c09bb1

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

html/mainPage/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ <h3>Scripting (beta)</h3>
140140
<div class="split" id="sidebar">
141141
<div class="toolbar tab">
142142
<button class="tab-button tablinks-rightpanel active" onclick="openMenu(event, 'tree', '-rightpanel')">Data</button>
143-
<button class="tab-button tablinks-rightpanel" id="wiki-button" onclick="openMenu(event, 'wikivg', '-rightpanel'); scrollWikiToCurrentPacket()">wiki.vg</button>
143+
<button class="tab-button tablinks-rightpanel" id="wiki-button" onclick="openMenu(event, 'wikivg', '-rightpanel'); scrollWikiToCurrentPacket()">Docs</button>
144144
<button class="tab-button tablinks-rightpanel" onclick="openMenu(event, 'hex', '-rightpanel'); scrollWikiToCurrentPacket()">Hex view</button>
145145
</div>
146146
<div class="box" id="sidebar-box">

html/mainPage/js/main.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,30 @@ var clusterize = new Clusterize({
562562
})
563563

564564
// TODO: move to own file?
565+
const isPrismarineDocs = (url) => url && url.includes('prismarinejs.github.io/minecraft-data')
566+
565567
async function fillWiki () {
566-
let data = (await axios.get(sharedVars.proxyCapabilities.wikiVgPage)).data
567-
// Allow it to load properly
568+
const wikiUrl = sharedVars.proxyCapabilities.wikiVgPage
569+
570+
if (isPrismarineDocs(wikiUrl)) {
571+
const iframe = document.getElementById('iframe')
572+
iframe.src = wikiUrl
573+
574+
const style = document.createElement('style')
575+
style.id = 'wiki-iframe-style'
576+
style.innerHTML = `
577+
#iframe::-webkit-scrollbar { width: 17px; }
578+
#iframe::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.3); border-radius: 10px; }
579+
#iframe::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); border-radius: 10px; }
580+
#iframe::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.5); }
581+
#iframe::-webkit-scrollbar-corner { background: #242424; }
582+
`
583+
document.head.appendChild(style)
584+
return
585+
}
586+
587+
// wiki.vg (Java): fetch HTML and inject
588+
let data = (await axios.get(wikiUrl)).data
568589
data = data
569590
.split('/images/')
570591
.join('https://wiki.vg/images/')
@@ -573,7 +594,6 @@ async function fillWiki () {
573594
.split('/load.php?')
574595
.join('https://wiki.vg/load.php?')
575596

576-
// TODO: Break or modify links?
577597
document.getElementById('iframe').contentWindow.document.write(data)
578598

579599
const style = document.createElement('style');
@@ -654,13 +674,26 @@ function scrollIdIntoView (id, bound) {
654674
}
655675

656676
function scrollWikiToCurrentPacket () {
657-
if (currentPacket) {
658-
const packet = sharedVars.allPackets[currentPacket]
677+
if (!currentPacket) return
678+
const packet = sharedVars.allPackets[currentPacket]
679+
const wikiUrl = sharedVars.proxyCapabilities.wikiVgPage
680+
681+
if (isPrismarineDocs(wikiUrl)) {
682+
const baseUrl = wikiUrl.split('#')[0]
683+
const packetAnchor = 'packet_' + (packet.meta.name || '')
684+
const iframe = document.getElementById('iframe')
659685
try {
660-
scrollIdIntoView(packet.hexIdString, packet.direction)
686+
iframe.contentWindow.location = baseUrl + '#' + packetAnchor
661687
} catch (err) {
662-
console.error(err);
688+
console.error(err)
663689
}
690+
return
691+
}
692+
693+
try {
694+
scrollIdIntoView(packet.hexIdString, packet.direction)
695+
} catch (err) {
696+
console.error(err)
664697
}
665698
}
666699

src/proxy/bedrock/proxy.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const minecraftFolder = require("minecraft-folder-path");
44

55
let scriptingEnabled = false
66

7-
// http://prismarinejs.github.io/minecraft-data/?v=bedrock_1.19.62&d=protocol#packet_server_to_client_handshake
8-
// http://prismarinejs.github.io/minecraft-data/?v=bedrock_[VERSION]&d=protocol#[PACKET]
7+
// https://prismarinejs.github.io/minecraft-data/?v=bedrock_{VERSION}&d=protocol#packet_{packet_name}
8+
// Example: https://prismarinejs.github.io/minecraft-data/?v=bedrock_1.21.130&d=protocol#packet_correct_player_move_prediction
99

1010
exports.capabilities = {
1111
modifyPackets: true,
@@ -14,7 +14,7 @@ exports.capabilities = {
1414
scriptingSupport: true,
1515
clientboundPackets: {},
1616
serverboundPackets: {},
17-
wikiVgPage: 'https://wiki.vg/Bedrock_Protocol',
17+
wikiVgPage: undefined, // Set in startProxy with version-specific prismarinejs URL
1818
versionId: undefined
1919
}
2020

@@ -81,8 +81,7 @@ exports.startProxy = function (passedHost, passedPort, passedListenPort, version
8181
exports.capabilities.clientboundPackets = toClientMappings
8282
exports.capabilities.serverboundPackets = toServerMappings
8383

84-
// TODO: minecraft-data docs should replace wikiVgPage
85-
//exports.capabilities.wikiVgPage = "http://prismarinejs.github.io/minecraft-data/?v=bedrock_{VERSION}&d=protocol".replace("{VERSION}", version)
84+
exports.capabilities.wikiVgPage = 'https://prismarinejs.github.io/minecraft-data/?v=bedrock_' + version + '&d=protocol'
8685

8786
exports.capabilities.versionId = 'node-bedrock-protocol-' + version.split('.').join('-')
8887

0 commit comments

Comments
 (0)