Skip to content

Commit 361c541

Browse files
committed
use SpecialRenderer in ItemRenderer
1 parent 653e7a0 commit 361c541

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/render/BlockModel.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ export class BlockModel {
8484
private guiLight?: BlockModelGuiLight | undefined,
8585
) {}
8686

87-
public getDisplayMesh(display: Display, uvProvider: TextureAtlasProvider, tint?: Color | ((index: number) => Color)) {
87+
public getDisplayMesh(display: Display, uvProvider: TextureAtlasProvider, tint?: Color | ((index: number) => Color), additionalMesh?: Mesh) {
8888
const mesh = this.getMesh(uvProvider, Cull.none(), tint)
89-
89+
if (additionalMesh){
90+
mesh.merge(additionalMesh)
91+
}
9092
const transform = this.display?.[display]
9193
const t = mat4.create()
9294
mat4.identity(t)

src/render/ItemRenderer.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mat4 } from 'gl-matrix'
2-
import { Identifier } from '../core/index.js'
32
import { ItemStack } from '../core/ItemStack.js'
4-
import type { Color } from '../index.js'
3+
import { Identifier } from '../core/index.js'
4+
import { Cull, SpecialRenderer, SpecialRenderers, type Color } from '../index.js'
55
import type { BlockModelProvider } from './BlockModel.js'
66
import { getItemColor } from './ItemColors.js'
77
import type { Mesh } from './Mesh.js'
@@ -48,7 +48,16 @@ export class ItemRenderer extends Renderer {
4848
if (!tint && this.item.id.namespace === Identifier.DEFAULT_NAMESPACE) {
4949
tint = getItemColor(this.item)
5050
}
51-
const mesh = model.getDisplayMesh('gui', this.resources, tint)
51+
var additionalMesh = undefined
52+
if (SpecialRenderers.has(this.item.id.toString())){
53+
additionalMesh = SpecialRenderer[this.item.id.toString()]({}, this.resources, Cull.none())
54+
// undo the scaling done by the special renderer
55+
const t = mat4.create()
56+
mat4.identity(t)
57+
mat4.scale(t, t, [16, 16, 16])
58+
additionalMesh.transform(t)
59+
}
60+
const mesh = model.getDisplayMesh('gui', this.resources, tint, additionalMesh)
5261
mesh.quads.forEach(q => {
5362
const normal = q.normal()
5463
q.forEach(v => v.normal = normal)

0 commit comments

Comments
 (0)