Skip to content

Commit

Permalink
Fix chest rendering
Browse files Browse the repository at this point in the history
Not perfect, but good enough
  • Loading branch information
misode committed Nov 21, 2023
1 parent 6400fe9 commit 1306635
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions src/render/SpecialRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mat4 } from 'gl-matrix'
import { Direction, Identifier } from '../core/index.js'
import { BlockDefinition } from './BlockDefinition.js'
import { BlockModel } from './BlockModel.js'
Expand Down Expand Up @@ -32,21 +33,51 @@ function liquidRenderer(type: string, level: number, uvProvider: TextureAtlasPro
}

function chestRenderer(facing: string, type: string, uvProvider: TextureAtlasProvider) {
const rotation = mat4.create()
mat4.translate(rotation, rotation, [0.5, 0.5, 0.5])
mat4.rotateY(rotation, rotation, facing === 'west' ? Math.PI / 2 : facing === 'south' ? Math.PI : facing === 'east' ? Math.PI * 3 / 2 : 0)
mat4.translate(rotation, rotation, [-0.5, -0.5, -0.5])
const id = Identifier.create('chest')
return dummy(id, uvProvider, {}, new BlockModel(id, undefined, {
0: 'block/chest',
}, [{
from: [1, 0, 1],
to: [15, 14, 15],
faces: {
up: { texture: '#0' },
down: { texture: '#0' },
north: { texture: '#0' },
east: { texture: '#0' },
south: { texture: '#0' },
west: { texture: '#0' },
0: 'entity/chest/normal',
}, [
{
from: [1, 0, 1],
to: [15, 10, 15],
faces: {
north: {uv: [10.5, 8.25, 14, 10.75], rotation: 180, texture: '#0'},
east: {uv: [7, 8.25, 10.5, 10.75], rotation: 180, texture: '#0'},
south: {uv: [3.5, 8.25, 7, 10.75], rotation: 180, texture: '#0'},
west: {uv: [0, 8.25, 3.5, 10.75], rotation: 180, texture: '#0'},
up: {uv: [7, 4.75, 10.5, 8.25], texture: '#0'},
down: {uv: [3.5, 4.75, 7, 8.25], texture: '#0'},
},
},
}]))
{
from: [1, 10, 1],
to: [15, 14, 15],
faces: {
north: {uv: [10.5, 3.75, 14, 4.75], rotation: 180, texture: '#0'},
east: {uv: [7, 3.75, 10.5, 4.75], rotation: 180, texture: '#0'},
south: {uv: [3.5, 3.75, 7, 4.75], rotation: 180, texture: '#0'},
west: {uv: [0, 3.75, 3.5, 4.75], rotation: 180, texture: '#0'},
up: {uv: [7, 0, 10.5, 3.5], texture: '#0'},
down: {uv: [3.5, 0, 7, 3.5], texture: '#0'},
},
},
{
from: [7, 8, 0],
to: [9, 12, 2],
faces: {
north: {uv: [0.25, 0.25, 0.75, 1.25], rotation: 180, texture: '#0'},
east: {uv: [0, 0.25, 0.25, 1.25], rotation: 180, texture: '#0'},
south: {uv: [1, 0.25, 1.5, 1.25], rotation: 180, texture: '#0'},
west: {uv: [0.75, 0.25, 1, 1.25], rotation: 180, texture: '#0'},
up: {uv: [0.25, 0, 0.75, 0.25], rotation: 180, texture: '#0'},
down: {uv: [0.75, 0, 1.25, 0.25], rotation: 180, texture: '#0'},
},
},
])).transform(rotation)
}

export const SpecialRenderer: {
Expand Down

0 comments on commit 1306635

Please sign in to comment.