@@ -5,9 +5,8 @@ import { BoneConfig } from '../nodeConfigs'
55import { BlockModelMesh , getBlockModel } from '../systems/minecraft/blockModelManager'
66import { type BlockStateValue , getBlockState } from '../systems/minecraft/blockstateManager'
77import { MINECRAFT_REGISTRY } from '../systems/minecraft/registryManager'
8- import { getCurrentVersion } from '../systems/minecraft/versionManager'
98import EVENTS from '../util/events'
10- import { parseBlock } from '../util/minecraftUtil'
9+ import { validateBlock } from '../util/minecraftUtil'
1110import { Valuable } from '../util/stores'
1211import { translate } from '../util/translation'
1312import { ResizableOutlinerElement } from './resizableOutlinerElement'
@@ -61,31 +60,8 @@ export class VanillaBlockDisplay extends ResizableOutlinerElement {
6160
6261 this . sanitizeName ( )
6362
64- const updateBlock = async ( newBlock : string ) => {
65- if ( ! MINECRAFT_REGISTRY . block ) {
66- requestAnimationFrame ( ( ) => void updateBlock ( newBlock ) )
67- return
68- }
69- const parsed = await parseBlock ( newBlock )
70- if ( ! parsed ) {
71- this . error . set ( 'Invalid block ID.' )
72- } else if (
73- ( parsed . resource . namespace === 'minecraft' || parsed . resource . namespace === '' ) &&
74- MINECRAFT_REGISTRY . block . has ( parsed . resource . name )
75- ) {
76- this . error . set ( '' )
77- this . preview_controller . updateGeometry ( this )
78- } else {
79- this . error . set ( `This block does not exist in Minecraft ${ getCurrentVersion ( ) ! . id } .` )
80- }
81- if ( this . mesh ?. outline instanceof THREE . LineSegments ) {
82- if ( this . error . get ( ) ) this . mesh . outline . material = ERROR_OUTLINE_MATERIAL
83- else this . mesh . outline . material = Canvas . outlineMaterial
84- }
85- }
86-
87- this . __block . subscribe ( value => {
88- void updateBlock ( value )
63+ this . __block . subscribe ( ( ) => {
64+ void this . updateBlock ( )
8965 } )
9066 }
9167
@@ -99,6 +75,10 @@ export class VanillaBlockDisplay extends ResizableOutlinerElement {
9975 this . __block . set ( value )
10076 }
10177
78+ getBlockValuable ( ) {
79+ return this . __block
80+ }
81+
10282 sanitizeName ( ) : string {
10383 this . name = sanitizeOutlinerElementName ( this . name , this . uuid )
10484 return this . name
@@ -164,6 +144,19 @@ export class VanillaBlockDisplay extends ResizableOutlinerElement {
164144 this . preview_controller . updateHighlight ( this )
165145 }
166146
147+ async updateBlock ( ) {
148+ const error = await validateBlock ( this . block )
149+ if ( error ) {
150+ this . error . set ( error )
151+ if ( this . mesh ?. outline instanceof THREE . LineSegments ) {
152+ if ( this . error . get ( ) ) this . mesh . outline . material = ERROR_OUTLINE_MATERIAL
153+ else this . mesh . outline . material = Canvas . outlineMaterial
154+ }
155+ return
156+ }
157+ this . preview_controller . updateGeometry ( this )
158+ }
159+
167160 applyBlockModel ( blockModel : BlockModelMesh ) {
168161 const mesh = this . mesh as THREE . Mesh
169162 mesh . name = this . uuid
@@ -180,7 +173,6 @@ export class VanillaBlockDisplay extends ResizableOutlinerElement {
180173 this . preview_controller . updateHighlight ( this )
181174 this . preview_controller . updateTransform ( this )
182175 mesh . visible = this . visibility
183- TickUpdates . selection = true
184176 }
185177}
186178VanillaBlockDisplay . prototype . icon = VanillaBlockDisplay . icon
@@ -223,10 +215,9 @@ export const PREVIEW_CONTROLLER = new NodePreviewController(VanillaBlockDisplay,
223215 . then ( result => {
224216 if ( ! result ?. mesh ) return
225217 el . applyBlockModel ( result )
226- TickUpdates . selection = true
227218 } )
228219 . catch ( err => {
229- console . error ( err )
220+ console . error ( 'Failed to get block model:' , err )
230221 if ( typeof err . message === 'string' ) {
231222 el . error . set ( err . message as string )
232223 }
0 commit comments