@minecraft/server 1.9.0-rc.1.20.70-preview.21 → 1.9.0-rc.1.20.70-preview.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.d.ts +1590 -714
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -15,7 +15,7 @@
15
15
  * ```json
16
16
  * {
17
17
  * "module_name": "@minecraft/server",
18
- * "version": "1.7.0"
18
+ * "version": "1.8.0"
19
19
  * }
20
20
  * ```
21
21
  *
@@ -577,34 +577,29 @@ export enum EquipmentSlot {
577
577
  }
578
578
 
579
579
  /**
580
- * @beta
581
580
  * Represents the type of fluid for use within a fluid
582
581
  * containing block, like a cauldron.
583
582
  */
584
583
  export enum FluidType {
585
584
  /**
586
- * @beta
587
585
  * @remarks
588
586
  * Represents lava as a type of fluid.
589
587
  *
590
588
  */
591
589
  Lava = 'Lava',
592
590
  /**
593
- * @beta
594
591
  * @remarks
595
592
  * Represents a potion as a type of fluid.
596
593
  *
597
594
  */
598
595
  Potion = 'Potion',
599
596
  /**
600
- * @beta
601
597
  * @remarks
602
598
  * Represents powder snow as a type of fluid.
603
599
  *
604
600
  */
605
601
  PowderSnow = 'PowderSnow',
606
602
  /**
607
- * @beta
608
603
  * @remarks
609
604
  * Represents water as a type of fluida.
610
605
  *
@@ -1077,7 +1072,6 @@ export class Block {
1077
1072
  */
1078
1073
  getComponent(componentId: string): BlockComponent | undefined;
1079
1074
  /**
1080
- * @beta
1081
1075
  * @remarks
1082
1076
  * Returns a set of tags for a block.
1083
1077
  *
@@ -1091,7 +1085,6 @@ export class Block {
1091
1085
  */
1092
1086
  getTags(): string[];
1093
1087
  /**
1094
- * @beta
1095
1088
  * @remarks
1096
1089
  * Checks to see if the permutation of this block has a
1097
1090
  * specific tag.
@@ -1246,6 +1239,24 @@ export class BlockEvent {
1246
1239
  /**
1247
1240
  * Represents the inventory of a block in the world. Used with
1248
1241
  * blocks like chests.
1242
+ * @example place_items_in_chest.js
1243
+ * ```typescript
1244
+ * import { world, MinecraftBlockTypes, Items, ItemStack } from "@minecraft/server";
1245
+ *
1246
+ * // Fetch block
1247
+ * const block = world.getDimension("overworld").getBlock({ x: 1, y: 2, z: 3 });
1248
+ *
1249
+ * // Make it a chest
1250
+ * block.setType(MinecraftBlockTypes.chest);
1251
+ *
1252
+ * // Get the inventory
1253
+ * const inventoryComponent = block.getComponent("inventory");
1254
+ * const inventoryContainer = inventoryComponent.container;
1255
+ *
1256
+ * // Set slot 0 to a stack of 10 apples
1257
+ * inventoryContainer.setItem(0, new ItemStack(Items.apple, 10, 0));
1258
+ *
1259
+ * ```
1249
1260
  */
1250
1261
  // @ts-ignore Class inheritance allowed for native defined classes
1251
1262
  export class BlockInventoryComponent extends BlockComponent {
@@ -1265,6 +1276,31 @@ export class BlockInventoryComponent extends BlockComponent {
1265
1276
  * properties (also sometimes called block state) which
1266
1277
  * describe a block (but does not belong to a specific {@link
1267
1278
  * Block}).
1279
+ * @example createTranslatedSign.ts
1280
+ * ```typescript
1281
+ * // A function the creates a sign at the specified location with the specified text
1282
+ * import { DimensionLocation, BlockPermutation, BlockComponentTypes } from '@minecraft/server';
1283
+ * import { MinecraftBlockTypes } from '@minecraft/vanilla-data';
1284
+ *
1285
+ * function createSignAt(location: DimensionLocation) {
1286
+ * const signBlock = location.dimension.getBlock(location);
1287
+ *
1288
+ * if (!signBlock) {
1289
+ * console.warn('Could not find a block at specified location.');
1290
+ * return;
1291
+ * }
1292
+ *
1293
+ * const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 });
1294
+ * signBlock.setPermutation(signPerm); // Update block to be a sign
1295
+ *
1296
+ * // Update the sign block's text
1297
+ * // with "Steve's Head"
1298
+ * const signComponent = signBlock.getComponent(BlockComponentTypes.Sign);
1299
+ * if (signComponent) {
1300
+ * signComponent.setText({ translate: 'item.skull.player.name', with: ['Steve'] });
1301
+ * }
1302
+ * }
1303
+ * ```
1268
1304
  */
1269
1305
  export class BlockPermutation {
1270
1306
  private constructor();
@@ -1280,7 +1316,6 @@ export class BlockPermutation {
1280
1316
  */
1281
1317
  getAllStates(): Record<string, boolean | number | string>;
1282
1318
  /**
1283
- * @beta
1284
1319
  * @remarks
1285
1320
  * Gets a state for the permutation.
1286
1321
  *
@@ -1302,7 +1337,6 @@ export class BlockPermutation {
1302
1337
  */
1303
1338
  matches(blockName: string, states?: Record<string, boolean | number | string>): boolean;
1304
1339
  /**
1305
- * @beta
1306
1340
  * @remarks
1307
1341
  * Returns a derived BlockPermutation with a specific property
1308
1342
  * set.
@@ -1325,43 +1359,43 @@ export class BlockPermutation {
1325
1359
  * @throws This function can throw errors.
1326
1360
  * @example addBlockColorCube.ts
1327
1361
  * ```typescript
1328
- * const allColorNames: string[] = [
1329
- * "white",
1330
- * "orange",
1331
- * "magenta",
1332
- * "light_blue",
1333
- * "yellow",
1334
- * "lime",
1335
- * "pink",
1336
- * "gray",
1337
- * "silver",
1338
- * "cyan",
1339
- * "purple",
1340
- * "blue",
1341
- * "brown",
1342
- * "green",
1343
- * "red",
1344
- * "black",
1345
- * ];
1346
- *
1347
- * const cubeDim = 7;
1348
- *
1349
- * let colorIndex = 0;
1350
- *
1351
- * for (let x = 0; x <= cubeDim; x++) {
1352
- * for (let y = 0; y <= cubeDim; y++) {
1353
- * for (let z = 0; z <= cubeDim; z++) {
1354
- * colorIndex++;
1355
- * overworld
1356
- * .getBlock({ x: targetLocation.x + x, y: targetLocation.y + y, z: targetLocation.z + z })
1357
- * ?.setPermutation(
1358
- * mc.BlockPermutation.resolve("minecraft:wool", {
1359
- * color: allColorNames[colorIndex % allColorNames.length],
1360
- * })
1361
- * );
1362
- * }
1362
+ * import { DimensionLocation, BlockPermutation } from '@minecraft/server';
1363
+ * import { MinecraftBlockTypes } from '@minecraft/vanilla-data';
1364
+ *
1365
+ * const allWoolBlocks: string[] = [
1366
+ * MinecraftBlockTypes.WhiteWool,
1367
+ * MinecraftBlockTypes.OrangeWool,
1368
+ * MinecraftBlockTypes.MagentaWool,
1369
+ * MinecraftBlockTypes.LightBlueWool,
1370
+ * MinecraftBlockTypes.YellowWool,
1371
+ * MinecraftBlockTypes.LimeWool,
1372
+ * MinecraftBlockTypes.PinkWool,
1373
+ * MinecraftBlockTypes.GrayWool,
1374
+ * MinecraftBlockTypes.LightGrayWool,
1375
+ * MinecraftBlockTypes.CyanWool,
1376
+ * MinecraftBlockTypes.PurpleWool,
1377
+ * MinecraftBlockTypes.BlueWool,
1378
+ * MinecraftBlockTypes.BrownWool,
1379
+ * MinecraftBlockTypes.GreenWool,
1380
+ * MinecraftBlockTypes.RedWool,
1381
+ * MinecraftBlockTypes.BlackWool,
1382
+ * ];
1383
+ *
1384
+ * const cubeDim = 7;
1385
+ *
1386
+ * function placeRainbowCube(location: DimensionLocation) {
1387
+ * let colorIndex = 0;
1388
+ * for (let x = 0; x <= cubeDim; x++) {
1389
+ * for (let y = 0; y <= cubeDim; y++) {
1390
+ * for (let z = 0; z <= cubeDim; z++) {
1391
+ * colorIndex++;
1392
+ * location.dimension
1393
+ * .getBlock({ x: location.x + x, y: location.y + y, z: location.z + z })
1394
+ * ?.setPermutation(BlockPermutation.resolve(allWoolBlocks[colorIndex % allWoolBlocks.length]));
1395
+ * }
1396
+ * }
1363
1397
  * }
1364
- * }
1398
+ * }
1365
1399
  * ```
1366
1400
  */
1367
1401
  static resolve(blockName: string, states?: Record<string, boolean | number | string>): BlockPermutation;
@@ -1412,6 +1446,103 @@ export class BlockPistonComponent extends BlockComponent {
1412
1446
  /**
1413
1447
  * @beta
1414
1448
  * Represents a block that can display text on it.
1449
+ * @example addTwoSidedSign.ts
1450
+ * ```typescript
1451
+ * // A function the creates a sign at the specified location with text on both sides and dye colors
1452
+ * import {
1453
+ * DimensionLocation,
1454
+ * BlockPermutation,
1455
+ * BlockSignComponent,
1456
+ * BlockComponentTypes,
1457
+ * DyeColor,
1458
+ * SignSide,
1459
+ * } from '@minecraft/server';
1460
+ * import { MinecraftBlockTypes } from '@minecraft/vanilla-data';
1461
+ *
1462
+ * function createSignAt(location: DimensionLocation) {
1463
+ * const block = location.dimension.getBlock(location);
1464
+ * if (!block) {
1465
+ * console.warn('Could not find a block at specified location.');
1466
+ * return;
1467
+ * }
1468
+ * const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, {
1469
+ * ground_sign_direction: 8,
1470
+ * });
1471
+ * block.setPermutation(signPerm);
1472
+ * const sign = block.getComponent(BlockComponentTypes.Sign);
1473
+ *
1474
+ * if (sign !== undefined) {
1475
+ * sign.setText(`Party Sign!\nThis is green on the front.`);
1476
+ * sign.setText(`Party Sign!\nThis is red on the back.`, SignSide.Back);
1477
+ * sign.setTextDyeColor(DyeColor.Green);
1478
+ * sign.setTextDyeColor(DyeColor.Red, SignSide.Back);
1479
+ *
1480
+ * // players cannot edit sign!
1481
+ * sign.setWaxed(true);
1482
+ * } else {
1483
+ * console.warn('Could not find a sign component on the block.');
1484
+ * }
1485
+ * }
1486
+ * ```
1487
+ * @example setSignText.ts
1488
+ * ```typescript
1489
+ * import {
1490
+ * BlockComponentTypes,
1491
+ * DimensionLocation,
1492
+ * RawMessage,
1493
+ * RawText,
1494
+ * } from '@minecraft/server';
1495
+ *
1496
+ * // Function which updates a sign blocks text to raw text
1497
+ * function updateSignText(signLocation: DimensionLocation) {
1498
+ * const block = signLocation.dimension.getBlock(signLocation);
1499
+ * if (!block) {
1500
+ * console.warn('Could not find a block at specified location.');
1501
+ * return;
1502
+ * }
1503
+ *
1504
+ * const sign = block.getComponent(BlockComponentTypes.Sign);
1505
+ * if (sign) {
1506
+ * // RawMessage
1507
+ * const helloWorldMessage: RawMessage = { text: 'Hello World' };
1508
+ * sign.setText(helloWorldMessage);
1509
+ *
1510
+ * // RawText
1511
+ * const helloWorldText: RawText = { rawtext: [{ text: 'Hello World' }] };
1512
+ * sign.setText(helloWorldText);
1513
+ *
1514
+ * // Regular string
1515
+ * sign.setText('Hello World');
1516
+ * } else {
1517
+ * console.warn('Could not find a sign component on the block.');
1518
+ * }
1519
+ * }
1520
+ * ```
1521
+ * @example createTranslatedSign.ts
1522
+ * ```typescript
1523
+ * // A function the creates a sign at the specified location with the specified text
1524
+ * import { DimensionLocation, BlockPermutation, BlockComponentTypes } from '@minecraft/server';
1525
+ * import { MinecraftBlockTypes } from '@minecraft/vanilla-data';
1526
+ *
1527
+ * function createSignAt(location: DimensionLocation) {
1528
+ * const signBlock = location.dimension.getBlock(location);
1529
+ *
1530
+ * if (!signBlock) {
1531
+ * console.warn('Could not find a block at specified location.');
1532
+ * return;
1533
+ * }
1534
+ *
1535
+ * const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 });
1536
+ * signBlock.setPermutation(signPerm); // Update block to be a sign
1537
+ *
1538
+ * // Update the sign block's text
1539
+ * // with "Steve's Head"
1540
+ * const signComponent = signBlock.getComponent(BlockComponentTypes.Sign);
1541
+ * if (signComponent) {
1542
+ * signComponent.setText({ translate: 'item.skull.player.name', with: ['Steve'] });
1543
+ * }
1544
+ * }
1545
+ * ```
1415
1546
  */
1416
1547
  // @ts-ignore Class inheritance allowed for native defined classes
1417
1548
  export class BlockSignComponent extends BlockComponent {
@@ -1481,50 +1612,39 @@ export class BlockSignComponent extends BlockComponent {
1481
1612
  * @throws
1482
1613
  * Throws if the provided message is greater than 512
1483
1614
  * characters in length.
1484
- * @example SetRawMessage.ts
1615
+ * @example setSignText.ts
1485
1616
  * ```typescript
1486
- * const signLocation: Vector3 = { x: 0, y: -60, z: 0 }; // Replace with your sign's coordinates
1487
- * const block = world.getDimension("overworld").getBlock(signLocation);
1488
- * if (!block) {
1489
- * world.sendMessage("Could not find a block at specified location.");
1490
- * return;
1491
- * }
1492
- * const sign = block.getComponent("minecraft:sign") as BlockSignComponent;
1493
- * const helloWorldMessage: RawMessage = { text: "Hello World" };
1494
- * sign.setText(helloWorldMessage);
1617
+ * import {
1618
+ * BlockComponentTypes,
1619
+ * DimensionLocation,
1620
+ * RawMessage,
1621
+ * RawText,
1622
+ * } from '@minecraft/server';
1623
+ *
1624
+ * // Function which updates a sign blocks text to raw text
1625
+ * function updateSignText(signLocation: DimensionLocation) {
1626
+ * const block = signLocation.dimension.getBlock(signLocation);
1627
+ * if (!block) {
1628
+ * console.warn('Could not find a block at specified location.');
1629
+ * return;
1630
+ * }
1495
1631
  *
1496
- * // Sign text will be saved as a RawText
1497
- * const result = sign.getRawText();
1498
- * world.sendMessage(JSON.stringify(result)); // { rawtext: [{ text: 'Hello World' }] };
1499
- * ```
1500
- * @example SetRawText.ts
1501
- * ```typescript
1502
- * const signLocation: Vector3 = { x: 0, y: -60, z: 0 }; // Replace with your sign's coordinates
1503
- * const block = world.getDimension("overworld").getBlock(signLocation);
1504
- * if (!block) {
1505
- * world.sendMessage("Could not find a block at specified location.");
1506
- * return;
1507
- * }
1508
- * const sign = block.getComponent("minecraft:sign") as BlockSignComponent;
1509
- * const helloWorldText: RawText = { rawtext: [{ text: "Hello World" }] };
1510
- * sign.setText(helloWorldText);
1632
+ * const sign = block.getComponent(BlockComponentTypes.Sign);
1633
+ * if (sign) {
1634
+ * // RawMessage
1635
+ * const helloWorldMessage: RawMessage = { text: 'Hello World' };
1636
+ * sign.setText(helloWorldMessage);
1511
1637
  *
1512
- * // There will be no data transformation unlike calling setText with a RawMessage
1513
- * const result = sign.getRawText();
1514
- * world.sendMessage(JSON.stringify(result)); // { rawtext: [{ text: 'Hello World' }] };
1515
- * ```
1516
- * @example SetString.ts
1517
- * ```typescript
1518
- * const signLocation: Vector3 = { x: 0, y: -60, z: 0 }; // Replace with your sign's coordinates
1519
- * const block = world.getDimension("overworld").getBlock(signLocation);
1520
- * if (!block) {
1521
- * world.sendMessage("Could not find a block at specified location.");
1522
- * return;
1638
+ * // RawText
1639
+ * const helloWorldText: RawText = { rawtext: [{ text: 'Hello World' }] };
1640
+ * sign.setText(helloWorldText);
1641
+ *
1642
+ * // Regular string
1643
+ * sign.setText('Hello World');
1644
+ * } else {
1645
+ * console.warn('Could not find a sign component on the block.');
1646
+ * }
1523
1647
  * }
1524
- * const sign = block.getComponent("minecraft:sign") as BlockSignComponent;
1525
- * // Set sign to say 'Hello'
1526
- * sign.setText("Hello World");
1527
- * world.sendMessage(sign.getText() ?? "undefined"); // 'Hello World'
1528
1648
  * ```
1529
1649
  */
1530
1650
  setText(message: RawMessage | RawText | string, side?: SignSide): void;
@@ -1601,7 +1721,6 @@ export class BlockStateType {
1601
1721
  }
1602
1722
 
1603
1723
  /**
1604
- * @beta
1605
1724
  * The type (or template) of a block. Does not contain
1606
1725
  * permutation data (state) other than the type of block it
1607
1726
  * represents. This type was introduced as of version
@@ -1613,6 +1732,18 @@ export class BlockType {
1613
1732
 
1614
1733
  /**
1615
1734
  * Contains information related to changes to a button push.
1735
+ * @example buttonPushEvent.ts
1736
+ * ```typescript
1737
+ * import { world, ButtonPushAfterEvent, system } from '@minecraft/server';
1738
+ *
1739
+ * world.afterEvents.buttonPush.subscribe((buttonPushEvent: ButtonPushAfterEvent) => {
1740
+ * const eventLoc = buttonPushEvent.block.location;
1741
+ *
1742
+ * world.sendMessage(
1743
+ * `Button push event at tick ${system.currentTick} Power:${buttonPushEvent.block.getRedstonePower()}`,
1744
+ * );
1745
+ * });
1746
+ * ```
1616
1747
  */
1617
1748
  // @ts-ignore Class inheritance allowed for native defined classes
1618
1749
  export class ButtonPushAfterEvent extends BlockEvent {
@@ -1628,6 +1759,18 @@ export class ButtonPushAfterEvent extends BlockEvent {
1628
1759
  /**
1629
1760
  * Manages callbacks that are connected to when a button is
1630
1761
  * pushed.
1762
+ * @example buttonPushEvent.ts
1763
+ * ```typescript
1764
+ * import { world, ButtonPushAfterEvent, system } from '@minecraft/server';
1765
+ *
1766
+ * world.afterEvents.buttonPush.subscribe((buttonPushEvent: ButtonPushAfterEvent) => {
1767
+ * const eventLoc = buttonPushEvent.block.location;
1768
+ *
1769
+ * world.sendMessage(
1770
+ * `Button push event at tick ${system.currentTick} Power:${buttonPushEvent.block.getRedstonePower()}`,
1771
+ * );
1772
+ * });
1773
+ * ```
1631
1774
  */
1632
1775
  // @ts-ignore Class inheritance allowed for native defined classes
1633
1776
  export class ButtonPushAfterEventSignal extends IButtonPushAfterEventSignal {
@@ -1730,6 +1873,54 @@ export class Component {
1730
1873
  * Represents a container that can hold sets of items. Used
1731
1874
  * with entities such as Players, Chest Minecarts, Llamas, and
1732
1875
  * more.
1876
+ * @example containers.js
1877
+ * ```typescript
1878
+ * let leftLocation = test.worldLocation({ x: 2, y: 2, z: 2 }); // left chest location
1879
+ * let rightLocation = test.worldLocation({ x: 4, y: 2, z: 2 }); // right chest location
1880
+ *
1881
+ * const chestCart = test.spawn("chest_minecart", { x: 6, y: 2, z: 2 });
1882
+ *
1883
+ * let leftChestBlock = defaultDimension.getBlock(leftLocation);
1884
+ * let rightChestBlock = defaultDimension.getBlock(rightLocation);
1885
+ *
1886
+ * leftChestBlock.setType(MinecraftBlockTypes.chest);
1887
+ * rightChestBlock.setType(MinecraftBlockTypes.chest);
1888
+ *
1889
+ * const rightChestInventoryComp = rightChestBlock.getComponent("inventory");
1890
+ * const leftChestInventoryComp = leftChestBlock.getComponent("inventory");
1891
+ * const chestCartInventoryComp = chestCart.getComponent("inventory");
1892
+ *
1893
+ * const rightChestContainer = rightChestInventoryComp.container;
1894
+ * const leftChestContainer = leftChestInventoryComp.container;
1895
+ * const chestCartContainer = chestCartInventoryComp.container;
1896
+ *
1897
+ * rightChestContainer.setItem(0, new ItemStack(Items.apple, 10, 0));
1898
+ * test.assert(rightChestContainer.getItem(0).id === "apple", "Expected apple in right container slot index 0");
1899
+ *
1900
+ * rightChestContainer.setItem(1, new ItemStack(Items.emerald, 10, 0));
1901
+ * test.assert(rightChestContainer.getItem(1).id === "emerald", "Expected emerald in right container slot index 1");
1902
+ *
1903
+ * test.assert(rightChestContainer.size === 27, "Unexpected size: " + rightChestContainer.size);
1904
+ * test.assert(
1905
+ * rightChestContainer.emptySlotsCount === 25,
1906
+ * "Unexpected emptySlotsCount: " + rightChestContainer.emptySlotsCount
1907
+ * );
1908
+ *
1909
+ * const itemStack = rightChestContainer.getItem(0);
1910
+ * test.assert(itemStack.id === "apple", "Expected apple");
1911
+ * test.assert(itemStack.amount === 10, "Expected 10 apples");
1912
+ * test.assert(itemStack.data === 0, "Expected 0 data");
1913
+ *
1914
+ * leftChestContainer.setItem(0, new ItemStack(Items.cake, 10, 0));
1915
+ *
1916
+ * rightChestContainer.transferItem(0, 4, chestCartContainer); // transfer the apple from the right chest to a chest cart
1917
+ * rightChestContainer.swapItems(1, 0, leftChestContainer); // swap the cake and emerald
1918
+ *
1919
+ * test.assert(chestCartContainer.getItem(4).id === "apple", "Expected apple in left container slot index 4");
1920
+ * test.assert(leftChestContainer.getItem(0).id === "emerald", "Expected emerald in left container slot index 0");
1921
+ * test.assert(rightChestContainer.getItem(1).id === "cake", "Expected cake in right container slot index 1");
1922
+ *
1923
+ * ```
1733
1924
  */
1734
1925
  export class Container {
1735
1926
  private constructor();
@@ -1791,9 +1982,16 @@ export class Container {
1791
1982
  * out of bounds.
1792
1983
  * @example getItem.ts
1793
1984
  * ```typescript
1794
- * // Get a copy of the first item in the player's hotbar
1795
- * const inventory = player.getComponent("inventory") as EntityInventoryComponent;
1796
- * const itemStack = inventory.container.getItem(0);
1985
+ * // A function that gets a copy of the first item in the player's hotbar
1986
+ * import { Player, EntityInventoryComponent, ItemStack } from '@minecraft/server';
1987
+ *
1988
+ * function getFirstHotbarItem(player: Player): ItemStack | undefined {
1989
+ * const inventory = player.getComponent(EntityInventoryComponent.componentId);
1990
+ * if (inventory && inventory.container) {
1991
+ * return inventory.container.getItem(0);
1992
+ * }
1993
+ * return undefined;
1994
+ * }
1797
1995
  * ```
1798
1996
  */
1799
1997
  getItem(slot: number): ItemStack | undefined;
@@ -1840,10 +2038,17 @@ export class Container {
1840
2038
  * or if the `fromSlot` or `toSlot` indices out of bounds.
1841
2039
  * @example moveItem.ts
1842
2040
  * ```typescript
1843
- * // Move an item from the first slot of fromPlayer's inventory to the fifth slot of toPlayer's inventory
1844
- * const fromInventory = fromPlayer.getComponent('inventory') as EntityInventoryComponent;
1845
- * const toInventory = toPlayer.getComponent('inventory') as EntityInventoryComponent;
1846
- * fromInventory.container.moveItem(0, 4, toInventory.container);
2041
+ * // A function that moves an item from one slot of the player's inventory to another player's inventory
2042
+ * import { Player, EntityComponentTypes } from '@minecraft/server';
2043
+ *
2044
+ * function moveBetweenPlayers(slotId: number, fromPlayer: Player, toPlayer: Player) {
2045
+ * const fromInventory = fromPlayer.getComponent(EntityComponentTypes.Inventory);
2046
+ * const toInventory = toPlayer.getComponent(EntityComponentTypes.Inventory);
2047
+ *
2048
+ * if (fromInventory && toInventory && fromInventory.container && toInventory.container) {
2049
+ * fromInventory.container.moveItem(slotId, slotId, toInventory.container);
2050
+ * }
2051
+ * }
1847
2052
  * ```
1848
2053
  */
1849
2054
  moveItem(fromSlot: number, toSlot: number, toContainer: Container): void;
@@ -1881,9 +2086,17 @@ export class Container {
1881
2086
  * invalid or if the `slot` or `otherSlot` are out of bounds.
1882
2087
  * @example swapItems.ts
1883
2088
  * ```typescript
1884
- * // Swaps an item between slots 0 and 4 in the player's inventory
1885
- * const inventory = fromPlayer.getComponent('inventory') as EntityInventoryComponent;
1886
- * inventory.container.swapItems(0, 4, inventory);
2089
+ * // A function that swaps an item from one slot of the player's inventory to another player's inventory
2090
+ * import { Player, EntityComponentTypes } from '@minecraft/server';
2091
+ *
2092
+ * function swapBetweenPlayers(slotId: number, fromPlayer: Player, toPlayer: Player) {
2093
+ * const fromInventory = fromPlayer.getComponent(EntityComponentTypes.Inventory);
2094
+ * const toInventory = toPlayer.getComponent(EntityComponentTypes.Inventory);
2095
+ *
2096
+ * if (fromInventory && toInventory && fromInventory.container && toInventory.container) {
2097
+ * fromInventory.container.swapItems(slotId, slotId, toInventory.container);
2098
+ * }
2099
+ * }
1887
2100
  * ```
1888
2101
  */
1889
2102
  swapItems(slot: number, otherSlot: number, otherContainer: Container): void;
@@ -1908,10 +2121,17 @@ export class Container {
1908
2121
  * or if the `fromSlot` or `toSlot` indices out of bounds.
1909
2122
  * @example transferItem.ts
1910
2123
  * ```typescript
1911
- * // Transfer an item from the first slot of fromPlayer's inventory to toPlayer's inventory
1912
- * const fromInventory = fromPlayer.getComponent('inventory') as EntityInventoryComponent;
1913
- * const toInventory = toPlayer.getComponent('inventory') as EntityInventoryComponent;
1914
- * fromInventory.container.transferItem(0, toInventory.container);
2124
+ * // A function that moves an item from one slot of the player's inventory to another player's inventory
2125
+ * import { Player, EntityComponentTypes } from '@minecraft/server';
2126
+ *
2127
+ * function moveBetweenPlayers(slotId: number, fromPlayer: Player, toPlayer: Player) {
2128
+ * const fromInventory = fromPlayer.getComponent(EntityComponentTypes.Inventory);
2129
+ * const toInventory = toPlayer.getComponent(EntityComponentTypes.Inventory);
2130
+ *
2131
+ * if (fromInventory && toInventory && fromInventory.container && toInventory.container) {
2132
+ * fromInventory.container.transferItem(slotId, toInventory.container);
2133
+ * }
2134
+ * }
1915
2135
  * ```
1916
2136
  */
1917
2137
  transferItem(fromSlot: number, toContainer: Container): ItemStack | undefined;
@@ -2264,7 +2484,6 @@ export class ContainerSlot {
2264
2484
  }
2265
2485
 
2266
2486
  /**
2267
- * @beta
2268
2487
  * Contains information related to firing of a data driven
2269
2488
  * entity event - for example, the minecraft:ageable_grow_up
2270
2489
  * event on a chicken.
@@ -2293,7 +2512,6 @@ export class DataDrivenEntityTriggerAfterEvent {
2293
2512
  }
2294
2513
 
2295
2514
  /**
2296
- * @beta
2297
2515
  * Contains event registration related to firing of a data
2298
2516
  * driven entity event - for example, the
2299
2517
  * minecraft:ageable_grow_up event on a chicken.
@@ -2361,39 +2579,21 @@ export class Dimension {
2361
2579
  * {@link LocationInUnloadedChunkError}
2362
2580
  *
2363
2581
  * {@link LocationOutOfWorldBoundariesError}
2364
- * @example createExplosion.ts
2365
- * ```typescript
2366
- * const overworld = mc.world.getDimension("overworld");
2367
- *
2368
- * log("Creating an explosion of radius 10.");
2369
- * overworld.createExplosion(targetLocation, 10);
2370
- * ```
2371
- * @example createFireAndWaterExplosions.ts
2582
+ * @example createExplosions.ts
2372
2583
  * ```typescript
2373
- * const overworld = mc.world.getDimension("overworld");
2374
- *
2375
- * const explosionLoc = { x: targetLocation.x + 0.5, y: targetLocation.y + 0.5, z: targetLocation.z + 0.5};
2376
- *
2377
- * log("Creating an explosion of radius 15 that causes fire.");
2378
- * overworld.createExplosion(explosionLoc, 15, { causesFire: true });
2584
+ * // Creates an explosion of radius 15 that does not break blocks
2585
+ * import { DimensionLocation } from '@minecraft/server';
2379
2586
  *
2380
- * const belowWaterLoc = { x: targetLocation.x + 3, y: targetLocation.y + 1,z: targetLocation.z + 3};
2587
+ * function createExplosions(location: DimensionLocation) {
2588
+ * // Creates an explosion of radius 15 that does not break blocks
2589
+ * location.dimension.createExplosion(location, 15, { breaksBlocks: false });
2381
2590
  *
2382
- * log("Creating an explosion of radius 10 that can go underwater.");
2383
- * overworld.createExplosion(belowWaterLoc, 10, { allowUnderwater: true });
2384
- * ```
2385
- * @example createNoBlockExplosion.ts
2386
- * ```typescript
2387
- * const overworld = mc.world.getDimension("overworld");
2591
+ * // Creates an explosion of radius 15 that does not cause fire
2592
+ * location.dimension.createExplosion(location, 15, { causesFire: true });
2388
2593
  *
2389
- * const explodeNoBlocksLoc = {
2390
- * x: Math.floor(targetLocation.x + 1),
2391
- * y: Math.floor(targetLocation.y + 2),
2392
- * z: Math.floor(targetLocation.z + 1)
2393
- * };
2394
- *
2395
- * log("Creating an explosion of radius 15 that does not break blocks.");
2396
- * overworld.createExplosion(explodeNoBlocksLoc, 15, { breaksBlocks: false });
2594
+ * // Creates an explosion of radius 10 that can go underwater
2595
+ * location.dimension.createExplosion(location, 10, { allowUnderwater: true });
2596
+ * }
2397
2597
  * ```
2398
2598
  */
2399
2599
  createExplosion(location: Vector3, radius: number, explosionOptions?: ExplosionOptions): boolean;
@@ -2446,60 +2646,52 @@ export class Dimension {
2446
2646
  * @returns
2447
2647
  * An entity array.
2448
2648
  * @throws This function can throw errors.
2449
- * @example bounceSkeletons.ts
2649
+ * @example checkFeatherNearby.ts
2450
2650
  * ```typescript
2451
- * let mobs = ["creeper", "skeleton", "sheep"];
2452
- *
2453
- * // create some sample mob data
2454
- * for (let i = 0; i < 10; i++) {
2455
- * overworld.spawnEntity(mobs[i % mobs.length], targetLocation);
2456
- * }
2457
- *
2458
- * let eqo: mc.EntityQueryOptions = {
2459
- * type: "skeleton",
2460
- * };
2651
+ * import { DimensionLocation, EntityComponentTypes } from "@minecraft/server";
2652
+ *
2653
+ * // Returns true if a feather item entity is within 'distance' blocks of 'location'.
2654
+ * function isFeatherNear(location: DimensionLocation, distance: number): boolean {
2655
+ * const items = location.dimension.getEntities({
2656
+ * location: location,
2657
+ * maxDistance: 20,
2658
+ * });
2659
+ *
2660
+ * for (const item of items) {
2661
+ * const itemComp = item.getComponent(EntityComponentTypes.Item);
2662
+ *
2663
+ * if (itemComp) {
2664
+ * if (itemComp.itemStack.typeId.endsWith('feather')) {
2665
+ * return true;
2666
+ * }
2667
+ * }
2668
+ * }
2461
2669
  *
2462
- * for (let entity of overworld.getEntities(eqo)) {
2463
- * entity.applyKnockback(0, 0, 0, 1);
2464
- * }
2670
+ * return false;
2671
+ * }
2465
2672
  * ```
2466
2673
  * @example tagsQuery.ts
2467
2674
  * ```typescript
2468
- * let mobs = ["creeper", "skeleton", "sheep"];
2469
- *
2470
- * // create some sample mob data
2471
- * for (let i = 0; i < 10; i++) {
2472
- * let mobTypeId = mobs[i % mobs.length];
2473
- * let entity = overworld.spawnEntity(mobTypeId, targetLocation);
2474
- * entity.addTag("mobparty." + mobTypeId);
2475
- * }
2476
- *
2477
- * let eqo: mc.EntityQueryOptions = {
2478
- * tags: ["mobparty.skeleton"],
2479
- * };
2480
- *
2481
- * for (let entity of overworld.getEntities(eqo)) {
2482
- * entity.kill();
2483
- * }
2484
- * ```
2485
- * @example testThatEntityIsFeatherItem.ts
2486
- * ```typescript
2487
- * const overworld = mc.world.getDimension("overworld");
2675
+ * import { EntityQueryOptions, DimensionLocation } from '@minecraft/server';
2676
+ *
2677
+ * function mobParty(targetLocation: DimensionLocation) {
2678
+ * const mobs = ['creeper', 'skeleton', 'sheep'];
2488
2679
  *
2489
- * const items = overworld.getEntities({
2490
- * location: targetLocation,
2491
- * maxDistance: 20,
2492
- * });
2680
+ * // create some sample mob data
2681
+ * for (let i = 0; i < 10; i++) {
2682
+ * const mobTypeId = mobs[i % mobs.length];
2683
+ * const entity = targetLocation.dimension.spawnEntity(mobTypeId, targetLocation);
2684
+ * entity.addTag('mobparty.' + mobTypeId);
2685
+ * }
2493
2686
  *
2494
- * for (const item of items) {
2495
- * const itemComp = item.getComponent("item") as mc.EntityItemComponent;
2687
+ * const eqo: EntityQueryOptions = {
2688
+ * tags: ['mobparty.skeleton'],
2689
+ * };
2496
2690
  *
2497
- * if (itemComp) {
2498
- * if (itemComp.itemStack.typeId.endsWith("feather")) {
2499
- * log("Success! Found a feather", 1);
2500
- * }
2691
+ * for (const entity of targetLocation.dimension.getEntities(eqo)) {
2692
+ * entity.kill();
2501
2693
  * }
2502
- * }
2694
+ * }
2503
2695
  * ```
2504
2696
  */
2505
2697
  getEntities(options?: EntityQueryOptions): Entity[];
@@ -2615,42 +2807,39 @@ export class Dimension {
2615
2807
  * {@link LocationOutOfWorldBoundariesError}
2616
2808
  * @example createOldHorse.ts
2617
2809
  * ```typescript
2618
- * const overworld = mc.world.getDimension("overworld");
2810
+ * // Spawns an adult horse
2811
+ * import { DimensionLocation } from '@minecraft/server';
2619
2812
  *
2620
- * log("Create a horse and triggering the 'ageable_grow_up' event, ensuring the horse is created as an adult");
2621
- * overworld.spawnEntity("minecraft:horse<minecraft:ageable_grow_up>", targetLocation);
2813
+ * function spawnAdultHorse(location: DimensionLocation) {
2814
+ * // Create a horse and triggering the 'ageable_grow_up' event, ensuring the horse is created as an adult
2815
+ * location.dimension.spawnEntity('minecraft:horse<minecraft:ageable_grow_up>', location);
2816
+ * }
2622
2817
  * ```
2623
2818
  * @example quickFoxLazyDog.ts
2624
2819
  * ```typescript
2625
- * const overworld = mc.world.getDimension("overworld");
2626
- *
2627
- * const fox = overworld.spawnEntity("minecraft:fox", {
2628
- * x: targetLocation.x + 1,
2629
- * y: targetLocation.y + 2,
2630
- * z: targetLocation.z + 3,
2631
- * });
2632
- *
2633
- * fox.addEffect("speed", 10, {
2634
- * amplifier: 2,
2635
- * });
2636
- * log("Created a fox.");
2637
- *
2638
- * const wolf = overworld.spawnEntity("minecraft:wolf", {
2639
- * x: targetLocation.x + 4,
2640
- * y: targetLocation.y + 2,
2641
- * z: targetLocation.z + 3,
2642
- * });
2643
- * wolf.addEffect("slowness", 10, {
2644
- * amplifier: 2,
2645
- * });
2646
- * wolf.isSneaking = true;
2647
- * log("Created a sneaking wolf.", 1);
2648
- * ```
2649
- * @example triggerEvent.ts
2650
- * ```typescript
2651
- * const creeper = overworld.spawnEntity("minecraft:creeper", targetLocation);
2652
- *
2653
- * creeper.triggerEvent("minecraft:start_exploding_forced");
2820
+ * // Spawns a fox over a dog
2821
+ * import { DimensionLocation } from '@minecraft/server';
2822
+ * import { MinecraftEntityTypes } from '@minecraft/vanilla-data';
2823
+ *
2824
+ * function spawnAdultHorse(location: DimensionLocation) {
2825
+ * // Create fox (our quick brown fox)
2826
+ * const fox = location.dimension.spawnEntity(MinecraftEntityTypes.Fox, {
2827
+ * x: location.x,
2828
+ * y: location.y + 2,
2829
+ * z: location.z,
2830
+ * });
2831
+ *
2832
+ * fox.addEffect('speed', 10, {
2833
+ * amplifier: 2,
2834
+ * });
2835
+ *
2836
+ * // Create wolf (our lazy dog)
2837
+ * const wolf = location.dimension.spawnEntity(MinecraftEntityTypes.Wolf, location);
2838
+ * wolf.addEffect('slowness', 10, {
2839
+ * amplifier: 2,
2840
+ * });
2841
+ * wolf.isSneaking = true;
2842
+ * }
2654
2843
  * ```
2655
2844
  */
2656
2845
  spawnEntity(identifier: string, location: Vector3): Entity;
@@ -2670,33 +2859,16 @@ export class Dimension {
2670
2859
  * {@link LocationInUnloadedChunkError}
2671
2860
  *
2672
2861
  * {@link LocationOutOfWorldBoundariesError}
2673
- * @example itemStacks.ts
2674
- * ```typescript
2675
- * const overworld = mc.world.getDimension('overworld');
2676
- *
2677
- * const oneItemLoc = { x: targetLocation.x + targetLocation.y + 3, y: 2, z: targetLocation.z + 1 };
2678
- * const fiveItemsLoc = { x: targetLocation.x + 1, y: targetLocation.y + 2, z: targetLocation.z + 1 };
2679
- * const diamondPickaxeLoc = { x: targetLocation.x + 2, y: targetLocation.y + 2, z: targetLocation.z + 4 };
2680
- *
2681
- * const oneEmerald = new mc.ItemStack(mc.MinecraftItemTypes.Emerald, 1);
2682
- * const onePickaxe = new mc.ItemStack(mc.MinecraftItemTypes.DiamondPickaxe, 1);
2683
- * const fiveEmeralds = new mc.ItemStack(mc.MinecraftItemTypes.Emerald, 5);
2684
- *
2685
- * log(`Spawning an emerald at (${oneItemLoc.x}, ${oneItemLoc.y}, ${oneItemLoc.z})`);
2686
- * overworld.spawnItem(oneEmerald, oneItemLoc);
2687
- *
2688
- * log(`Spawning five emeralds at (${fiveItemsLoc.x}, ${fiveItemsLoc.y}, ${fiveItemsLoc.z})`);
2689
- * overworld.spawnItem(fiveEmeralds, fiveItemsLoc);
2690
- *
2691
- * log(`Spawning a diamond pickaxe at (${diamondPickaxeLoc.x}, ${diamondPickaxeLoc.y}, ${diamondPickaxeLoc.z})`);
2692
- * overworld.spawnItem(onePickaxe, diamondPickaxeLoc);
2693
- * ```
2694
- * @example spawnItem.ts
2862
+ * @example spawnFeatherItem.ts
2695
2863
  * ```typescript
2696
- * const featherItem = new mc.ItemStack(mc.MinecraftItemTypes.Feather, 1);
2864
+ * // Spawns a feather at a location
2865
+ * import { ItemStack, DimensionLocation } from '@minecraft/server';
2866
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
2697
2867
  *
2698
- * overworld.spawnItem(featherItem, targetLocation);
2699
- * log(`New feather created at ${targetLocation.x}, ${targetLocation.y}, ${targetLocation.z}!`);
2868
+ * function spawnFeather(location: DimensionLocation) {
2869
+ * const featherItem = new ItemStack(MinecraftItemTypes.Feather, 1);
2870
+ * location.dimension.spawnItem(featherItem, location);
2871
+ * }
2700
2872
  * ```
2701
2873
  */
2702
2874
  spawnItem(itemStack: ItemStack, location: Vector3): Entity;
@@ -2721,18 +2893,27 @@ export class Dimension {
2721
2893
  * {@link LocationOutOfWorldBoundariesError}
2722
2894
  * @example spawnParticle.ts
2723
2895
  * ```typescript
2724
- * for (let i = 0; i < 100; i++) {
2725
- * const molang = new mc.MolangVariableMap();
2726
- *
2727
- * molang.setColorRGB("variable.color", { red: Math.random(), green: Math.random(), blue: Math.random(), alpha: 1 });
2728
- *
2729
- * let newLocation = {
2730
- * x: targetLocation.x + Math.floor(Math.random() * 8) - 4,
2731
- * y: targetLocation.y + Math.floor(Math.random() * 8) - 4,
2732
- * z: targetLocation.z + Math.floor(Math.random() * 8) - 4,
2733
- * };
2734
- * overworld.spawnParticle("minecraft:colored_flame_particle", newLocation, molang);
2735
- * }
2896
+ * // A function that spawns a particle at a random location near the target location for all players in the server
2897
+ * import { world, MolangVariableMap, DimensionLocation, Vector3 } from '@minecraft/server';
2898
+ *
2899
+ * function spawnConfetti(location: DimensionLocation) {
2900
+ * for (let i = 0; i < 100; i++) {
2901
+ * const molang = new MolangVariableMap();
2902
+ *
2903
+ * molang.setColorRGB('variable.color', {
2904
+ * red: Math.random(),
2905
+ * green: Math.random(),
2906
+ * blue: Math.random()
2907
+ * });
2908
+ *
2909
+ * const newLocation: Vector3 = {
2910
+ * x: location.x + Math.floor(Math.random() * 8) - 4,
2911
+ * y: location.y + Math.floor(Math.random() * 8) - 4,
2912
+ * z: location.z + Math.floor(Math.random() * 8) - 4,
2913
+ * };
2914
+ * location.dimension.spawnParticle('minecraft:colored_flame_particle', newLocation, molang);
2915
+ * }
2916
+ * }
2736
2917
  * ```
2737
2918
  */
2738
2919
  spawnParticle(effectName: string, location: Vector3, molangVariables?: MolangVariableMap): void;
@@ -2821,7 +3002,6 @@ export class Effect {
2821
3002
  }
2822
3003
 
2823
3004
  /**
2824
- * @beta
2825
3005
  * Contains information related to changes to an effect - like
2826
3006
  * poison - being added to an entity.
2827
3007
  */
@@ -2842,7 +3022,6 @@ export class EffectAddAfterEvent {
2842
3022
  }
2843
3023
 
2844
3024
  /**
2845
- * @beta
2846
3025
  * Manages callbacks that are connected to when an effect is
2847
3026
  * added to an entity.
2848
3027
  */
@@ -2873,7 +3052,6 @@ export class EffectAddAfterEventSignal {
2873
3052
  }
2874
3053
 
2875
3054
  /**
2876
- * @beta
2877
3055
  * Contains information related to changes to an effect - like
2878
3056
  * poison - being added to an entity.
2879
3057
  */
@@ -2906,7 +3084,6 @@ export class EffectAddBeforeEvent {
2906
3084
  }
2907
3085
 
2908
3086
  /**
2909
- * @beta
2910
3087
  * Manages callbacks that are connected to when an effect is
2911
3088
  * added to an entity.
2912
3089
  */
@@ -3029,7 +3206,10 @@ export class Entity {
3029
3206
  readonly isInWater: boolean;
3030
3207
  /**
3031
3208
  * @remarks
3032
- * Whether the entity is on top of a solid block.
3209
+ * Whether the entity is on top of a solid block. This property
3210
+ * may behave in unexpected ways. This property will always be
3211
+ * true when an Entity is first spawned, and if the Entity has
3212
+ * no gravity this property may be incorrect.
3033
3213
  *
3034
3214
  * @throws This property can throw when used.
3035
3215
  */
@@ -3118,40 +3298,48 @@ export class Entity {
3118
3298
  * amplifier are outside of the valid ranges, or if the effect
3119
3299
  * does not exist.
3120
3300
  * @throws This function can throw errors.
3121
- * @example addEffect.js
3301
+ * @example poisonVillager.ts
3122
3302
  * ```typescript
3123
- * const villagerId = 'minecraft:villager_v2<minecraft:ageable_grow_up>';
3124
- * const villagerLoc: mc.Vector3 = { x: 1, y: 2, z: 1 };
3125
- * const villager = test.spawn(villagerId, villagerLoc);
3126
- * const duration = 20;
3303
+ * // Spawns a villager and gives it the poison effect
3304
+ * import {
3305
+ * DimensionLocation,
3306
+ * } from '@minecraft/server';
3307
+ * import { MinecraftEffectTypes } from '@minecraft/vanilla-data';
3308
+ *
3309
+ * function spawnPoisonedVillager(location: DimensionLocation) {
3310
+ * const villagerType = 'minecraft:villager_v2<minecraft:ageable_grow_up>';
3311
+ * const villager = location.dimension.spawnEntity(villagerType, location);
3312
+ * const duration = 20;
3313
+ *
3314
+ * villager.addEffect(MinecraftEffectTypes.Poison, duration, { amplifier: 1 });
3315
+ * }
3127
3316
  *
3128
- * villager.addEffect(EffectTypes.get('poison'), duration, { amplifier: 1 });
3129
3317
  * ```
3130
3318
  * @example quickFoxLazyDog.ts
3131
3319
  * ```typescript
3132
- * const overworld = mc.world.getDimension("overworld");
3133
- *
3134
- * const fox = overworld.spawnEntity("minecraft:fox", {
3135
- * x: targetLocation.x + 1,
3136
- * y: targetLocation.y + 2,
3137
- * z: targetLocation.z + 3,
3138
- * });
3139
- *
3140
- * fox.addEffect("speed", 10, {
3141
- * amplifier: 2,
3142
- * });
3143
- * log("Created a fox.");
3144
- *
3145
- * const wolf = overworld.spawnEntity("minecraft:wolf", {
3146
- * x: targetLocation.x + 4,
3147
- * y: targetLocation.y + 2,
3148
- * z: targetLocation.z + 3,
3149
- * });
3150
- * wolf.addEffect("slowness", 10, {
3151
- * amplifier: 2,
3152
- * });
3153
- * wolf.isSneaking = true;
3154
- * log("Created a sneaking wolf.", 1);
3320
+ * // Spawns a fox over a dog
3321
+ * import { DimensionLocation } from '@minecraft/server';
3322
+ * import { MinecraftEntityTypes } from '@minecraft/vanilla-data';
3323
+ *
3324
+ * function spawnAdultHorse(location: DimensionLocation) {
3325
+ * // Create fox (our quick brown fox)
3326
+ * const fox = location.dimension.spawnEntity(MinecraftEntityTypes.Fox, {
3327
+ * x: location.x,
3328
+ * y: location.y + 2,
3329
+ * z: location.z,
3330
+ * });
3331
+ *
3332
+ * fox.addEffect('speed', 10, {
3333
+ * amplifier: 2,
3334
+ * });
3335
+ *
3336
+ * // Create wolf (our lazy dog)
3337
+ * const wolf = location.dimension.spawnEntity(MinecraftEntityTypes.Wolf, location);
3338
+ * wolf.addEffect('slowness', 10, {
3339
+ * amplifier: 2,
3340
+ * });
3341
+ * wolf.isSneaking = true;
3342
+ * }
3155
3343
  * ```
3156
3344
  */
3157
3345
  addEffect(effectType: EffectType | string, duration: number, options?: EntityEffectOptions): void;
@@ -3168,25 +3356,6 @@ export class Entity {
3168
3356
  * Returns true if the tag was added successfully. This can
3169
3357
  * fail if the tag already exists on the entity.
3170
3358
  * @throws This function can throw errors.
3171
- * @example tagsQuery.ts
3172
- * ```typescript
3173
- * let mobs = ["creeper", "skeleton", "sheep"];
3174
- *
3175
- * // create some sample mob data
3176
- * for (let i = 0; i < 10; i++) {
3177
- * let mobTypeId = mobs[i % mobs.length];
3178
- * let entity = overworld.spawnEntity(mobTypeId, targetLocation);
3179
- * entity.addTag("mobparty." + mobTypeId);
3180
- * }
3181
- *
3182
- * let eqo: mc.EntityQueryOptions = {
3183
- * tags: ["mobparty.skeleton"],
3184
- * };
3185
- *
3186
- * for (let entity of overworld.getEntities(eqo)) {
3187
- * entity.kill();
3188
- * }
3189
- * ```
3190
3359
  */
3191
3360
  addTag(tag: string): boolean;
3192
3361
  /**
@@ -3208,16 +3377,25 @@ export class Entity {
3208
3377
  * @throws This function can throw errors.
3209
3378
  * @example applyDamageThenHeal.ts
3210
3379
  * ```typescript
3211
- * const skelly = overworld.spawnEntity("minecraft:skeleton", targetLocation);
3380
+ * // A function that applies damage and then heals the entity
3381
+ * import { Entity, EntityComponentTypes, system, world } from '@minecraft/server';
3382
+ *
3383
+ * function applyDamageAndHeal(entity: Entity) {
3384
+ * entity.applyDamage(19); // Many mobs have max damage of 20 so this is a near-death mob
3212
3385
  *
3213
- * skelly.applyDamage(19); // skeletons have max damage of 20 so this is a near-death skeleton
3386
+ * system.runTimeout(() => {
3387
+ * const health = entity.getComponent(EntityComponentTypes.Health);
3388
+ * if (health) {
3389
+ * world.sendMessage(`Entity health before heal: ${health.currentValue}`);
3214
3390
  *
3215
- * mc.system.runTimeout(() => {
3216
- * let health = skelly.getComponent("health") as mc.EntityHealthComponent;
3217
- * log("Skeleton health before heal: " + health.currentValue);
3218
- * health.resetToMaxValue();
3219
- * log("Skeleton health after heal: " + health.currentValue);
3220
- * }, 20);
3391
+ * health.resetToMaxValue();
3392
+ *
3393
+ * world.sendMessage(`Entity after before heal: ${health.currentValue}`);
3394
+ * } else {
3395
+ * console.warn('Entity does not have health component');
3396
+ * }
3397
+ * }, 40); // Run in a few seconds (40 ticks)
3398
+ * }
3221
3399
  * ```
3222
3400
  */
3223
3401
  applyDamage(amount: number, options?: EntityApplyDamageByProjectileOptions | EntityApplyDamageOptions): boolean;
@@ -3231,14 +3409,19 @@ export class Entity {
3231
3409
  * @param vector
3232
3410
  * Impulse vector.
3233
3411
  * @throws This function can throw errors.
3234
- * @example applyImpulse.ts
3412
+ * @example yeetEntity.ts
3235
3413
  * ```typescript
3236
- * const zombie = overworld.spawnEntity("minecraft:zombie", targetLocation);
3414
+ * // A function that throws entities up in the air
3415
+ * import { Entity } from '@minecraft/server';
3237
3416
  *
3238
- * zombie.clearVelocity();
3417
+ * function yeetEntity(entity: Entity) {
3239
3418
  *
3240
- * // throw the zombie up in the air
3241
- * zombie.applyImpulse({ x: 0, y: 0.5, z: 0 });
3419
+ * // Zero out the entity's velocity before applying impulse
3420
+ * entity.clearVelocity();
3421
+ *
3422
+ * // throw the zombie up in the air
3423
+ * entity.applyImpulse({ x: 0, y: 15, z: 0 });
3424
+ * }
3242
3425
  * ```
3243
3426
  */
3244
3427
  applyImpulse(vector: Vector3): void;
@@ -3260,20 +3443,24 @@ export class Entity {
3260
3443
  * @throws This function can throw errors.
3261
3444
  * @example bounceSkeletons.ts
3262
3445
  * ```typescript
3263
- * let mobs = ["creeper", "skeleton", "sheep"];
3446
+ * import { EntityQueryOptions, DimensionLocation } from '@minecraft/server';
3264
3447
  *
3265
- * // create some sample mob data
3266
- * for (let i = 0; i < 10; i++) {
3267
- * overworld.spawnEntity(mobs[i % mobs.length], targetLocation);
3268
- * }
3448
+ * function mobParty(targetLocation: DimensionLocation) {
3449
+ * const mobs = ['creeper', 'skeleton', 'sheep'];
3269
3450
  *
3270
- * let eqo: mc.EntityQueryOptions = {
3271
- * type: "skeleton",
3272
- * };
3451
+ * // create some sample mob data
3452
+ * for (let i = 0; i < 10; i++) {
3453
+ * targetLocation.dimension.spawnEntity(mobs[i % mobs.length], targetLocation);
3454
+ * }
3455
+ *
3456
+ * const eqo: EntityQueryOptions = {
3457
+ * type: 'skeleton',
3458
+ * };
3273
3459
  *
3274
- * for (let entity of overworld.getEntities(eqo)) {
3275
- * entity.applyKnockback(0, 0, 0, 1);
3276
- * }
3460
+ * for (const entity of targetLocation.dimension.getEntities(eqo)) {
3461
+ * entity.applyKnockback(0, 0, 0, 1);
3462
+ * }
3463
+ * }
3277
3464
  * ```
3278
3465
  */
3279
3466
  applyKnockback(directionX: number, directionZ: number, horizontalStrength: number, verticalStrength: number): void;
@@ -3293,14 +3480,19 @@ export class Entity {
3293
3480
  * This function can't be called in read-only mode.
3294
3481
  *
3295
3482
  * @throws This function can throw errors.
3296
- * @example applyImpulse.ts
3483
+ * @example yeetEntity.ts
3297
3484
  * ```typescript
3298
- * const zombie = overworld.spawnEntity("minecraft:zombie", targetLocation);
3485
+ * // A function that throws entities up in the air
3486
+ * import { Entity } from '@minecraft/server';
3487
+ *
3488
+ * function yeetEntity(entity: Entity) {
3299
3489
  *
3300
- * zombie.clearVelocity();
3490
+ * // Zero out the entity's velocity before applying impulse
3491
+ * entity.clearVelocity();
3301
3492
  *
3302
- * // throw the zombie up in the air
3303
- * zombie.applyImpulse({ x: 0, y: 0.5, z: 0 });
3493
+ * // throw the zombie up in the air
3494
+ * entity.applyImpulse({ x: 0, y: 15, z: 0 });
3495
+ * }
3304
3496
  * ```
3305
3497
  */
3306
3498
  clearVelocity(): void;
@@ -3319,32 +3511,23 @@ export class Entity {
3319
3511
  * @returns
3320
3512
  * Returns whether the entity was on fire.
3321
3513
  * @throws This function can throw errors.
3322
- * @example setOnFire.ts
3514
+ * @example setEntityOnFire.ts
3323
3515
  * ```typescript
3324
- * const skelly = overworld.spawnEntity("minecraft:skeleton", targetLocation);
3516
+ * import { world, Entity, EntityComponentTypes, system } from "@minecraft/server";
3325
3517
  *
3326
- * skelly.setOnFire(20, true);
3518
+ * function setAblaze(entity: Entity) {
3519
+ * entity.setOnFire(20, true);
3327
3520
  *
3328
- * mc.system.runTimeout(() => {
3329
- * let onfire = skelly.getComponent("onfire") as mc.EntityOnFireComponent;
3330
- * log(onfire.onFireTicksRemaining + " fire ticks remaining.");
3521
+ * system.runTimeout(() => {
3522
+ * const onfire = entity.getComponent(EntityComponentTypes.OnFire);
3523
+ * if (onfire) {
3524
+ * world.sendMessage(`${onfire.onFireTicksRemaining} fire ticks remaining, extinguishing the entity.`);
3525
+ * }
3526
+ * // This will extinguish the entity
3527
+ * entity.extinguishFire(true);
3528
+ * }, 30); // Run in 30 ticks or ~1.5 seconds
3331
3529
  *
3332
- * skelly.extinguishFire(true);
3333
- * log("Never mind. Fire extinguished.");
3334
- * }, 20);
3335
- * ```
3336
- * @example teleport.ts
3337
- * ```typescript
3338
- * const cow = overworld.spawnEntity("minecraft:cow", targetLocation);
3339
- *
3340
- * mc.system.runTimeout(() => {
3341
- * cow.teleport(
3342
- * { x: targetLocation.x + 2, y: targetLocation.y + 2, z: targetLocation.z + 2 },
3343
- * {
3344
- * facingLocation: targetLocation,
3345
- * }
3346
- * );
3347
- * }, 20);
3530
+ * }
3348
3531
  * ```
3349
3532
  */
3350
3533
  extinguishFire(useEffects?: boolean): boolean;
@@ -3513,13 +3696,19 @@ export class Entity {
3513
3696
  * @throws This function can throw errors.
3514
3697
  * @example getFireworkVelocity.ts
3515
3698
  * ```typescript
3516
- * const fireworkRocket = overworld.spawnEntity("minecraft:fireworks_rocket", targetLocation);
3699
+ * // A function that spawns fireworks and logs their velocity after 5 ticks
3700
+ * import { DimensionLocation, system, world } from '@minecraft/server';
3701
+ * import { MinecraftEntityTypes } from '@minecraft/vanilla-data';
3702
+ *
3703
+ * function spawnFireworks(location: DimensionLocation) {
3704
+ * const fireworkRocket = location.dimension.spawnEntity(MinecraftEntityTypes.FireworksRocket, location);
3517
3705
  *
3518
- * mc.system.runTimeout(() => {
3519
- * let velocity = fireworkRocket.getVelocity();
3706
+ * system.runTimeout(() => {
3707
+ * const velocity = fireworkRocket.getVelocity();
3520
3708
  *
3521
- * log("Velocity of firework is: (x: " + velocity.x + ", y:" + velocity.y + ", z:" + velocity.z + ")");
3522
- * }, 5);
3709
+ * world.sendMessage(`Velocity of firework is: ${velocity.x}, ${velocity.y}, ${velocity.z}`);
3710
+ * }, 5);
3711
+ * }
3523
3712
  * ```
3524
3713
  */
3525
3714
  getVelocity(): Vector3;
@@ -3579,22 +3768,26 @@ export class Entity {
3579
3768
  * @throws This function can throw errors.
3580
3769
  * @example tagsQuery.ts
3581
3770
  * ```typescript
3582
- * let mobs = ["creeper", "skeleton", "sheep"];
3583
- *
3584
- * // create some sample mob data
3585
- * for (let i = 0; i < 10; i++) {
3586
- * let mobTypeId = mobs[i % mobs.length];
3587
- * let entity = overworld.spawnEntity(mobTypeId, targetLocation);
3588
- * entity.addTag("mobparty." + mobTypeId);
3589
- * }
3590
- *
3591
- * let eqo: mc.EntityQueryOptions = {
3592
- * tags: ["mobparty.skeleton"],
3593
- * };
3594
- *
3595
- * for (let entity of overworld.getEntities(eqo)) {
3596
- * entity.kill();
3597
- * }
3771
+ * import { EntityQueryOptions, DimensionLocation } from '@minecraft/server';
3772
+ *
3773
+ * function mobParty(targetLocation: DimensionLocation) {
3774
+ * const mobs = ['creeper', 'skeleton', 'sheep'];
3775
+ *
3776
+ * // create some sample mob data
3777
+ * for (let i = 0; i < 10; i++) {
3778
+ * const mobTypeId = mobs[i % mobs.length];
3779
+ * const entity = targetLocation.dimension.spawnEntity(mobTypeId, targetLocation);
3780
+ * entity.addTag('mobparty.' + mobTypeId);
3781
+ * }
3782
+ *
3783
+ * const eqo: EntityQueryOptions = {
3784
+ * tags: ['mobparty.skeleton'],
3785
+ * };
3786
+ *
3787
+ * for (const entity of targetLocation.dimension.getEntities(eqo)) {
3788
+ * entity.kill();
3789
+ * }
3790
+ * }
3598
3791
  * ```
3599
3792
  */
3600
3793
  kill(): boolean;
@@ -3755,32 +3948,23 @@ export class Entity {
3755
3948
  * is less than or equal to zero, the entity is wet or the
3756
3949
  * entity is immune to fire.
3757
3950
  * @throws This function can throw errors.
3758
- * @example setOnFire.ts
3951
+ * @example setEntityOnFire.ts
3759
3952
  * ```typescript
3760
- * const skelly = overworld.spawnEntity("minecraft:skeleton", targetLocation);
3953
+ * import { world, Entity, EntityComponentTypes, system } from "@minecraft/server";
3761
3954
  *
3762
- * skelly.setOnFire(20, true);
3955
+ * function setAblaze(entity: Entity) {
3956
+ * entity.setOnFire(20, true);
3763
3957
  *
3764
- * mc.system.runTimeout(() => {
3765
- * let onfire = skelly.getComponent("onfire") as mc.EntityOnFireComponent;
3766
- * log(onfire.onFireTicksRemaining + " fire ticks remaining.");
3958
+ * system.runTimeout(() => {
3959
+ * const onfire = entity.getComponent(EntityComponentTypes.OnFire);
3960
+ * if (onfire) {
3961
+ * world.sendMessage(`${onfire.onFireTicksRemaining} fire ticks remaining, extinguishing the entity.`);
3962
+ * }
3963
+ * // This will extinguish the entity
3964
+ * entity.extinguishFire(true);
3965
+ * }, 30); // Run in 30 ticks or ~1.5 seconds
3767
3966
  *
3768
- * skelly.extinguishFire(true);
3769
- * log("Never mind. Fire extinguished.");
3770
- * }, 20);
3771
- * ```
3772
- * @example teleport.ts
3773
- * ```typescript
3774
- * const cow = overworld.spawnEntity("minecraft:cow", targetLocation);
3775
- *
3776
- * mc.system.runTimeout(() => {
3777
- * cow.teleport(
3778
- * { x: targetLocation.x + 2, y: targetLocation.y + 2, z: targetLocation.z + 2 },
3779
- * {
3780
- * facingLocation: targetLocation,
3781
- * }
3782
- * );
3783
- * }, 20);
3967
+ * }
3784
3968
  * ```
3785
3969
  */
3786
3970
  setOnFire(seconds: number, useEffects?: boolean): boolean;
@@ -3833,22 +4017,27 @@ export class Entity {
3833
4017
  * @throws This function can throw errors.
3834
4018
  * @example teleportMovement.ts
3835
4019
  * ```typescript
3836
- * const pig = overworld.spawnEntity("minecraft:pig", targetLocation);
4020
+ * import { world, system } from '@minecraft/server';
4021
+ *
4022
+ * const overworld = world.getDimension('overworld');
4023
+ * const targetLocation = { x: 0, y: 0, z: 0 };
3837
4024
  *
3838
- * let inc = 1;
3839
- * let runId = mc.system.runInterval(() => {
4025
+ * const pig = overworld.spawnEntity('minecraft:pig', targetLocation);
4026
+ *
4027
+ * let inc = 1;
4028
+ * const runId = system.runInterval(() => {
3840
4029
  * pig.teleport(
3841
- * { x: targetLocation.x + inc / 4, y: targetLocation.y + inc / 4, z: targetLocation.z + inc / 4 },
3842
- * {
3843
- * facingLocation: targetLocation,
3844
- * }
4030
+ * { x: targetLocation.x + inc / 4, y: targetLocation.y + inc / 4, z: targetLocation.z + inc / 4 },
4031
+ * {
4032
+ * facingLocation: targetLocation,
4033
+ * },
3845
4034
  * );
3846
4035
  *
3847
4036
  * if (inc > 100) {
3848
- * mc.system.clearRun(runId);
4037
+ * system.clearRun(runId);
3849
4038
  * }
3850
4039
  * inc++;
3851
- * }, 4);
4040
+ * }, 4);
3852
4041
  * ```
3853
4042
  */
3854
4043
  teleport(location: Vector3, teleportOptions?: TeleportOptions): void;
@@ -3869,9 +4058,15 @@ export class Entity {
3869
4058
  * an error will be thrown.
3870
4059
  * @example triggerEvent.ts
3871
4060
  * ```typescript
3872
- * const creeper = overworld.spawnEntity("minecraft:creeper", targetLocation);
4061
+ * // A function that spawns a creeper and triggers it to explode immediately
4062
+ * import { DimensionLocation } from '@minecraft/server';
4063
+ * import { MinecraftEntityTypes } from '@minecraft/vanilla-data';
4064
+ *
4065
+ * function spawnExplodingCreeper(location: DimensionLocation) {
4066
+ * const creeper = location.dimension.spawnEntity(MinecraftEntityTypes.Creeper, location);
3873
4067
  *
3874
- * creeper.triggerEvent("minecraft:start_exploding_forced");
4068
+ * creeper.triggerEvent('minecraft:start_exploding_forced');
4069
+ * }
3875
4070
  * ```
3876
4071
  */
3877
4072
  triggerEvent(eventName: string): void;
@@ -4108,6 +4303,39 @@ export class EntityDieAfterEventSignal {
4108
4303
  /**
4109
4304
  * Provides access to a mob's equipment slots. This component
4110
4305
  * exists for all mob entities.
4306
+ * @example givePlayerElytra.ts
4307
+ * ```typescript
4308
+ * // Gives the player Elytra
4309
+ * import { EquipmentSlot, ItemStack, Player, EntityComponentTypes } from '@minecraft/server';
4310
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
4311
+ *
4312
+ * function giveEquipment(player: Player) {
4313
+ * const equipmentCompPlayer = player.getComponent(EntityComponentTypes.Equippable);
4314
+ * if (equipmentCompPlayer) {
4315
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.Elytra));
4316
+ * }
4317
+ * }
4318
+ * ```
4319
+ * @example givePlayerEquipment.ts
4320
+ * ```typescript
4321
+ * // Gives the player some equipment
4322
+ * import { EquipmentSlot, ItemStack, Player, EntityComponentTypes } from '@minecraft/server';
4323
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
4324
+ *
4325
+ * function giveEquipment(player: Player) {
4326
+ * const equipmentCompPlayer = player.getComponent(EntityComponentTypes.Equippable);
4327
+ * if (equipmentCompPlayer) {
4328
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Head, new ItemStack(MinecraftItemTypes.GoldenHelmet));
4329
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.IronChestplate));
4330
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Legs, new ItemStack(MinecraftItemTypes.DiamondLeggings));
4331
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Feet, new ItemStack(MinecraftItemTypes.NetheriteBoots));
4332
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Mainhand, new ItemStack(MinecraftItemTypes.WoodenSword));
4333
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Offhand, new ItemStack(MinecraftItemTypes.Shield));
4334
+ * } else {
4335
+ * console.warn('No equipment component found on player');
4336
+ * }
4337
+ * }
4338
+ * ```
4111
4339
  */
4112
4340
  // @ts-ignore Class inheritance allowed for native defined classes
4113
4341
  export class EntityEquippableComponent extends EntityComponent {
@@ -4314,6 +4542,28 @@ export class EntityHealthChangedAfterEventSignal {
4314
4542
 
4315
4543
  /**
4316
4544
  * Defines the health properties of an entity.
4545
+ * @example applyDamageThenHeal.ts
4546
+ * ```typescript
4547
+ * // A function that applies damage and then heals the entity
4548
+ * import { Entity, EntityComponentTypes, system, world } from '@minecraft/server';
4549
+ *
4550
+ * function applyDamageAndHeal(entity: Entity) {
4551
+ * entity.applyDamage(19); // Many mobs have max damage of 20 so this is a near-death mob
4552
+ *
4553
+ * system.runTimeout(() => {
4554
+ * const health = entity.getComponent(EntityComponentTypes.Health);
4555
+ * if (health) {
4556
+ * world.sendMessage(`Entity health before heal: ${health.currentValue}`);
4557
+ *
4558
+ * health.resetToMaxValue();
4559
+ *
4560
+ * world.sendMessage(`Entity after before heal: ${health.currentValue}`);
4561
+ * } else {
4562
+ * console.warn('Entity does not have health component');
4563
+ * }
4564
+ * }, 40); // Run in a few seconds (40 ticks)
4565
+ * }
4566
+ * ```
4317
4567
  */
4318
4568
  // @ts-ignore Class inheritance allowed for native defined classes
4319
4569
  export class EntityHealthComponent extends EntityAttributeComponent {
@@ -4677,6 +4927,30 @@ export class EntityIsTamedComponent extends EntityComponent {
4677
4927
  * represents a free-floating item in the world. Lets you
4678
4928
  * retrieve the actual item stack contents via the itemStack
4679
4929
  * property.
4930
+ * @example checkFeatherNearby.ts
4931
+ * ```typescript
4932
+ * import { DimensionLocation, EntityComponentTypes } from "@minecraft/server";
4933
+ *
4934
+ * // Returns true if a feather item entity is within 'distance' blocks of 'location'.
4935
+ * function isFeatherNear(location: DimensionLocation, distance: number): boolean {
4936
+ * const items = location.dimension.getEntities({
4937
+ * location: location,
4938
+ * maxDistance: 20,
4939
+ * });
4940
+ *
4941
+ * for (const item of items) {
4942
+ * const itemComp = item.getComponent(EntityComponentTypes.Item);
4943
+ *
4944
+ * if (itemComp) {
4945
+ * if (itemComp.itemStack.typeId.endsWith('feather')) {
4946
+ * return true;
4947
+ * }
4948
+ * }
4949
+ * }
4950
+ *
4951
+ * return false;
4952
+ * }
4953
+ * ```
4680
4954
  */
4681
4955
  // @ts-ignore Class inheritance allowed for native defined classes
4682
4956
  export class EntityItemComponent extends EntityComponent {
@@ -4828,6 +5102,24 @@ export class EntityMovementSkipComponent extends EntityBaseMovementComponent {
4828
5102
  /**
4829
5103
  * @beta
4830
5104
  * When present on an entity, this entity is on fire.
5105
+ * @example setEntityOnFire.ts
5106
+ * ```typescript
5107
+ * import { world, Entity, EntityComponentTypes, system } from "@minecraft/server";
5108
+ *
5109
+ * function setAblaze(entity: Entity) {
5110
+ * entity.setOnFire(20, true);
5111
+ *
5112
+ * system.runTimeout(() => {
5113
+ * const onfire = entity.getComponent(EntityComponentTypes.OnFire);
5114
+ * if (onfire) {
5115
+ * world.sendMessage(`${onfire.onFireTicksRemaining} fire ticks remaining, extinguishing the entity.`);
5116
+ * }
5117
+ * // This will extinguish the entity
5118
+ * entity.extinguishFire(true);
5119
+ * }, 30); // Run in 30 ticks or ~1.5 seconds
5120
+ *
5121
+ * }
5122
+ * ```
4831
5123
  */
4832
5124
  // @ts-ignore Class inheritance allowed for native defined classes
4833
5125
  export class EntityOnFireComponent extends EntityComponent {
@@ -5004,6 +5296,18 @@ export class EntitySkinIdComponent extends EntityComponent {
5004
5296
  /**
5005
5297
  * Contains data related to an entity spawning within the
5006
5298
  * world.
5299
+ * @example logEntitySpawnEvents.ts
5300
+ * ```typescript
5301
+ * // Register a new function that is called when a new entity is created.
5302
+ * import { world, EntitySpawnAfterEvent } from '@minecraft/server';
5303
+ *
5304
+ * world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => {
5305
+ * const spawnLocation = entityEvent.entity.location;
5306
+ * world.sendMessage(
5307
+ * `New entity of type '${entityEvent.entity.typeId}' spawned at ${spawnLocation.x}, ${spawnLocation.y}, ${spawnLocation.z}!`,
5308
+ * );
5309
+ * });
5310
+ * ```
5007
5311
  */
5008
5312
  export class EntitySpawnAfterEvent {
5009
5313
  private constructor();
@@ -5026,6 +5330,18 @@ export class EntitySpawnAfterEvent {
5026
5330
  /**
5027
5331
  * Registers a script-based event handler for handling what
5028
5332
  * happens when an entity spawns.
5333
+ * @example logEntitySpawnEvents.ts
5334
+ * ```typescript
5335
+ * // Register a new function that is called when a new entity is created.
5336
+ * import { world, EntitySpawnAfterEvent } from '@minecraft/server';
5337
+ *
5338
+ * world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => {
5339
+ * const spawnLocation = entityEvent.entity.location;
5340
+ * world.sendMessage(
5341
+ * `New entity of type '${entityEvent.entity.typeId}' spawned at ${spawnLocation.x}, ${spawnLocation.y}, ${spawnLocation.z}!`,
5342
+ * );
5343
+ * });
5344
+ * ```
5029
5345
  */
5030
5346
  export class EntitySpawnAfterEventSignal {
5031
5347
  private constructor();
@@ -5038,21 +5354,6 @@ export class EntitySpawnAfterEventSignal {
5038
5354
  *
5039
5355
  * @param callback
5040
5356
  * Function that handles the spawn event.
5041
- * @example runEntitySpawnEvent.ts
5042
- * ```typescript
5043
- * // register a new function that is called when a new entity is created.
5044
- * mc.world.afterEvents.entitySpawn.subscribe((entityEvent: mc.EntitySpawnAfterEvent) => {
5045
- * if (entityEvent && entityEvent.entity) {
5046
- * log(`New entity of type '${entityEvent.entity.typeId}' created!`, 1);
5047
- * } else {
5048
- * log(`The entity event didn't work as expected.`, -1);
5049
- * }
5050
- * });
5051
- *
5052
- * mc.system.runTimeout(() => {
5053
- * createOldHorse(log, targetLocation);
5054
- * }, 20);
5055
- * ```
5056
5357
  */
5057
5358
  subscribe(callback: (arg: EntitySpawnAfterEvent) => void): (arg: EntitySpawnAfterEvent) => void;
5058
5359
  /**
@@ -5486,19 +5787,23 @@ export class ItemDurabilityComponent extends ItemComponent {
5486
5787
  /**
5487
5788
  * @remarks
5488
5789
  * Returns the maximum chance that this item would be damaged
5489
- * using the damageRange property, given an unbreaking level.
5790
+ * using the damageRange property, given an unbreaking
5791
+ * enchantment level.
5490
5792
  *
5491
5793
  * This function can't be called in read-only mode.
5492
5794
  *
5795
+ * @param unbreakingEnchantmentLevel
5796
+ * Unbreaking factor to consider in factoring the damage
5797
+ * chance. Incoming unbreaking parameter must be within the
5798
+ * range [0, 3].
5493
5799
  * @throws This function can throw errors.
5494
5800
  */
5495
5801
  getDamageChance(unbreakingEnchantmentLevel?: number): number;
5496
5802
  /**
5497
5803
  * @remarks
5498
- * Returns the min and max variables used by the damage chance
5499
- * formula:
5500
- * chance = (min + ((max - min) / (unbreaking + 1)))
5501
- *
5804
+ * A range of numbers that is used to calculate the damage
5805
+ * chance for an item. The damage chance will fall within this
5806
+ * range.
5502
5807
  *
5503
5808
  * This function can't be called in read-only mode.
5504
5809
  *
@@ -5609,6 +5914,58 @@ export class ItemReleaseUseAfterEventSignal {
5609
5914
 
5610
5915
  /**
5611
5916
  * Defines a collection of items.
5917
+ * @example givePlayerIronFireSword.ts
5918
+ * ```typescript
5919
+ * // Spawns a bunch of item stacks
5920
+ * import { ItemComponentTypes, ItemStack, Player } from '@minecraft/server';
5921
+ * import { MinecraftItemTypes, MinecraftEnchantmentTypes } from '@minecraft/vanilla-data';
5922
+ *
5923
+ * function giveFireSword(player: Player) {
5924
+ * const ironFireSword = new ItemStack(MinecraftItemTypes.DiamondSword, 1);
5925
+ *
5926
+ * const enchantments = ironFireSword?.getComponent(ItemComponentTypes.Enchantable);
5927
+ * if (enchantments) {
5928
+ * enchantments.addEnchantment({ type: MinecraftEnchantmentTypes.FireAspect, level: 1 });
5929
+ * }
5930
+ *
5931
+ * const inventory = player.getComponent('minecraft:inventory');
5932
+ * if (inventory === undefined || inventory.container === undefined) {
5933
+ * return;
5934
+ * }
5935
+ * inventory.container.setItem(0, ironFireSword);
5936
+ * }
5937
+ * ```
5938
+ * @example givePlayerEquipment.ts
5939
+ * ```typescript
5940
+ * // Gives the player some equipment
5941
+ * import { EquipmentSlot, ItemStack, Player, EntityComponentTypes } from '@minecraft/server';
5942
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
5943
+ *
5944
+ * function giveEquipment(player: Player) {
5945
+ * const equipmentCompPlayer = player.getComponent(EntityComponentTypes.Equippable);
5946
+ * if (equipmentCompPlayer) {
5947
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Head, new ItemStack(MinecraftItemTypes.GoldenHelmet));
5948
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.IronChestplate));
5949
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Legs, new ItemStack(MinecraftItemTypes.DiamondLeggings));
5950
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Feet, new ItemStack(MinecraftItemTypes.NetheriteBoots));
5951
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Mainhand, new ItemStack(MinecraftItemTypes.WoodenSword));
5952
+ * equipmentCompPlayer.setEquipment(EquipmentSlot.Offhand, new ItemStack(MinecraftItemTypes.Shield));
5953
+ * } else {
5954
+ * console.warn('No equipment component found on player');
5955
+ * }
5956
+ * }
5957
+ * ```
5958
+ * @example spawnFeatherItem.ts
5959
+ * ```typescript
5960
+ * // Spawns a feather at a location
5961
+ * import { ItemStack, DimensionLocation } from '@minecraft/server';
5962
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
5963
+ *
5964
+ * function spawnFeather(location: DimensionLocation) {
5965
+ * const featherItem = new ItemStack(MinecraftItemTypes.Feather, 1);
5966
+ * location.dimension.spawnItem(featherItem, location);
5967
+ * }
5968
+ * ```
5612
5969
  */
5613
5970
  export class ItemStack {
5614
5971
  /**
@@ -5701,6 +6058,14 @@ export class ItemStack {
5701
6058
  * the range of 1-255.
5702
6059
  */
5703
6060
  constructor(itemType: ItemType | string, amount?: number);
6061
+ /**
6062
+ * @beta
6063
+ * @remarks
6064
+ * Clears all dynamic properties that have been set on this
6065
+ * item stack.
6066
+ *
6067
+ */
6068
+ clearDynamicProperties(): void;
5704
6069
  /**
5705
6070
  * @remarks
5706
6071
  * Creates an exact copy of the item stack, including any
@@ -5743,10 +6108,24 @@ export class ItemStack {
5743
6108
  * otherwise undefined.
5744
6109
  * @example durability.ts
5745
6110
  * ```typescript
5746
- * // Get the maximum durability of a custom sword item
5747
- * const itemStack = new ItemStack('custom:sword');
5748
- * const durability = itemStack.getComponent(ItemComponentTypes.Durability);
5749
- * const maxDurability = durability.maxDurability;
6111
+ * // Gives a player a half-damaged diamond sword
6112
+ * import { ItemStack, Player, ItemComponentTypes, EntityComponentTypes } from '@minecraft/server';
6113
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
6114
+ *
6115
+ * function giveHurtDiamondSword(player: Player) {
6116
+ * const hurtDiamondSword = new ItemStack(MinecraftItemTypes.DiamondSword);
6117
+ * const durabilityComponent = hurtDiamondSword.getComponent(ItemComponentTypes.Durability);
6118
+ * if (durabilityComponent !== undefined) {
6119
+ * durabilityComponent.damage = durabilityComponent.maxDurability / 2;
6120
+ * }
6121
+ *
6122
+ * const inventory = player.getComponent(EntityComponentTypes.Inventory);
6123
+ * if (inventory === undefined || inventory.container === undefined) {
6124
+ * return;
6125
+ * }
6126
+ *
6127
+ * inventory.container.addItem(hurtDiamondSword);
6128
+ * }
5750
6129
  * ```
5751
6130
  */
5752
6131
  getComponent(componentId: string): ItemComponent | undefined;
@@ -5758,25 +6137,59 @@ export class ItemStack {
5758
6137
  */
5759
6138
  getComponents(): ItemComponent[];
5760
6139
  /**
6140
+ * @beta
5761
6141
  * @remarks
5762
- * Returns the lore value - a secondary display string - for an
5763
- * ItemStack.
6142
+ * Returns a property value.
5764
6143
  *
6144
+ * @param identifier
6145
+ * The property identifier.
5765
6146
  * @returns
5766
- * An array of lore lines. If the item does not have lore,
5767
- * returns an empty array.
6147
+ * Returns the value for the property, or undefined if the
6148
+ * property has not been set.
5768
6149
  */
5769
- getLore(): string[];
6150
+ getDynamicProperty(identifier: string): boolean | number | string | Vector3 | undefined;
5770
6151
  /**
6152
+ * @beta
5771
6153
  * @remarks
5772
- * Returns a set of tags associated with this item stack.
6154
+ * Returns the available set of dynamic property identifiers
6155
+ * that have been used on this entity.
5773
6156
  *
6157
+ * @returns
6158
+ * A string array of the dynamic properties set on this entity.
5774
6159
  */
5775
- getTags(): string[];
6160
+ getDynamicPropertyIds(): string[];
5776
6161
  /**
6162
+ * @beta
5777
6163
  * @remarks
5778
- * Returns true if the specified component is present on this
5779
- * item stack.
6164
+ * Returns the total size, in bytes, of all the dynamic
6165
+ * properties that are currently stored for this entity. This
6166
+ * includes the size of both the key and the value. This can
6167
+ * be useful for diagnosing performance warning signs - if, for
6168
+ * example, an entity has many megabytes of associated dynamic
6169
+ * properties, it may be slow to load on various devices.
6170
+ *
6171
+ */
6172
+ getDynamicPropertyTotalByteCount(): number;
6173
+ /**
6174
+ * @remarks
6175
+ * Returns the lore value - a secondary display string - for an
6176
+ * ItemStack.
6177
+ *
6178
+ * @returns
6179
+ * An array of lore lines. If the item does not have lore,
6180
+ * returns an empty array.
6181
+ */
6182
+ getLore(): string[];
6183
+ /**
6184
+ * @remarks
6185
+ * Returns a set of tags associated with this item stack.
6186
+ *
6187
+ */
6188
+ getTags(): string[];
6189
+ /**
6190
+ * @remarks
6191
+ * Returns true if the specified component is present on this
6192
+ * item stack.
5780
6193
  *
5781
6194
  * @param componentId
5782
6195
  * The identifier of the component (e.g., 'minecraft:food') to
@@ -5825,9 +6238,24 @@ export class ItemStack {
5825
6238
  * Throws if any of the provided block identifiers are invalid.
5826
6239
  * @example example.ts
5827
6240
  * ```typescript
6241
+ * const specialPickaxe = new ItemStack('minecraft:diamond_pickaxe');
6242
+ * specialPickaxe.setCanDestroy(['minecraft:cobblestone', 'minecraft:obsidian']);
6243
+ *
5828
6244
  * // Creates a diamond pickaxe that can destroy cobblestone and obsidian
5829
- * const specialPickaxe = new ItemStack("minecraft:diamond_pickaxe");
5830
- * specialPickaxe.setCanDestroy(["minecraft:cobblestone", "minecraft:obsidian"]);
6245
+ * import { ItemStack, Player } from '@minecraft/server';
6246
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
6247
+ *
6248
+ * function giveRestrictedPickaxe(player: Player) {
6249
+ * const specialPickaxe = new ItemStack(MinecraftItemTypes.DiamondPickaxe);
6250
+ * specialPickaxe.setCanPlaceOn([MinecraftItemTypes.Cobblestone, MinecraftItemTypes.Obsidian]);
6251
+ *
6252
+ * const inventory = player.getComponent('inventory');
6253
+ * if (inventory === undefined || inventory.container === undefined) {
6254
+ * return;
6255
+ * }
6256
+ *
6257
+ * inventory.container.addItem(specialPickaxe);
6258
+ * }
5831
6259
  * ```
5832
6260
  */
5833
6261
  setCanDestroy(blockIdentifiers?: string[]): void;
@@ -5847,11 +6275,37 @@ export class ItemStack {
5847
6275
  * @example example.ts
5848
6276
  * ```typescript
5849
6277
  * // Creates a gold block that can be placed on grass and dirt
5850
- * const specialGoldBlock = new ItemStack("minecraft:gold_block");
5851
- * specialPickaxe.setCanPlaceOn(["minecraft:grass", "minecraft:dirt"]);
6278
+ * import { ItemStack, Player, EntityComponentTypes } from '@minecraft/server';
6279
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
6280
+ *
6281
+ * function giveRestrictedGoldBlock(player: Player) {
6282
+ * const specialGoldBlock = new ItemStack(MinecraftItemTypes.GoldBlock);
6283
+ * specialGoldBlock.setCanPlaceOn([MinecraftItemTypes.Grass, MinecraftItemTypes.Dirt]);
6284
+ *
6285
+ * const inventory = player.getComponent(EntityComponentTypes.Inventory);
6286
+ * if (inventory === undefined || inventory.container === undefined) {
6287
+ * return;
6288
+ * }
6289
+ *
6290
+ * inventory.container.addItem(specialGoldBlock);
6291
+ * }
5852
6292
  * ```
5853
6293
  */
5854
6294
  setCanPlaceOn(blockIdentifiers?: string[]): void;
6295
+ /**
6296
+ * @beta
6297
+ * @remarks
6298
+ * Sets a specified property to a value. Note: This function
6299
+ * only works with non-stackable items.
6300
+ *
6301
+ * @param identifier
6302
+ * The property identifier.
6303
+ * @param value
6304
+ * Data value of the property to set.
6305
+ * @throws
6306
+ * Throws if the item stack is stackable.
6307
+ */
6308
+ setDynamicProperty(identifier: string, value?: boolean | number | string | Vector3): void;
5855
6309
  /**
5856
6310
  * @remarks
5857
6311
  * Sets the lore value - a secondary display string - for an
@@ -5867,28 +6321,24 @@ export class ItemStack {
5867
6321
  * @throws This function can throw errors.
5868
6322
  * @example diamondAwesomeSword.ts
5869
6323
  * ```typescript
5870
- * const diamondAwesomeSword = new mc.ItemStack(mc.MinecraftItemTypes.diamondSword, 1);
5871
- * let players = mc.world.getAllPlayers();
5872
- *
5873
- * diamondAwesomeSword.setLore(["§c§lDiamond Sword of Awesome§r", "+10 coolness", "§p+4 shiny§r"]);
5874
- *
5875
- * // hover over/select the item in your inventory to see the lore.
5876
- * const inventory = players[0].getComponent("inventory") as mc.EntityInventoryComponent;
5877
- * inventory.container.setItem(0, diamondAwesomeSword);
5878
- *
5879
- * let item = inventory.container.getItem(0);
6324
+ * import { EntityComponentTypes, ItemStack, Player } from '@minecraft/server';
6325
+ * import { MinecraftItemTypes } from '@minecraft/vanilla-data';
6326
+ *
6327
+ * function giveAwesomeSword(player: Player) {
6328
+ * const diamondAwesomeSword = new ItemStack(MinecraftItemTypes.DiamondSword, 1);
6329
+ * diamondAwesomeSword.setLore([
6330
+ * '§c§lDiamond Sword of Awesome§r',
6331
+ * '+10 coolness', '§p+4 shiny§r'
6332
+ * ]);
6333
+ *
6334
+ * // hover over/select the item in your inventory to see the lore.
6335
+ * const inventory = player.getComponent(EntityComponentTypes.Inventory);
6336
+ * if (inventory === undefined || inventory.container === undefined) {
6337
+ * return;
6338
+ * }
5880
6339
  *
5881
- * if (item) {
5882
- * let enchants = item.getComponent("minecraft:enchantments") as mc.ItemEnchantsComponent;
5883
- * let knockbackEnchant = new mc.Enchantment("knockback", 3);
5884
- * enchants.enchantments.addEnchantment(knockbackEnchant);
5885
- * }
5886
- * ```
5887
- * @example multilineLore.ts
5888
- * ```typescript
5889
- * // Set the lore of an item to multiple lines of text
5890
- * const itemStack = new ItemStack("minecraft:diamond_sword");
5891
- * itemStack.setLore(["Line 1", "Line 2", "Line 3"]);
6340
+ * inventory.container.setItem(0, diamondAwesomeSword);
6341
+ * }
5892
6342
  * ```
5893
6343
  */
5894
6344
  setLore(loreList?: string[]): void;
@@ -6338,6 +6788,17 @@ export class ItemUseOnBeforeEventSignal {
6338
6788
  /**
6339
6789
  * Contains information related to changes to a lever
6340
6790
  * activating or deactivating.
6791
+ * @example leverActionEvent.ts
6792
+ * ```typescript
6793
+ * import { world, system, LeverActionAfterEvent } from '@minecraft/server';
6794
+ *
6795
+ * world.afterEvents.leverAction.subscribe((leverActivateEvent: LeverActionAfterEvent) => {
6796
+ * console.warn(
6797
+ * `Lever event at ${system.currentTick} with power: ${leverActivateEvent.block.getRedstonePower()}`,
6798
+ * );
6799
+ * });
6800
+ *
6801
+ * ```
6341
6802
  */
6342
6803
  // @ts-ignore Class inheritance allowed for native defined classes
6343
6804
  export class LeverActionAfterEvent extends BlockEvent {
@@ -6360,6 +6821,17 @@ export class LeverActionAfterEvent extends BlockEvent {
6360
6821
  /**
6361
6822
  * Manages callbacks that are connected to lever moves
6362
6823
  * (activates or deactivates).
6824
+ * @example leverActionEvent.ts
6825
+ * ```typescript
6826
+ * import { world, system, LeverActionAfterEvent } from '@minecraft/server';
6827
+ *
6828
+ * world.afterEvents.leverAction.subscribe((leverActivateEvent: LeverActionAfterEvent) => {
6829
+ * console.warn(
6830
+ * `Lever event at ${system.currentTick} with power: ${leverActivateEvent.block.getRedstonePower()}`,
6831
+ * );
6832
+ * });
6833
+ *
6834
+ * ```
6363
6835
  */
6364
6836
  // @ts-ignore Class inheritance allowed for native defined classes
6365
6837
  export class LeverActionAfterEventSignal extends ILeverActionAfterEventSignal {
@@ -6480,6 +6952,16 @@ export class MolangVariableMap {
6480
6952
  * @beta
6481
6953
  * Contains information related to changes to a piston
6482
6954
  * expanding or retracting.
6955
+ * @example pistonAfterEvent.ts
6956
+ * ```typescript
6957
+ * import { world, system, PistonActivateAfterEvent } from '@minecraft/server';
6958
+ *
6959
+ * world.afterEvents.pistonActivate.subscribe((pistonEvent: PistonActivateAfterEvent) => {
6960
+ * console.warn(
6961
+ * `Piston event at ${system.currentTick} ${(pistonEvent.piston.isMoving ? ' Moving' : 'Not moving')} with state: ${pistonEvent.piston.state}`,
6962
+ * );
6963
+ * });
6964
+ * ```
6483
6965
  */
6484
6966
  // @ts-ignore Class inheritance allowed for native defined classes
6485
6967
  export class PistonActivateAfterEvent extends BlockEvent {
@@ -6501,58 +6983,23 @@ export class PistonActivateAfterEvent extends BlockEvent {
6501
6983
  /**
6502
6984
  * @beta
6503
6985
  * Manages callbacks that are connected to piston activations.
6986
+ * @example pistonAfterEvent.ts
6987
+ * ```typescript
6988
+ * import { world, system, PistonActivateAfterEvent } from '@minecraft/server';
6989
+ *
6990
+ * world.afterEvents.pistonActivate.subscribe((pistonEvent: PistonActivateAfterEvent) => {
6991
+ * console.warn(
6992
+ * `Piston event at ${system.currentTick} ${(pistonEvent.piston.isMoving ? ' Moving' : 'Not moving')} with state: ${pistonEvent.piston.state}`,
6993
+ * );
6994
+ * });
6995
+ * ```
6504
6996
  */
6505
6997
  export class PistonActivateAfterEventSignal {
6506
6998
  private constructor();
6507
6999
  /**
6508
7000
  * @remarks
6509
- * Adds a callback that will be called when a piston expands or
6510
- * retracts.
6511
- *
6512
7001
  * This function can't be called in read-only mode.
6513
7002
  *
6514
- * @example pistonAfterEvent.ts
6515
- * ```typescript
6516
- * // set up a couple of piston blocks
6517
- * let piston = overworld.getBlock(targetLocation);
6518
- * let button = overworld.getBlock({
6519
- * x: targetLocation.x,
6520
- * y: targetLocation.y + 1,
6521
- * z: targetLocation.z,
6522
- * });
6523
- *
6524
- * if (piston === undefined || button === undefined) {
6525
- * log("Could not find block at location.");
6526
- * return -1;
6527
- * }
6528
- *
6529
- * piston.setPermutation(
6530
- * mc.BlockPermutation.resolve("piston").withState("facing_direction", 3)
6531
- * );
6532
- * button.setPermutation(
6533
- * mc.BlockPermutation.resolve("acacia_button").withState("facing_direction", 1)
6534
- * );
6535
- *
6536
- * mc.world.afterEvents.pistonActivate.subscribe(
6537
- * (pistonEvent: mc.PistonActivateAfterEvent) => {
6538
- * let eventLoc = pistonEvent.piston.block.location;
6539
- *
6540
- * if (
6541
- * eventLoc.x === targetLocation.x &&
6542
- * eventLoc.y === targetLocation.y &&
6543
- * eventLoc.z === targetLocation.z
6544
- * ) {
6545
- * log(
6546
- * "Piston event at " +
6547
- * mc.system.currentTick +
6548
- * (pistonEvent.piston.isMoving ? " Moving" : "") +
6549
- * " State: " +
6550
- * pistonEvent.piston.state
6551
- * );
6552
- * }
6553
- * }
6554
- * );
6555
- * ```
6556
7003
  */
6557
7004
  subscribe(callback: (arg: PistonActivateAfterEvent) => void): (arg: PistonActivateAfterEvent) => void;
6558
7005
  /**
@@ -6700,30 +7147,6 @@ export class Player extends Entity {
6700
7147
  * @param soundOptions
6701
7148
  * Additional optional options for the sound.
6702
7149
  * @throws This function can throw errors.
6703
- * @example playMusicAndSound.ts
6704
- * ```typescript
6705
- * let players = mc.world.getPlayers();
6706
- *
6707
- * const musicOptions: mc.MusicOptions = {
6708
- * fade: 0.5,
6709
- * loop: true,
6710
- * volume: 1.0,
6711
- * };
6712
- * mc.world.playMusic("music.menu", musicOptions);
6713
- *
6714
- * const worldSoundOptions: mc.WorldSoundOptions = {
6715
- * pitch: 0.5,
6716
- * volume: 4.0,
6717
- * };
6718
- * mc.world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions);
6719
- *
6720
- * const playerSoundOptions: mc.PlayerSoundOptions = {
6721
- * pitch: 1.0,
6722
- * volume: 1.0,
6723
- * };
6724
- *
6725
- * players[0].playSound("bucket.fill_water", playerSoundOptions);
6726
- * ```
6727
7150
  */
6728
7151
  playSound(soundId: string, soundOptions?: PlayerSoundOptions): void;
6729
7152
  /**
@@ -6745,43 +7168,32 @@ export class Player extends Entity {
6745
7168
  * This method can throw if the provided {@link RawMessage} is
6746
7169
  * in an invalid format. For example, if an empty `name` string
6747
7170
  * is provided to `score`.
6748
- * @example nestedTranslation.ts
7171
+ * @example sendMessagesToPlayer.ts
6749
7172
  * ```typescript
6750
- * // Displays "Apple or Coal"
6751
- * let rawMessage = {
6752
- * translate: "accessibility.list.or.two",
6753
- * with: { rawtext: [{ translate: "item.apple.name" }, { translate: "item.coal.name" }] },
6754
- * };
6755
- * player.sendMessage(rawMessage);
6756
- * ```
6757
- * @example scoreWildcard.ts
6758
- * ```typescript
6759
- * // Displays the player's score for objective "obj". Each player will see their own score.
6760
- * const rawMessage = { score: { name: "*", objective: "obj" } };
6761
- * world.sendMessage(rawMessage);
6762
- * ```
6763
- * @example sendBasicMessage.ts
6764
- * ```typescript
6765
- * let players = mc.world.getPlayers();
7173
+ * import { Player } from "@minecraft/server";
6766
7174
  *
6767
- * players[0].sendMessage("Hello World!");
6768
- * ```
6769
- * @example sendTranslatedMessage.ts
6770
- * ```typescript
6771
- * let players = mc.world.getPlayers();
7175
+ * function sendPlayerMessages(player: Player) {
7176
+ * // Displays "First or Second"
7177
+ * const rawMessage = { translate: 'accessibility.list.or.two', with: ['First', 'Second'] };
7178
+ * player.sendMessage(rawMessage);
6772
7179
  *
6773
- * players[0].sendMessage({ translate: "authentication.welcome", with: ["Amazing Player 1"] });
6774
- * ```
6775
- * @example simpleString.ts
6776
- * ```typescript
6777
- * // Displays "Hello, world!"
6778
- * world.sendMessage("Hello, world!");
6779
- * ```
6780
- * @example translation.ts
6781
- * ```typescript
6782
- * // Displays "First or Second"
6783
- * const rawMessage = { translate: "accessibility.list.or.two", with: ["First", "Second"] };
6784
- * player.sendMessage(rawMessage);
7180
+ * // Displays "Hello, world!"
7181
+ * player.sendMessage('Hello, world!');
7182
+ *
7183
+ * // Displays "Welcome, Amazing Player 1!"
7184
+ * player.sendMessage({ translate: 'authentication.welcome', with: ['Amazing Player 1'] });
7185
+ *
7186
+ * // Displays the player's score for objective "obj". Each player will see their own score.
7187
+ * const rawMessageWithScore = { score: { name: '*', objective: 'obj' } };
7188
+ * player.sendMessage(rawMessageWithScore);
7189
+ *
7190
+ * // Displays "Apple or Coal"
7191
+ * const rawMessageWithNestedTranslations = {
7192
+ * translate: 'accessibility.list.or.two',
7193
+ * with: { rawtext: [{ translate: 'item.apple.name' }, { translate: 'item.coal.name' }] },
7194
+ * };
7195
+ * player.sendMessage(rawMessageWithNestedTranslations);
7196
+ * }
6785
7197
  * ```
6786
7198
  */
6787
7199
  sendMessage(message: (RawMessage | string)[] | RawMessage | string): void;
@@ -7925,6 +8337,51 @@ export class ScoreboardScoreInfo {
7925
8337
  /**
7926
8338
  * Contains information about user interface elements that are
7927
8339
  * showing up on the screen.
8340
+ * @example setTitle.ts
8341
+ * ```typescript
8342
+ * import { world } from '@minecraft/server';
8343
+ *
8344
+ * world.afterEvents.playerSpawn.subscribe((event) => {
8345
+ * event.player.onScreenDisplay.setTitle('§o§6You respawned!§r');
8346
+ * });
8347
+ * ```
8348
+ * @example setTitleAndSubtitle.ts
8349
+ * ```typescript
8350
+ * import { world } from '@minecraft/server';
8351
+ *
8352
+ * world.afterEvents.playerSpawn.subscribe((event) => {
8353
+ * event.player.onScreenDisplay.setTitle('You respawned', {
8354
+ * stayDuration: 100,
8355
+ * fadeInDuration: 2,
8356
+ * fadeOutDuration: 4,
8357
+ * subtitle: 'Try not to die next time!',
8358
+ * });
8359
+ * });
8360
+ * ```
8361
+ * @example titleCountdown.ts
8362
+ * ```typescript
8363
+ * import { world, system } from '@minecraft/server';
8364
+ *
8365
+ * world.afterEvents.playerSpawn.subscribe(event => {
8366
+ * event.player.onScreenDisplay.setTitle('Get ready!', {
8367
+ * stayDuration: 220,
8368
+ * fadeInDuration: 2,
8369
+ * fadeOutDuration: 4,
8370
+ * subtitle: '10',
8371
+ * });
8372
+ *
8373
+ * let countdown = 10;
8374
+ *
8375
+ * const intervalId = system.runInterval(() => {
8376
+ * countdown--;
8377
+ * event.player.onScreenDisplay.updateSubtitle(countdown.toString());
8378
+ *
8379
+ * if (countdown == 0) {
8380
+ * system.clearRun(intervalId);
8381
+ * }
8382
+ * }, 20);
8383
+ * });
8384
+ * ```
7928
8385
  */
7929
8386
  export class ScreenDisplay {
7930
8387
  private constructor();
@@ -7957,44 +8414,50 @@ export class ScreenDisplay {
7957
8414
  * This function can't be called in read-only mode.
7958
8415
  *
7959
8416
  * @throws This function can throw errors.
7960
- * @example countdown.ts
7961
- * ```typescript
7962
- * let players = mc.world.getPlayers();
7963
- *
7964
- * players[0].onScreenDisplay.setTitle("Get ready!", {
7965
- * stayDuration: 220,
7966
- * fadeInDuration: 2,
7967
- * fadeOutDuration: 4,
7968
- * subtitle: "10",
7969
- * });
7970
- *
7971
- * let countdown = 10;
7972
- *
7973
- * let intervalId = mc.system.runInterval(() => {
7974
- * countdown--;
7975
- * players[0].onScreenDisplay.updateSubtitle(countdown.toString());
7976
- *
7977
- * if (countdown == 0) {
7978
- * mc.system.clearRun(intervalId);
7979
- * }
7980
- * }, 20);
7981
- * ```
7982
8417
  * @example setTitle.ts
7983
8418
  * ```typescript
7984
- * let players = mc.world.getPlayers();
8419
+ * import { world } from '@minecraft/server';
7985
8420
  *
7986
- * players[0].onScreenDisplay.setTitle("§o§6Fancy Title§r");
8421
+ * world.afterEvents.playerSpawn.subscribe((event) => {
8422
+ * event.player.onScreenDisplay.setTitle('§o§6You respawned!§r');
8423
+ * });
7987
8424
  * ```
7988
8425
  * @example setTitleAndSubtitle.ts
7989
8426
  * ```typescript
7990
- * let players = mc.world.getPlayers();
7991
- *
7992
- * players[0].onScreenDisplay.setTitle("Chapter 1", {
7993
- * stayDuration: 100,
7994
- * fadeInDuration: 2,
7995
- * fadeOutDuration: 4,
7996
- * subtitle: "Trouble in Block Town",
7997
- * });
8427
+ * import { world } from '@minecraft/server';
8428
+ *
8429
+ * world.afterEvents.playerSpawn.subscribe((event) => {
8430
+ * event.player.onScreenDisplay.setTitle('You respawned', {
8431
+ * stayDuration: 100,
8432
+ * fadeInDuration: 2,
8433
+ * fadeOutDuration: 4,
8434
+ * subtitle: 'Try not to die next time!',
8435
+ * });
8436
+ * });
8437
+ * ```
8438
+ * @example titleCountdown.ts
8439
+ * ```typescript
8440
+ * import { world, system } from '@minecraft/server';
8441
+ *
8442
+ * world.afterEvents.playerSpawn.subscribe(event => {
8443
+ * event.player.onScreenDisplay.setTitle('Get ready!', {
8444
+ * stayDuration: 220,
8445
+ * fadeInDuration: 2,
8446
+ * fadeOutDuration: 4,
8447
+ * subtitle: '10',
8448
+ * });
8449
+ *
8450
+ * let countdown = 10;
8451
+ *
8452
+ * const intervalId = system.runInterval(() => {
8453
+ * countdown--;
8454
+ * event.player.onScreenDisplay.updateSubtitle(countdown.toString());
8455
+ *
8456
+ * if (countdown == 0) {
8457
+ * system.clearRun(intervalId);
8458
+ * }
8459
+ * }, 20);
8460
+ * });
7998
8461
  * ```
7999
8462
  */
8000
8463
  setTitle(title: (RawMessage | string)[] | RawMessage | string, options?: TitleDisplayOptions): void;
@@ -8107,7 +8570,7 @@ export class System {
8107
8570
  /**
8108
8571
  * @remarks
8109
8572
  * Cancels the execution of a function run that was previously
8110
- * scheduled via the `run` function.
8573
+ * scheduled via {@link System.run}.
8111
8574
  *
8112
8575
  */
8113
8576
  clearRun(runId: number): void;
@@ -8125,18 +8588,22 @@ export class System {
8125
8588
  * function to cancel the execution of this run.
8126
8589
  * @example trapTick.ts
8127
8590
  * ```typescript
8128
- * const overworld = mc.world.getDimension("overworld");
8591
+ * import { system, world } from '@minecraft/server';
8129
8592
  *
8130
- * try {
8131
- * // Minecraft runs at 20 ticks per second.
8132
- * if (mc.system.currentTick % 1200 === 0) {
8133
- * mc.world.sendMessage("Another minute passes...");
8593
+ * function printEveryMinute() {
8594
+ * try {
8595
+ * // Minecraft runs at 20 ticks per second.
8596
+ * if (system.currentTick % 1200 === 0) {
8597
+ * world.sendMessage('Another minute passes...');
8598
+ * }
8599
+ * } catch (e) {
8600
+ * console.warn('Error: ' + e);
8134
8601
  * }
8135
- * } catch (e) {
8136
- * console.warn("Error: " + e);
8137
- * }
8138
8602
  *
8139
- * mc.system.run(trapTick);
8603
+ * system.run(printEveryMinute);
8604
+ * }
8605
+ *
8606
+ * printEveryMinute();
8140
8607
  * ```
8141
8608
  */
8142
8609
  run(callback: () => void): number;
@@ -8154,11 +8621,13 @@ export class System {
8154
8621
  * to stop the run of this function on an interval.
8155
8622
  * @example every30Seconds.ts
8156
8623
  * ```typescript
8157
- * let intervalRunIdentifier = Math.floor(Math.random() * 10000);
8624
+ * import { system, world } from '@minecraft/server';
8625
+ *
8626
+ * const intervalRunIdentifier = Math.floor(Math.random() * 10000);
8158
8627
  *
8159
- * mc.system.runInterval(() => {
8160
- * mc.world.sendMessage("This is an interval run " + intervalRunIdentifier + " sending a message every 30 seconds.");
8161
- * }, 600);
8628
+ * system.runInterval(() => {
8629
+ * world.sendMessage('This is an interval run ' + intervalRunIdentifier + ' sending a message every 30 seconds.');
8630
+ * }, 600);
8162
8631
  * ```
8163
8632
  */
8164
8633
  runInterval(callback: () => void, tickInterval?: number): number;
@@ -8256,6 +8725,37 @@ export class TargetBlockHitAfterEventSignal {
8256
8725
 
8257
8726
  /**
8258
8727
  * Contains information related to changes to a trip wire trip.
8728
+ * @example tripWireTripEvent.ts
8729
+ * ```typescript
8730
+ * import { Vector3, world, BlockPermutation, TripWireTripAfterEvent, system } from '@minecraft/server';
8731
+ *
8732
+ * const overworld = world.getDimension('overworld');
8733
+ * const targetLocation: Vector3 = { x: 0, y: 0, z: 0 };
8734
+ *
8735
+ * // set up a tripwire
8736
+ * const redstone = overworld.getBlock({ x: targetLocation.x, y: targetLocation.y - 1, z: targetLocation.z });
8737
+ * const tripwire = overworld.getBlock(targetLocation);
8738
+ *
8739
+ * if (redstone === undefined || tripwire === undefined) {
8740
+ * console.warn('Could not find block at location.');
8741
+ * } else {
8742
+ *
8743
+ * redstone.setPermutation(BlockPermutation.resolve('redstone_block'));
8744
+ * tripwire.setPermutation(BlockPermutation.resolve('tripwire'));
8745
+ *
8746
+ * world.afterEvents.tripWireTrip.subscribe((tripWireTripEvent: TripWireTripAfterEvent) => {
8747
+ * const eventLoc = tripWireTripEvent.block.location;
8748
+ *
8749
+ * if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) {
8750
+ * console.warn(
8751
+ * 'Tripwire trip event at tick ' +
8752
+ * system.currentTick +
8753
+ * (tripWireTripEvent.sources.length > 0 ? ' by entity ' + tripWireTripEvent.sources[0].id : ''),
8754
+ * );
8755
+ * }
8756
+ * });
8757
+ * }
8758
+ * ```
8259
8759
  */
8260
8760
  // @ts-ignore Class inheritance allowed for native defined classes
8261
8761
  export class TripWireTripAfterEvent extends BlockEvent {
@@ -8277,6 +8777,37 @@ export class TripWireTripAfterEvent extends BlockEvent {
8277
8777
  /**
8278
8778
  * Manages callbacks that are connected to when a trip wire is
8279
8779
  * tripped.
8780
+ * @example tripWireTripEvent.ts
8781
+ * ```typescript
8782
+ * import { Vector3, world, BlockPermutation, TripWireTripAfterEvent, system } from '@minecraft/server';
8783
+ *
8784
+ * const overworld = world.getDimension('overworld');
8785
+ * const targetLocation: Vector3 = { x: 0, y: 0, z: 0 };
8786
+ *
8787
+ * // set up a tripwire
8788
+ * const redstone = overworld.getBlock({ x: targetLocation.x, y: targetLocation.y - 1, z: targetLocation.z });
8789
+ * const tripwire = overworld.getBlock(targetLocation);
8790
+ *
8791
+ * if (redstone === undefined || tripwire === undefined) {
8792
+ * console.warn('Could not find block at location.');
8793
+ * } else {
8794
+ *
8795
+ * redstone.setPermutation(BlockPermutation.resolve('redstone_block'));
8796
+ * tripwire.setPermutation(BlockPermutation.resolve('tripwire'));
8797
+ *
8798
+ * world.afterEvents.tripWireTrip.subscribe((tripWireTripEvent: TripWireTripAfterEvent) => {
8799
+ * const eventLoc = tripWireTripEvent.block.location;
8800
+ *
8801
+ * if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) {
8802
+ * console.warn(
8803
+ * 'Tripwire trip event at tick ' +
8804
+ * system.currentTick +
8805
+ * (tripWireTripEvent.sources.length > 0 ? ' by entity ' + tripWireTripEvent.sources[0].id : ''),
8806
+ * );
8807
+ * }
8808
+ * });
8809
+ * }
8810
+ * ```
8280
8811
  */
8281
8812
  export class TripWireTripAfterEventSignal {
8282
8813
  private constructor();
@@ -8314,7 +8845,17 @@ export class WeatherChangeAfterEvent {
8314
8845
  *
8315
8846
  */
8316
8847
  readonly dimension: string;
8848
+ /**
8849
+ * @remarks
8850
+ * The weather type after the weather was changed.
8851
+ *
8852
+ */
8317
8853
  readonly newWeather: WeatherType;
8854
+ /**
8855
+ * @remarks
8856
+ * The weather type before the weather was changed.
8857
+ *
8858
+ */
8318
8859
  readonly previousWeather: WeatherType;
8319
8860
  }
8320
8861
 
@@ -8436,57 +8977,72 @@ export class World {
8436
8977
  * @throws
8437
8978
  * Throws if the given dynamic property identifier is not
8438
8979
  * defined.
8439
- * @example incrementProperty.ts
8980
+ * @example incrementDynamicProperty.ts
8440
8981
  * ```typescript
8441
- * let number = mc.world.getDynamicProperty("samplelibrary:number");
8982
+ * import * as mc from '@minecraft/server';
8442
8983
  *
8443
- * log("Current value is: " + number);
8984
+ * function incrementProperty(propertyName: string): boolean {
8985
+ * let number = mc.world.getDynamicProperty(propertyName);
8444
8986
  *
8445
- * if (number === undefined) {
8446
- * number = 0;
8447
- * }
8987
+ * console.warn('Current value is: ' + number);
8448
8988
  *
8449
- * if (typeof number !== "number") {
8450
- * log("Number is of an unexpected type.");
8451
- * return -1;
8452
- * }
8989
+ * if (number === undefined) {
8990
+ * number = 0;
8991
+ * }
8992
+ *
8993
+ * if (typeof number !== 'number') {
8994
+ * console.warn('Number is of an unexpected type.');
8995
+ * return false;
8996
+ * }
8453
8997
  *
8454
- * mc.world.setDynamicProperty("samplelibrary:number", number + 1);
8998
+ * mc.world.setDynamicProperty(propertyName, number + 1);
8999
+ * return true;
9000
+ * }
9001
+ *
9002
+ * incrementProperty('samplelibrary:number');
8455
9003
  * ```
8456
- * @example incrementPropertyInJsonBlob.ts
9004
+ * @example incrementDynamicPropertyInJsonBlob.ts
8457
9005
  * ```typescript
8458
- * let paintStr = mc.world.getDynamicProperty("samplelibrary:longerjson");
8459
- * let paint: { color: string; intensity: number } | undefined = undefined;
9006
+ * import * as mc from '@minecraft/server';
8460
9007
  *
8461
- * log("Current value is: " + paintStr);
9008
+ * function updateWorldProperty(propertyName: string): boolean {
9009
+ * let paintStr = mc.world.getDynamicProperty(propertyName);
9010
+ * let paint: { color: string; intensity: number } | undefined = undefined;
8462
9011
  *
8463
- * if (paintStr === undefined) {
8464
- * paint = {
8465
- * color: "purple",
8466
- * intensity: 0,
8467
- * };
8468
- * } else {
8469
- * if (typeof paintStr !== "string") {
8470
- * log("Paint is of an unexpected type.");
8471
- * return -1;
9012
+ * console.log('Current value is: ' + paintStr);
9013
+ *
9014
+ * if (paintStr === undefined) {
9015
+ * paint = {
9016
+ * color: 'purple',
9017
+ * intensity: 0,
9018
+ * };
9019
+ * } else {
9020
+ * if (typeof paintStr !== 'string') {
9021
+ * console.warn('Paint is of an unexpected type.');
9022
+ * return false;
9023
+ * }
9024
+ *
9025
+ * try {
9026
+ * paint = JSON.parse(paintStr);
9027
+ * } catch (e) {
9028
+ * console.warn('Error parsing serialized struct.');
9029
+ * return false;
9030
+ * }
8472
9031
  * }
8473
9032
  *
8474
- * try {
8475
- * paint = JSON.parse(paintStr);
8476
- * } catch (e) {
8477
- * log("Error parsing serialized struct.");
8478
- * return -1;
9033
+ * if (!paint) {
9034
+ * console.warn('Error parsing serialized struct.');
9035
+ * return false;
8479
9036
  * }
8480
- * }
8481
9037
  *
8482
- * if (!paint) {
8483
- * log("Error parsing serialized struct.");
8484
- * return -1;
8485
- * }
9038
+ * paint.intensity++;
9039
+ * paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits
9040
+ * mc.world.setDynamicProperty(propertyName, paintStr);
9041
+ *
9042
+ * return true;
9043
+ * }
8486
9044
  *
8487
- * paint.intensity++;
8488
- * paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits
8489
- * mc.world.setDynamicProperty("samplelibrary:longerjson", paintStr);
9045
+ * updateWorldProperty('samplelibrary:longerjson');
8490
9046
  * ```
8491
9047
  */
8492
9048
  getDynamicProperty(identifier: string): boolean | number | string | Vector3 | undefined;
@@ -8556,27 +9112,34 @@ export class World {
8556
9112
  * @throws This function can throw errors.
8557
9113
  * @example playMusicAndSound.ts
8558
9114
  * ```typescript
8559
- * let players = mc.world.getPlayers();
9115
+ * import { world, MusicOptions, WorldSoundOptions, PlayerSoundOptions, Vector3 } from '@minecraft/server';
9116
+ *
9117
+ * const players = world.getPlayers();
9118
+ * const targetLocation: Vector3 = {
9119
+ * x: 0,
9120
+ * y: 0,
9121
+ * z: 0,
9122
+ * };
8560
9123
  *
8561
- * const musicOptions: mc.MusicOptions = {
9124
+ * const musicOptions: MusicOptions = {
8562
9125
  * fade: 0.5,
8563
9126
  * loop: true,
8564
9127
  * volume: 1.0,
8565
- * };
8566
- * mc.world.playMusic("music.menu", musicOptions);
9128
+ * };
9129
+ * world.playMusic('music.menu', musicOptions);
8567
9130
  *
8568
- * const worldSoundOptions: mc.WorldSoundOptions = {
9131
+ * const worldSoundOptions: WorldSoundOptions = {
8569
9132
  * pitch: 0.5,
8570
9133
  * volume: 4.0,
8571
- * };
8572
- * mc.world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions);
9134
+ * };
9135
+ * world.playSound('ambient.weather.thunder', targetLocation, worldSoundOptions);
8573
9136
  *
8574
- * const playerSoundOptions: mc.PlayerSoundOptions = {
9137
+ * const playerSoundOptions: PlayerSoundOptions = {
8575
9138
  * pitch: 1.0,
8576
9139
  * volume: 1.0,
8577
- * };
9140
+ * };
8578
9141
  *
8579
- * players[0].playSound("bucket.fill_water", playerSoundOptions);
9142
+ * players[0].playSound('bucket.fill_water', playerSoundOptions);
8580
9143
  * ```
8581
9144
  */
8582
9145
  playMusic(trackId: string, musicOptions?: MusicOptions): void;
@@ -8593,27 +9156,34 @@ export class World {
8593
9156
  * An error will be thrown if volume is less than 0.0.
8594
9157
  * @example playMusicAndSound.ts
8595
9158
  * ```typescript
8596
- * let players = mc.world.getPlayers();
9159
+ * import { world, MusicOptions, WorldSoundOptions, PlayerSoundOptions, Vector3 } from '@minecraft/server';
8597
9160
  *
8598
- * const musicOptions: mc.MusicOptions = {
9161
+ * const players = world.getPlayers();
9162
+ * const targetLocation: Vector3 = {
9163
+ * x: 0,
9164
+ * y: 0,
9165
+ * z: 0,
9166
+ * };
9167
+ *
9168
+ * const musicOptions: MusicOptions = {
8599
9169
  * fade: 0.5,
8600
9170
  * loop: true,
8601
9171
  * volume: 1.0,
8602
- * };
8603
- * mc.world.playMusic("music.menu", musicOptions);
9172
+ * };
9173
+ * world.playMusic('music.menu', musicOptions);
8604
9174
  *
8605
- * const worldSoundOptions: mc.WorldSoundOptions = {
9175
+ * const worldSoundOptions: WorldSoundOptions = {
8606
9176
  * pitch: 0.5,
8607
9177
  * volume: 4.0,
8608
- * };
8609
- * mc.world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions);
9178
+ * };
9179
+ * world.playSound('ambient.weather.thunder', targetLocation, worldSoundOptions);
8610
9180
  *
8611
- * const playerSoundOptions: mc.PlayerSoundOptions = {
9181
+ * const playerSoundOptions: PlayerSoundOptions = {
8612
9182
  * pitch: 1.0,
8613
9183
  * volume: 1.0,
8614
- * };
9184
+ * };
8615
9185
  *
8616
- * players[0].playSound("bucket.fill_water", playerSoundOptions);
9186
+ * players[0].playSound('bucket.fill_water', playerSoundOptions);
8617
9187
  * ```
8618
9188
  */
8619
9189
  playSound(soundId: string, location: Vector3, soundOptions?: WorldSoundOptions): void;
@@ -8646,28 +9216,36 @@ export class World {
8646
9216
  * is provided to `score`.
8647
9217
  * @example nestedTranslation.ts
8648
9218
  * ```typescript
9219
+ * import { world } from '@minecraft/server';
9220
+ *
8649
9221
  * // Displays "Apple or Coal"
8650
- * let rawMessage = {
8651
- * translate: "accessibility.list.or.two",
8652
- * with: { rawtext: [{ translate: "item.apple.name" }, { translate: "item.coal.name" }] },
9222
+ * const rawMessage = {
9223
+ * translate: 'accessibility.list.or.two',
9224
+ * with: { rawtext: [{ translate: 'item.apple.name' }, { translate: 'item.coal.name' }] },
8653
9225
  * };
8654
9226
  * world.sendMessage(rawMessage);
8655
9227
  * ```
8656
9228
  * @example scoreWildcard.ts
8657
9229
  * ```typescript
9230
+ * import { world } from '@minecraft/server';
9231
+ *
8658
9232
  * // Displays the player's score for objective "obj". Each player will see their own score.
8659
- * const rawMessage = { score: { name: "*", objective: "obj" } };
9233
+ * const rawMessage = { score: { name: '*', objective: 'obj' } };
8660
9234
  * world.sendMessage(rawMessage);
8661
9235
  * ```
8662
9236
  * @example simpleString.ts
8663
9237
  * ```typescript
9238
+ * import { world } from '@minecraft/server';
9239
+ *
8664
9240
  * // Displays "Hello, world!"
8665
- * world.sendMessage("Hello, world!");
9241
+ * world.sendMessage('Hello, world!');
8666
9242
  * ```
8667
9243
  * @example translation.ts
8668
9244
  * ```typescript
9245
+ * import { world } from '@minecraft/server';
9246
+ *
8669
9247
  * // Displays "First or Second"
8670
- * const rawMessage = { translate: "accessibility.list.or.two", with: ["First", "Second"] };
9248
+ * const rawMessage = { translate: 'accessibility.list.or.two', with: ['First', 'Second'] };
8671
9249
  * world.sendMessage(rawMessage);
8672
9250
  * ```
8673
9251
  */
@@ -8710,57 +9288,72 @@ export class World {
8710
9288
  * @throws
8711
9289
  * Throws if the given dynamic property identifier is not
8712
9290
  * defined.
8713
- * @example incrementProperty.ts
9291
+ * @example incrementDynamicProperty.ts
8714
9292
  * ```typescript
8715
- * let number = mc.world.getDynamicProperty("samplelibrary:number");
9293
+ * import * as mc from '@minecraft/server';
9294
+ *
9295
+ * function incrementProperty(propertyName: string): boolean {
9296
+ * let number = mc.world.getDynamicProperty(propertyName);
9297
+ *
9298
+ * console.warn('Current value is: ' + number);
8716
9299
  *
8717
- * log("Current value is: " + number);
9300
+ * if (number === undefined) {
9301
+ * number = 0;
9302
+ * }
8718
9303
  *
8719
- * if (number === undefined) {
8720
- * number = 0;
8721
- * }
9304
+ * if (typeof number !== 'number') {
9305
+ * console.warn('Number is of an unexpected type.');
9306
+ * return false;
9307
+ * }
8722
9308
  *
8723
- * if (typeof number !== "number") {
8724
- * log("Number is of an unexpected type.");
8725
- * return -1;
8726
- * }
9309
+ * mc.world.setDynamicProperty(propertyName, number + 1);
9310
+ * return true;
9311
+ * }
8727
9312
  *
8728
- * mc.world.setDynamicProperty("samplelibrary:number", number + 1);
9313
+ * incrementProperty('samplelibrary:number');
8729
9314
  * ```
8730
- * @example incrementPropertyInJsonBlob.ts
9315
+ * @example incrementDynamicPropertyInJsonBlob.ts
8731
9316
  * ```typescript
8732
- * let paintStr = mc.world.getDynamicProperty("samplelibrary:longerjson");
8733
- * let paint: { color: string; intensity: number } | undefined = undefined;
9317
+ * import * as mc from '@minecraft/server';
8734
9318
  *
8735
- * log("Current value is: " + paintStr);
9319
+ * function updateWorldProperty(propertyName: string): boolean {
9320
+ * let paintStr = mc.world.getDynamicProperty(propertyName);
9321
+ * let paint: { color: string; intensity: number } | undefined = undefined;
8736
9322
  *
8737
- * if (paintStr === undefined) {
8738
- * paint = {
8739
- * color: "purple",
8740
- * intensity: 0,
8741
- * };
8742
- * } else {
8743
- * if (typeof paintStr !== "string") {
8744
- * log("Paint is of an unexpected type.");
8745
- * return -1;
9323
+ * console.log('Current value is: ' + paintStr);
9324
+ *
9325
+ * if (paintStr === undefined) {
9326
+ * paint = {
9327
+ * color: 'purple',
9328
+ * intensity: 0,
9329
+ * };
9330
+ * } else {
9331
+ * if (typeof paintStr !== 'string') {
9332
+ * console.warn('Paint is of an unexpected type.');
9333
+ * return false;
9334
+ * }
9335
+ *
9336
+ * try {
9337
+ * paint = JSON.parse(paintStr);
9338
+ * } catch (e) {
9339
+ * console.warn('Error parsing serialized struct.');
9340
+ * return false;
9341
+ * }
8746
9342
  * }
8747
9343
  *
8748
- * try {
8749
- * paint = JSON.parse(paintStr);
8750
- * } catch (e) {
8751
- * log("Error parsing serialized struct.");
8752
- * return -1;
9344
+ * if (!paint) {
9345
+ * console.warn('Error parsing serialized struct.');
9346
+ * return false;
8753
9347
  * }
8754
- * }
8755
9348
  *
8756
- * if (!paint) {
8757
- * log("Error parsing serialized struct.");
8758
- * return -1;
8759
- * }
9349
+ * paint.intensity++;
9350
+ * paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits
9351
+ * mc.world.setDynamicProperty(propertyName, paintStr);
8760
9352
  *
8761
- * paint.intensity++;
8762
- * paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits
8763
- * mc.world.setDynamicProperty("samplelibrary:longerjson", paintStr);
9353
+ * return true;
9354
+ * }
9355
+ *
9356
+ * updateWorldProperty('samplelibrary:longerjson');
8764
9357
  * ```
8765
9358
  */
8766
9359
  setDynamicProperty(identifier: string, value?: boolean | number | string | Vector3): void;
@@ -8800,7 +9393,6 @@ export class WorldAfterEvents {
8800
9393
  */
8801
9394
  readonly buttonPush: ButtonPushAfterEventSignal;
8802
9395
  /**
8803
- * @beta
8804
9396
  * @remarks
8805
9397
  * This event is fired when an entity event has been triggered
8806
9398
  * that will update the component definition state of an
@@ -8808,6 +9400,14 @@ export class WorldAfterEvents {
8808
9400
  *
8809
9401
  */
8810
9402
  readonly dataDrivenEntityTrigger: DataDrivenEntityTriggerAfterEventSignal;
9403
+ /**
9404
+ * @beta
9405
+ * @remarks
9406
+ * This event fires when an effect, like poisoning, is added to
9407
+ * an entity.
9408
+ *
9409
+ */
9410
+ readonly effectAdd: EffectAddAfterEventSignal;
8811
9411
  /**
8812
9412
  * @remarks
8813
9413
  * This event fires when an entity dies.
@@ -8859,6 +9459,13 @@ export class WorldAfterEvents {
8859
9459
  *
8860
9460
  */
8861
9461
  readonly entitySpawn: EntitySpawnAfterEventSignal;
9462
+ /**
9463
+ * @beta
9464
+ * @remarks
9465
+ * This event is fired after an explosion occurs.
9466
+ *
9467
+ */
9468
+ readonly explosion: ExplosionAfterEventSignal;
8862
9469
  /**
8863
9470
  * @remarks
8864
9471
  * This event fires when a chargeable item completes charging.
@@ -9026,6 +9633,14 @@ export class WorldAfterEvents {
9026
9633
  */
9027
9634
  export class WorldBeforeEvents {
9028
9635
  private constructor();
9636
+ /**
9637
+ * @beta
9638
+ * @remarks
9639
+ * This event is triggered after an event has been added to an
9640
+ * entity.
9641
+ *
9642
+ */
9643
+ readonly effectAdd: EffectAddBeforeEventSignal;
9029
9644
  /**
9030
9645
  * @remarks
9031
9646
  * Fires before an entity is removed from the world (for
@@ -9033,6 +9648,13 @@ export class WorldBeforeEvents {
9033
9648
  *
9034
9649
  */
9035
9650
  readonly entityRemove: EntityRemoveBeforeEventSignal;
9651
+ /**
9652
+ * @beta
9653
+ * @remarks
9654
+ * This event is fired after an explosion occurs.
9655
+ *
9656
+ */
9657
+ readonly explosion: ExplosionBeforeEventSignal;
9036
9658
  /**
9037
9659
  * @remarks
9038
9660
  * This event fires when an item is successfully used by a
@@ -9251,7 +9873,6 @@ export interface CameraSetRotOptions {
9251
9873
  }
9252
9874
 
9253
9875
  /**
9254
- * @beta
9255
9876
  * Contains a set of updates to the component definition state
9256
9877
  * of an entity.
9257
9878
  */
@@ -9366,7 +9987,6 @@ export interface EntityDamageSource {
9366
9987
  }
9367
9988
 
9368
9989
  /**
9369
- * @beta
9370
9990
  * Specifies additional filters that are used in registering a
9371
9991
  * data driven trigger event for entities.
9372
9992
  */
@@ -9449,6 +10069,161 @@ export interface EntityHitInformation {
9449
10069
 
9450
10070
  /**
9451
10071
  * Contains options for selecting entities within an area.
10072
+ * @example testBlockConditional.ts
10073
+ * ```typescript
10074
+ * import { Dimension } from '@minecraft/server';
10075
+ *
10076
+ * // Having this command:
10077
+ *
10078
+ * // execute as @e[type=fox] positioned as @s if block ^ ^-1 ^ stone run summon salmon
10079
+ *
10080
+ * // Equivalent scripting code would be:
10081
+ * function spawnFish(dimension: Dimension) {
10082
+ * dimension
10083
+ * .getEntities({
10084
+ * type: 'fox',
10085
+ * })
10086
+ * .filter(entity => {
10087
+ * const block = dimension.getBlock({
10088
+ * x: entity.location.x,
10089
+ * y: entity.location.y - 1,
10090
+ * z: entity.location.z,
10091
+ * });
10092
+ *
10093
+ * return block !== undefined && block.matches('minecraft:stone');
10094
+ * })
10095
+ * .forEach(entity => {
10096
+ * dimension.spawnEntity('salmon', entity.location);
10097
+ * });
10098
+ * }
10099
+ * ```
10100
+ * @example testPlaySoundChained.ts
10101
+ * ```typescript
10102
+ * import { Dimension } from '@minecraft/server';
10103
+ *
10104
+ * // Having this command:
10105
+ *
10106
+ * // execute as @e[type=armor_stand,name=myArmorStand,tag=dummyTag1,tag=!dummyTag2] run playsound raid.horn @a
10107
+ *
10108
+ * // Equivalent scripting code would be:
10109
+ * function playSounds(dimension: Dimension) {
10110
+ * const targetPlayers = dimension.getPlayers();
10111
+ * const originEntities = dimension.getEntities({
10112
+ * type: 'armor_stand',
10113
+ * name: 'myArmorStand',
10114
+ * tags: ['dummyTag1'],
10115
+ * excludeTags: ['dummyTag2'],
10116
+ * });
10117
+ *
10118
+ * originEntities.forEach(entity => {
10119
+ * targetPlayers.forEach(player => {
10120
+ * player.playSound('raid.horn');
10121
+ * });
10122
+ * });
10123
+ * }
10124
+ * ```
10125
+ * @example testSendMessageAllPlayers.ts
10126
+ * ```typescript
10127
+ * import { Dimension } from '@minecraft/server';
10128
+ *
10129
+ * // Having this command:
10130
+ *
10131
+ * // execute as @e[type=armor_stand,name=myArmorStand,tag=dummyTag1,tag=!dummyTag2] run tellraw @a { "rawtext": [{"translate": "hello.world" }] }
10132
+ *
10133
+ * // Equivalent scripting code would be:
10134
+ * function sendMessagesToPlayers(dimension: Dimension) {
10135
+ * const targetPlayers = dimension.getPlayers();
10136
+ * const originEntities = dimension.getEntities({
10137
+ * type: 'armor_stand',
10138
+ * name: 'myArmorStand',
10139
+ * tags: ['dummyTag1'],
10140
+ * excludeTags: ['dummyTag2'],
10141
+ * });
10142
+ *
10143
+ * originEntities.forEach(entity => {
10144
+ * targetPlayers.forEach(player => {
10145
+ * player.sendMessage({ rawtext: [{ translate: 'hello.world' }] });
10146
+ * });
10147
+ * });
10148
+ * }
10149
+ * ```
10150
+ * @example testSetScoreBoardChained.ts
10151
+ * ```typescript
10152
+ * import { Dimension, world } from '@minecraft/server';
10153
+ *
10154
+ * // Having these commands:
10155
+ *
10156
+ * // scoreboard objectives add scoreObjective1 dummy
10157
+ * // scoreboard players set @e[type=armor_stand,name=myArmorStand] scoreObjective1 -1
10158
+ *
10159
+ * // Equivalent scripting code would be:
10160
+ * function setScores(dimension: Dimension) {
10161
+ * const objective = world.scoreboard.addObjective('scoreObjective1', 'dummy');
10162
+ * dimension
10163
+ * .getEntities({
10164
+ * type: 'armor_stand',
10165
+ * name: 'myArmorStand',
10166
+ * })
10167
+ * .forEach(entity => {
10168
+ * if (entity.scoreboardIdentity !== undefined) {
10169
+ * objective.setScore(entity.scoreboardIdentity, -1);
10170
+ * }
10171
+ * });
10172
+ * }
10173
+ * ```
10174
+ * @example testSummonMobChained.ts
10175
+ * ```typescript
10176
+ * import { Dimension } from '@minecraft/server';
10177
+ *
10178
+ * // Having this command:
10179
+ *
10180
+ * // execute as @e[type=armor_stand] run execute as @a[x=0,y=-60,z=0,c=4,r=15] run summon pig ~1 ~ ~
10181
+ *
10182
+ * // Equivalent scripting code would be:
10183
+ * function spawnPigs(dimension: Dimension) {
10184
+ * const armorStandArray = dimension.getEntities({
10185
+ * type: 'armor_stand',
10186
+ * });
10187
+ * const playerArray = dimension.getPlayers({
10188
+ * location: { x: 0, y: -60, z: 0 },
10189
+ * closest: 4,
10190
+ * maxDistance: 15,
10191
+ * });
10192
+ * armorStandArray.forEach(entity => {
10193
+ * playerArray.forEach(player => {
10194
+ * dimension.spawnEntity('pig', {
10195
+ * x: player.location.x + 1,
10196
+ * y: player.location.y,
10197
+ * z: player.location.z,
10198
+ * });
10199
+ * });
10200
+ * });
10201
+ * }
10202
+ * ```
10203
+ * @example checkFeatherNearby.ts
10204
+ * ```typescript
10205
+ * import { DimensionLocation, EntityComponentTypes } from "@minecraft/server";
10206
+ *
10207
+ * // Returns true if a feather item entity is within 'distance' blocks of 'location'.
10208
+ * function isFeatherNear(location: DimensionLocation, distance: number): boolean {
10209
+ * const items = location.dimension.getEntities({
10210
+ * location: location,
10211
+ * maxDistance: 20,
10212
+ * });
10213
+ *
10214
+ * for (const item of items) {
10215
+ * const itemComp = item.getComponent(EntityComponentTypes.Item);
10216
+ *
10217
+ * if (itemComp) {
10218
+ * if (itemComp.itemStack.typeId.endsWith('feather')) {
10219
+ * return true;
10220
+ * }
10221
+ * }
10222
+ * }
10223
+ *
10224
+ * return false;
10225
+ * }
10226
+ * ```
9452
10227
  */
9453
10228
  export interface EntityQueryOptions {
9454
10229
  /**
@@ -9677,6 +10452,22 @@ export interface EntityRaycastOptions {
9677
10452
  * @beta
9678
10453
  * Additional configuration options for the {@link
9679
10454
  * Dimension.createExplosion} method.
10455
+ * @example createExplosions.ts
10456
+ * ```typescript
10457
+ * // Creates an explosion of radius 15 that does not break blocks
10458
+ * import { DimensionLocation } from '@minecraft/server';
10459
+ *
10460
+ * function createExplosions(location: DimensionLocation) {
10461
+ * // Creates an explosion of radius 15 that does not break blocks
10462
+ * location.dimension.createExplosion(location, 15, { breaksBlocks: false });
10463
+ *
10464
+ * // Creates an explosion of radius 15 that does not cause fire
10465
+ * location.dimension.createExplosion(location, 15, { causesFire: true });
10466
+ *
10467
+ * // Creates an explosion of radius 10 that can go underwater
10468
+ * location.dimension.createExplosion(location, 10, { allowUnderwater: true });
10469
+ * }
10470
+ * ```
9680
10471
  */
9681
10472
  export interface ExplosionOptions {
9682
10473
  /**
@@ -9798,6 +10589,67 @@ export interface PlayerSoundOptions {
9798
10589
 
9799
10590
  /**
9800
10591
  * Defines a JSON structure that is used for more flexible.
10592
+ * @example addTranslatedSign.ts
10593
+ * ```typescript
10594
+ * import { DimensionLocation, world, BlockPermutation, BlockComponentTypes } from '@minecraft/server';
10595
+ *
10596
+ * function placeTranslatedSign(location: DimensionLocation, text: string) {
10597
+ * const signBlock = location.dimension.getBlock(location);
10598
+ *
10599
+ * if (!signBlock) {
10600
+ * console.warn('Could not find a block at specified location.');
10601
+ * return;
10602
+ * }
10603
+ * const signPerm = BlockPermutation.resolve('minecraft:standing_sign', { ground_sign_direction: 8 });
10604
+ * signBlock.setPermutation(signPerm);
10605
+ *
10606
+ * const signComponent = signBlock.getComponent(BlockComponentTypes.Sign);
10607
+ * if (signComponent) {
10608
+ * signComponent.setText({ translate: 'item.skull.player.name', with: [text] });
10609
+ * } else {
10610
+ * console.error('Could not find a sign component on the block.');
10611
+ * }
10612
+ * }
10613
+ *
10614
+ * placeTranslatedSign(
10615
+ * {
10616
+ * dimension: world.getDimension('overworld'),
10617
+ * x: 0,
10618
+ * y: 0,
10619
+ * z: 0,
10620
+ * },
10621
+ * 'Steve',
10622
+ * );
10623
+ * ```
10624
+ * @example showTranslatedMessageForm.ts
10625
+ * ```typescript
10626
+ * import { world, Player } from '@minecraft/server';
10627
+ * import { MessageFormData, MessageFormResponse } from '@minecraft/server-ui';
10628
+ *
10629
+ * function showMessage(player: Player) {
10630
+ * const messageForm = new MessageFormData()
10631
+ * .title({ translate: 'permissions.removeplayer' })
10632
+ * .body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] })
10633
+ * .button1('Player 1')
10634
+ * .button2('Player 2');
10635
+ *
10636
+ * messageForm
10637
+ * .show(player)
10638
+ * .then((formData: MessageFormResponse) => {
10639
+ * // player canceled the form, or another dialog was up and open.
10640
+ * if (formData.canceled || formData.selection === undefined) {
10641
+ * return;
10642
+ * }
10643
+ *
10644
+ * console.warn(`You selected ${formData.selection === 0 ? 'Player 1' : 'Player 2'}`);
10645
+ * })
10646
+ * .catch((error: Error) => {
10647
+ * console.warn('Failed to show form: ' + error);
10648
+ * });
10649
+ * };
10650
+ *
10651
+ * showMessage(world.getAllPlayers()[0]);
10652
+ * ```
9801
10653
  */
9802
10654
  export interface RawMessage {
9803
10655
  /**
@@ -9949,6 +10801,30 @@ export interface ScriptEventMessageFilterOptions {
9949
10801
 
9950
10802
  /**
9951
10803
  * Contains additional options for teleporting an entity.
10804
+ * @example teleportMovement.ts
10805
+ * ```typescript
10806
+ * import { world, system } from '@minecraft/server';
10807
+ *
10808
+ * const overworld = world.getDimension('overworld');
10809
+ * const targetLocation = { x: 0, y: 0, z: 0 };
10810
+ *
10811
+ * const pig = overworld.spawnEntity('minecraft:pig', targetLocation);
10812
+ *
10813
+ * let inc = 1;
10814
+ * const runId = system.runInterval(() => {
10815
+ * pig.teleport(
10816
+ * { x: targetLocation.x + inc / 4, y: targetLocation.y + inc / 4, z: targetLocation.z + inc / 4 },
10817
+ * {
10818
+ * facingLocation: targetLocation,
10819
+ * },
10820
+ * );
10821
+ *
10822
+ * if (inc > 100) {
10823
+ * system.clearRun(runId);
10824
+ * }
10825
+ * inc++;
10826
+ * }, 4);
10827
+ * ```
9952
10828
  */
9953
10829
  export interface TeleportOptions {
9954
10830
  /**