@@ -4,12 +4,13 @@ import { stringifyError } from 'lib/util'
44import { AbstractPoint } from 'lib/utils/point'
55import { Vec } from 'lib/vector'
66
7- export type AreaCreator = new ( o : any ) => Area
7+ export type AreaCreator = new ( db : any , dimensionType ?: DimensionType ) => Area
88export type AreaWithType < T = AreaCreator > = T & { type : string }
99
1010export interface AreaAsJson extends JsonObject {
1111 t : string
1212 d : JsonObject
13+ dd ?: DimensionType
1314}
1415
1516export abstract class Area < T extends JsonObject = JsonObject > {
@@ -19,15 +20,17 @@ export abstract class Area<T extends JsonObject = JsonObject> {
1920
2021 static asSaveableArea < T extends AreaCreator > ( this : T ) {
2122 const b = this as AreaWithType < T >
22- b . type = new ( this as unknown as AreaCreator ) ( { } ) . type
23+ world . afterEvents . worldLoad . subscribe ( ( ) => {
24+ b . type = new ( this as unknown as AreaCreator ) ( { } ) . type
2325
24- if ( ( this as unknown as typeof Area ) . loaded ) {
25- throw new Error (
26- `Registering area type ${ b . type } failed. Regions are already restored from json. Registering area should occur on the import-time.` ,
27- )
28- }
26+ if ( ( this as unknown as typeof Area ) . loaded ) {
27+ throw new Error (
28+ `Registering area type ${ b . type } failed. Regions are already restored from json. Registering area should occur on the import-time.` ,
29+ )
30+ }
2931
30- ; ( this as unknown as typeof Area ) . areas . push ( b as unknown as AreaWithType )
32+ ; ( this as unknown as typeof Area ) . areas . push ( b as unknown as AreaWithType )
33+ } )
3134 return b
3235 }
3336
@@ -40,7 +43,7 @@ export abstract class Area<T extends JsonObject = JsonObject> {
4043 return
4144 }
4245
43- return new area ( a . d )
46+ return new area ( a . d , a . dd )
4447 }
4548
4649 constructor (
@@ -92,7 +95,7 @@ export abstract class Area<T extends JsonObject = JsonObject> {
9295 * restore the same state
9396 */
9497 toJSON ( ) : AreaAsJson {
95- return { t : this . type , d : this . database }
98+ return { t : this . type , d : this . database , dd : this . dimensionType === 'overworld' ? undefined : this . dimensionType }
9699 }
97100
98101 protected get dimension ( ) {
0 commit comments