Skip to content

Commit

Permalink
Hope to release soon (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Jun 24, 2024
2 parents 7220e39 + a3a530f commit abc0b4f
Show file tree
Hide file tree
Showing 33 changed files with 1,730 additions and 103 deletions.
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ You can try this out at [mcraft.fun](https://mcraft.fun/), [pcm.gg](https://pcm.
- Play with friends over internet! (P2P is powered by Peer.js discovery servers)
- First-class touch (mobile) & controller support
- Resource pack support
- Builtin JEI with recipes & guides for every item (also replaces creative inventory)
- even even more!

All components that are in [Storybook](https://mcraft.fun/storybook) are published as npm module and can be used in other projects: [`minecraft-react`](https://npmjs.com/minecraft-react)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@
"ignoreDependencies": []
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"[email protected]": "patches/[email protected]"
}
},
"packageManager": "[email protected]"
Expand Down
16 changes: 16 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/examples/jsm/webxr/VRButton.js b/examples/jsm/webxr/VRButton.js
index 6856a21b17aa45d7922bbf776fd2d7e63c7a9b4e..0925b706f7629bd52f0bb5af469536af8f5fce2c 100644
--- a/examples/jsm/webxr/VRButton.js
+++ b/examples/jsm/webxr/VRButton.js
@@ -62,7 +62,10 @@ class VRButton {
// ('local' is always available for immersive sessions and doesn't need to
// be requested separately.)

- const sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking', 'layers' ] };
+ const sessionInit = {
+ optionalFeatures: ['local-floor', 'bounded-floor', 'layers'],
+ domOverlay: { root: document.body },
+ };
navigator.xr.requestSession( 'immersive-vr', sessionInit ).then( onSessionStarted );

} else {
23 changes: 13 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prismarine-viewer/viewer/lib/mesher/mesher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ setInterval(() => {
//@ts-ignore
postMessage({ type: 'geometry', key, geometry }, transferable)
} else {
console.info('[mesher] Missing section', x, y, z)
// console.info('[mesher] Missing section', x, y, z)
}
const dirtyTimes = dirtySections.get(key)
if (!dirtyTimes) throw new Error('dirtySections.get(key) is falsy')
Expand Down
2 changes: 1 addition & 1 deletion prismarine-viewer/viewer/lib/mesher/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ export function getSectionGeometry (sx, sy, sz, world: World) {
delete attr.t_uvs

attr.positions = new Float32Array(attr.positions) as any
attr.normals = new Float32Array(attr.normals) as any
attr.normals = new Uint8ClampedArray(attr.normals) as any
attr.colors = new Float32Array(attr.colors) as any
attr.uvs = new Float32Array(attr.uvs) as any

Expand Down
4 changes: 2 additions & 2 deletions prismarine-viewer/viewer/lib/viewerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export class ViewerWrapper {
renderIntervalUnfocused: number | undefined
fpsInterval

constructor(public canvas: HTMLCanvasElement, public renderer?: THREE.WebGLRenderer) {
constructor (public canvas: HTMLCanvasElement, public renderer?: THREE.WebGLRenderer) {
if (this.renderer) this.globalObject.renderer = this.renderer
}
addToPage (startRendering = true) {
if (this.addedToPage) throw new Error('Already added to page')
Expand All @@ -30,7 +31,6 @@ export class ViewerWrapper {
this.canvas.id = 'viewer-canvas'
document.body.appendChild(this.canvas)

if (this.renderer) this.globalObject.renderer = this.renderer
this.addedToPage = true

let max = 0
Expand Down
58 changes: 58 additions & 0 deletions prismarine-viewer/viewer/lib/workerProxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export function createWorkerProxy<T extends Record<string, (...args: any[]) => void>> (handlers: T): { __workerProxy: T } {
addEventListener('message', (event) => {
const { type, args } = event.data
if (handlers[type]) {
handlers[type](...args)
}
})
return null as any
}

/**
* in main thread
* ```ts
* // either:
* import type { importedTypeWorkerProxy } from './worker'
* // or:
* type importedTypeWorkerProxy = import('./worker').importedTypeWorkerProxy
*
* const workerChannel = useWorkerProxy<typeof importedTypeWorkerProxy>(worker)
* ```
*/
export const useWorkerProxy = <T extends { __workerProxy: Record<string, (...args: any[]) => void> }> (worker: Worker, autoTransfer = true): T['__workerProxy'] & {
transfer: (...args: Transferable[]) => T['__workerProxy']
} => {
// in main thread
return new Proxy({} as any, {
get: (target, prop) => {
if (prop === 'transfer') return (...transferable: Transferable[]) => {
return new Proxy({}, {
get: (target, prop) => {
return (...args: any[]) => {
worker.postMessage({
type: prop,
args,
}, transferable)
}
}
})
}
return (...args: any[]) => {
const transfer = autoTransfer ? args.filter(arg => arg instanceof ArrayBuffer || arg instanceof MessagePort || arg instanceof ImageBitmap || arg instanceof OffscreenCanvas) : []
worker.postMessage({
type: prop,
args,
}, transfer)
}
}
})
}

// const workerProxy = createWorkerProxy({
// startRender (canvas: HTMLCanvasElement) {
// },
// })

// const worker = useWorkerProxy(null, workerProxy)

// worker.
15 changes: 10 additions & 5 deletions prismarine-viewer/viewer/lib/worldDataEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class WorldDataEmitter extends EventEmitter {
private eventListeners: Record<string, any> = {};
private emitter: WorldDataEmitter

constructor(public world: import('prismarine-world').world.World | typeof __type_bot['world'], public viewDistance: number, position: Vec3 = new Vec3(0, 0, 0)) {
constructor (public world: typeof __type_bot['world'], public viewDistance: number, position: Vec3 = new Vec3(0, 0, 0)) {
super()
this.loadedChunks = {}
this.lastPos = new Vec3(0, 0, 0).update(position)
Expand Down Expand Up @@ -123,10 +123,15 @@ export class WorldDataEmitter extends EventEmitter {
}

async _loadChunks (positions: Vec3[], sliceSize = 5, waitTime = 0) {
for (let i = 0; i < positions.length; i += sliceSize) {
await new Promise((resolve) => setTimeout(resolve, waitTime))
await Promise.all(positions.slice(i, i + sliceSize).map((p) => this.loadChunk(p)))
}
let i = 0
const interval = setInterval(() => {
if (i >= positions.length) {
clearInterval(interval)
return
}
this.loadChunk(positions[i])
i++
}, 1)
}

readdDebug () {
Expand Down
3 changes: 2 additions & 1 deletion prismarine-viewer/viewer/lib/worldrendererThree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ export class WorldRendererThree extends WorldRendererCommon {

render () {
tweenJs.update()
this.renderer.render(this.scene, this.camera)
const cam = this.camera instanceof THREE.Group ? this.camera.children.find(child => child instanceof THREE.PerspectiveCamera) as THREE.PerspectiveCamera : this.camera
this.renderer.render(this.scene, cam)
}

renderSign (position: Vec3, rotation: number, isWall: boolean, isHanging: boolean, blockEntity) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/esbuildPlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const plugins = [
})

const removeNodeModulesSourcemaps = (map) => {
const doNotRemove = ['prismarine', 'mineflayer', 'flying-squid', '@jspm/core', 'minecraft']
const doNotRemove = ['prismarine', 'mineflayer', 'flying-squid', '@jspm/core', 'minecraft', 'three']
map.sourcesContent.forEach((_, i) => {
if (map.sources[i].includes('node_modules') && !doNotRemove.some(x => map.sources[i].includes(x))) {
map.sourcesContent[i] = null
Expand Down
41 changes: 41 additions & 0 deletions scripts/getMissingRecipes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//@ts-check
// tsx ./scripts/getMissingRecipes.mjs
import MinecraftData from 'minecraft-data'
import supportedVersions from '../src/supportedVersions.mjs'
import fs from 'fs'

console.time('import-data')
const { descriptionGenerators } = await import('../src/itemsDescriptions')
console.timeEnd('import-data')

const data = MinecraftData(supportedVersions.at(-1))

const hasDescription = name => {
for (const [key, value] of descriptionGenerators) {
if (Array.isArray(key) && key.includes(name)) {
return true
}
if (key instanceof RegExp && key.test(name)) {
return true
}
}
return false
}

const result = []
for (const item of data.itemsArray) {
const recipes = data.recipes[item.id]
if (!recipes) {
if (item.name.endsWith('_slab') || item.name.endsWith('_stairs') || item.name.endsWith('_wall')) {
console.warn('Must have recipe!', item.name)
continue
}
if (hasDescription(item.name)) {
continue
}

result.push(item.name)
}
}

fs.writeFileSync('./generated/noRecipies.json', JSON.stringify(result, null, 2))
12 changes: 12 additions & 0 deletions src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ window.inspectPacket = (packetName, full = false) => {
})
return returnobj
}

// for advanced debugging, use with watch expression

let stats_ = {}
window.addStatHit = (key) => {
stats_[key] ??= 0
stats_[key]++
}
setInterval(() => {
window.stats = stats_
stats_ = {}
}, 1000)
12 changes: 12 additions & 0 deletions src/errorLoadingScreenHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const guessProblem = (errorMessage: string) => {
if (errorMessage.endsWith('Socket error: ECONNREFUSED')) {
return 'Most probably the server is not running.'
}
}

export const loadingTexts = [
'Like the project? Give us a star on GitHub or rate us on AlternativeTo!',
'To stay updated with the latest changes, go to the GitHub page, click on "Watch", choose "Custom", and then opt for "Releases"!',
'Upvote features on GitHub issues to help us prioritize them!',
'Want to contribute to the project? Check out Contributing.md on GitHub!',
]
5 changes: 0 additions & 5 deletions src/guessProblem.ts

This file was deleted.

Loading

0 comments on commit abc0b4f

Please sign in to comment.