Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: app <-> renderer REWORK. Add new layers for stability #315

Merged
merged 43 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c65db9a
a working refactor
zardoy Mar 4, 2025
4381ef4
removing bobbing & panorama
zardoy Mar 4, 2025
d8294d5
even more appViewer usage
zardoy Mar 4, 2025
1861edf
delayLoadUntilFocus
zardoy Mar 4, 2025
d197859
big resourcemanager refactor
zardoy Mar 5, 2025
d74d860
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 15, 2025
67d90a5
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 18, 2025
6eb50cd
last dont crash
zardoy Mar 18, 2025
dc073cd
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 18, 2025
400f598
update server data for index 0
zardoy Mar 20, 2025
5364085
fix possible crash on non existing server data update
zardoy Mar 20, 2025
de3edda
a lot of imports update, data cleanup, add thousands errors
zardoy Mar 20, 2025
c1a7765
final code cleanup i think
zardoy Mar 20, 2025
ccb0004
fix reload hand
zardoy Mar 20, 2025
9fedafe
move threejs entities & cursor block to renderer
zardoy Mar 21, 2025
136b051
smooth camera movement!
zardoy Mar 21, 2025
f88e9c8
Refactor renderer state management and move vr
zardoy Mar 21, 2025
cae2b61
fix all remaining reactive state linking
zardoy Mar 21, 2025
82d0638
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 21, 2025
b483923
rm unused three imports
zardoy Mar 21, 2025
dc2ad7c
disable signs, disable playground since its not used by anyone
zardoy Mar 21, 2025
8ee4dc3
disable displaying unknown non interactible entitites
zardoy Mar 21, 2025
11abbfc
disable check
zardoy Mar 21, 2025
5eedb3c
disable playground
zardoy Mar 21, 2025
8ddac97
dont use bot
zardoy Mar 21, 2025
853e0e1
up readme
zardoy Mar 21, 2025
d450a31
fix typo
zardoy Mar 21, 2025
b579ee1
Revert "disable playground"
zardoy Mar 21, 2025
ed04197
disable in other way
zardoy Mar 21, 2025
e917764
fix lint
zardoy Mar 21, 2025
01971d4
fix: allow to go back when not crashed game
zardoy Mar 21, 2025
eb4c8e5
fix mesher config pass
zardoy Mar 21, 2025
272b0df
renderers cleanup
zardoy Mar 21, 2025
f72621d
make initial resource pack load optimised, rework it
zardoy Mar 21, 2025
92853e2
final fixes
zardoy Mar 21, 2025
4b31817
fix test
zardoy Mar 21, 2025
1a8813e
fix breaking and possible e.name crash
zardoy Mar 22, 2025
ffcf42d
fix elippse
zardoy Mar 24, 2025
0ee491f
fix invalid yaw
zardoy Mar 24, 2025
6380d03
Merge remote-tracking branch 'origin/next' into renderer-rewrite
zardoy Mar 24, 2025
7d934eb
fix merge
zardoy Mar 24, 2025
b952211
fix type
zardoy Mar 24, 2025
545e6ec
Merge branch 'next' into renderer-rewrite
zardoy Mar 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ localSettings.mjs
dist*
.DS_Store
.idea/
world
/world
data*.json
out
*.iml
Expand Down
1 change: 1 addition & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ For building the project yourself / contributing, see [Development, Debugging &
- Custom protocol channel extensions (eg for custom block models in the world)
- Play with friends over internet! (P2P is powered by Peer.js discovery servers)
- ~~Google Drive support for reading / saving worlds back to the cloud~~
- Support for custom rendering 3D engines. Modular architecture.
- 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
1 change: 1 addition & 0 deletions renderer/playground/baseScene.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import { Vec3 } from 'vec3'
import * as THREE from 'three'
import '../../src/getCollisionShapes'
Expand Down
19 changes: 10 additions & 9 deletions renderer/playground/playground.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { BasePlaygroundScene } from './baseScene'
import { playgroundGlobalUiState } from './playgroundUi'
import * as scenes from './scenes'
if (!new URL(location.href).searchParams.get('playground')) location.href = '/?playground=true'
// import { BasePlaygroundScene } from './baseScene'
// import { playgroundGlobalUiState } from './playgroundUi'
// import * as scenes from './scenes'

const qsScene = new URLSearchParams(window.location.search).get('scene')
const Scene: typeof BasePlaygroundScene = qsScene ? scenes[qsScene] : scenes.main
playgroundGlobalUiState.scenes = ['main', 'railsCobweb', 'floorRandom', 'lightingStarfield', 'transparencyIssue', 'entities', 'frequentUpdates', 'slabsOptimization', 'allEntities']
playgroundGlobalUiState.selected = qsScene ?? 'main'
// const qsScene = new URLSearchParams(window.location.search).get('scene')
// const Scene: typeof BasePlaygroundScene = qsScene ? scenes[qsScene] : scenes.main
// playgroundGlobalUiState.scenes = ['main', 'railsCobweb', 'floorRandom', 'lightingStarfield', 'transparencyIssue', 'entities', 'frequentUpdates', 'slabsOptimization', 'allEntities']
// playgroundGlobalUiState.selected = qsScene ?? 'main'

const scene = new Scene()
globalThis.scene = scene
// const scene = new Scene()
// globalThis.scene = scene
1 change: 1 addition & 0 deletions renderer/playground/scenes/allEntities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import { BasePlaygroundScene } from '../baseScene'
import { EntityDebugFlags, EntityMesh, rendererSpecialHandled } from '../../viewer/lib/entity/EntityMesh'

Expand Down Expand Up @@ -42,7 +43,7 @@
errors?: string[];
}> = []
const { mcData } = window
const entityNames = Object.keys(mcData.entitiesArray.reduce((acc, entity) => {

Check warning on line 46 in renderer/playground/scenes/allEntities.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

`Array#reduce()` is not allowed
acc[entity.name] = true
return acc
}, {}))
Expand Down
1 change: 1 addition & 0 deletions renderer/playground/scenes/entities.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import * as THREE from 'three'
import { Vec3 } from 'vec3'
import { BasePlaygroundScene } from '../baseScene'
Expand Down
1 change: 1 addition & 0 deletions renderer/playground/scenes/frequentUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import { Vec3 } from 'vec3'
import { BasePlaygroundScene } from '../baseScene'

