forked from hytopiagg/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.d.ts
More file actions
6156 lines (5661 loc) · 208 KB
/
server.d.ts
File metadata and controls
6156 lines (5661 loc) · 208 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type { AnyPacket } from '@hytopia.com/server-protocol';
import type { ErrorEvent as ErrorEvent_2 } from 'ws';
import EventEmitter from 'eventemitter3';
import http from 'http';
import type { IncomingMessage } from 'http';
import type { InputSchema } from '@hytopia.com/server-protocol';
import type { LobbyMembershipDto } from '@hytopia.com/creative-lib/dist/impl/getSession';
import mediasoup from 'mediasoup';
import protocol from '@hytopia.com/server-protocol';
import RAPIER from '@dimforge/rapier3d-simd-compat';
import { SdpMatrix3 } from '@dimforge/rapier3d-simd-compat';
import type { Socket } from 'net';
import { WebSocket as WebSocket_2 } from 'ws';
/**
* Represents a audio playback in a world.
*
* @remarks
* Audio instances are created directly as instances.
* They support a variety of configuration options through
* the {@link AudioOptions} constructor argument.
*
* <h2>Events</h2>
*
* This class is an EventRouter, and instances of it emit
* events with payloads listed under {@link AudioEventPayloads}
*
* @example
* ```typescript
* (new Audio({
* uri: 'music/song.mp3', // relative to the server's assets directory in the project root, resolves to assets/music/song.mp3
* loop: true,
* volume: 0.5,
* })).play(world);
* ```
*
* @eventProperty
*
* @public
*/
export declare class Audio extends EventRouter implements protocol.Serializable {
/**
* @param options - The options for the Audio instance.
*/
constructor(options: AudioOptions);
/** The unique identifier for the audio. */
get id(): number | undefined;
/** The entity to which the audio is attached if explicitly set. */
get attachedToEntity(): Entity | undefined;
/** The cutoff distance where the audio will be reduced to 0 volume. */
get cutoffDistance(): number;
/** The duration of the audio in seconds if explicitly set. */
get duration(): number | undefined;
/** The detune of the audio in cents if explicitly set. */
get detune(): number | undefined;
/** The amount of distortion to apply to the audio if explicitly set. */
get distortion(): number | undefined;
/** Whether the audio is looped. */
get loop(): boolean;
/** The offset time in seconds from which the audio should start playing if explicitly set. */
get offset(): number | undefined;
/** Whether the audio has loaded into the world. Audio is loaded the first time play() is called. */
get isLoaded(): boolean;
/** Whether the audio is currently playing. */
get isPlaying(): boolean;
/** Whether the audio is positional (Entity or position attached). */
get isPositional(): boolean;
/** The position of the audio in the world if explicitly set. */
get position(): Vector3Like | undefined;
/** The playback rate of the audio if explicitly set. */
get playbackRate(): number | undefined;
/** The reference distance of the audio if explicitly set. */
get referenceDistance(): number;
/** The server tick at which the audio started playing. */
get startTick(): number | undefined;
/** The URI of the audio asset. */
get uri(): string;
/** The volume of the audio if explicitly set. */
get volume(): number | undefined;
/** The world the audio is in if already loaded. */
get world(): World | undefined;
/**
* Plays or resumes the audio.
*
* @param world - The world to play the audio in.
* @param restart - If true, the audio will restart from the beginning if it is already playing.
*/
play(world: World, restart?: boolean): void;
/**
* Pauses the audio.
*/
pause(): void;
/**
* Sets the entity to which the audio is attached, following its position.
*
* @param entity - The entity to attach the Audio to.
*/
setAttachedToEntity(entity: Entity): void;
/**
* Sets the cutoff distance of the audio.
*
* @remarks
* The cutoff distance defines the maximum range at which the audio can be heard.
* Beyond this distance, the audio volume becomes zero. As the listener moves
* from the reference distance toward the cutoff distance, the volume decreases
* linearly, providing a natural spatial audio experience with smooth volume
* falloff based on distance.
*
* @param cutoffDistance - The cutoff distance.
*/
setCutoffDistance(cutoffDistance: number): void;
/**
* Sets the detune of the audio.
*
* @param detune - The detune in cents.
*/
setDetune(detune: number): void;
/**
* Sets the distortion of the audio.
*
* @param distortion - The distortion amount.
*/
setDistortion(distortion: number): void;
/**
* Sets the position of the audio. Will detach from entity if attached.
*
* @param position - The position in the world.
*/
setPosition(position: Vector3Like): void;
/**
* Sets the playback rate of the audio.
*
* @param playbackRate - The playback rate.
*/
setPlaybackRate(playbackRate: number): void;
/**
* Sets the reference distance of the audio.
*
* @remarks
* The reference distance defines the range within which the audio plays at
* full volume. When a listener is within this distance from the audio source,
* they will hear the sound at its maximum volume. Beyond this distance, the
* volume decreases linearly until reaching the cutoff distance, where the
* sound becomes inaudible. This creates a natural spatial audio experience
* with smooth volume falloff based on distance.
*
* @param referenceDistance - The reference distance.
*/
setReferenceDistance(referenceDistance: number): void;
/**
* Sets the volume of the audio.
*
* @param volume - The volume level.
*/
setVolume(volume: number): void;
}
/** Event types an Audio instance can emit. See {@link AudioEventPayloads} for the payloads. @public */
export declare enum AudioEvent {
PAUSE = "AUDIO.PAUSE",
PLAY = "AUDIO.PLAY",
PLAY_RESTART = "AUDIO.PLAY_RESTART",
SET_ATTACHED_TO_ENTITY = "AUDIO.SET_ATTACHED_TO_ENTITY",
SET_CUTOFF_DISTANCE = "AUDIO.SET_CUTOFF_DISTANCE",
SET_DETUNE = "AUDIO.SET_DETUNE",
SET_DISTORTION = "AUDIO.SET_DISTORTION",
SET_POSITION = "AUDIO.SET_POSITION",
SET_PLAYBACK_RATE = "AUDIO.SET_PLAYBACK_RATE",
SET_REFERENCE_DISTANCE = "AUDIO.SET_REFERENCE_DISTANCE",
SET_VOLUME = "AUDIO.SET_VOLUME"
}
/** Event payloads for Audio emitted events. @public */
export declare interface AudioEventPayloads {
/** Emitted when the audio is paused. */
[AudioEvent.PAUSE]: {
audio: Audio;
};
/** Emitted when the audio is played. */
[AudioEvent.PLAY]: {
audio: Audio;
};
/** Emitted when the audio is restarted. */
[AudioEvent.PLAY_RESTART]: {
audio: Audio;
};
/** Emitted when the audio is attached to an entity. */
[AudioEvent.SET_ATTACHED_TO_ENTITY]: {
audio: Audio;
entity: Entity | undefined;
};
/** Emitted when the audio's cutoff distance is set. */
[AudioEvent.SET_CUTOFF_DISTANCE]: {
audio: Audio;
cutoffDistance: number;
};
/** Emitted when the audio's detune is set. */
[AudioEvent.SET_DETUNE]: {
audio: Audio;
detune: number;
};
/** Emitted when the audio's distortion is set. */
[AudioEvent.SET_DISTORTION]: {
audio: Audio;
distortion: number;
};
/** Emitted when the audio's position is set. */
[AudioEvent.SET_POSITION]: {
audio: Audio;
position: Vector3Like;
};
/** Emitted when the audio's playback rate is set. */
[AudioEvent.SET_PLAYBACK_RATE]: {
audio: Audio;
playbackRate: number;
};
/** Emitted when the audio's reference distance is set. */
[AudioEvent.SET_REFERENCE_DISTANCE]: {
audio: Audio;
referenceDistance: number;
};
/** Emitted when the audio's volume is set. */
[AudioEvent.SET_VOLUME]: {
audio: Audio;
volume: number;
};
}
/**
* Manages audio instances in a world.
*
* @remarks
* The AudioManager is created internally as a singleton
* for each {@link World} instance in a game server.
* It allows retrieval of all loaded audio, entity
* attached audio, looped audio, and more.
*
* @example
* ```typescript
* // Stop all audio in the world
* const audioManager = world.audioManager;
* audioManager.getAllAudios().map(audio => audio.pause());
* ```
*
* @public
*/
export declare class AudioManager {
/** The world the audio manager is for. */
get world(): World;
/**
* Retrieves all loaded audio instances for the world.
*
* @returns An array of audio instances.
*/
getAllAudios(): Audio[];
/**
* Retrieves all loaded audio instances attached to a specific entity.
*
* @param entity - The entity to get attached audio instances for.
* @returns An array of audio instances.
*/
getAllEntityAttachedAudios(entity: Entity): Audio[];
/**
* Retrieves all looped audio instances for the world.
*
* @returns An array of audio instances.
*/
getAllLoopedAudios(): Audio[];
/**
* Retrieves all oneshot (non-looped) audio instances for the world.
*
* @returns An array of audio instances.
*/
getAllOneshotAudios(): Audio[];
/**
* Unregisters and stops an audio instance from the audio manager.
*
* @param audio - The audio instance to pause and unregister.
*/
unregisterAudio(audio: Audio): void;
/**
* Unregisters and stops all audio instances attached to a specific entity.
*
* @param entity - The entity to pause and unregister audio instances for.
*/
unregisterEntityAttachedAudios(entity: Entity): void;
}
/** Options for creating an Audio instance. @public */
export declare interface AudioOptions {
/** If set, audio playback will follow the entity's position. */
attachedToEntity?: Entity;
/** The cutoff distance between the audio source and the listener where the audio will be reduced to 0 volume. Must be greater than reference distance. Defaults to reference distance + 10. */
cutoffDistance?: number;
/** The duration of the audio in seconds. Defaults to full duration. */
duration?: number;
/** The detuning of the audio in cents. */
detune?: number;
/** The amount of distortion to apply to the audio. */
distortion?: number;
/** Whether the audio should loop when it reaches the end. Defaults to false. */
loop?: boolean;
/** The offset time in seconds from which the audio should start playing. */
offset?: number;
/** The position in the world where the audio is played. */
position?: Vector3Like;
/** The playback speed of the audio. Defaults to 1. */
playbackRate?: number;
/** The maximum reference distance between the audio source and the listener where the audio will still be max volume. Defaults to 10. */
referenceDistance?: number;
/** The URI or path to the audio asset to be played. */
uri: string;
/** The volume level of the audio. Defaults to 0.5. */
volume?: number;
}
/** The options for a ball collider. @public */
export declare interface BallColliderOptions extends BaseColliderOptions {
shape: ColliderShape.BALL;
/** The radius of the ball collider. */
radius?: number;
}
/** The base options for a collider. @public */
export declare interface BaseColliderOptions {
/** The shape of the collider. */
shape: ColliderShape;
/** The bounciness of the collider. */
bounciness?: number;
/** The bounciness combine rule of the collider. */
bouncinessCombineRule?: CoefficientCombineRule;
/** The collision groups the collider belongs to. */
collisionGroups?: CollisionGroups;
/** Whether the collider is enabled. */
enabled?: boolean;
/** The flags of the collider if the shape is a trimesh */
flags?: number;
/** The friction of the collider. */
friction?: number;
/** The friction combine rule of the collider. */
frictionCombineRule?: CoefficientCombineRule;
/** Whether the collider is a sensor. */
isSensor?: boolean;
/** The mass of the collider. */
mass?: number;
/** The on collision callback for the collider. */
onCollision?: CollisionCallback;
/** The parent rigid body of the collider. */
parentRigidBody?: RigidBody;
/** The relative position of the collider. Relative to parent rigid body. */
relativePosition?: Vector3Like;
/** The relative rotation of the collider. Relative to parent rigid body. */
relativeRotation?: QuaternionLike;
/** The simulation the collider is in, if provided the collider will automatically be added to the simulation. */
simulation?: Simulation;
/** An arbitrary identifier tag of the collider. Useful for your own logic. */
tag?: string;
}
/**
* A base class for entity controller implementations.
*
* @remarks
* The BaseEntityController should be extended
* by a more specific entity controller that you or a
* plugin implements. Entity controllers are intended to
* be used as one controller instance per entity, but
* are flexible enough for edge cases such as if you want to create
* niche behavior of one controller for many entities that
* behave in unison.
*
* <h2>Events</h2>
*
* This class is an EventRouter, and instances of it emit
* events with payloads listed under {@link BaseEntityControllerEventPayloads}
*
* @public
*/
export declare abstract class BaseEntityController extends EventRouter {
/**
* Override this method to handle the attachment of an entity
* to your entity controller.
* @param entity - The entity to attach the controller to.
*/
attach(entity: Entity): void;
/**
* Override this method to handle the despawn of an entity
* from your entity controller.
* @param entity - The entity to despawn.
*/
despawn(entity: Entity): void;
/**
* Override this method to handle the detachment of an entity
* from your entity controller.
* @param entity - The entity to detach.
*/
detach(entity: Entity): void;
/**
* Override this method to handle the spawning of an entity
* to your entity controller.
* @param entity - The entity to spawn.
*/
spawn(entity: Entity): void;
/**
* Override this method to handle entity movements
* based on player input for your entity controller.
* This is called every tick by a PlayerEntity with a
* entity controller.
* @param entity - The entity to tick.
* @param input - The current input state of the player.
* @param cameraOrientation - The current camera orientation state of the player.
* @param deltaTimeMs - The delta time in milliseconds since the last tick.
*/
tickWithPlayerInput(entity: PlayerEntity, input: PlayerInput, cameraOrientation: PlayerCameraOrientation, deltaTimeMs: number): void;
/**
* Override this method to handle entity movements
* based on your entity controller.
* @param deltaTimeMs - The delta time in milliseconds since the last tick.
*/
tick(entity: Entity, deltaTimeMs: number): void;
}
/** Event types a BaseEntityController instance can emit. See {@link BaseEntityControllerEventPayloads} for the payloads. @public */
export declare enum BaseEntityControllerEvent {
ATTACH = "BASE_ENTITY_CONTROLLER.ATTACH",
DESPAWN = "BASE_ENTITY_CONTROLLER.DESPAWN",
DETACH = "BASE_ENTITY_CONTROLLER.DETACH",
SPAWN = "BASE_ENTITY_CONTROLLER.SPAWN",
TICK = "BASE_ENTITY_CONTROLLER.TICK",
TICK_WITH_PLAYER_INPUT = "BASE_ENTITY_CONTROLLER.TICK_WITH_PLAYER_INPUT"
}
/** Event payloads for BaseEntityController emitted events. @public */
export declare interface BaseEntityControllerEventPayloads {
/** Emitted when an entity is attached to the controller. */
[BaseEntityControllerEvent.ATTACH]: {
entity: Entity;
};
/** Emitted when an entity is despawned. */
[BaseEntityControllerEvent.DESPAWN]: {
entity: Entity;
};
/** Emitted when an entity is detached from the controller. */
[BaseEntityControllerEvent.DETACH]: {
entity: Entity;
};
/** Emitted when an entity is spawned. */
[BaseEntityControllerEvent.SPAWN]: {
entity: Entity;
};
/** Emitted when an entity is ticked. */
[BaseEntityControllerEvent.TICK]: {
entity: Entity;
deltaTimeMs: number;
};
/** Emitted when an entity is ticked with player input. */
[BaseEntityControllerEvent.TICK_WITH_PLAYER_INPUT]: {
entity: PlayerEntity;
input: PlayerInput;
cameraOrientation: PlayerCameraOrientation;
deltaTimeMs: number;
};
}
/** The base options for an entity. @public */
export declare interface BaseEntityOptions {
/** The entity controller to use for the entity. */
controller?: BaseEntityController;
/** The opacity of the entity between 0 and 1. 0 is fully transparent, 1 is fully opaque. */
opacity?: number;
/** The parent entity of the entity, entities with a parent will ignore creating their own colliders. */
parent?: Entity;
/** The name of the parent's node (if parent is a model entity) to attach the entity to. */
parentNodeName?: string;
/** The rigid body options for the entity. */
rigidBodyOptions?: RigidBodyOptions;
/** An arbitrary identifier tag of the entity. Useful for your own logic. */
tag?: string;
/** The tint color of the entity as a hex code. */
tintColor?: RgbColor;
/** The name of the entity. */
name?: string;
}
/** The base options for a rigid body. @public */
export declare interface BaseRigidBodyOptions {
/** The type of the rigid body, defaults to {@link RigidBodyType.DYNAMIC}. */
type?: RigidBodyType;
/** The colliders of the rigid body, provided as {@link ColliderOptions}. */
colliders?: ColliderOptions[];
/** Whether the rigid body is enabled. */
enabled?: boolean;
/** The position of the rigid body. */
position?: Vector3Like;
/** The rotation of the rigid body. */
rotation?: QuaternionLike;
/** The simulation the rigid body is in. If provided, the rigid body will be automatically added to the simulation. */
simulation?: Simulation;
}
/**
* Represents a block in a world.
*
* @remarks
* Instances of this class are created internally but made
* publicly available through various public facing API
* methods.
*
* @public
*/
export declare class Block {
/** The global coordinate of the block. */
readonly globalCoordinate: Vector3Like;
/** The block type of the block. */
readonly blockType: BlockType;
/**
* Gets the most adjacent neighbor global coordinate of this block
* based on a relative hit point, typically from a raycast.
*
* @param hitPoint - The hit point on this block to get the neighbor coordinate from.
* @returns A neighbor global coordinate of this block based on the hit point.
*/
getNeighborGlobalCoordinateFromHitPoint(hitPoint: Vector3Like): Vector3Like;
}
/** The options for a block collider. @public */
export declare interface BlockColliderOptions extends BaseColliderOptions {
shape: ColliderShape.BLOCK;
/** The half extents of the block collider. */
halfExtents?: Vector3Like;
}
/** The options for creating a block entity. @public */
export declare interface BlockEntityOptions extends BaseEntityOptions {
/** The half extents of the visual size of the block entity when blockTextureUri is set. If no rigidBodyOptions.colliders are provided, a block collider with the size of the half extents will be created. */
blockHalfExtents?: Vector3Like;
/** The texture uri of a entity if the entity is a block entity, if set rigidBodyOptions collider shape [0] must be a block */
blockTextureUri?: string;
}
/**
* Represents a block type.
*
* @remarks
* Block types are created directly as instances.
* They support a variety of configuration options through
* the {@link BlockTypeOptions} constructor argument.
* Block types are registered with a {@link BlockTypeRegistry} instance,
* allowing you to create custom blocks with unique visual representations
* and behaviors.
*
* <h2>Events</h2>
*
* This class is an EventRouter, and instances of it emit
* events with payloads listed under {@link BlockTypeEventPayloads}
*
* @example
* ```typescript
* const stoneBlockTypeId = 10;
* world.blockTypeRegistry.registerBlockType(stoneBlockTypeId, new BlockType({
* id: stoneBlockTypeId,
* textureUri: 'textures/stone.png',
* name: 'Stone',
* }));
*
* // Create a stone block at coordinate 0, 1, 0
* world.chunkLattice.setBlock({ x: 0, y: 1, z: 0 }, stoneBlockTypeId);
* ```
*
* @public
*/
export declare class BlockType extends EventRouter implements protocol.Serializable {
/**
* Creates a new block type instance.
* @param world - The world the block type is for.
* @param options - The options for the block type.
*/
constructor(options?: BlockTypeOptions);
/** The unique identifier for the block type. */
get id(): number;
/** The collider options for the block type. */
get colliderOptions(): TrimeshColliderOptions;
/** Whether the block type is a liquid. */
get isLiquid(): boolean;
/** Whether the block type is meshable. */
get isMeshable(): boolean;
/** The name of the block type. */
get name(): string;
/** The URI of the texture for the block type. */
get textureUri(): string;
}
/** Event types a BlockType instance can emit. See {@link BlockTypeEventPayloads} for the payloads. @public */
export declare enum BlockTypeEvent {
ENTITY_COLLISION = "BLOCK_TYPE.ENTITY_COLLISION",
ENTITY_CONTACT_FORCE = "BLOCK_TYPE.ENTITY_CONTACT_FORCE"
}
/** Event payloads for BlockType emitted events. @public */
export declare interface BlockTypeEventPayloads {
/** Emitted when an entity collides with a block type. */
[BlockTypeEvent.ENTITY_COLLISION]: {
blockType: BlockType;
entity: Entity;
started: boolean;
colliderHandleA: number;
colliderHandleB: number;
};
/** Emitted when an entity's contact force is applied to a block type. */
[BlockTypeEvent.ENTITY_CONTACT_FORCE]: {
blockType: BlockType;
entity: Entity;
contactForceData: ContactForceData;
};
}
/** Options for creating a block type instance. @public */
export declare interface BlockTypeOptions {
/** The unique numeric identifier for the block type. */
id: number;
/** The custom collider options for the block type. */
customColliderOptions?: TrimeshColliderOptions;
/** Whether the block type is a liquid. */
isLiquid?: boolean;
/** The name of the block type. */
name: string;
/** The URI of the texture asset for the block type. */
textureUri: string;
}
/**
* Manages known block types in a world.
*
* @remarks
* Block type registries are created internally as a singleton
* for each {@link World} instance in a game server. A block
* type registry allows you to register and retrieve block
* types by their unique id for a world.
*
* <h2>Events</h2>
*
* This class is an EventRouter, and instances of it emit
* events with payloads listed under {@link BlockTypeRegistryEventPayloads}
*
* @example
* ```typescript
* world.blockTypeRegistry.registerGenericBlockType({
* id: 15,
* textureUri: 'textures/dirt.png',
* name: 'Dirt',
* });
* ```
*
* @public
*/
export declare class BlockTypeRegistry extends EventRouter implements protocol.Serializable {
/** The world the block type registry is for. */
get world(): World;
/**
* Get all registered block types.
* @returns An array of all registered block types.
*/
getAllBlockTypes(): BlockType[];
/**
* Get a registered block type by its id.
* @param id - The id of the block type to get.
* @returns The block type with the given id.
*/
getBlockType(id: number): BlockType;
/**
* Register a generic block type.
* @param blockTypeOptions - The options for the block type.
* @returns The registered block type.
*/
registerGenericBlockType(blockTypeOptions: BlockTypeOptions): BlockType;
/**
* Register a block type.
* @param blockType - The block type to register.
*/
registerBlockType(blockType: BlockType): void;
}
/** Event types a BlockTypeRegistry instance can emit. See {@link BlockTypeRegistryEventPayloads} for the payloads. @public */
export declare enum BlockTypeRegistryEvent {
REGISTER_BLOCK_TYPE = "BLOCK_TYPE_REGISTRY.REGISTER_BLOCK_TYPE"
}
/** Event payloads for BlockTypeRegistry emitted events. @public */
export declare interface BlockTypeRegistryEventPayloads {
/** Emitted when a block type is registered. */
[BlockTypeRegistryEvent.REGISTER_BLOCK_TYPE]: {
blockTypeRegistry: BlockTypeRegistry;
id: number;
blockType: BlockType;
};
}
/** The options for a capsule collider. @public */
export declare interface CapsuleColliderOptions extends BaseColliderOptions {
shape: ColliderShape.CAPSULE;
/** The half height of the capsule collider. */
halfHeight?: number;
/** The radius of the capsule collider. */
radius?: number;
}
/** Event types a ChatManager instance can emit. See {@link ChatEventPayloads} for the payloads. @public */
export declare enum ChatEvent {
BROADCAST_MESSAGE = "CHAT.BROADCAST_MESSAGE",
PLAYER_MESSAGE = "CHAT.PLAYER_MESSAGE"
}
/** Event payloads for ChatManager emitted events. @public */
export declare interface ChatEventPayloads {
/** Emitted when a broadcast message is sent. */
[ChatEvent.BROADCAST_MESSAGE]: {
player: Player | undefined;
message: string;
color?: string;
};
/** Emitted when a message is sent to a specific player. */
[ChatEvent.PLAYER_MESSAGE]: {
player: Player;
message: string;
color?: string;
};
}
/**
* Manages chat and commands in a world.
*
* @remarks
* The ChatManager is created internally as a singleton
* for each {@link World} instance in a game server.
* The ChatManager allows you to broadcast messages,
* send messages to specific players, and register
* commands that can be used in chat to execute game
* logic.
*
* <h2>Events</h2>
*
* This class is an EventRouter, and instances of it emit
* events with payloads listed under {@link ChatEventPayloads}
*
* @example
* ```typescript
* world.chatManager.registerCommand('/kick', (player, args, message) => {
* const admins = [ 'arkdev', 'testuser123' ];
* if (admins.includes(player.username)) {
* const targetUsername = args[0];
* const targetPlayer = world.playerManager.getConnectedPlayerByUsername(targetUsername);
*
* if (targetPlayer) {
* targetPlayer.disconnect();
* }
* }
* });
* ```
*
* @public
*/
export declare class ChatManager extends EventRouter {
/**
* Register a command and its callback.
* @param command - The command to register.
* @param callback - The callback function to execute when the command is used.
*/
registerCommand(command: string, callback: CommandCallback): void;
/**
* Unregister a command.
* @param command - The command to unregister.
*/
unregisterCommand(command: string): void;
/**
* Send a system broadcast message to all players in the world.
* @param message - The message to send.
* @param color - The color of the message as a hex color code, excluding #.
*
* @example
* ```typescript
* chatManager.sendBroadcastMessage('Hello, world!', 'FF00AA');
* ```
*/
sendBroadcastMessage(message: string, color?: string): void;
/**
* Send a system message to a specific player, only visible to them.
* @param player - The player to send the message to.
* @param message - The message to send.
* @param color - The color of the message as a hex color code, excluding #.
*
* @example
* ```typescript
* chatManager.sendPlayerMessage(player, 'Hello, player!', 'FF00AA');
* ```
*/
sendPlayerMessage(player: Player, message: string, color?: string): void;
}
/**
* A 16^3 chunk of blocks. Used to represent a world's terrain.
*
* @remarks
* Chunks make up the bulk of the terrain in a world. Chunks are
* fixed size, each containing 16^3 possible blocks as
* a 16x16x16 cube. Chunks can be spawned, despawned, have their
* unique blocks set or removed, and more. Chunks represent their
* internal block coordinates in local space, meaning only coordinates
* x: 0...15, y: 0...15, z: 0...15 are valid.
*
* The Chunk follows a spawn and despawn lifecycle pattern.
* When you create a chunk, when you're ready to load it in your
* world you use .spawn(). To remove it, you use .despawn().
*
* Use .setBlock() to set the block type id at a specific local cooridnate.
* Block type ids are ones that have been registered in the {@link BlockTypeRegistry}
* associated with the {@link World} the chunk belongs to. A block type id of 0
* is used to represent no block. Removing a block is done by .setBlock(localCoordinate, 0).
*
* <h2>Events</h2>
*
* This class is an EventRouter, and instances of it emit
* events with payloads listed under {@link ChunkEventPayloads}
*
* @example
* ```typescript
* // Assume we previously registered a stone block with type id of 10..
*
* const chunk = new Chunk();
*
* chunk.setBlock({ x: 0, y: 0, z: 0 }, 10); // Set the block at 0, 0, 0 to stone
* chunk.spawn(world, { x: 16, y: 0, z: 16 }); // Spawn the chunk at global coordinate 16, 0, 16
* ```
*
* @public
*/
export declare class Chunk extends EventRouter implements protocol.Serializable {
/**
* Creates a new chunk instance.
*/
constructor();
/** The blocks in the chunk as a flat Uint8Array[4096], each index as 0 or a block type id. */
get blocks(): Readonly<Uint8Array>;
/** Whether the chunk is actively simulated in the internal physics engine. */
get isSimulated(): boolean;
/** Whether the chunk has been spawned. */
get isSpawned(): boolean;
/** The origin coordinate of the chunk. */
get originCoordinate(): Vector3Like | undefined;
/** The world the chunk belongs to. */
get world(): World | undefined;
/**
* Convert a block index to a local coordinate.
* @param index - The index of the block to convert.
* @returns The local coordinate of the block.
*/
static blockIndexToLocalCoordinate(index: number): Vector3Like;
/**
* Convert a global coordinate to a local coordinate.
* @param globalCoordinate - The global coordinate to convert.
* @returns The local coordinate.
*/
static globalCoordinateToLocalCoordinate(globalCoordinate: Vector3Like): Vector3Like;
/**
* Convert a global coordinate to an origin coordinate.
* @param globalCoordinate - The global coordinate to convert.
* @returns The origin coordinate.
*/
static globalCoordinateToOriginCoordinate(globalCoordinate: Vector3Like): Vector3Like;
/**
* Check if an origin coordinate is valid.
* @param coordinate - The coordinate to check.
* @returns Whether the coordinate is valid.
*/
static isValidOriginCoordinate(coordinate: Vector3Like): boolean;
/**
* Spawn the chunk in the world.
* @param world - The world to spawn the chunk in.
* @param originCoordinate - The origin coordinate of the chunk.
*/
spawn(world: World, originCoordinate: Vector3Like): void;
/**
* Despawn the chunk from the world.
*/
despawn(): void;
/**
* Get the block type id at a specific local coordinate.
* @param localCoordinate - The local coordinate of the block to get.
* @returns The block type id.
*/
getBlockId(localCoordinate: Vector3Like): number;
/**
* Check if a block exists at a specific local coordinate.
* @param localCoordinate - The local coordinate of the block to check.
* @returns Whether a block exists.
*/
hasBlock(localCoordinate: Vector3Like): boolean;
/**
* Set the block at a specific local coordinate by block type id.
* @param localCoordinate - The local coordinate of the block to set.
* @param blockTypeId - The block type id to set.
*/
setBlock(localCoordinate: Vector3Like, blockTypeId: number): void;
private _meshColliders;
}
/** Event types a Chunk instance can emit. See {@link ChunkEventPayloads} for the payloads. @public */
export declare enum ChunkEvent {
DESPAWN = "CHUNK.DESPAWN",
SET_BLOCK = "CHUNK.SET_BLOCK",
SPAWN = "CHUNK.SPAWN"
}
/** Event payloads for Chunk emitted events. @public */
export declare interface ChunkEventPayloads {
/** Emitted when a chunk is despawned. */
[ChunkEvent.DESPAWN]: {
chunk: Chunk;
};
/** Emitted when a block is set in a chunk. */
[ChunkEvent.SET_BLOCK]: {
chunk: Chunk;
globalCoordinate: Vector3Like;
localCoordinate: Vector3Like;
blockTypeId: number;
};
/** Emitted when a chunk is spawned. */
[ChunkEvent.SPAWN]: {
chunk: Chunk;
};
}
/**
* A lattice of chunks that represent a world's terrain.
*
* @remarks
* The ChunkLattice lattice tracks the current terrain of a world,
* comprised of {@link Chunk} instances.
*
* @public
*/
export declare class ChunkLattice {
/**
* Creates a new chunk lattice instance.
* @param world - The world the chunk lattice is for.