Skip to content

Commit fb39504

Browse files
committed
fix: fix on 1.18.2 many blocks like mushrom blocks, fence gates, deepslate, basalt, copper stuff like ore, infested stone, cakes and tinted glass was resulting in instant breaking on the client
dev: add debugTestPing
1 parent 353ba2e commit fb39504

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

scripts/makeOptimizedMcData.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,19 @@ const dataTypeBundling = {
9090
},
9191
blocks: {
9292
arrKey: 'name',
93-
processData(current, prev) {
93+
processData(current, prev, _, version) {
9494
for (const block of current) {
95+
const prevBlock = prev?.find(x => x.name === block.name)
9596
if (block.transparent) {
9697
const forceOpaque = block.name.includes('shulker_box') || block.name.match(/^double_.+_slab\d?$/) || ['melon_block', 'lit_pumpkin', 'lit_redstone_ore', 'lit_furnace'].includes(block.name)
9798

98-
const prevBlock = prev?.find(x => x.name === block.name)
9999
if (forceOpaque || (prevBlock && !prevBlock.transparent)) {
100100
block.transparent = false
101101
}
102102
}
103+
if (block.hardness === 0 && prevBlock && prevBlock.hardness > 0) {
104+
block.hardness = prevBlock.hardness
105+
}
103106
}
104107
}
105108
// ignoreRemoved: true,

src/mineflayer/mc-protocol.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import net from 'net'
12
import { Client } from 'minecraft-protocol'
23
import { appQueryParams } from '../appParams'
34
import { downloadAllMinecraftData, getVersionAutoSelect } from '../connect'
45
import { gameAdditionalState } from '../globalState'
56
import { ProgressReporter } from '../core/progressReporter'
7+
import { parseServerAddress } from '../parseServerAddress'
8+
import { getCurrentProxy } from '../react/ServersList'
69
import { pingServerVersion, validatePacket } from './minecraft-protocol-extra'
710
import { getWebsocketStream } from './websocket-core'
811

@@ -35,14 +38,16 @@ setInterval(() => {
3538
}, 1000)
3639

3740

38-
export const getServerInfo = async (ip: string, port?: number, preferredVersion = getVersionAutoSelect(), ping = false, progressReporter?: ProgressReporter) => {
41+
export const getServerInfo = async (ip: string, port?: number, preferredVersion = getVersionAutoSelect(), ping = false, progressReporter?: ProgressReporter, setProxyParams?: ProxyParams) => {
3942
await downloadAllMinecraftData()
4043
const isWebSocket = ip.startsWith('ws://') || ip.startsWith('wss://')
4144
let stream
4245
if (isWebSocket) {
4346
progressReporter?.setMessage('Connecting to WebSocket server')
4447
stream = (await getWebsocketStream(ip)).mineflayerStream
4548
progressReporter?.setMessage('WebSocket connected. Ping packet sent, waiting for response')
49+
} else if (setProxyParams) {
50+
setProxy(setProxyParams)
4651
}
4752
window.setLoadingMessage = (message?: string) => {
4853
if (message === undefined) {
@@ -59,3 +64,45 @@ export const getServerInfo = async (ip: string, port?: number, preferredVersion
5964
window.setLoadingMessage = undefined
6065
})
6166
}
67+
68+
globalThis.debugTestPing = async (ip: string) => {
69+
const parsed = parseServerAddress(ip, false)
70+
const result = await getServerInfo(parsed.host, parsed.port ? Number(parsed.port) : undefined, undefined, true, undefined, { address: getCurrentProxy(), })
71+
console.log('result', result)
72+
return result
73+
}
74+
75+
export const getDefaultProxyParams = () => {
76+
return {
77+
headers: {
78+
Authorization: `Bearer ${new URLSearchParams(location.search).get('token') ?? ''}`
79+
}
80+
}
81+
}
82+
83+
export type ProxyParams = {
84+
address?: string
85+
headers?: Record<string, string>
86+
}
87+
88+
export const setProxy = (proxyParams: ProxyParams) => {
89+
if (proxyParams.address?.startsWith(':')) {
90+
proxyParams.address = `${location.protocol}//${location.hostname}${proxyParams.address}`
91+
}
92+
if (proxyParams.address && location.port !== '80' && location.port !== '443' && !/:\d+$/.test(proxyParams.address)) {
93+
const https = proxyParams.address.startsWith('https://') || location.protocol === 'https:'
94+
proxyParams.address = `${proxyParams.address}:${https ? 443 : 80}`
95+
}
96+
97+
const parsedProxy = parseServerAddress(proxyParams.address, false)
98+
const proxy = { host: parsedProxy.host, port: parsedProxy.port }
99+
proxyParams.headers ??= getDefaultProxyParams().headers
100+
net['setProxy']({
101+
hostname: proxy.host,
102+
port: proxy.port,
103+
headers: proxyParams.headers
104+
})
105+
return {
106+
proxy
107+
}
108+
}

0 commit comments

Comments
 (0)