@@ -14,6 +14,10 @@ const mcData = minecraftData(VERSION)
1414const { nearestMatch } = mapcolors
1515const { createCanvas } = canvas
1616
17+ const SPAWNED_SCREENS = {
18+ screens : [ ] ,
19+ }
20+
1721export function register_screen ( { id, size : { width, height } } ) {
1822 return world => ( {
1923 ...world ,
@@ -106,6 +110,8 @@ export function spawn_screen(
106110 } )
107111 }
108112 }
113+
114+ SPAWNED_SCREENS . screens [ SPAWNED_SCREENS . screens . length ] = screen_id
109115}
110116
111117export function update_screen (
@@ -154,12 +160,15 @@ export function update_screen(
154160
155161export function destroy_screen ( { client, world } , { screen_id } ) {
156162 const { size, start_id } = world . screens [ screen_id ]
157-
158163 client . write ( 'entity_destroy' , {
159164 entityIds : Array . from ( {
160165 length : size . width * size . height ,
161166 } ) . map ( ( v , index ) => start_id + index ) ,
162167 } )
168+
169+ SPAWNED_SCREENS . screens = SPAWNED_SCREENS . screens . filter (
170+ id => id !== screen_id
171+ )
163172}
164173
165174export function copy_canvas ( old_canvas ) {
@@ -214,7 +223,7 @@ export default {
214223 const { position } = state
215224 for ( const [ screen_id , screen ] of Object . entries ( world . screens ) ) {
216225 const intersect = screen_ray_intersection ( screen , position )
217- if ( intersect ) {
226+ if ( intersect && SPAWNED_SCREENS . screens . includes ( screen_id ) ) {
218227 const { x, y } = intersect
219228 events . emit ( Context . SCREEN_INTERRACT , {
220229 x,
0 commit comments