Skip to content

Commit 923a70c

Browse files
authored
Release (#394)
2 parents cedb077 + b9c8ade commit 923a70c

34 files changed

+493
-278
lines changed

README.MD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ For building the project yourself / contributing, see [Development, Debugging &
1414

1515
> **Note**: You can deploy it on your own server in less than a minute using a one-liner script from [Minecraft Everywhere repo](https://github.com/zardoy/minecraft-everywhere)
1616
17-
1817
### Big Features
1918

2019
- Official Mineflayer [plugin integration](https://github.com/zardoy/mcraft-fun-mineflayer-plugin)! View / Control your bot remotely.
@@ -57,6 +56,7 @@ Howerver, it's known that these browsers have issues:
5756

5857
Server versions 1.8 - 1.21.4 are supported.
5958
First class versions (most of the features are tested on these versions):
59+
6060
- 1.19.4
6161
- 1.21.4
6262

@@ -125,11 +125,11 @@ There is world renderer playground ([link](https://mcon.vercel.app/playground/))
125125

126126
However, there are many things that can be done in online production version (like debugging actual source code). Also you can access some global variables in the console and there are a few useful examples:
127127

128-
- `localStorage.debug = '*'` - Enables all debug messages! Warning: this will start all packets spam.
128+
- If you type `debugToggle`, press enter in console - It will enables all debug messages! Warning: this will start all packets spam.
129129
Instead I recommend setting `options.debugLogNotFrequentPackets`. Also you can use `debugTopPackets` (with JSON.stringify) to see what packets were received/sent by name
130130

131131
- `bot` - Mineflayer bot instance. See Mineflayer documentation for more.
132-
- `viewer` - Three.js viewer instance, basically does all the rendering.
132+
- `world` - Three.js world instance, basically does all the rendering (part of renderer backend).
133133
- `world.sectionObjects` - Object with all active chunk sections (geometries) in the world. Each chunk section is a Three.js mesh or group.
134134
- `debugSceneChunks` - The same as above, but relative to current bot position (e.g. 0,0 is the current chunk).
135135
- `debugChangedOptions` - See what options are changed. Don't change options here.
@@ -139,7 +139,7 @@ Instead I recommend setting `options.debugLogNotFrequentPackets`. Also you can u
139139

140140
- `nbt.simplify(someNbt)` - Simplifies nbt data, so it's easier to read.
141141

142-
The most useful thing in devtools is the watch expression. You can add any expression there and it will be re-evaluated in real time. For example, you can add `camera.position` to see the camera position and so on.
142+
The most useful thing in devtools is the watch expression. You can add any expression there and it will be re-evaluated in real time. For example, you can add `world.getCameraPosition()` to see the camera position and so on.
143143

144144
<img src="./docs-assets/watch-expr.png" alt="Watch expression" width="480"/>
145145

config.mcraft-only.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"alwaysReconnectButton": true,
3-
"reportBugButtonWithReconnect": true
3+
"reportBugButtonWithReconnect": true,
4+
"allowAutoConnect": true
45
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
"mc-assets": "^0.2.62",
157157
"minecraft-inventory-gui": "github:zardoy/minecraft-inventory-gui#next",
158158
"mineflayer": "github:zardoy/mineflayer#gen-the-master",
159-
"mineflayer-mouse": "^0.1.11",
159+
"mineflayer-mouse": "^0.1.14",
160160
"mineflayer-pathfinder": "^2.4.4",
161161
"npm-run-all": "^4.1.5",
162162
"os-browserify": "^0.3.0",

pnpm-lock.yaml

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

renderer/viewer/baseGraphicsBackend.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { proxy } from 'valtio'
12
import { NonReactiveState, RendererReactiveState } from '../../src/appViewer'
23

34
export const getDefaultRendererState = (): {
45
reactive: RendererReactiveState
56
nonReactive: NonReactiveState
67
} => {
78
return {
8-
reactive: {
9+
reactive: proxy({
910
world: {
1011
chunksLoaded: new Set(),
1112
heightmaps: new Map(),
@@ -15,7 +16,7 @@ export const getDefaultRendererState = (): {
1516
},
1617
renderer: '',
1718
preventEscapeMenu: false
18-
},
19+
}),
1920
nonReactive: {
2021
world: {
2122
chunksLoaded: new Set(),

renderer/viewer/lib/worldDataEmitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class WorldDataEmitter extends (EventEmitter as new () => TypedEmitter<Wo
210210
if (bot?.time?.timeOfDay) {
211211
this.emitter.emit('time', bot.time.timeOfDay)
212212
}
213-
if (bot.entity) {
213+
if (bot?.entity) {
214214
this.emitter.emit('playerEntity', bot.entity)
215215
}
216216
this.emitterGotConnected()

renderer/viewer/three/documentRenderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ export class DocumentRenderer {
6161
this.previousCanvasWidth = this.canvas.width
6262
this.previousCanvasHeight = this.canvas.height
6363

64+
const supportsWebGL2 = 'WebGL2RenderingContext' in window
6465
// Only initialize stats and DOM-related features in main thread
65-
if (!externalCanvas) {
66+
if (!externalCanvas && supportsWebGL2) {
6667
this.stats = new TopRightStats(this.canvas as HTMLCanvasElement, this.config.statsVisible)
6768
this.setupFpsTracking()
6869
}

renderer/viewer/three/entities.ts

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ export class Entities {
717717
return typeof component === 'string' ? component : component.text ?? ''
718718
}
719719

720-
getItemMesh (item, specificProps: ItemSpecificContextProperties, previousModel?: string) {
720+
getItemMesh (item, specificProps: ItemSpecificContextProperties, faceCamera = false, previousModel?: string) {
721721
if (!item.nbt && item.nbtData) item.nbt = item.nbtData
722722
const textureUv = this.worldRenderer.getItemRenderData(item, specificProps)
723723
if (previousModel && previousModel === textureUv?.modelName) return undefined
@@ -757,26 +757,37 @@ export class Entities {
757757
itemsTexture.needsUpdate = true
758758
itemsTexture.magFilter = THREE.NearestFilter
759759
itemsTexture.minFilter = THREE.NearestFilter
760-
const itemsTextureFlipped = itemsTexture.clone()
761-
itemsTextureFlipped.repeat.x *= -1
762-
itemsTextureFlipped.needsUpdate = true
763-
itemsTextureFlipped.offset.set(u + (sizeX), 1 - v - sizeY)
764-
const material = new THREE.MeshStandardMaterial({
765-
map: itemsTexture,
766-
transparent: true,
767-
alphaTest: 0.1,
768-
})
769-
const materialFlipped = new THREE.MeshStandardMaterial({
770-
map: itemsTextureFlipped,
771-
transparent: true,
772-
alphaTest: 0.1,
773-
})
774-
const mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 0), [
775-
// top left and right bottom are black box materials others are transparent
776-
new THREE.MeshBasicMaterial({ color: 0x00_00_00 }), new THREE.MeshBasicMaterial({ color: 0x00_00_00 }),
777-
new THREE.MeshBasicMaterial({ color: 0x00_00_00 }), new THREE.MeshBasicMaterial({ color: 0x00_00_00 }),
778-
material, materialFlipped,
779-
])
760+
let mesh: THREE.Object3D
761+
let itemsTextureFlipped: THREE.Texture | undefined
762+
if (faceCamera) {
763+
const spriteMat = new THREE.SpriteMaterial({
764+
map: itemsTexture,
765+
transparent: true,
766+
alphaTest: 0.1,
767+
})
768+
mesh = new THREE.Sprite(spriteMat)
769+
} else {
770+
itemsTextureFlipped = itemsTexture.clone()
771+
itemsTextureFlipped.repeat.x *= -1
772+
itemsTextureFlipped.needsUpdate = true
773+
itemsTextureFlipped.offset.set(u + (sizeX), 1 - v - sizeY)
774+
const material = new THREE.MeshStandardMaterial({
775+
map: itemsTexture,
776+
transparent: true,
777+
alphaTest: 0.1,
778+
})
779+
const materialFlipped = new THREE.MeshStandardMaterial({
780+
map: itemsTextureFlipped,
781+
transparent: true,
782+
alphaTest: 0.1,
783+
})
784+
mesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 0), [
785+
// top left and right bottom are black box materials others are transparent
786+
new THREE.MeshBasicMaterial({ color: 0x00_00_00 }), new THREE.MeshBasicMaterial({ color: 0x00_00_00 }),
787+
new THREE.MeshBasicMaterial({ color: 0x00_00_00 }), new THREE.MeshBasicMaterial({ color: 0x00_00_00 }),
788+
material, materialFlipped,
789+
])
790+
}
780791
let SCALE = 1
781792
if (specificProps['minecraft:display_context'] === 'ground') {
782793
SCALE = 0.5
@@ -805,8 +816,6 @@ export class Entities {
805816
}
806817

807818
update (entity: SceneEntity['originalEntity'], overrides) {
808-
const justAdded = !this.entities[entity.id]
809-
810819
const isPlayerModel = entity.name === 'player'
811820
if (entity.name === 'zombie_villager' || entity.name === 'husk') {
812821
overrides.texture = `textures/1.16.4/entity/${entity.name === 'zombie_villager' ? 'zombie_villager/zombie_villager.png' : `zombie/${entity.name}.png`}`
@@ -817,6 +826,7 @@ export class Entities {
817826
}
818827
// this can be undefined in case where packet entity_destroy was sent twice (so it was already deleted)
819828
let e = this.entities[entity.id]
829+
const justAdded = !e
820830

821831
if (entity.delete) {
822832
if (!e) return
@@ -836,30 +846,32 @@ export class Entities {
836846
if (e === undefined) {
837847
const group = new THREE.Group() as unknown as SceneEntity
838848
group.originalEntity = entity
839-
if (entity.name === 'item' || entity.name === 'tnt' || entity.name === 'falling_block') {
840-
const item = entity.name === 'tnt'
841-
? { name: 'tnt' }
849+
if (entity.name === 'item' || entity.name === 'tnt' || entity.name === 'falling_block' || entity.name === 'snowball'
850+
|| entity.name === 'egg' || entity.name === 'ender_pearl' || entity.name === 'experience_bottle'
851+
|| entity.name === 'splash_potion' || entity.name === 'lingering_potion') {
852+
const item = entity.name === 'tnt' || entity.type === 'projectile'
853+
? { name: entity.name }
842854
: entity.name === 'falling_block'
843855
? { blockState: entity['objectData'] }
844856
: entity.metadata?.find((m: any) => typeof m === 'object' && m?.itemCount)
845857
if (item) {
846858
const object = this.getItemMesh(item, {
847859
'minecraft:display_context': 'ground',
848-
})
860+
}, entity.type === 'projectile')
849861
if (object) {
850862
mesh = object.mesh
851-
if (entity.name === 'item') {
863+
if (entity.name === 'item' || entity.type === 'projectile') {
852864
mesh.scale.set(0.5, 0.5, 0.5)
853-
mesh.position.set(0, 0.2, 0)
865+
mesh.position.set(0, entity.name === 'item' ? 0.2 : 0.1, 0)
854866
} else {
855867
mesh.scale.set(2, 2, 2)
856868
mesh.position.set(0, 0.5, 0)
857869
}
858870
// set faces
859871
// mesh.position.set(targetPos.x + 0.5 + 2, targetPos.y + 0.5, targetPos.z + 0.5)
860872
// viewer.scene.add(mesh)
861-
const clock = new THREE.Clock()
862873
if (entity.name === 'item') {
874+
const clock = new THREE.Clock()
863875
mesh.onBeforeRender = () => {
864876
const delta = clock.getDelta()
865877
mesh!.rotation.y += delta

renderer/viewer/three/holdingBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ export default class HoldingBlock {
357357
'minecraft:display_context': 'firstperson',
358358
'minecraft:use_duration': this.worldRenderer.playerStateReactive.itemUsageTicks,
359359
'minecraft:using_item': !!this.worldRenderer.playerStateReactive.itemUsageTicks,
360-
}, this.lastItemModelName)
360+
}, false, this.lastItemModelName)
361361
if (result) {
362362
const { mesh: itemMesh, isBlock, modelName } = result
363363
if (isBlock) {

renderer/viewer/three/panorama.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { loadThreeJsTextureFromUrl, loadThreeJsTextureFromUrlSync } from './thre
1313
import { WorldRendererThree } from './worldrendererThree'
1414
import { EntityMesh } from './entity/EntityMesh'
1515
import { DocumentRenderer } from './documentRenderer'
16+
import { PANORAMA_VERSION } from './panoramaShared'
1617

1718
const panoramaFiles = [
1819
'panorama_3.png', // right (+x)
@@ -156,7 +157,7 @@ export class PanoramaRenderer {
156157
}
157158

158159
async worldBlocksPanorama () {
159-
const version = '1.21.4'
160+
const version = PANORAMA_VERSION
160161
const fullResourceManager = this.options.resourcesManager as ResourcesManager
161162
fullResourceManager.currentConfig = { version, noInventoryGui: true, }
162163
await fullResourceManager.updateAssetsData({ })

0 commit comments

Comments
 (0)