Expand Down
1 change: 1 addition & 0 deletions renderer/playground/scenes/lightingStarfield.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import * as THREE from 'three'
import { Vec3 } from 'vec3'
import { BasePlaygroundScene } from '../baseScene'
Expand Down
2 changes: 1 addition & 1 deletion renderer/playground/scenes/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
// eslint-disable-next-line import/no-named-as-default
import GUI, { Controller } from 'lil-gui'
import * as THREE from 'three'
Expand Down Expand Up @@ -173,7 +174,6 @@
canvas.height = size
renderer.setSize(size, size)

//@ts-expect-error
viewer.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 10)
viewer.scene.background = null

Expand Down Expand Up @@ -213,7 +213,7 @@
})
if (onlyCurrent) {
viewer.render()
onWorldUpdate()

Check warning on line 216 in renderer/playground/scenes/main.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
} else {
// will be called on every render update
viewer.world.renderUpdateEmitter.addListener('update', onWorldUpdate)
Expand Down Expand Up @@ -248,9 +248,9 @@
zip.file(`${blockName}.png`, dataUrl.split(',')[1], { base64: true })

if (onlyCurrent) {
end()

Check warning on line 251 in renderer/playground/scenes/main.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
} else {
nextBlock()

Check warning on line 253 in renderer/playground/scenes/main.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
}
const nextBlock = async () => {
Expand All @@ -264,7 +264,7 @@
if (blockName) {
updateBlock()
} else {
end()

Check warning on line 267 in renderer/playground/scenes/main.ts

View workflow job for this annotation

GitHub Actions / build-and-deploy

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions renderer/viewer/baseGraphicsBackend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { RendererReactiveState } from '../../src/appViewer'

export const getDefaultRendererState = (): RendererReactiveState => {
return {
world: {
chunksLoaded: [],
chunksTotalNumber: 0,
allChunksLoaded: true,
mesherWork: false,
intersectMedia: null
},
renderer: '',
preventEscapeMenu: false
}
}
File renamed without changes.
6 changes: 0 additions & 6 deletions renderer/viewer/index.js

This file was deleted.

17 changes: 16 additions & 1 deletion renderer/viewer/lib/basePlayerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Vec3 } from 'vec3'
import TypedEmitter from 'typed-emitter'
import { ItemSelector } from 'mc-assets/dist/itemDefinitions'
import { proxy } from 'valtio'
import { GameMode } from 'mineflayer'
import { HandItemBlock } from './holdingBlock'

export type MovementState = 'NOT_MOVING' | 'WALKING' | 'SPRINTING' | 'SNEAKING'
Expand All @@ -22,6 +23,7 @@ export interface IPlayerState {
isFlying(): boolean
isSprinting (): boolean
getItemUsageTicks?(): number
getPosition(): Vec3
// isUsingItem?(): boolean
getHeldItem?(isLeftHand: boolean): HandItemBlock | undefined
username?: string
Expand All @@ -31,12 +33,21 @@ export interface IPlayerState {

reactive: {
playerSkin: string | undefined
inWater: boolean
backgroundColor: [number, number, number]
ambientLight: number
directionalLight: number
gameMode?: GameMode
}
}

export class BasePlayerState implements IPlayerState {
reactive = proxy({
playerSkin: undefined
playerSkin: undefined as string | undefined,
inWater: false,
backgroundColor: [0, 0, 0] as [number, number, number],
ambientLight: 0,
directionalLight: 0,
})
protected movementState: MovementState = 'NOT_MOVING'
protected velocity = new Vec3(0, 0, 0)
Expand Down Expand Up @@ -74,6 +85,10 @@ export class BasePlayerState implements IPlayerState {
return this.sprinting
}

getPosition (): Vec3 {
return new Vec3(0, 0, 0)
}
Comment on lines +88 to +90
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Returning a constant (0, 0, 0)
The new getPosition method always returns (0, 0, 0). If you plan to track actual player movement, consider switching from this placeholder to dynamic logic reflecting the real player coordinates.


// For testing purposes
setState (state: Partial<{
movementState: MovementState
Expand Down
Loading
Loading