This repository was archived by the owner on Nov 13, 2023. It is now read-only.
forked from JaylyDev/ScriptAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
770 lines (770 loc) · 25.6 KB
/
index.js
File metadata and controls
770 lines (770 loc) · 25.6 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
// Script example for ScriptAPI
// Author: Jayly <https://github.com/JaylyDev>
// Project: https://github.com/JaylyDev/ScriptAPI
import * as Minecraft from "@minecraft/server";
/**
* A simulated player can be used to represent
* how a player moves throughout the world and to support
* testing of how entities and the environment will react to a
* player. This type derives much of its structure and methods
* from the {@link Minecraft.Player} type.
*/
export class SimulatedPlayer {
/**
* Dimension that the simulated player is currently within.
* @throws This property can throw when used.
*/
get 'dimension'() { return this.__player.dimension; }
;
/**
* Location of the center of the head component of the player.
* @throws This property can throw when used.
*/
get 'headLocation'() { return this.__player.getHeadLocation(); }
;
/**
* Rotation of the head across pitch and yaw angles.
* @throws This property can throw when used.
*/
get 'headRotation'() { return this.__player.headRotation; }
;
/**
* Identifier for the player.
* @throws This property can throw when used.
*/
get 'id'() { return this.__player.id; }
;
/**
* Unique identifier of the type of the entity - for example,
* 'minecraft:player'.
* @throws This property can throw when used.
*/
get 'typeId'() { return this.__player.typeId; }
;
/**
* True if the player is currently using a sneaking movement.
*/
get 'isSneaking'() {
return this.__player.isSneaking;
}
set 'isSneaking'(value) {
this.__player.isSneaking = value;
}
/**
* Current location of the player.
* @throws This property can throw when used.
*/
get 'location'() { return this.__player.location; }
;
/**
* Name of the player.
* @throws This property can throw when used.
*/
get 'name'() { return this.__player.name; }
;
/**
* Optional name tag of the player.
*/
get 'nameTag'() {
return this.__player.nameTag;
}
set 'nameTag'(value) {
this.__player.nameTag = value;
}
/**
* Contains methods for manipulating the on-screen display of a
* Player.
*/
get 'onScreenDisplay'() { return this.__player.onScreenDisplay; }
;
/**
* Main rotation of the entity.
* @throws This property can throw when used.
*/
get 'rotation'() { return this.__player.getRotation(); }
;
/**
* Returns a scoreboard identity that represents this entity.
* @throws This property can throw when used.
*/
get 'scoreboard'() { return this.__player.scoreboard; }
;
/**
* Manages the selected slot in the player's hotbar.
*/
get 'selectedSlot'() {
return this.__player.selectedSlot;
}
;
set 'selectedSlot'(value) {
this.__player.selectedSlot = value;
}
/**
* Retrieves or sets an entity that is used as the target of
* AI-related behaviors, like attacking.
*/
get 'target'() {
return this.__player.target;
}
;
/**
* Current speed of the player across X, Y, and Z dimensions.
* @throws This property can throw when used.
*/
get 'velocity'() { return new Minecraft.Vector(this.__player.getVelocity().x, this.__player.getVelocity().y, this.__player.getVelocity().z); }
;
/**
* Vector of the current view of the player.
* @throws This property can throw when used.
*/
get 'viewDirection'() { return this.__player.getViewDirection(); }
;
/**
* @remarks
* Adds an effect, like poison, to the entity.
* @param effectType
* Type of effect to add to the entity.
* @param duration
* Amount of time, in seconds, for the effect to apply.
* @param amplifier
* Optional amplification of the effect to apply.
* @param showParticles
* @throws This function can throw errors.
*/
addEffect(effectType, duration, amplifier, showParticles) { return this.__player.addEffect(effectType, duration, amplifier, showParticles); }
;
/**
* @remarks
* Adds experience to a simulated player.
* @param amount
* Amount of experience to add.
* @throws This function can throw errors.
*/
addExperience(amount) { return this.__player.addExperience(amount); }
;
/**
* @remarks
* Adds a specified tag to a simulated player.
* @param tag
* Content of the tag to add.
* @throws This function can throw errors.
*/
addTag(tag) { return this.__player.addTag(tag); }
;
/**
* @remarks
* Causes the simulated player to make an attack 'swipe'.
* Returns true if the attack was performed - for example, the
* player was not on cooldown and had a valid target. Target
* selection is performed by raycasting from the player's head.
* @throws This function can throw errors.
*/
attack() { return this.__player.attack(); }
;
/**
* @remarks
* Causes the simulated player to attack the provided target.
* Returns true if the attack was performed - for example, the
* player was not on cooldown and had a valid target. The
* attack can be performed at any distance and does not require
* line of sight to the target entity.
* @param entity
* @throws This function can throw errors.
*/
attackEntity(entity) { return this.__player.attackEntity(entity); }
;
/**
* @remarks
* Destroys the block at blockLocation, respecting the rules of
* the server player's game mode. The block will be hit until
* broken, an item is used or stopBreakingBlock is called.
* Returns true if the block at blockLocation is solid.
* @param blockLocation
* Location of the block to interact with.
* @param direction
* Direction to place the specified item within.
* @throws This function can throw errors.
*/
breakBlock(blockLocation, direction) { return this.__player.breakBlock(blockLocation, direction); }
;
/**
* @remarks
* Gets the first block that intersects with the vector of the
* view of this entity.
* @param options
* Additional options for processing this raycast query.
* @throws This function can throw errors.
*/
getBlockFromViewDirection(options) { return this.__player.getBlockFromViewDirection(options); }
;
/**
* @remarks
* Gets a component (that represents additional capabilities)
* for an entity.
* @param componentId
* The identifier of the component (e.g., 'minecraft:rideable')
* to retrieve. If no namespace prefix is specified,
* 'minecraft:' is assumed. If the component is not present on
* the entity, undefined is returned.
*/
getComponent(componentId) { return this.__player.getComponent(componentId); }
;
/**
* @remarks
* Returns all components that are both present on this entity
* and supported by the API.
*/
getComponents() { return this.__player.getComponents(); }
;
/**
* @remarks
* Returns a property value.
* @param identifier
* @returns
* Returns the value for the property, or undefined if the
* property has not been set.
* @throws This function can throw errors.
*/
getDynamicProperty(identifier) { return this.__player.getDynamicProperty(identifier); }
;
/**
* @remarks
* Returns the effect for the specified EffectType on the
* entity, or undefined if the effect is not present.
* @param effectType
* @returns
* Effect object for the specified effect, or undefined if the
* effect is not present.
* @throws This function can throw errors.
*/
getEffect(effectType) { return this.__player.getEffect(effectType); }
;
/**
* @remarks
* Gets the first entity that intersects with the vector of the
* view of this entity.
* @param options
* Additional options for processing this raycast query.
* @throws This function can throw errors.
*/
getEntitiesFromViewDirection(options) { return this.__player.getEntitiesFromViewDirection(options); }
;
/**
* @remarks
* Gets the current item cooldown time for a particular
* cooldown category.
velocity * @param itemCategory
* Specifies the cooldown category to retrieve the current
* cooldown for.
* @throws This function can throw errors.
*/
getItemCooldown(itemCategory) { return this.__player.getItemCooldown(itemCategory); }
;
/**
* @remarks
* Returns all tags associated with this simulated player.
* @throws This function can throw errors.
*/
getTags() { return this.__player.getTags(); }
;
/**
* @remarks
* Gives the simulated player a particular item stack.
* @param itemStack
* Item to give.
* @param selectSlot
* Whether to set the selected slot once given.
* @throws This function can throw errors.
*/
giveItem(itemStack, selectSlot) { return this.__player.giveItem(itemStack, selectSlot); }
;
/**
* @remarks
* Returns true if the specified component is present on this
* entity.
* @param componentId
* The identifier of the component (e.g., 'minecraft:rideable')
* to retrieve. If no namespace prefix is specified,
* 'minecraft:' is assumed.
*/
hasComponent(componentId) { return this.__player.hasComponent(componentId); }
;
/**
* @remarks
* Tests whether a simulated player has a particular tag.
* @param tag
* Identifier of the tag to test for.
* @throws This function can throw errors.
*/
hasTag(tag) { return this.__player.hasTag(tag); }
;
/**
* @remarks
* Performs a raycast from the player’s head and interacts with
* the first intersected block or entity. Returns true if the
* interaction was successful. Maximum range is 6 blocks.
* @throws This function can throw errors.
*/
interact() { return this.__player.interact(); }
;
/**
* @remarks
* Causes the simulated player to interact with a block. The
* block at the specified block location must be solid. Returns
* true if the interaction was performed.
* @param blockLocation
* Location of the block to interact with.
* @param direction
* Direction to place the specified item within.
* @throws This function can throw errors.
*/
interactWithBlock(blockLocation, direction) { return this.__player.interactWithBlock(blockLocation, direction); }
;
/**
* @remarks
* Causes the simulated player to interact with a mob. Returns
* true if the interaction was performed.
* @param entity
* Entity to interact with.
* @throws This function can throw errors.
*/
interactWithEntity(entity) { return this.__player.interactWithEntity(entity); }
;
/**
* @remarks
* Causes the simulated player to jump.
* @returns
* True if a jump was performed.
* @throws This function can throw errors.
*/
jump() { return this.__player.jump(); }
;
/**
* @remarks
* Removes this simulated player from the world.
*/
kick(reason) {
if (reason)
this.__test.print(`§e${this.__player.name} is kicked from the game: ${reason}`);
else
this.__test.print(`§e${this.__player.name} is kicked from the game`);
return this.__test.removeSimulatedPlayer(this.__player);
}
;
/**
* @remarks
* Kills this entity. The entity will drop loot as normal.
* @throws This function can throw errors.
*/
kill() { return this.__player.kill(); }
;
/**
* @remarks
* Rotates the simulated player's head/body to look at the
* given block location.
* @param blockLocation
* @throws This function can throw errors.
*/
lookAtBlock(blockLocation) { return this.__player.lookAtBlock(blockLocation); }
;
/**
* @remarks
* Rotates the simulated player's head/body to look at the
* given entity.
* @param entity
* @throws This function can throw errors.
*/
lookAtEntity(entity) { return this.__player.lookAtEntity(entity); }
;
/**
* @remarks
* Rotates the simulated player's head/body to look at the
* given location.
* @param location
* @throws This function can throw errors.
*/
lookAtLocation(location) { return this.__player.lookAtLocation(location); }
;
/**
* @remarks
* Orders the simulated player to walk in the given direction
* relative to the GameTest.
* @param westEast
* @param northSouth
* @param speed
* @throws This function can throw errors.
*/
move(westEast, northSouth, speed) { return this.__player.move(westEast, northSouth, speed); }
;
/**
* @remarks
* Orders the simulated player to walk in the given direction
* relative to the player's current rotation.
* @param leftRight
* @param backwardForward
* @param speed
* @throws This function can throw errors.
*/
moveRelative(leftRight, backwardForward, speed) { return this.__player.moveRelative(leftRight, backwardForward, speed); }
;
/**
* @remarks
* Orders the simulated player to move to the given block
* location in a straight line. If a move or navigation is
* already playing, this will override the last
* move/navigation.
* @param blockLocation
* @param speed
* @throws This function can throw errors.
*/
moveToBlock(blockLocation, speed) { return this.__player.moveToBlock(blockLocation, speed); }
;
/**
* @remarks
* Orders the simulated player to move to the given location in
* a straight line. If a move or navigation is already playing,
* this will override the last move/navigation.
* @param location
* @param speed
* @throws This function can throw errors.
*/
moveToLocation(location, speed) { return this.__player.moveToLocation(location, speed); }
;
/**
* @remarks
* Orders the simulated player to move to a specific block
* location using navigation. If a move or navigation is
* already playing, this will override the last move/walk. Note
* that if the simulated player gets stuck, that simulated
* player will stop. The player must be touching the ground in
* order to start navigation.
* @param blockLocation
* @param speed
* @throws This function can throw errors.
*/
navigateToBlock(blockLocation, speed) { return this.__player.navigateToBlock(blockLocation, speed); }
;
/**
* @remarks
* Will use navigation to follow the selected entity to within
* a one block radius. If a move or navigation is already
* playing, this will override the last move/navigation.
* @param entity
* @param speed
* @throws This function can throw errors.
*/
navigateToEntity(entity, speed) { return this.__player.navigateToEntity(entity, speed); }
;
/**
* @remarks
* Orders the simulated player to move to a specific location
* using navigation. If a move or navigation is already
* playing, this will override the last move/walk. Note that if
* the simulated player gets stuck, that simulated player will
* stop. The player must be touching the ground in order to
* start navigation.
* @param location
* @param speed
* @throws This function can throw errors.
*/
navigateToLocation(location, speed) { return this.__player.navigateToLocation(location, speed); }
;
/**
* @remarks
* Use navigation to follow the route provided via the
* locations parameter. If a move or navigation is already
* playing, this will override the last move/navigation.
* @param locations
* A list of locations to use for routing.
* @param speed
* Net speed to use for doing the navigation.
* @throws This function can throw errors.
*/
navigateToLocations(locations, speed) { return this.__player.navigateToLocations(locations, speed); }
;
/**
* @remarks
* This method is inherited from Player, but is inoperative in
* the case of a SimulatedPlayer.
* @param soundID
* Identifier of the sound to play.
* @param soundOptions
* Additional optional options for the sound.
* @throws This function can throw errors.
*/
playSound(soundID, soundOptions) { return this.__player.playSound(soundID, soundOptions); }
;
/**
* @remarks
* Removes a specified property.
* @param identifier
* @throws This function can throw errors.
*/
removeDynamicProperty(identifier) { return this.__player.removeDynamicProperty(identifier); }
;
/**
* @remarks
* Removes a specified tag from a simulated player.
* @param tag
* Content of the tag to remove.
* @throws This function can throw errors.
*/
removeTag(tag) { return this.__player.removeTag(tag); }
;
/**
* @remarks
* Causes the simulated player to turn by the provided angle,
* relative to the player's current rotation.
* @param angleInDegrees
* @throws This function can throw errors.
*/
rotateBody(angleInDegrees) { return this.__player.rotateBody(angleInDegrees); }
;
/**
* @remarks
* Runs a particular command from the context of this simulated
* player.
* @param commandString
* Command to run. Note that command strings should not start
* with slash.
* @returns
* For commands that return data, returns a JSON structure with
* command response values.
* @throws This function can throw errors.
* @example commands.js
* ```typescript
* player.runCommandAsync("say You got a new high score!");
* player.runCommandAsync("scoreboard players set @s score 10");
*
* ```
* @deprecated
*/
runCommand(commandString) {
throw new ReferenceError("runCommand function has been deprecated");
}
;
/**
* @remarks
* Runs a particular command asynchronously from the context of
* this entity. Where possible, running a command
* asynchronously is recommended, especially for long running
* operations.
* @param commandString
* Command to run. Note that command strings should not start
* with slash.
* @returns
* For commands that return data, returns a JSON structure with
* command response values.
* @throws This function can throw errors.
*/
runCommandAsync(commandString) { return this.__player.runCommandAsync(commandString); }
;
/**
* @remarks
* Causes the simulated player to turn to face the provided
* angle, relative to the GameTest.
* @param angleInDegrees
* @throws This function can throw errors.
*/
setBodyRotation(angleInDegrees) { return this.__player.setBodyRotation(angleInDegrees); }
;
/**
* @remarks
* Sets a specified property to a value.
* @param identifier
* @param value
* Data value of the property to set.
* @throws This function can throw errors.
*/
setDynamicProperty(identifier, value) { return this.__player.setDynamicProperty(identifier, value); }
;
/**
* @remarks
* Sets the game mode that the simulated player is operating
* under.
* @param gameMode
* Game mode to set.
* @throws This function can throw errors.
*/
setGameMode(gameMode) { return this.__player.setGameMode(gameMode); }
;
/**
* @remarks
* Sets a particular item for the simulated player.
* @param itemStack
* Item to set.
* @param slot
* Slot to place the given item in.
* @param selectSlot
* Whether to set the selected slot once set.
* @throws This function can throw errors.
*/
setItem(itemStack, slot, selectSlot) { return this.__player.setItem(itemStack, slot, selectSlot); }
;
/**
* @remarks
* Sets the main rotation of the entity.
* @param degreesX
* @param degreesY
* @throws This function can throw errors.
*/
setRotation(degreesX, degreesY) { return this.__player.setRotation(degreesX, degreesY); }
;
/**
* @remarks
* Sets a velocity for the entity to move with.
* @param velocity
* X/Y/Z components of the velocity.
* @throws This function can throw errors.
*/
setVelocity(velocity) { return this.__player.applyImpulse(velocity); }
;
/**
* @remarks
* Sets the item cooldown time for a particular cooldown
* category.
* @param itemCategory
* Specifies the cooldown category to retrieve the current
* cooldown for.
* @param tickDuration
* Duration in ticks of the item cooldown.
* @throws This function can throw errors.
*/
startItemCooldown(itemCategory, tickDuration) { return this.__player.startItemCooldown(itemCategory, tickDuration); }
;
/**
* @remarks
* Stops destroying the block that is currently being hit.
* @throws This function can throw errors.
*/
stopBreakingBlock() { return this.__player.stopBreakingBlock(); }
;
/**
* @remarks
* Stops interacting with entities or blocks.
* @throws This function can throw errors.
*/
stopInteracting() { return this.__player.stopInteracting(); }
;
/**
* @remarks
* Stops moving/walking/following if the simulated player is
* moving.
* @throws This function can throw errors.
*/
stopMoving() { return this.__player.stopMoving(); }
;
/**
* @remarks
* Stops using the currently active item.
* @throws This function can throw errors.
*/
stopUsingItem() { return this.__player.stopUsingItem(); }
;
/**
* @remarks
* Teleports the selected player to a new location
* @param location
* New location for the player.
* @param dimension
* Dimension to move the selected player to.
* @param xRotation
* X rotation of the player after teleportation.
* @param yRotation
* Y rotation of the player after teleportation.
* @throws This function can throw errors.
*/
teleport(location, dimension, xRotation, yRotation) { return this.__player.teleport(location, dimension, xRotation, yRotation); }
;
/**
* @remarks
* Teleports the selected player to a new location, and will
* have the player facing a specified location.
* @param location
* New location for the player.
* @param dimension
* Dimension to move the selected player to.
* @param facingLocation
* Location that this player will be facing.
* @throws This function can throw errors.
*/
teleportFacing(location, dimension, facingLocation) { return this.__player.teleportFacing(location, dimension, facingLocation); }
;
/**
* @remarks
* Triggers an entity type event. For every entity, a number of
* events are defined in an entities' definition for key entity
* behaviors; for example, creepers have a
* minecraft:start_exploding type event.
* @param eventName
* Name of the entity type event to trigger. If a namespace is
* not specified, minecraft: is assumed.
* @throws This function can throw errors.
*/
triggerEvent(eventName) { return this.__player.triggerEvent(eventName); }
;
/**
* @remarks
* Causes the simulated player to use an item. Does not consume
* the item. Returns false if the item is on cooldown.
* @param itemStack
* Item to use.
* @throws This function can throw errors.
*/
useItem(itemStack) { return this.__player.useItem(itemStack); }
;
/**
* @remarks
* Causes the simulated player to hold and use an item in their
* inventory.
* @param slot
* Index of the inventory slot.
* @throws This function can throw errors.
*/
useItemInSlot(slot) { return this.__player.useItemInSlot(slot); }
;
/**
* @remarks
* Causes the simulated player to use an item in their
* inventory on a block. The block at the specified block
* location must be solid. Returns true if the item was used.
* @param slot
* Index of the slot to use.
* @param blockLocation
* Location to use the item upon.
* @param direction
* Direction to place the specified item within.
* @param faceLocationX
* Block-face-relative X position where to place the item.
* @param faceLocationY
* Block-face-relative Y position where to place the item.
* @throws This function can throw errors.
*/
useItemInSlotOnBlock(slot, blockLocation, direction, faceLocationX, faceLocationY) { return this.__player.useItemInSlotOnBlock(slot, blockLocation, direction, faceLocationX, faceLocationY); }
;
/**
* @remarks
* Causes the simulated player to use an item on a block. The
* block at the specified block location must be solid. Returns
* true if the item was used.
* @param itemStack
* Item to use.
* @param blockLocation
* Location to use the item upon.
* @param direction
* Direction to place the specified item within.
* @param faceLocationX
* Block-face-relative X position where to place the item.
* @param faceLocationY
* Block-face-relative Y position where to place the item.
* @throws This function can throw errors.
*/
useItemOnBlock(itemStack, blockLocation, direction, faceLocationX, faceLocationY) { return this.__player.useItemOnBlock(itemStack, blockLocation, direction, faceLocationX, faceLocationY); }
;
constructor(player, test) {
this.__player = player;
this.__test = test;
}
;
}
;