@@ -30,6 +30,26 @@ const CASSETTE_DECK_URL = `https://services.enginehub.org/cassette-deck/minecraf
3030const URL_1_13 =
3131 'https://launcher.mojang.com/v1/objects/c0b970952cdd279912da384cdbfc0c26e6c6090b/client.jar' ;
3232
33+ function blockKey ( block : Block ) : string {
34+ const props = block . properties ?? { } ;
35+ const keys = Object . keys ( props ) ;
36+ if ( keys . length === 0 ) {
37+ return block . type ;
38+ }
39+
40+ keys . sort ( ) ;
41+ let out = block . type + '[' ;
42+ for ( let i = 0 ; i < keys . length ; i ++ ) {
43+ const key = keys [ i ] ;
44+ if ( i > 0 ) {
45+ out += ',' ;
46+ }
47+ out += key + '=' + String ( props [ key ] ) ;
48+ }
49+ out += ']' ;
50+ return out ;
51+ }
52+
3353async function getClientJarUrlDefault ( {
3454 dataVersion,
3555 corsBypassUrl,
@@ -88,9 +108,8 @@ export async function renderSchematic(
88108
89109 scene . ambientColor = new Color3 ( 0.5 , 0.5 , 0.5 ) ;
90110 if ( backgroundColor !== 'transparent' ) {
91- scene . clearColor = Color4 . FromHexString (
92- `#${ backgroundColor . toString ( 16 ) } FF`
93- ) ;
111+ const hex = backgroundColor . toString ( 16 ) . padStart ( 6 , '0' ) ;
112+ scene . clearColor = Color4 . FromHexString ( `#${ hex } FF` ) ;
94113 } else {
95114 scene . clearColor = new Color4 ( 0 , 0 , 0 , 0 ) ;
96115 }
@@ -142,7 +161,7 @@ export async function renderSchematic(
142161 ] ) ;
143162 const modelLoader = getModelLoader ( resourceLoader ) ;
144163
145- const blockModelLookup : Map < Block , BlockModelData > = new Map ( ) ;
164+ const blockModelLookup : Map < string , BlockModelData > = new Map ( ) ;
146165
147166 for ( const block of loadedSchematic . blockTypes ) {
148167 if ( INVISIBLE_BLOCKS . has ( block . type ) ) {
@@ -159,11 +178,17 @@ export async function renderSchematic(
159178 continue ;
160179 }
161180
162- blockModelLookup . set ( block , blockModelData ) ;
181+ blockModelLookup . set ( blockKey ( block ) , blockModelData ) ;
163182 }
164183
165184 Mesh . INSTANCEDMESH_SORT_TRANSPARENT = true ;
166185
186+ const worldXBase = - worldWidth / 2 + 0.5 ;
187+ const worldYBase = - worldHeight / 2 + 0.5 ;
188+ const worldZBase = - worldLength / 2 + 0.5 ;
189+
190+ const neighborPos = { x : 0 , y : 0 , z : 0 } ;
191+
167192 scene . blockMaterialDirtyMechanism = true ;
168193 for ( const pos of loadedSchematic ) {
169194 const { x, y, z } = pos ;
@@ -173,7 +198,7 @@ export async function renderSchematic(
173198 continue ;
174199 }
175200
176- const modelData = blockModelLookup . get ( block ) ;
201+ const modelData = blockModelLookup . get ( blockKey ( block ) ) ;
177202 if ( ! modelData ) {
178203 continue ;
179204 }
@@ -182,11 +207,10 @@ export async function renderSchematic(
182207
183208 for ( const face of POSSIBLE_FACES ) {
184209 const faceOffset = faceToFacingVector ( face ) ;
185- const offBlock = loadedSchematic . getBlock ( {
186- x : x + faceOffset [ 0 ] ,
187- y : y + faceOffset [ 1 ] ,
188- z : z + faceOffset [ 2 ] ,
189- } ) ;
210+ neighborPos . x = x + faceOffset [ 0 ] ;
211+ neighborPos . y = y + faceOffset [ 1 ] ;
212+ neighborPos . z = z + faceOffset [ 2 ] ;
213+ const offBlock = loadedSchematic . getBlock ( neighborPos ) ;
190214
191215 if ( ! offBlock || NON_OCCLUDING_BLOCKS . has ( offBlock . type ) ) {
192216 anyVisible = true ;
@@ -206,12 +230,10 @@ export async function renderSchematic(
206230 continue ;
207231 }
208232
209- mesh . position . x += - worldWidth / 2 + x + 0.5 ;
210- mesh . position . y += - worldHeight / 2 + y + 0.5 ;
211- mesh . position . z += - worldLength / 2 + z + 0.5 ;
233+ mesh . position . x += worldXBase + x ;
234+ mesh . position . y += worldYBase + y ;
235+ mesh . position . z += worldZBase + z ;
212236 mesh . freezeWorldMatrix ( ) ;
213-
214- scene . addMesh ( mesh ) ;
215237 }
216238 }
217239 scene . blockMaterialDirtyMechanism = false ;
@@ -254,8 +276,10 @@ export async function renderSchematic(
254276 engine . setSize ( width , height ) ;
255277 } ,
256278 destroy ( ) {
257- engine . dispose ( ) ;
258279 hasDestroyed = true ;
280+ engine . stopRenderLoop ( render ) ;
281+ scene . dispose ( ) ;
282+ engine . dispose ( ) ;
259283 } ,
260284 render,
261285 getEngine ( ) : Engine {
0 commit comments