add transparent block model override

This commit is contained in:
Vitaly Turovsky 2025-02-24 21:53:43 +03:00
commit 6d29413a5d
4 changed files with 44 additions and 2 deletions

1
experiments/state.html Normal file
View file

@ -0,0 +1 @@
<script src="state.ts" type="module"></script>

37
experiments/state.ts Normal file
View file

@ -0,0 +1,37 @@
import { SmoothSwitcher } from '../renderer/viewer/lib/smoothSwitcher'
const div = document.createElement('div')
div.style.width = '100px'
div.style.height = '100px'
div.style.backgroundColor = 'red'
document.body.appendChild(div)
const pos = {x: 0, y: 0}
const positionSwitcher = new SmoothSwitcher(() => pos, (key, value) => {
pos[key] = value
})
globalThis.positionSwitcher = positionSwitcher
document.body.addEventListener('keydown', e => {
if (e.code === 'ArrowLeft' || e.code === 'ArrowRight') {
const to = {
x: e.code === 'ArrowLeft' ? -100 : 100
}
console.log(pos, to)
positionSwitcher.transitionTo(to, e.code === 'ArrowLeft' ? 'Left' : 'Right', () => {
console.log('Switched to ', e.code === 'ArrowLeft' ? 'Left' : 'Right')
})
}
if (e.code === 'Space') {
pos.x = 200
}
})
const render = () => {
positionSwitcher.update()
div.style.transform = `translate(${pos.x}px, ${pos.y}px)`
requestAnimationFrame(render)
}
render()

View file

@ -144,7 +144,7 @@ export class World {
if (!this.blockCache[cacheKey]) {
const b = column.getBlock(locInChunk) as unknown as WorldBlock
if (modelOverride) {
b.name = modelOverride
// b.name = modelOverride
}
b.isCube = isCube(b.shapes)
this.blockCache[cacheKey] = b
@ -228,6 +228,11 @@ export class World {
}
block.models = null
}
if (block.models && modelOverride) {
const model = block.models[0]
block.transparent = model['transparent'] ?? block.transparent
}
} catch (err) {
this.erroredBlockModel ??= blockProvider.getAllResolvedModels0_1({ name: 'errored', properties: {} })
block.models ??= this.erroredBlockModel

View file

@ -41,7 +41,6 @@ customEvents.on('mineflayerBotCreated', async () => {
bot._client.on(CHANNEL_NAME as any, (data) => {
const { worldName, x, y, z, model } = data
console.debug('Received model data:', { worldName, x, y, z, model })
const chunkX = Math.floor(x / 16) * 16
const chunkZ = Math.floor(z / 16) * 16