diff --git a/original/package.json b/original/package.json index a1aed6b..a5eb6ad 100644 --- a/original/package.json +++ b/original/package.json @@ -9,7 +9,7 @@ "@minecraft/server-gametest": "beta", "@minecraft/server-net": "beta", "@minecraft/server-ui": "beta", - "@minecraft/vanilla-data": "1.21.50-preview.20" + "@minecraft/vanilla-data": "preview" }, "overrides": { "@minecraft/debug-utilities": { diff --git a/translate-pieces/examples/BlockConditional.ts b/translate-pieces/examples/BlockConditional.ts index 0ca9a35..5b67e11 100644 --- a/translate-pieces/examples/BlockConditional.ts +++ b/translate-pieces/examples/BlockConditional.ts @@ -1,25 +1,20 @@ -import { Dimension } from '@minecraft/server'; +import { DimensionLocation } from "@minecraft/server"; -// Having this command: +function blockConditional(targetLocation: DimensionLocation) { + targetLocation.dimension + .getEntities({ + type: "fox", + }) + .filter((entity) => { + const block = targetLocation.dimension.getBlock({ + x: entity.location.x, + y: entity.location.y - 1, + z: entity.location.z, + }); -// execute as @e[type=fox] positioned as @s if block ^ ^-1 ^ stone run summon salmon - -// Equivalent scripting code would be: -function spawnFish(dimension: Dimension) { - dimension - .getEntities({ - type: 'fox', - }) - .filter(entity => { - const block = dimension.getBlock({ - x: entity.location.x, - y: entity.location.y - 1, - z: entity.location.z, - }); - - return block !== undefined && block.matches('minecraft:stone'); - }) - .forEach(entity => { - dimension.spawnEntity('salmon', entity.location); - }); + return block !== undefined && block.matches("minecraft:stone"); + }) + .forEach((entity) => { + targetLocation.dimension.spawnEntity("salmon", entity.location); + }); } diff --git a/translate-pieces/examples/EntityPropertyOptions.ts b/translate-pieces/examples/EntityPropertyOptions.ts deleted file mode 100644 index e448401..0000000 --- a/translate-pieces/examples/EntityPropertyOptions.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { world, EntityQueryOptions } from '@minecraft/server'; - -// Having this command: - -// execute as @e[has_property={property=propId}] - -// Equivalent scripting code would be: -function findEntitiesHavingAProperty(propId: string) { - const queryOption: EntityQueryOptions = { - propertyOptions: [{ propertyId: propId }] - }; - - const overworld = world.getDimension('overworld'); - const entities = overworld.getEntities(queryOption); -} - -// Having this command: - -// execute as @e[has_property={propId=propValue}] - -// Equivalent scripting code would be: -function findEntitiesHavingPropertyEqualsTo(propId: string, propValue: boolean | number | string) { - const queryOption: EntityQueryOptions = { - propertyOptions: [{ propertyId: propId, value: { equals: propValue } }] - }; - - const overworld = world.getDimension('overworld'); - const entities = overworld.getEntities(queryOption); -} diff --git a/translate-pieces/examples/PlaySoundChained.ts b/translate-pieces/examples/PlaySoundChained.ts index be4fa5c..0f207f2 100644 --- a/translate-pieces/examples/PlaySoundChained.ts +++ b/translate-pieces/examples/PlaySoundChained.ts @@ -1,22 +1,17 @@ -import { Dimension } from '@minecraft/server'; +import { DimensionLocation } from "@minecraft/server"; -// Having this command: +function playSoundChained(targetLocation: DimensionLocation) { + const targetPlayers = targetLocation.dimension.getPlayers(); + const originEntities = targetLocation.dimension.getEntities({ + type: "armor_stand", + name: "myArmorStand", + tags: ["dummyTag1"], + excludeTags: ["dummyTag2"], + }); -// execute as @e[type=armor_stand,name=myArmorStand,tag=dummyTag1,tag=!dummyTag2] run playsound raid.horn @a - -// Equivalent scripting code would be: -function playSounds(dimension: Dimension) { - const targetPlayers = dimension.getPlayers(); - const originEntities = dimension.getEntities({ - type: 'armor_stand', - name: 'myArmorStand', - tags: ['dummyTag1'], - excludeTags: ['dummyTag2'], - }); - - originEntities.forEach(entity => { - targetPlayers.forEach(player => { - player.playSound('raid.horn'); - }); + originEntities.forEach((entity) => { + targetPlayers.forEach((player) => { + player.playSound("raid.horn"); }); + }); } diff --git a/translate-pieces/examples/SendMessageAllPlayers.ts b/translate-pieces/examples/SendMessageAllPlayers.ts deleted file mode 100644 index c361b6d..0000000 --- a/translate-pieces/examples/SendMessageAllPlayers.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Dimension } from '@minecraft/server'; - -// Having this command: - -// execute as @e[type=armor_stand,name=myArmorStand,tag=dummyTag1,tag=!dummyTag2] run tellraw @a { "rawtext": [{"translate": "hello.world" }] } - -// Equivalent scripting code would be: -function sendMessagesToPlayers(dimension: Dimension) { - const targetPlayers = dimension.getPlayers(); - const originEntities = dimension.getEntities({ - type: 'armor_stand', - name: 'myArmorStand', - tags: ['dummyTag1'], - excludeTags: ['dummyTag2'], - }); - - originEntities.forEach(entity => { - targetPlayers.forEach(player => { - player.sendMessage({ rawtext: [{ translate: 'hello.world' }] }); - }); - }); -} diff --git a/translate-pieces/examples/SetScoreBoardChained.ts b/translate-pieces/examples/SetScoreBoardChained.ts index 732951e..956df16 100644 --- a/translate-pieces/examples/SetScoreBoardChained.ts +++ b/translate-pieces/examples/SetScoreBoardChained.ts @@ -1,21 +1,17 @@ -import { Dimension, world } from '@minecraft/server'; +import { world, DimensionLocation } from "@minecraft/server"; -// Having these commands: - -// scoreboard objectives add scoreObjective1 dummy -// scoreboard players set @e[type=armor_stand,name=myArmorStand] scoreObjective1 -1 - -// Equivalent scripting code would be: -function setScores(dimension: Dimension) { - const objective = world.scoreboard.addObjective('scoreObjective1', 'dummy'); - dimension - .getEntities({ - type: 'armor_stand', - name: 'myArmorStand', - }) - .forEach(entity => { - if (entity.scoreboardIdentity !== undefined) { - objective.setScore(entity.scoreboardIdentity, -1); - } - }); +function setScoreboardChained( + targetLocation: DimensionLocation +) { + const objective = world.scoreboard.addObjective("scoreObjective1", "dummy"); + targetLocation.dimension + .getEntities({ + type: "armor_stand", + name: "myArmorStand", + }) + .forEach((entity) => { + if (entity.scoreboardIdentity !== undefined) { + objective.setScore(entity.scoreboardIdentity, -1); + } + }); } diff --git a/translate-pieces/examples/SummonMobChained.ts b/translate-pieces/examples/SummonMobChained.ts index 3fa3632..bae19b8 100644 --- a/translate-pieces/examples/SummonMobChained.ts +++ b/translate-pieces/examples/SummonMobChained.ts @@ -1,26 +1,21 @@ -import { Dimension } from '@minecraft/server'; +import { DimensionLocation } from "@minecraft/server"; -// Having this command: - -// execute as @e[type=armor_stand] run execute as @a[x=0,y=-60,z=0,c=4,r=15] run summon pig ~1 ~ ~ - -// Equivalent scripting code would be: -function spawnPigs(dimension: Dimension) { - const armorStandArray = dimension.getEntities({ - type: 'armor_stand', - }); - const playerArray = dimension.getPlayers({ - location: { x: 0, y: -60, z: 0 }, - closest: 4, - maxDistance: 15, - }); - armorStandArray.forEach(entity => { - playerArray.forEach(player => { - dimension.spawnEntity('pig', { - x: player.location.x + 1, - y: player.location.y, - z: player.location.z, - }); - }); +function summonMobChained(targetLocation: DimensionLocation) { + const armorStandArray = targetLocation.dimension.getEntities({ + type: "armor_stand", + }); + const playerArray = targetLocation.dimension.getPlayers({ + location: { x: 0, y: -60, z: 0 }, + closest: 4, + maxDistance: 15, + }); + armorStandArray.forEach((entity) => { + playerArray.forEach((player) => { + targetLocation.dimension.spawnEntity("pig", { + x: player.location.x + 1, + y: player.location.y, + z: player.location.z, + }); }); + }); } diff --git a/translate-pieces/examples/actionFormAskFavoriteMonth.ts b/translate-pieces/examples/actionFormAskFavoriteMonth.ts deleted file mode 100644 index bcff6d3..0000000 --- a/translate-pieces/examples/actionFormAskFavoriteMonth.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Player } from '@minecraft/server'; -import { ActionFormData, ActionFormResponse } from '@minecraft/server-ui'; - -function askFavoriteMonth(player: Player) { - const form = new ActionFormData() - .title('Months') - .body('Choose your favorite month!') - .button('January') - .button('February') - .button('March') - .button('April') - .button('May'); - - form.show(player).then((response: ActionFormResponse) => { - if (response.selection === 3) { - player.sendMessage('I like April too!'); - } else { - player.sendMessage('Nah, April is the best.'); - } - }); -} diff --git a/translate-pieces/examples/addBlockColorCube.ts b/translate-pieces/examples/addBlockColorCube.ts index e7b4194..9313e94 100644 --- a/translate-pieces/examples/addBlockColorCube.ts +++ b/translate-pieces/examples/addBlockColorCube.ts @@ -1,7 +1,9 @@ -import { DimensionLocation, BlockPermutation } from '@minecraft/server'; -import { MinecraftBlockTypes } from '@minecraft/vanilla-data'; +import { BlockPermutation, DimensionLocation } from "@minecraft/server"; +import { Vector3Utils } from "@minecraft/math"; +import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; -const allWoolBlocks: string[] = [ +function addBlockColorCube(targetLocation: DimensionLocation) { + const allWoolBlocks: string[] = [ MinecraftBlockTypes.WhiteWool, MinecraftBlockTypes.OrangeWool, MinecraftBlockTypes.MagentaWool, @@ -18,20 +20,20 @@ const allWoolBlocks: string[] = [ MinecraftBlockTypes.GreenWool, MinecraftBlockTypes.RedWool, MinecraftBlockTypes.BlackWool, -]; + ]; -const cubeDim = 7; + const cubeDim = 7; -function placeRainbowCube(location: DimensionLocation) { - let colorIndex = 0; - for (let x = 0; x <= cubeDim; x++) { - for (let y = 0; y <= cubeDim; y++) { - for (let z = 0; z <= cubeDim; z++) { - colorIndex++; - location.dimension - .getBlock({ x: location.x + x, y: location.y + y, z: location.z + z }) - ?.setPermutation(BlockPermutation.resolve(allWoolBlocks[colorIndex % allWoolBlocks.length])); - } - } + let colorIndex = 0; + + for (let x = 0; x <= cubeDim; x++) { + for (let y = 0; y <= cubeDim; y++) { + for (let z = 0; z <= cubeDim; z++) { + colorIndex++; + targetLocation.dimension + .getBlock(Vector3Utils.add(targetLocation, { x, y, z })) + ?.setPermutation(BlockPermutation.resolve(allWoolBlocks[colorIndex % allWoolBlocks.length])); + } } + } } diff --git a/translate-pieces/examples/addSign.ts b/translate-pieces/examples/addSign.ts new file mode 100644 index 0000000..e0687d4 --- /dev/null +++ b/translate-pieces/examples/addSign.ts @@ -0,0 +1,22 @@ +import { world, BlockPermutation, BlockSignComponent, BlockComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; + +function addSign(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const players = world.getPlayers(); + + const dim = players[0].dimension; + + const signBlock = dim.getBlock(targetLocation); + + if (!signBlock) { + log("Could not find a block at specified location."); + return -1; + } + const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 }); + + signBlock.setPermutation(signPerm); + + const signComponent = signBlock.getComponent(BlockComponentTypes.Sign) as BlockSignComponent; + + signComponent?.setText(`Basic sign!\nThis is green on the front.`); +} diff --git a/translate-pieces/examples/addTranslatedSign.604a92ba.ts b/translate-pieces/examples/addTranslatedSign.604a92ba.ts new file mode 100644 index 0000000..1907b54 --- /dev/null +++ b/translate-pieces/examples/addTranslatedSign.604a92ba.ts @@ -0,0 +1,22 @@ +import { world, BlockPermutation, BlockSignComponent, BlockComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; + +function addTranslatedSign(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const players = world.getPlayers(); + + const dim = players[0].dimension; + + const signBlock = dim.getBlock(targetLocation); + + if (!signBlock) { + log("Could not find a block at specified location."); + return -1; + } + const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 }); + + signBlock.setPermutation(signPerm); + + const signComponent = signBlock.getComponent(BlockComponentTypes.Sign) as BlockSignComponent; + + signComponent?.setText({ translate: "item.skull.player.name", with: [players[0].name] }); +} diff --git a/translate-pieces/examples/addTranslatedSign.ts b/translate-pieces/examples/addTranslatedSign.9d3a2d98.ts similarity index 100% rename from translate-pieces/examples/addTranslatedSign.ts rename to translate-pieces/examples/addTranslatedSign.9d3a2d98.ts diff --git a/translate-pieces/examples/addTwoSidedSign.ts b/translate-pieces/examples/addTwoSidedSign.ts index 93dd837..5b64241 100644 --- a/translate-pieces/examples/addTwoSidedSign.ts +++ b/translate-pieces/examples/addTwoSidedSign.ts @@ -1,35 +1,28 @@ -// A function the creates a sign at the specified location with text on both sides and dye colors -import { - DimensionLocation, - BlockPermutation, - BlockSignComponent, - BlockComponentTypes, - DyeColor, - SignSide, -} from '@minecraft/server'; -import { MinecraftBlockTypes } from '@minecraft/vanilla-data'; +import { BlockPermutation, BlockSignComponent, SignSide, DyeColor, BlockComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; -function createSignAt(location: DimensionLocation) { - const block = location.dimension.getBlock(location); - if (!block) { - console.warn('Could not find a block at specified location.'); - return; - } - const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { - ground_sign_direction: 8, - }); - block.setPermutation(signPerm); - const sign = block.getComponent(BlockComponentTypes.Sign); +function addTwoSidedSign(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const signBlock = targetLocation.dimension.getBlock(targetLocation); - if (sign !== undefined) { - sign.setText(`Party Sign!\nThis is green on the front.`); - sign.setText(`Party Sign!\nThis is red on the back.`, SignSide.Back); - sign.setTextDyeColor(DyeColor.Green); - sign.setTextDyeColor(DyeColor.Red, SignSide.Back); + if (!signBlock) { + log("Could not find a block at specified location."); + return -1; + } + const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 }); - // players cannot edit sign! - sign.setWaxed(true); - } else { - console.warn('Could not find a sign component on the block.'); - } + signBlock.setPermutation(signPerm); + + const signComponent = signBlock.getComponent(BlockComponentTypes.Sign) as BlockSignComponent; + + if (signComponent) { + signComponent.setText(`Party Sign!\nThis is green on the front.`); + signComponent.setText(`Party Sign!\nThis is red on the back.`, SignSide.Back); + signComponent.setTextDyeColor(DyeColor.Green); + signComponent.setTextDyeColor(DyeColor.Red, SignSide.Back); + + // players cannot edit sign! + signComponent.setWaxed(true); + } else { + log("Could not find sign component."); + } } diff --git a/translate-pieces/examples/applyDamageThenHeal.ts b/translate-pieces/examples/applyDamageThenHeal.ts index debd008..3cc5f65 100644 --- a/translate-pieces/examples/applyDamageThenHeal.ts +++ b/translate-pieces/examples/applyDamageThenHeal.ts @@ -1,19 +1,18 @@ -// A function that applies damage and then heals the entity -import { Entity, EntityComponentTypes, system, world } from '@minecraft/server'; +import { system, EntityHealthComponent, EntityComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; -function applyDamageAndHeal(entity: Entity) { - entity.applyDamage(19); // Many mobs have max damage of 20 so this is a near-death mob +function applyDamageThenHeal( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + const skelly = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Skeleton, targetLocation); - system.runTimeout(() => { - const health = entity.getComponent(EntityComponentTypes.Health); - if (health) { - world.sendMessage(`Entity health before heal: ${health.currentValue}`); + skelly.applyDamage(19); // skeletons have max damage of 20 so this is a near-death skeleton - health.resetToMaxValue(); - - world.sendMessage(`Entity after before heal: ${health.currentValue}`); - } else { - console.warn('Entity does not have health component'); - } - }, 40); // Run in a few seconds (40 ticks) + system.runTimeout(() => { + const health = skelly.getComponent(EntityComponentTypes.Health) as EntityHealthComponent; + log("Skeleton health before heal: " + health?.currentValue); + health?.resetToMaxValue(); + log("Skeleton health after heal: " + health?.currentValue); + }, 20); } diff --git a/translate-pieces/examples/applyImpulse.ts b/translate-pieces/examples/applyImpulse.ts new file mode 100644 index 0000000..4178a10 --- /dev/null +++ b/translate-pieces/examples/applyImpulse.ts @@ -0,0 +1,11 @@ +import { DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function applyImpulse(targetLocation: DimensionLocation) { + const zombie = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Zombie, targetLocation); + + zombie.clearVelocity(); + + // throw the zombie up in the air + zombie.applyImpulse({ x: 0, y: 0.5, z: 0 }); +} diff --git a/translate-pieces/examples/bounceSkeletons.ts b/translate-pieces/examples/bounceSkeletons.ts index 280e1bf..e5a9f9e 100644 --- a/translate-pieces/examples/bounceSkeletons.ts +++ b/translate-pieces/examples/bounceSkeletons.ts @@ -1,18 +1,18 @@ -import { EntityQueryOptions, DimensionLocation } from '@minecraft/server'; +import { EntityQueryOptions, DimensionLocation } from "@minecraft/server"; -function mobParty(targetLocation: DimensionLocation) { - const mobs = ['creeper', 'skeleton', 'sheep']; +function bounceSkeletons(targetLocation: DimensionLocation) { + const mobs = ["creeper", "skeleton", "sheep"]; - // create some sample mob data - for (let i = 0; i < 10; i++) { - targetLocation.dimension.spawnEntity(mobs[i % mobs.length], targetLocation); - } + // create some sample mob data + for (let i = 0; i < 10; i++) { + targetLocation.dimension.spawnEntity(mobs[i % mobs.length], targetLocation); + } - const eqo: EntityQueryOptions = { - type: 'skeleton', - }; + const eqo: EntityQueryOptions = { + type: "skeleton", + }; - for (const entity of targetLocation.dimension.getEntities(eqo)) { - entity.applyKnockback(0, 0, 0, 1); - } + for (const entity of targetLocation.dimension.getEntities(eqo)) { + entity.applyKnockback(0, 0, 0, 1); + } } diff --git a/translate-pieces/examples/buttonPushEvent.ts b/translate-pieces/examples/buttonPushEvent.ts index 3143bf4..b247b29 100644 --- a/translate-pieces/examples/buttonPushEvent.ts +++ b/translate-pieces/examples/buttonPushEvent.ts @@ -1,9 +1,28 @@ -import { world, ButtonPushAfterEvent, system } from '@minecraft/server'; +import { world, system, BlockPermutation, ButtonPushAfterEvent, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; -world.afterEvents.buttonPush.subscribe((buttonPushEvent: ButtonPushAfterEvent) => { +function buttonPushEvent(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + // set up a button on cobblestone + const cobblestone = targetLocation.dimension.getBlock(targetLocation); + const button = targetLocation.dimension.getBlock({ + x: targetLocation.x, + y: targetLocation.y + 1, + z: targetLocation.z, + }); + + if (cobblestone === undefined || button === undefined) { + log("Could not find block at location."); + return -1; + } + + cobblestone.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.Cobblestone)); + button.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.AcaciaButton).withState("facing_direction", 1)); + + world.afterEvents.buttonPush.subscribe((buttonPushEvent: ButtonPushAfterEvent) => { const eventLoc = buttonPushEvent.block.location; - world.sendMessage( - `Button push event at tick ${system.currentTick} Power:${buttonPushEvent.block.getRedstonePower()}`, - ); -}); + if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y + 1 && eventLoc.z === targetLocation.z) { + log("Button push event at tick " + system.currentTick); + } + }); +} diff --git a/translate-pieces/examples/checkBlockTags.ts b/translate-pieces/examples/checkBlockTags.ts new file mode 100644 index 0000000..3b41aab --- /dev/null +++ b/translate-pieces/examples/checkBlockTags.ts @@ -0,0 +1,13 @@ +import { DimensionLocation } from "@minecraft/server"; + +function checkBlockTags(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + // Fetch the block + const block = targetLocation.dimension.getBlock(targetLocation); + + // check that the block is loaded + if (block) { + log(`Block is dirt: ${block.hasTag("dirt")}`); + log(`Block is wood: ${block.hasTag("wood")}`); + log(`Block is stone: ${block.hasTag("stone")}`); + } +} diff --git a/translate-pieces/examples/checkFeatherNearby.ts b/translate-pieces/examples/checkFeatherNearby.ts deleted file mode 100644 index 6ff9137..0000000 --- a/translate-pieces/examples/checkFeatherNearby.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { DimensionLocation, EntityComponentTypes } from "@minecraft/server"; - -// Returns true if a feather item entity is within 'distance' blocks of 'location'. -function isFeatherNear(location: DimensionLocation, distance: number): boolean { - const items = location.dimension.getEntities({ - location: location, - maxDistance: 20, - }); - - for (const item of items) { - const itemComp = item.getComponent(EntityComponentTypes.Item); - - if (itemComp) { - if (itemComp.itemStack.typeId.endsWith('feather')) { - return true; - } - } - } - - return false; -} diff --git a/translate-pieces/examples/check_block_tags.25c0e459.js b/translate-pieces/examples/check_block_tags.25c0e459.js deleted file mode 100644 index 93e38e1..0000000 --- a/translate-pieces/examples/check_block_tags.25c0e459.js +++ /dev/null @@ -1,9 +0,0 @@ -import { world } from "@minecraft/server"; - -// Fetch the block -const block = world.getDimension("overworld").getBlock({ x: 1, y: 2, z: 3 }); -const blockPerm = block.getPermutation(); - -console.log(`Block is dirt: ${blockPerm.hasTag("dirt")}`); -console.log(`Block is wood: ${blockPerm.hasTag("wood")}`); -console.log(`Block is stone: ${blockPerm.hasTag("stone")}`); diff --git a/translate-pieces/examples/check_block_tags.d8a9d838.js b/translate-pieces/examples/check_block_tags.d8a9d838.js deleted file mode 100644 index 87f201e..0000000 --- a/translate-pieces/examples/check_block_tags.d8a9d838.js +++ /dev/null @@ -1,8 +0,0 @@ -import { world } from "@minecraft/server"; - -// Fetch the block -const block = world.getDimension("overworld").getBlock({ x: 1, y: 2, z: 3 }); - -console.log(`Block is dirt: ${block.hasTag("dirt")}`); -console.log(`Block is wood: ${block.hasTag("wood")}`); -console.log(`Block is stone: ${block.hasTag("stone")}`); diff --git a/translate-pieces/examples/containers.js b/translate-pieces/examples/containers.js deleted file mode 100644 index dae0e2c..0000000 --- a/translate-pieces/examples/containers.js +++ /dev/null @@ -1,45 +0,0 @@ -let leftLocation = test.worldLocation({ x: 2, y: 2, z: 2 }); // left chest location -let rightLocation = test.worldLocation({ x: 4, y: 2, z: 2 }); // right chest location - -const chestCart = test.spawn("chest_minecart", { x: 6, y: 2, z: 2 }); - -let leftChestBlock = defaultDimension.getBlock(leftLocation); -let rightChestBlock = defaultDimension.getBlock(rightLocation); - -leftChestBlock.setType(MinecraftBlockTypes.chest); -rightChestBlock.setType(MinecraftBlockTypes.chest); - -const rightChestInventoryComp = rightChestBlock.getComponent("inventory"); -const leftChestInventoryComp = leftChestBlock.getComponent("inventory"); -const chestCartInventoryComp = chestCart.getComponent("inventory"); - -const rightChestContainer = rightChestInventoryComp.container; -const leftChestContainer = leftChestInventoryComp.container; -const chestCartContainer = chestCartInventoryComp.container; - -rightChestContainer.setItem(0, new ItemStack(Items.apple, 10, 0)); -test.assert(rightChestContainer.getItem(0).id === "apple", "Expected apple in right container slot index 0"); - -rightChestContainer.setItem(1, new ItemStack(Items.emerald, 10, 0)); -test.assert(rightChestContainer.getItem(1).id === "emerald", "Expected emerald in right container slot index 1"); - -test.assert(rightChestContainer.size === 27, "Unexpected size: " + rightChestContainer.size); -test.assert( - rightChestContainer.emptySlotsCount === 25, - "Unexpected emptySlotsCount: " + rightChestContainer.emptySlotsCount -); - -const itemStack = rightChestContainer.getItem(0); -test.assert(itemStack.id === "apple", "Expected apple"); -test.assert(itemStack.amount === 10, "Expected 10 apples"); -test.assert(itemStack.data === 0, "Expected 0 data"); - -leftChestContainer.setItem(0, new ItemStack(Items.cake, 10, 0)); - -rightChestContainer.transferItem(0, 4, chestCartContainer); // transfer the apple from the right chest to a chest cart -rightChestContainer.swapItems(1, 0, leftChestContainer); // swap the cake and emerald - -test.assert(chestCartContainer.getItem(4).id === "apple", "Expected apple in left container slot index 4"); -test.assert(leftChestContainer.getItem(0).id === "emerald", "Expected emerald in left container slot index 0"); -test.assert(rightChestContainer.getItem(1).id === "cake", "Expected cake in right container slot index 1"); - diff --git a/translate-pieces/examples/containers.ts b/translate-pieces/examples/containers.ts new file mode 100644 index 0000000..375e5ad --- /dev/null +++ b/translate-pieces/examples/containers.ts @@ -0,0 +1,72 @@ +import { ItemStack, EntityInventoryComponent, BlockInventoryComponent, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes, MinecraftItemTypes, MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function containers(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const xLocation = targetLocation; // left chest location + const xPlusTwoLocation = { x: targetLocation.x + 2, y: targetLocation.y, z: targetLocation.z }; // right chest + + const chestCart = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.ChestMinecart, { + x: targetLocation.x + 4, + y: targetLocation.y, + z: targetLocation.z, + }); + + const xChestBlock = targetLocation.dimension.getBlock(xLocation); + const xPlusTwoChestBlock = targetLocation.dimension.getBlock(xPlusTwoLocation); + + if (!xChestBlock || !xPlusTwoChestBlock) { + log("Could not retrieve chest blocks."); + return; + } + + xChestBlock.setType(MinecraftBlockTypes.Chest); + xPlusTwoChestBlock.setType(MinecraftBlockTypes.Chest); + + const xPlusTwoChestInventoryComp = xPlusTwoChestBlock.getComponent("inventory") as BlockInventoryComponent; + const xChestInventoryComponent = xChestBlock.getComponent("inventory") as BlockInventoryComponent; + const chestCartInventoryComp = chestCart.getComponent("inventory") as EntityInventoryComponent; + + const xPlusTwoChestContainer = xPlusTwoChestInventoryComp.container; + const xChestContainer = xChestInventoryComponent.container; + const chestCartContainer = chestCartInventoryComp.container; + + if (!xPlusTwoChestContainer || !xChestContainer || !chestCartContainer) { + log("Could not retrieve chest containers."); + return; + } + + xPlusTwoChestContainer.setItem(0, new ItemStack(MinecraftItemTypes.Apple, 10)); + if (xPlusTwoChestContainer.getItem(0)?.typeId !== MinecraftItemTypes.Apple) { + log("Expected apple in x+2 container slot index 0", -1); + } + + xPlusTwoChestContainer.setItem(1, new ItemStack(MinecraftItemTypes.Emerald, 10)); + if (xPlusTwoChestContainer.getItem(1)?.typeId !== MinecraftItemTypes.Emerald) { + log("Expected emerald in x+2 container slot index 1", -1); + } + + if (xPlusTwoChestContainer.size !== 27) { + log("Unexpected size: " + xPlusTwoChestContainer.size, -1); + } + + if (xPlusTwoChestContainer.emptySlotsCount !== 25) { + log("Unexpected emptySlotsCount: " + xPlusTwoChestContainer.emptySlotsCount, -1); + } + + xChestContainer.setItem(0, new ItemStack(MinecraftItemTypes.Cake, 10)); + + xPlusTwoChestContainer.transferItem(0, chestCartContainer); // transfer the apple from the xPlusTwo chest to a chest cart + xPlusTwoChestContainer.swapItems(1, 0, xChestContainer); // swap the cake from x and the emerald from xPlusTwo + + if (chestCartContainer.getItem(0)?.typeId !== MinecraftItemTypes.Apple) { + log("Expected apple in minecraft chest container slot index 0", -1); + } + + if (xChestContainer.getItem(0)?.typeId === MinecraftItemTypes.Emerald) { + log("Expected emerald in x container slot index 0", -1); + } + + if (xPlusTwoChestContainer.getItem(1)?.typeId === MinecraftItemTypes.Cake) { + log("Expected cake in x+2 container slot index 1", -1); + } +} diff --git a/translate-pieces/examples/countdown.ts b/translate-pieces/examples/countdown.ts new file mode 100644 index 0000000..00c5da3 --- /dev/null +++ b/translate-pieces/examples/countdown.ts @@ -0,0 +1,23 @@ +import { world, system, DimensionLocation } from "@minecraft/server"; + +function countdown(targetLocation: DimensionLocation) { + const players = world.getPlayers(); + + players[0].onScreenDisplay.setTitle("Get ready!", { + stayDuration: 220, + fadeInDuration: 2, + fadeOutDuration: 4, + subtitle: "10", + }); + + let countdown = 10; + + const intervalId = system.runInterval(() => { + countdown--; + players[0].onScreenDisplay.updateSubtitle(countdown.toString()); + + if (countdown == 0) { + system.clearRun(intervalId); + } + }, 20); +} diff --git a/translate-pieces/examples/createActionForm.js b/translate-pieces/examples/createActionForm.js deleted file mode 100644 index 52bdbb6..0000000 --- a/translate-pieces/examples/createActionForm.js +++ /dev/null @@ -1,14 +0,0 @@ -const form = new ActionFormData() - .title("Months") - .body("Choose your favorite month!") - .button("January") - .button("February") - .button("March") - .button("April") - .button("May"); - -form.show(players[0]).then((response) => { - if (response.selection === 3) { - dimension.runCommand("say I like April too!"); - } -}); diff --git a/translate-pieces/examples/createExplosion.ts b/translate-pieces/examples/createExplosion.ts new file mode 100644 index 0000000..ec958f5 --- /dev/null +++ b/translate-pieces/examples/createExplosion.ts @@ -0,0 +1,6 @@ +import { DimensionLocation } from "@minecraft/server"; + +function createExplosion(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + log("Creating an explosion of radius 10."); + targetLocation.dimension.createExplosion(targetLocation, 10); +} diff --git a/translate-pieces/examples/createExplosions.ts b/translate-pieces/examples/createExplosions.ts index 79192f2..9e561b8 100644 --- a/translate-pieces/examples/createExplosions.ts +++ b/translate-pieces/examples/createExplosions.ts @@ -1,13 +1,14 @@ -// Creates an explosion of radius 15 that does not break blocks -import { DimensionLocation } from '@minecraft/server'; +import { DimensionLocation } from "@minecraft/server"; +import { Vector3Utils } from "@minecraft/math"; -function createExplosions(location: DimensionLocation) { - // Creates an explosion of radius 15 that does not break blocks - location.dimension.createExplosion(location, 15, { breaksBlocks: false }); +function createExplosions(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const explosionLoc = Vector3Utils.add(targetLocation, { x: 0.5, y: 0.5, z: 0.5 }); - // Creates an explosion of radius 15 that does not cause fire - location.dimension.createExplosion(location, 15, { causesFire: true }); + log("Creating an explosion of radius 15 that causes fire."); + targetLocation.dimension.createExplosion(explosionLoc, 15, { causesFire: true }); - // Creates an explosion of radius 10 that can go underwater - location.dimension.createExplosion(location, 10, { allowUnderwater: true }); + const belowWaterLoc = Vector3Utils.add(targetLocation, { x: 3, y: 1, z: 3 }); + + log("Creating an explosion of radius 10 that can go underwater."); + targetLocation.dimension.createExplosion(belowWaterLoc, 10, { allowUnderwater: true }); } diff --git a/translate-pieces/examples/createNoBlockExplosion.ts b/translate-pieces/examples/createNoBlockExplosion.ts new file mode 100644 index 0000000..122e1bf --- /dev/null +++ b/translate-pieces/examples/createNoBlockExplosion.ts @@ -0,0 +1,12 @@ +import { DimensionLocation } from "@minecraft/server"; +import { Vector3Utils } from "@minecraft/math"; + +function createNoBlockExplosion( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + const explodeNoBlocksLoc = Vector3Utils.floor(Vector3Utils.add(targetLocation, { x: 1, y: 2, z: 1 })); + + log("Creating an explosion of radius 15 that does not break blocks."); + targetLocation.dimension.createExplosion(explodeNoBlocksLoc, 15, { breaksBlocks: false }); +} diff --git a/translate-pieces/examples/createOldHorse.ts b/translate-pieces/examples/createOldHorse.ts deleted file mode 100644 index 0d2c600..0000000 --- a/translate-pieces/examples/createOldHorse.ts +++ /dev/null @@ -1,7 +0,0 @@ -// Spawns an adult horse -import { DimensionLocation } from '@minecraft/server'; - -function spawnAdultHorse(location: DimensionLocation) { - // Create a horse and triggering the 'ageable_grow_up' event, ensuring the horse is created as an adult - location.dimension.spawnEntity('minecraft:horse', location); -} diff --git a/translate-pieces/examples/createTranslatedSign.ts b/translate-pieces/examples/createTranslatedSign.ts deleted file mode 100644 index e493a72..0000000 --- a/translate-pieces/examples/createTranslatedSign.ts +++ /dev/null @@ -1,22 +0,0 @@ -// A function the creates a sign at the specified location with the specified text -import { DimensionLocation, BlockPermutation, BlockComponentTypes } from '@minecraft/server'; -import { MinecraftBlockTypes } from '@minecraft/vanilla-data'; - -function createSignAt(location: DimensionLocation) { - const signBlock = location.dimension.getBlock(location); - - if (!signBlock) { - console.warn('Could not find a block at specified location.'); - return; - } - - const signPerm = BlockPermutation.resolve(MinecraftBlockTypes.StandingSign, { ground_sign_direction: 8 }); - signBlock.setPermutation(signPerm); // Update block to be a sign - - // Update the sign block's text - // with "Steve's Head" - const signComponent = signBlock.getComponent(BlockComponentTypes.Sign); - if (signComponent) { - signComponent.setText({ translate: 'item.skull.player.name', with: ['Steve'] }); - } -} diff --git a/translate-pieces/examples/cubeGenerator.ts b/translate-pieces/examples/cubeGenerator.ts index c883e24..0c77fae 100644 --- a/translate-pieces/examples/cubeGenerator.ts +++ b/translate-pieces/examples/cubeGenerator.ts @@ -1,27 +1,21 @@ -import { BlockPermutation, DimensionLocation, world, ButtonPushAfterEvent, system } from '@minecraft/server'; +import { system, BlockPermutation, DimensionLocation } from "@minecraft/server"; -// A simple generator that places blocks in a cube at a specific location -// with a specific size, yielding after every block place. -function* blockPlacingGenerator(blockPerm: BlockPermutation, startingLocation: DimensionLocation, size: number) { - for (let x = startingLocation.x; x < startingLocation.x + size; x++) { - for (let y = startingLocation.y; y < startingLocation.y + size; y++) { - for (let z = startingLocation.z; z < startingLocation.z + size; z++) { - const block = startingLocation.dimension.getBlock({ x: x, y: y, z: z }); - if (block) { - block.setPermutation(blockPerm); - } - yield; - } - } - } +function cubeGenerator(targetLocation: DimensionLocation) { + const blockPerm = BlockPermutation.resolve("minecraft:cobblestone"); + + system.runJob(blockPlacingGenerator(blockPerm, targetLocation, 15)); } -// When a button is pushed, we will place a 15x15x15 cube of cobblestone 10 blocks above it -world.afterEvents.buttonPush.subscribe((buttonPushEvent: ButtonPushAfterEvent) => { - const cubePos = buttonPushEvent.block.location; - cubePos.y += 10; - - const blockPerm = BlockPermutation.resolve('minecraft:cobblestone'); - - system.runJob(blockPlacingGenerator(blockPerm, { dimension: buttonPushEvent.dimension, ...cubePos }, 15)); -}); +function* blockPlacingGenerator(blockPerm: BlockPermutation, startingLocation: DimensionLocation, size: number) { + for (let x = startingLocation.x; x < startingLocation.x + size; x++) { + for (let y = startingLocation.y; y < startingLocation.y + size; y++) { + for (let z = startingLocation.z; z < startingLocation.z + size; z++) { + const block = startingLocation.dimension.getBlock({ x: x, y: y, z: z }); + if (block) { + block.setPermutation(blockPerm); + } + yield; + } + } + } +} diff --git a/translate-pieces/examples/customCommand.ts b/translate-pieces/examples/customCommand.ts new file mode 100644 index 0000000..bef9e90 --- /dev/null +++ b/translate-pieces/examples/customCommand.ts @@ -0,0 +1,24 @@ +import { world, DimensionLocation } from "@minecraft/server"; + +function customCommand(targetLocation: DimensionLocation) { + const chatCallback = world.beforeEvents.chatSend.subscribe((eventData) => { + if (eventData.message.includes("cancel")) { + // Cancel event if the message contains "cancel" + eventData.cancel = true; + } else { + const args = eventData.message.split(" "); + + if (args.length > 0) { + switch (args[0].toLowerCase()) { + case "echo": + // Send a modified version of chat message + world.sendMessage(`Echo '${eventData.message.substring(4).trim()}'`); + break; + case "help": + world.sendMessage(`Available commands: echo `); + break; + } + } + } + }); +} diff --git a/translate-pieces/examples/custom_command.js b/translate-pieces/examples/custom_command.js deleted file mode 100644 index 0b06d05..0000000 --- a/translate-pieces/examples/custom_command.js +++ /dev/null @@ -1,9 +0,0 @@ -const chatCallback = World.beforeEvents.chatSend.subscribe((eventData) => { - if (eventData.message.includes("cancel")) { - // Cancel event if the message contains "cancel" - eventData.canceled = true; - } else { - // Modify chat message being sent - eventData.message = `Modified '${eventData.message}'`; - } -}); diff --git a/translate-pieces/examples/durability.ts b/translate-pieces/examples/durability.ts deleted file mode 100644 index 934f90a..0000000 --- a/translate-pieces/examples/durability.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Gives a player a half-damaged diamond sword -import { ItemStack, Player, ItemComponentTypes, EntityComponentTypes } from '@minecraft/server'; -import { MinecraftItemTypes } from '@minecraft/vanilla-data'; - -function giveHurtDiamondSword(player: Player) { - const hurtDiamondSword = new ItemStack(MinecraftItemTypes.DiamondSword); - const durabilityComponent = hurtDiamondSword.getComponent(ItemComponentTypes.Durability); - if (durabilityComponent !== undefined) { - durabilityComponent.damage = durabilityComponent.maxDurability / 2; - } - - const inventory = player.getComponent(EntityComponentTypes.Inventory); - if (inventory === undefined || inventory.container === undefined) { - return; - } - - inventory.container.addItem(hurtDiamondSword); -} diff --git a/translate-pieces/examples/every30Seconds.ts b/translate-pieces/examples/every30Seconds.ts index c4f613c..a10d486 100644 --- a/translate-pieces/examples/every30Seconds.ts +++ b/translate-pieces/examples/every30Seconds.ts @@ -1,7 +1,9 @@ -import { system, world } from '@minecraft/server'; +import { world, system, DimensionLocation } from "@minecraft/server"; -const intervalRunIdentifier = Math.floor(Math.random() * 10000); +function every30Seconds(targetLocation: DimensionLocation) { + const intervalRunIdentifier = Math.floor(Math.random() * 10000); -system.runInterval(() => { - world.sendMessage('This is an interval run ' + intervalRunIdentifier + ' sending a message every 30 seconds.'); -}, 600); + system.runInterval(() => { + world.sendMessage("This is an interval run " + intervalRunIdentifier + " sending a message every 30 seconds."); + }, 600); +} diff --git a/translate-pieces/examples/findEntitiesHavingPropertyEqualsTo.ts b/translate-pieces/examples/findEntitiesHavingPropertyEqualsTo.ts new file mode 100644 index 0000000..8e71588 --- /dev/null +++ b/translate-pieces/examples/findEntitiesHavingPropertyEqualsTo.ts @@ -0,0 +1,12 @@ +import { EntityQueryOptions, DimensionLocation } from "@minecraft/server"; + +function findEntitiesHavingPropertyEqualsTo( + targetLocation: DimensionLocation +) { + // Minecraft bees have a has_nectar boolean property + const queryOption: EntityQueryOptions = { + propertyOptions: [{ propertyId: "minecraft:has_nectar", value: { equals: true } }], + }; + + const entities = targetLocation.dimension.getEntities(queryOption); +} diff --git a/translate-pieces/examples/findFeathers.js b/translate-pieces/examples/findFeathers.js deleted file mode 100644 index 8c67216..0000000 --- a/translate-pieces/examples/findFeathers.js +++ /dev/null @@ -1 +0,0 @@ -test.assertItemEntityCountIs(Items.feather, expectedFeatherLoc, 0, 1); diff --git a/translate-pieces/examples/getFireworkVelocity.ts b/translate-pieces/examples/getFireworkVelocity.ts index b129838..a9eb806 100644 --- a/translate-pieces/examples/getFireworkVelocity.ts +++ b/translate-pieces/examples/getFireworkVelocity.ts @@ -1,13 +1,15 @@ -// A function that spawns fireworks and logs their velocity after 5 ticks -import { DimensionLocation, system, world } from '@minecraft/server'; -import { MinecraftEntityTypes } from '@minecraft/vanilla-data'; +import { system, DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; -function spawnFireworks(location: DimensionLocation) { - const fireworkRocket = location.dimension.spawnEntity(MinecraftEntityTypes.FireworksRocket, location); +function getFireworkVelocity( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + const fireworkRocket = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.FireworksRocket, targetLocation); - system.runTimeout(() => { - const velocity = fireworkRocket.getVelocity(); + system.runTimeout(() => { + const velocity = fireworkRocket.getVelocity(); - world.sendMessage(`Velocity of firework is: ${velocity.x}, ${velocity.y}, ${velocity.z}`); - }, 5); + log("Velocity of firework is: (x: " + velocity.x + ", y:" + velocity.y + ", z:" + velocity.z + ")"); + }, 5); } diff --git a/translate-pieces/examples/getFirstHotbarItem.ts b/translate-pieces/examples/getFirstHotbarItem.ts new file mode 100644 index 0000000..7363826 --- /dev/null +++ b/translate-pieces/examples/getFirstHotbarItem.ts @@ -0,0 +1,17 @@ +import { world, EntityInventoryComponent, DimensionLocation } from "@minecraft/server"; + +function getFirstHotbarItem(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + for (const player of world.getAllPlayers()) { + const inventory = player.getComponent(EntityInventoryComponent.componentId) as EntityInventoryComponent; + if (inventory && inventory.container) { + const firstItem = inventory.container.getItem(0); + + if (firstItem) { + log("First item in hotbar is: " + firstItem.typeId); + } + + return inventory.container.getItem(0); + } + return undefined; + } +} diff --git a/translate-pieces/examples/getItem.ts b/translate-pieces/examples/getItem.ts deleted file mode 100644 index 21aaab5..0000000 --- a/translate-pieces/examples/getItem.ts +++ /dev/null @@ -1,10 +0,0 @@ -// A function that gets a copy of the first item in the player's hotbar -import { Player, EntityInventoryComponent, ItemStack } from '@minecraft/server'; - -function getFirstHotbarItem(player: Player): ItemStack | undefined { - const inventory = player.getComponent(EntityInventoryComponent.componentId); - if (inventory && inventory.container) { - return inventory.container.getItem(0); - } - return undefined; -} diff --git a/translate-pieces/examples/giveDestroyRestrictedPickaxe.ts b/translate-pieces/examples/giveDestroyRestrictedPickaxe.ts new file mode 100644 index 0000000..f11ecc5 --- /dev/null +++ b/translate-pieces/examples/giveDestroyRestrictedPickaxe.ts @@ -0,0 +1,18 @@ +import { world, ItemStack, EntityInventoryComponent, DimensionLocation } from "@minecraft/server"; +import { MinecraftItemTypes } from "@minecraft/vanilla-data"; + +function giveDestroyRestrictedPickaxe( + targetLocation: DimensionLocation +) { + for (const player of world.getAllPlayers()) { + const specialPickaxe = new ItemStack(MinecraftItemTypes.DiamondPickaxe); + specialPickaxe.setCanDestroy([MinecraftItemTypes.Cobblestone, MinecraftItemTypes.Obsidian]); + + const inventory = player.getComponent("inventory") as EntityInventoryComponent; + if (inventory === undefined || inventory.container === undefined) { + return; + } + + inventory.container.addItem(specialPickaxe); + } +} diff --git a/translate-pieces/examples/giveHurtDiamondSword.ts b/translate-pieces/examples/giveHurtDiamondSword.ts new file mode 100644 index 0000000..cc0b346 --- /dev/null +++ b/translate-pieces/examples/giveHurtDiamondSword.ts @@ -0,0 +1,21 @@ +import { world, ItemStack, EntityInventoryComponent, EntityComponentTypes, ItemComponentTypes, ItemDurabilityComponent, DimensionLocation } from "@minecraft/server"; +import { MinecraftItemTypes } from "@minecraft/vanilla-data"; + +function giveHurtDiamondSword( + targetLocation: DimensionLocation +) { + const hurtDiamondSword = new ItemStack(MinecraftItemTypes.DiamondSword); + + const durabilityComponent = hurtDiamondSword.getComponent(ItemComponentTypes.Durability) as ItemDurabilityComponent; + + if (durabilityComponent !== undefined) { + durabilityComponent.damage = durabilityComponent.maxDurability / 2; + } + + for (const player of world.getAllPlayers()) { + const inventory = player.getComponent(EntityComponentTypes.Inventory) as EntityInventoryComponent; + if (inventory && inventory.container) { + inventory.container.addItem(hurtDiamondSword); + } + } +} diff --git a/translate-pieces/examples/givePlaceRestrictedGoldBlock.ts b/translate-pieces/examples/givePlaceRestrictedGoldBlock.ts new file mode 100644 index 0000000..30e491f --- /dev/null +++ b/translate-pieces/examples/givePlaceRestrictedGoldBlock.ts @@ -0,0 +1,18 @@ +import { world, ItemStack, EntityInventoryComponent, EntityComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftItemTypes } from "@minecraft/vanilla-data"; + +function givePlaceRestrictedGoldBlock( + targetLocation: DimensionLocation +) { + for (const player of world.getAllPlayers()) { + const specialGoldBlock = new ItemStack(MinecraftItemTypes.GoldBlock); + specialGoldBlock.setCanPlaceOn([MinecraftItemTypes.GrassBlock, MinecraftItemTypes.Dirt]); + + const inventory = player.getComponent(EntityComponentTypes.Inventory) as EntityInventoryComponent; + if (inventory === undefined || inventory.container === undefined) { + return; + } + + inventory.container.addItem(specialGoldBlock); + } +} diff --git a/translate-pieces/examples/givePlayerEquipment.ts b/translate-pieces/examples/givePlayerEquipment.ts index 99290e9..6ea49c4 100644 --- a/translate-pieces/examples/givePlayerEquipment.ts +++ b/translate-pieces/examples/givePlayerEquipment.ts @@ -1,17 +1,31 @@ -// Gives the player some equipment -import { EquipmentSlot, ItemStack, Player, EntityComponentTypes } from '@minecraft/server'; -import { MinecraftItemTypes } from '@minecraft/vanilla-data'; +import { world, ItemStack, EntityEquippableComponent, EquipmentSlot, EntityComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftItemTypes } from "@minecraft/vanilla-data"; -function giveEquipment(player: Player) { - const equipmentCompPlayer = player.getComponent(EntityComponentTypes.Equippable); - if (equipmentCompPlayer) { - equipmentCompPlayer.setEquipment(EquipmentSlot.Head, new ItemStack(MinecraftItemTypes.GoldenHelmet)); - equipmentCompPlayer.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.IronChestplate)); - equipmentCompPlayer.setEquipment(EquipmentSlot.Legs, new ItemStack(MinecraftItemTypes.DiamondLeggings)); - equipmentCompPlayer.setEquipment(EquipmentSlot.Feet, new ItemStack(MinecraftItemTypes.NetheriteBoots)); - equipmentCompPlayer.setEquipment(EquipmentSlot.Mainhand, new ItemStack(MinecraftItemTypes.WoodenSword)); - equipmentCompPlayer.setEquipment(EquipmentSlot.Offhand, new ItemStack(MinecraftItemTypes.Shield)); - } else { - console.warn('No equipment component found on player'); - } +function givePlayerEquipment( + targetLocation: DimensionLocation +) { + const players = world.getAllPlayers(); + + const armorStandLoc = { x: targetLocation.x, y: targetLocation.y, z: targetLocation.z + 4 }; + const armorStand = players[0].dimension.spawnEntity(MinecraftItemTypes.ArmorStand, armorStandLoc); + + const equipmentCompPlayer = players[0].getComponent(EntityComponentTypes.Equippable) as EntityEquippableComponent; + if (equipmentCompPlayer) { + equipmentCompPlayer.setEquipment(EquipmentSlot.Head, new ItemStack(MinecraftItemTypes.GoldenHelmet)); + equipmentCompPlayer.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.IronChestplate)); + equipmentCompPlayer.setEquipment(EquipmentSlot.Legs, new ItemStack(MinecraftItemTypes.DiamondLeggings)); + equipmentCompPlayer.setEquipment(EquipmentSlot.Feet, new ItemStack(MinecraftItemTypes.NetheriteBoots)); + equipmentCompPlayer.setEquipment(EquipmentSlot.Mainhand, new ItemStack(MinecraftItemTypes.WoodenSword)); + equipmentCompPlayer.setEquipment(EquipmentSlot.Offhand, new ItemStack(MinecraftItemTypes.Shield)); + } + + const equipmentCompArmorStand = armorStand.getComponent(EntityComponentTypes.Equippable) as EntityEquippableComponent; + if (equipmentCompArmorStand) { + equipmentCompArmorStand.setEquipment(EquipmentSlot.Head, new ItemStack(MinecraftItemTypes.GoldenHelmet)); + equipmentCompArmorStand.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.IronChestplate)); + equipmentCompArmorStand.setEquipment(EquipmentSlot.Legs, new ItemStack(MinecraftItemTypes.DiamondLeggings)); + equipmentCompArmorStand.setEquipment(EquipmentSlot.Feet, new ItemStack(MinecraftItemTypes.NetheriteBoots)); + equipmentCompArmorStand.setEquipment(EquipmentSlot.Mainhand, new ItemStack(MinecraftItemTypes.WoodenSword)); + equipmentCompArmorStand.setEquipment(EquipmentSlot.Offhand, new ItemStack(MinecraftItemTypes.Shield)); + } } diff --git a/translate-pieces/examples/givePlayerIronFireSword.ts b/translate-pieces/examples/givePlayerIronFireSword.ts deleted file mode 100644 index 4129783..0000000 --- a/translate-pieces/examples/givePlayerIronFireSword.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Spawns a bunch of item stacks -import { EnchantmentType, ItemComponentTypes, ItemStack, Player } from '@minecraft/server'; -import { MinecraftItemTypes, MinecraftEnchantmentTypes } from '@minecraft/vanilla-data'; - -function giveFireSword(player: Player) { - const ironFireSword = new ItemStack(MinecraftItemTypes.DiamondSword, 1); - - const enchantments = ironFireSword?.getComponent(ItemComponentTypes.Enchantable); - if (enchantments) { - enchantments.addEnchantment({ type: new EnchantmentType(MinecraftEnchantmentTypes.FireAspect), level: 1 }); - } - - const inventory = player.getComponent('minecraft:inventory'); - if (inventory === undefined || inventory.container === undefined) { - return; - } - inventory.container.setItem(0, ironFireSword); -} diff --git a/translate-pieces/examples/giveRestrictedGoldBlock.ts b/translate-pieces/examples/giveRestrictedGoldBlock.ts deleted file mode 100644 index da1ee2d..0000000 --- a/translate-pieces/examples/giveRestrictedGoldBlock.ts +++ /dev/null @@ -1,15 +0,0 @@ -// Creates a gold block that can be placed on grass and dirt -import { ItemStack, Player, EntityComponentTypes } from '@minecraft/server'; -import { MinecraftItemTypes } from '@minecraft/vanilla-data'; - -function giveRestrictedGoldBlock(player: Player) { - const specialGoldBlock = new ItemStack(MinecraftItemTypes.GoldBlock); - specialGoldBlock.setCanPlaceOn([MinecraftItemTypes.Grass, MinecraftItemTypes.Dirt]); - - const inventory = player.getComponent(EntityComponentTypes.Inventory); - if (inventory === undefined || inventory.container === undefined) { - return; - } - - inventory.container.addItem(specialGoldBlock); -} diff --git a/translate-pieces/examples/giveRestrictedPickaxe.ts b/translate-pieces/examples/giveRestrictedPickaxe.ts deleted file mode 100644 index 8d2a428..0000000 --- a/translate-pieces/examples/giveRestrictedPickaxe.ts +++ /dev/null @@ -1,18 +0,0 @@ -const specialPickaxe = new ItemStack('minecraft:diamond_pickaxe'); -specialPickaxe.setCanDestroy(['minecraft:cobblestone', 'minecraft:obsidian']); - -// Creates a diamond pickaxe that can destroy cobblestone and obsidian -import { ItemStack, Player } from '@minecraft/server'; -import { MinecraftItemTypes } from '@minecraft/vanilla-data'; - -function giveRestrictedPickaxe(player: Player) { - const specialPickaxe = new ItemStack(MinecraftItemTypes.DiamondPickaxe); - specialPickaxe.setCanPlaceOn([MinecraftItemTypes.Cobblestone, MinecraftItemTypes.Obsidian]); - - const inventory = player.getComponent('inventory'); - if (inventory === undefined || inventory.container === undefined) { - return; - } - - inventory.container.addItem(specialPickaxe); -} diff --git a/translate-pieces/examples/horseArmorTest.js b/translate-pieces/examples/horseArmorTest.js deleted file mode 100644 index 98d0d52..0000000 --- a/translate-pieces/examples/horseArmorTest.js +++ /dev/null @@ -1 +0,0 @@ -test.assertEntityHasArmor("minecraft:horse", armorSlotTorso, "diamond_horse_armor", 0, horseLocation, true); diff --git a/translate-pieces/examples/incrementDynamicProperty.ts b/translate-pieces/examples/incrementDynamicProperty.ts index ac867a8..ecdcea4 100644 --- a/translate-pieces/examples/incrementDynamicProperty.ts +++ b/translate-pieces/examples/incrementDynamicProperty.ts @@ -1,21 +1,21 @@ -import * as mc from '@minecraft/server'; +import { world, DimensionLocation } from "@minecraft/server"; -function incrementProperty(propertyName: string): boolean { - let number = mc.world.getDynamicProperty(propertyName); +function incrementDynamicProperty( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + let number = world.getDynamicProperty("samplelibrary:number"); - console.warn('Current value is: ' + number); + log("Current value is: " + number); - if (number === undefined) { - number = 0; - } + if (number === undefined) { + number = 0; + } - if (typeof number !== 'number') { - console.warn('Number is of an unexpected type.'); - return false; - } + if (typeof number !== "number") { + log("Number is of an unexpected type."); + return -1; + } - mc.world.setDynamicProperty(propertyName, number + 1); - return true; + world.setDynamicProperty("samplelibrary:number", number + 1); } - -incrementProperty('samplelibrary:number'); diff --git a/translate-pieces/examples/incrementDynamicPropertyInJsonBlob.ts b/translate-pieces/examples/incrementDynamicPropertyInJsonBlob.ts index 3c26cc6..8353a97 100644 --- a/translate-pieces/examples/incrementDynamicPropertyInJsonBlob.ts +++ b/translate-pieces/examples/incrementDynamicPropertyInJsonBlob.ts @@ -1,40 +1,39 @@ -import * as mc from '@minecraft/server'; +import { world, DimensionLocation } from "@minecraft/server"; -function updateWorldProperty(propertyName: string): boolean { - let paintStr = mc.world.getDynamicProperty(propertyName); - let paint: { color: string; intensity: number } | undefined = undefined; +function incrementDynamicPropertyInJsonBlob( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + let paintStr = world.getDynamicProperty("samplelibrary:longerjson"); + let paint: { color: string; intensity: number } | undefined = undefined; - console.log('Current value is: ' + paintStr); + log("Current value is: " + paintStr); - if (paintStr === undefined) { - paint = { - color: 'purple', - intensity: 0, - }; - } else { - if (typeof paintStr !== 'string') { - console.warn('Paint is of an unexpected type.'); - return false; - } - - try { - paint = JSON.parse(paintStr); - } catch (e) { - console.warn('Error parsing serialized struct.'); - return false; - } + if (paintStr === undefined) { + paint = { + color: "purple", + intensity: 0, + }; + } else { + if (typeof paintStr !== "string") { + log("Paint is of an unexpected type."); + return -1; } - if (!paint) { - console.warn('Error parsing serialized struct.'); - return false; + try { + paint = JSON.parse(paintStr); + } catch (e) { + log("Error parsing serialized struct."); + return -1; } + } - paint.intensity++; - paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits - mc.world.setDynamicProperty(propertyName, paintStr); + if (!paint) { + log("Error parsing serialized struct."); + return -1; + } - return true; + paint.intensity++; + paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits + world.setDynamicProperty("samplelibrary:longerjson", paintStr); } - -updateWorldProperty('samplelibrary:longerjson'); diff --git a/translate-pieces/examples/itemStacks.ts b/translate-pieces/examples/itemStacks.ts new file mode 100644 index 0000000..c15f569 --- /dev/null +++ b/translate-pieces/examples/itemStacks.ts @@ -0,0 +1,21 @@ +import { ItemStack, DimensionLocation } from "@minecraft/server"; +import { MinecraftItemTypes } from "@minecraft/vanilla-data"; + +function itemStacks(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const oneItemLoc = { x: targetLocation.x + targetLocation.y + 3, y: 2, z: targetLocation.z + 1 }; + const fiveItemsLoc = { x: targetLocation.x + 1, y: targetLocation.y + 2, z: targetLocation.z + 1 }; + const diamondPickaxeLoc = { x: targetLocation.x + 2, y: targetLocation.y + 2, z: targetLocation.z + 4 }; + + const oneEmerald = new ItemStack(MinecraftItemTypes.Emerald, 1); + const onePickaxe = new ItemStack(MinecraftItemTypes.DiamondPickaxe, 1); + const fiveEmeralds = new ItemStack(MinecraftItemTypes.Emerald, 5); + + log(`Spawning an emerald at (${oneItemLoc.x}, ${oneItemLoc.y}, ${oneItemLoc.z})`); + targetLocation.dimension.spawnItem(oneEmerald, oneItemLoc); + + log(`Spawning five emeralds at (${fiveItemsLoc.x}, ${fiveItemsLoc.y}, ${fiveItemsLoc.z})`); + targetLocation.dimension.spawnItem(fiveEmeralds, fiveItemsLoc); + + log(`Spawning a diamond pickaxe at (${diamondPickaxeLoc.x}, ${diamondPickaxeLoc.y}, ${diamondPickaxeLoc.z})`); + targetLocation.dimension.spawnItem(onePickaxe, diamondPickaxeLoc); +} diff --git a/translate-pieces/examples/leverActionEvent.ts b/translate-pieces/examples/leverActionEvent.ts index 4c12050..f9fd075 100644 --- a/translate-pieces/examples/leverActionEvent.ts +++ b/translate-pieces/examples/leverActionEvent.ts @@ -1,8 +1,30 @@ -import { world, system, LeverActionAfterEvent } from '@minecraft/server'; +import { world, system, BlockPermutation, LeverActionAfterEvent, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; -world.afterEvents.leverAction.subscribe((leverActivateEvent: LeverActionAfterEvent) => { - console.warn( - `Lever event at ${system.currentTick} with power: ${leverActivateEvent.block.getRedstonePower()}`, - ); -}); +function leverActionEvent(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + // set up a lever + const cobblestone = targetLocation.dimension.getBlock(targetLocation); + const lever = targetLocation.dimension.getBlock({ + x: targetLocation.x, + y: targetLocation.y + 1, + z: targetLocation.z, + }); + if (cobblestone === undefined || lever === undefined) { + log("Could not find block at location."); + return -1; + } + + cobblestone.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.Cobblestone)); + lever.setPermutation( + BlockPermutation.resolve(MinecraftBlockTypes.Lever).withState("lever_direction", "up_north_south") + ); + + world.afterEvents.leverAction.subscribe((leverActionEvent: LeverActionAfterEvent) => { + const eventLoc = leverActionEvent.block.location; + + if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y + 1 && eventLoc.z === targetLocation.z) { + log("Lever activate event at tick " + system.currentTick); + } + }); +} diff --git a/translate-pieces/examples/logEntitySpawnEvent.ts b/translate-pieces/examples/logEntitySpawnEvent.ts new file mode 100644 index 0000000..e882c0c --- /dev/null +++ b/translate-pieces/examples/logEntitySpawnEvent.ts @@ -0,0 +1,23 @@ +import { world, system, EntitySpawnAfterEvent, DimensionLocation } from "@minecraft/server"; +import { Vector3Utils } from "@minecraft/math"; + +function logEntitySpawnEvent( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + // register a new function that is called when a new entity is created. + world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => { + if (entityEvent && entityEvent.entity) { + log(`New entity of type ${entityEvent.entity.typeId} created!`, 1); + } else { + log(`The entity event did not work as expected.`, -1); + } + }); + + system.runTimeout(() => { + targetLocation.dimension.spawnEntity( + "minecraft:horse", + Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 }) + ); + }, 20); +} diff --git a/translate-pieces/examples/logEntitySpawnEvents.ts b/translate-pieces/examples/logEntitySpawnEvents.ts deleted file mode 100644 index 6da578e..0000000 --- a/translate-pieces/examples/logEntitySpawnEvents.ts +++ /dev/null @@ -1,9 +0,0 @@ -// Register a new function that is called when a new entity is created. -import { world, EntitySpawnAfterEvent } from '@minecraft/server'; - -world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => { - const spawnLocation = entityEvent.entity.location; - world.sendMessage( - `New entity of type '${entityEvent.entity.typeId}' spawned at ${spawnLocation.x}, ${spawnLocation.y}, ${spawnLocation.z}!`, - ); -}); diff --git a/translate-pieces/examples/messageFormSimple.ts b/translate-pieces/examples/messageFormSimple.ts deleted file mode 100644 index b01d053..0000000 --- a/translate-pieces/examples/messageFormSimple.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Player } from '@minecraft/server'; -import { MessageFormResponse, MessageFormData } from '@minecraft/server-ui'; - -function showMessage(player: Player) { - const messageForm = new MessageFormData() - .title({ translate: 'permissions.removeplayer' }) // "Remove player" - .body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] }) // "Player 1 or Player 2" - .button1('Player 1') - .button2('Player 2'); - - messageForm - .show(player) - .then((formData: MessageFormResponse) => { - // player canceled the form, or another dialog was up and open. - if (formData.canceled || formData.selection === undefined) { - return; - } - - player.sendMessage(`You selected ${formData.selection === 0 ? 'Player 1' : 'Player 2'}`); - }) - .catch((error: Error) => { - player.sendMessage('Failed to show form: ' + error); - }); -} diff --git a/translate-pieces/examples/minibiomes.ts b/translate-pieces/examples/minibiomes.ts new file mode 100644 index 0000000..42b79e5 --- /dev/null +++ b/translate-pieces/examples/minibiomes.ts @@ -0,0 +1,17 @@ +import { EntityComponentTypes } from "@minecraft/server"; +import { Test, register } from "@minecraft/server-gametest"; +import { MinecraftBlockTypes, MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function minibiomes(test: Test) { + const minecart = test.spawn(MinecraftEntityTypes.Minecart, { x: 9, y: 7, z: 7 }); + const pig = test.spawn(MinecraftEntityTypes.Pig, { x: 9, y: 7, z: 7 }); + + test.setBlockType(MinecraftBlockTypes.Cobblestone, { x: 10, y: 7, z: 7 }); + + const minecartRideableComp = minecart.getComponent(EntityComponentTypes.Rideable); + + minecartRideableComp?.addRider(pig); + + test.succeedWhenEntityPresent(MinecraftEntityTypes.Pig, { x: 8, y: 3, z: 1 }, true); +} +register("ChallengeTests", "minibiomes", minibiomes).structureName("gametests:minibiomes").maxTicks(160); diff --git a/translate-pieces/examples/modalFormSimple.ts b/translate-pieces/examples/modalFormSimple.ts deleted file mode 100644 index 361821b..0000000 --- a/translate-pieces/examples/modalFormSimple.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Player } from '@minecraft/server'; -import { ModalFormData } from '@minecraft/server-ui'; - -function showExampleModal(player: Player) { - const modalForm = new ModalFormData().title('Example Modal Controls for §o§7ModalFormData§r'); - - modalForm.toggle('Toggle w/o default'); - modalForm.toggle('Toggle w/ default', true); - - modalForm.slider('Slider w/o default', 0, 50, 5); - modalForm.slider('Slider w/ default', 0, 50, 5, 30); - - modalForm.dropdown('Dropdown w/o default', ['option 1', 'option 2', 'option 3']); - modalForm.dropdown('Dropdown w/ default', ['option 1', 'option 2', 'option 3'], 2); - - modalForm.textField('Input w/o default', 'type text here'); - modalForm.textField('Input w/ default', 'type text here', 'this is default'); - - modalForm - .show(player) - .then(formData => { - player.sendMessage(`Modal form results: ${JSON.stringify(formData.formValues, undefined, 2)}`); - }) - .catch((error: Error) => { - player.sendMessage('Failed to show form: ' + error); - return -1; - }); -} diff --git a/translate-pieces/examples/moveBetweenContainers.ts b/translate-pieces/examples/moveBetweenContainers.ts new file mode 100644 index 0000000..2bce0f9 --- /dev/null +++ b/translate-pieces/examples/moveBetweenContainers.ts @@ -0,0 +1,25 @@ +import { world, EntityInventoryComponent, EntityComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function moveBetweenContainers( + targetLocation: DimensionLocation +) { + const players = world.getAllPlayers(); + + const chestCart = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.ChestMinecart, { + x: targetLocation.x + 1, + y: targetLocation.y, + z: targetLocation.z, + }); + + if (players.length > 0) { + const fromPlayer = players[0]; + + const fromInventory = fromPlayer.getComponent(EntityComponentTypes.Inventory) as EntityInventoryComponent; + const toInventory = chestCart.getComponent(EntityComponentTypes.Inventory) as EntityInventoryComponent; + + if (fromInventory && toInventory && fromInventory.container && toInventory.container) { + fromInventory.container.moveItem(0, 0, toInventory.container); + } + } +} diff --git a/translate-pieces/examples/moveItem.ts b/translate-pieces/examples/moveItem.ts deleted file mode 100644 index 4dd21a9..0000000 --- a/translate-pieces/examples/moveItem.ts +++ /dev/null @@ -1,11 +0,0 @@ -// A function that moves an item from one slot of the player's inventory to another player's inventory -import { Player, EntityComponentTypes } from '@minecraft/server'; - -function moveBetweenPlayers(slotId: number, fromPlayer: Player, toPlayer: Player) { - const fromInventory = fromPlayer.getComponent(EntityComponentTypes.Inventory); - const toInventory = toPlayer.getComponent(EntityComponentTypes.Inventory); - - if (fromInventory && toInventory && fromInventory.container && toInventory.container) { - fromInventory.container.moveItem(slotId, slotId, toInventory.container); - } -} diff --git a/translate-pieces/examples/nestedTranslation.ts b/translate-pieces/examples/nestedTranslation.ts index 04bcfc5..89121e9 100644 --- a/translate-pieces/examples/nestedTranslation.ts +++ b/translate-pieces/examples/nestedTranslation.ts @@ -1,8 +1,10 @@ -import { world } from '@minecraft/server'; +import { world, DimensionLocation } from "@minecraft/server"; -// Displays "Apple or Coal" -const rawMessage = { - translate: 'accessibility.list.or.two', - with: { rawtext: [{ translate: 'item.apple.name' }, { translate: 'item.coal.name' }] }, -}; -world.sendMessage(rawMessage); +function nestedTranslation(targetLocation: DimensionLocation) { + // Displays "Apple or Coal" + const rawMessage = { + translate: "accessibility.list.or.two", + with: { rawtext: [{ translate: "item.apple.name" }, { translate: "item.coal.name" }] }, + }; + world.sendMessage(rawMessage); +} diff --git a/translate-pieces/examples/phantomsShouldFlyFromCats.ts b/translate-pieces/examples/phantomsShouldFlyFromCats.ts new file mode 100644 index 0000000..29257c5 --- /dev/null +++ b/translate-pieces/examples/phantomsShouldFlyFromCats.ts @@ -0,0 +1,12 @@ +import { Test, register } from "@minecraft/server-gametest"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function phantomsShouldFlyFromCats(test: Test) { + test.spawn(MinecraftEntityTypes.Cat, { x: 4, y: 3, z: 3 }); + test.spawn(MinecraftEntityTypes.Phantom, { x: 4, y: 3, z: 3 }); + + test.succeedWhenEntityPresent(MinecraftEntityTypes.Phantom, { x: 4, y: 6, z: 3 }, true); +} + +register("MobBehaviorTests", "phantoms_should_fly_from_cats", phantomsShouldFlyFromCats) + .structureName("gametests:glass_cells"); diff --git a/translate-pieces/examples/pistonAfterEvent.ts b/translate-pieces/examples/pistonAfterEvent.ts index cd4f7c7..b713f6a 100644 --- a/translate-pieces/examples/pistonAfterEvent.ts +++ b/translate-pieces/examples/pistonAfterEvent.ts @@ -1,7 +1,36 @@ -import { world, system, PistonActivateAfterEvent } from '@minecraft/server'; +import { world, system, BlockPermutation, BlockPistonState, PistonActivateAfterEvent, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; -world.afterEvents.pistonActivate.subscribe((pistonEvent: PistonActivateAfterEvent) => { - console.warn( - `Piston event at ${system.currentTick} ${(pistonEvent.piston.isMoving ? ' Moving' : 'Not moving')} with state: ${pistonEvent.piston.state}`, - ); -}); +function pistonAfterEvent(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + // set up a couple of piston blocks + const piston = targetLocation.dimension.getBlock(targetLocation); + const button = targetLocation.dimension.getBlock({ + x: targetLocation.x, + y: targetLocation.y + 1, + z: targetLocation.z, + }); + + if (piston === undefined || button === undefined) { + log("Could not find block at location."); + return -1; + } + + piston.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.Piston).withState("facing_direction", 3)); + button.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.AcaciaButton).withState("facing_direction", 1)); + + world.afterEvents.pistonActivate.subscribe((pistonEvent: PistonActivateAfterEvent) => { + const eventLoc = pistonEvent.piston.block.location; + + if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) { + log( + "Piston event at " + + system.currentTick + + (pistonEvent.piston.isMoving ? " Moving" : "") + + (pistonEvent.piston.state === BlockPistonState.Expanding ? " Expanding" : "") + + (pistonEvent.piston.state === BlockPistonState.Expanded ? " Expanded" : "") + + (pistonEvent.piston.state === BlockPistonState.Retracting ? " Retracting" : "") + + (pistonEvent.piston.state === BlockPistonState.Retracted ? " Retracted" : "") + ); + } + }); +} diff --git a/translate-pieces/examples/placeItemsInChest.ts b/translate-pieces/examples/placeItemsInChest.ts new file mode 100644 index 0000000..94d9221 --- /dev/null +++ b/translate-pieces/examples/placeItemsInChest.ts @@ -0,0 +1,28 @@ +import { ItemStack, BlockInventoryComponent, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes, MinecraftItemTypes } from "@minecraft/vanilla-data"; + +function placeItemsInChest(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + // Fetch block + const block = targetLocation.dimension.getBlock(targetLocation); + + if (!block) { + log("Could not find block. Maybe it is not loaded?", -1); + return; + } + + // Make it a chest + block.setType(MinecraftBlockTypes.Chest); + + // Get the inventory + const inventoryComponent = block.getComponent("inventory") as BlockInventoryComponent; + + if (!inventoryComponent || !inventoryComponent.container) { + log("Could not find inventory component.", -1); + return; + } + + const inventoryContainer = inventoryComponent.container; + + // Set slot 0 to a stack of 10 apples + inventoryContainer.setItem(0, new ItemStack(MinecraftItemTypes.Apple, 10)); +} diff --git a/translate-pieces/examples/place_items_in_chest.js b/translate-pieces/examples/place_items_in_chest.js deleted file mode 100644 index fb1bf20..0000000 --- a/translate-pieces/examples/place_items_in_chest.js +++ /dev/null @@ -1,15 +0,0 @@ -import { world, MinecraftBlockTypes, Items, ItemStack } from "@minecraft/server"; - -// Fetch block -const block = world.getDimension("overworld").getBlock({ x: 1, y: 2, z: 3 }); - -// Make it a chest -block.setType(MinecraftBlockTypes.chest); - -// Get the inventory -const inventoryComponent = block.getComponent("inventory"); -const inventoryContainer = inventoryComponent.container; - -// Set slot 0 to a stack of 10 apples -inventoryContainer.setItem(0, new ItemStack(Items.apple, 10, 0)); - diff --git a/translate-pieces/examples/playMusicAndSound.ts b/translate-pieces/examples/playMusicAndSound.ts index 57e70a6..7ddf6e5 100644 --- a/translate-pieces/examples/playMusicAndSound.ts +++ b/translate-pieces/examples/playMusicAndSound.ts @@ -1,30 +1,25 @@ -import { world, MusicOptions, WorldSoundOptions, PlayerSoundOptions, Vector3 } from '@minecraft/server'; -import { MinecraftDimensionTypes } from '@minecraft/vanilla-data'; +import { world, MusicOptions, WorldSoundOptions, PlayerSoundOptions, DimensionLocation } from "@minecraft/server"; -const players = world.getPlayers(); -const targetLocation: Vector3 = { - x: 0, - y: 0, - z: 0, -}; +function playMusicAndSound(targetLocation: DimensionLocation) { + const players = world.getPlayers(); -const musicOptions: MusicOptions = { + const musicOptions: MusicOptions = { fade: 0.5, loop: true, volume: 1.0, -}; -world.playMusic('music.menu', musicOptions); + }; + world.playMusic("music.menu", musicOptions); -const worldSoundOptions: WorldSoundOptions = { + const worldSoundOptions: WorldSoundOptions = { pitch: 0.5, volume: 4.0, -}; -const overworld = world.getDimension(MinecraftDimensionTypes.Overworld); -overworld.playSound('ambient.weather.thunder', targetLocation, worldSoundOptions); + }; + world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions); -const playerSoundOptions: PlayerSoundOptions = { + const playerSoundOptions: PlayerSoundOptions = { pitch: 1.0, volume: 1.0, -}; + }; -players[0].playSound('bucket.fill_water', playerSoundOptions); + players[0].playSound("bucket.fill_water", playerSoundOptions); +} diff --git a/translate-pieces/examples/poisonVillager.ts b/translate-pieces/examples/poisonVillager.ts deleted file mode 100644 index 5121666..0000000 --- a/translate-pieces/examples/poisonVillager.ts +++ /dev/null @@ -1,14 +0,0 @@ -// Spawns a villager and gives it the poison effect -import { - DimensionLocation, -} from '@minecraft/server'; -import { MinecraftEffectTypes } from '@minecraft/vanilla-data'; - -function spawnPoisonedVillager(location: DimensionLocation) { - const villagerType = 'minecraft:villager_v2'; - const villager = location.dimension.spawnEntity(villagerType, location); - const duration = 20; - - villager.addEffect(MinecraftEffectTypes.Poison, duration, { amplifier: 1 }); -} - diff --git a/translate-pieces/examples/quickFoxLazyDog.ts b/translate-pieces/examples/quickFoxLazyDog.ts index a232736..1c3e1b9 100644 --- a/translate-pieces/examples/quickFoxLazyDog.ts +++ b/translate-pieces/examples/quickFoxLazyDog.ts @@ -1,23 +1,26 @@ -// Spawns a fox over a dog -import { DimensionLocation } from '@minecraft/server'; -import { MinecraftEntityTypes } from '@minecraft/vanilla-data'; +import { DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes, MinecraftEffectTypes } from "@minecraft/vanilla-data"; -function spawnAdultHorse(location: DimensionLocation) { - // Create fox (our quick brown fox) - const fox = location.dimension.spawnEntity(MinecraftEntityTypes.Fox, { - x: location.x, - y: location.y + 2, - z: location.z, - }); +function quickFoxLazyDog(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const fox = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Fox, { + x: targetLocation.x + 1, + y: targetLocation.y + 2, + z: targetLocation.z + 3, + }); - fox.addEffect('speed', 10, { - amplifier: 2, - }); + fox.addEffect(MinecraftEffectTypes.Speed, 10, { + amplifier: 2, + }); + log("Created a fox."); - // Create wolf (our lazy dog) - const wolf = location.dimension.spawnEntity(MinecraftEntityTypes.Wolf, location); - wolf.addEffect('slowness', 10, { - amplifier: 2, - }); - wolf.isSneaking = true; + const wolf = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Wolf, { + x: targetLocation.x + 4, + y: targetLocation.y + 2, + z: targetLocation.z + 3, + }); + wolf.addEffect(MinecraftEffectTypes.Slowness, 10, { + amplifier: 2, + }); + wolf.isSneaking = true; + log("Created a sneaking wolf.", 1); } diff --git a/translate-pieces/examples/scoreWildcard.ts b/translate-pieces/examples/scoreWildcard.ts index be1b615..013269f 100644 --- a/translate-pieces/examples/scoreWildcard.ts +++ b/translate-pieces/examples/scoreWildcard.ts @@ -1,5 +1,7 @@ -import { world } from '@minecraft/server'; +import { world, DimensionLocation } from "@minecraft/server"; -// Displays the player's score for objective "obj". Each player will see their own score. -const rawMessage = { score: { name: '*', objective: 'obj' } }; -world.sendMessage(rawMessage); +function scoreWildcard(targetLocation: DimensionLocation) { + // Displays the player's score for objective "obj". Each player will see their own score. + const rawMessage = { score: { name: "*", objective: "obj" } }; + world.sendMessage(rawMessage); +} diff --git a/translate-pieces/examples/sendBasicMessage.ts b/translate-pieces/examples/sendBasicMessage.ts new file mode 100644 index 0000000..3151509 --- /dev/null +++ b/translate-pieces/examples/sendBasicMessage.ts @@ -0,0 +1,7 @@ +import { world, DimensionLocation } from "@minecraft/server"; + +function sendBasicMessage(targetLocation: DimensionLocation) { + const players = world.getPlayers(); + + players[0].sendMessage("Hello World!"); +} diff --git a/translate-pieces/examples/sendMessagesToPlayer.ts b/translate-pieces/examples/sendMessagesToPlayer.ts deleted file mode 100644 index 3b81212..0000000 --- a/translate-pieces/examples/sendMessagesToPlayer.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Player } from "@minecraft/server"; - -function sendPlayerMessages(player: Player) { - // Displays "First or Second" - const rawMessage = { translate: 'accessibility.list.or.two', with: ['First', 'Second'] }; - player.sendMessage(rawMessage); - - // Displays "Hello, world!" - player.sendMessage('Hello, world!'); - - // Displays "Welcome, Amazing Player 1!" - player.sendMessage({ translate: 'authentication.welcome', with: ['Amazing Player 1'] }); - - // Displays the player's score for objective "obj". Each player will see their own score. - const rawMessageWithScore = { score: { name: '*', objective: 'obj' } }; - player.sendMessage(rawMessageWithScore); - - // Displays "Apple or Coal" - const rawMessageWithNestedTranslations = { - translate: 'accessibility.list.or.two', - with: { rawtext: [{ translate: 'item.apple.name' }, { translate: 'item.coal.name' }] }, - }; - player.sendMessage(rawMessageWithNestedTranslations); -} diff --git a/translate-pieces/examples/sendPlayerMessages.ts b/translate-pieces/examples/sendPlayerMessages.ts new file mode 100644 index 0000000..1af137d --- /dev/null +++ b/translate-pieces/examples/sendPlayerMessages.ts @@ -0,0 +1,26 @@ +import { world, DimensionLocation } from "@minecraft/server"; + +function sendPlayerMessages(targetLocation: DimensionLocation) { + for (const player of world.getAllPlayers()) { + // Displays "First or Second" + const rawMessage = { translate: "accessibility.list.or.two", with: ["First", "Second"] }; + player.sendMessage(rawMessage); + + // Displays "Hello, world!" + player.sendMessage("Hello, world!"); + + // Displays "Welcome, Amazing Player 1!" + player.sendMessage({ translate: "authentication.welcome", with: ["Amazing Player 1"] }); + + // Displays the player's score for objective "obj". Each player will see their own score. + const rawMessageWithScore = { score: { name: "*", objective: "obj" } }; + player.sendMessage(rawMessageWithScore); + + // Displays "Apple or Coal" + const rawMessageWithNestedTranslations = { + translate: "accessibility.list.or.two", + with: { rawtext: [{ translate: "item.apple.name" }, { translate: "item.coal.name" }] }, + }; + player.sendMessage(rawMessageWithNestedTranslations); + } +} diff --git a/translate-pieces/examples/sendTranslatedMessage.ts b/translate-pieces/examples/sendTranslatedMessage.ts new file mode 100644 index 0000000..2994f32 --- /dev/null +++ b/translate-pieces/examples/sendTranslatedMessage.ts @@ -0,0 +1,9 @@ +import { world, DimensionLocation } from "@minecraft/server"; + +function sendTranslatedMessage( + targetLocation: DimensionLocation +) { + const players = world.getPlayers(); + + players[0].sendMessage({ translate: "authentication.welcome", with: ["Amazing Player 1"] }); +} diff --git a/translate-pieces/examples/setEntityOnFire.ts b/translate-pieces/examples/setEntityOnFire.ts deleted file mode 100644 index ad89352..0000000 --- a/translate-pieces/examples/setEntityOnFire.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { world, Entity, EntityComponentTypes, system } from "@minecraft/server"; - -function setAblaze(entity: Entity) { - entity.setOnFire(20, true); - - system.runTimeout(() => { - const onfire = entity.getComponent(EntityComponentTypes.OnFire); - if (onfire) { - world.sendMessage(`${onfire.onFireTicksRemaining} fire ticks remaining, extinguishing the entity.`); - } - // This will extinguish the entity - entity.extinguishFire(true); - }, 30); // Run in 30 ticks or ~1.5 seconds - -} diff --git a/translate-pieces/examples/setOnFire.ts b/translate-pieces/examples/setOnFire.ts new file mode 100644 index 0000000..4defa8f --- /dev/null +++ b/translate-pieces/examples/setOnFire.ts @@ -0,0 +1,16 @@ +import { system, EntityOnFireComponent, EntityComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function setOnFire(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const skelly = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Skeleton, targetLocation); + + skelly.setOnFire(20, true); + + system.runTimeout(() => { + const onfire = skelly.getComponent(EntityComponentTypes.OnFire) as EntityOnFireComponent; + log(onfire?.onFireTicksRemaining + " fire ticks remaining."); + + skelly.extinguishFire(true); + log("Never mind. Fire extinguished."); + }, 20); +} diff --git a/translate-pieces/examples/setSignText.ts b/translate-pieces/examples/setSignText.ts deleted file mode 100644 index 9d74feb..0000000 --- a/translate-pieces/examples/setSignText.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { - BlockComponentTypes, - DimensionLocation, - RawMessage, - RawText, -} from '@minecraft/server'; - -// Function which updates a sign blocks text to raw text -function updateSignText(signLocation: DimensionLocation) { - const block = signLocation.dimension.getBlock(signLocation); - if (!block) { - console.warn('Could not find a block at specified location.'); - return; - } - - const sign = block.getComponent(BlockComponentTypes.Sign); - if (sign) { - // RawMessage - const helloWorldMessage: RawMessage = { text: 'Hello World' }; - sign.setText(helloWorldMessage); - - // RawText - const helloWorldText: RawText = { rawtext: [{ text: 'Hello World' }] }; - sign.setText(helloWorldText); - - // Regular string - sign.setText('Hello World'); - } else { - console.warn('Could not find a sign component on the block.'); - } -} diff --git a/translate-pieces/examples/setTitle.ts b/translate-pieces/examples/setTitle.ts index 3bf9262..c79cdc9 100644 --- a/translate-pieces/examples/setTitle.ts +++ b/translate-pieces/examples/setTitle.ts @@ -1,5 +1,9 @@ -import { world } from '@minecraft/server'; +import { world, DimensionLocation } from "@minecraft/server"; -world.afterEvents.playerSpawn.subscribe((event) => { - event.player.onScreenDisplay.setTitle('§o§6You respawned!§r'); -}); +function setTitle(targetLocation: DimensionLocation) { + const players = world.getPlayers(); + + if (players.length > 0) { + players[0].onScreenDisplay.setTitle("§o§6Fancy Title§r"); + } +} diff --git a/translate-pieces/examples/setTitleAndSubtitle.ts b/translate-pieces/examples/setTitleAndSubtitle.ts index 12d067a..a30195d 100644 --- a/translate-pieces/examples/setTitleAndSubtitle.ts +++ b/translate-pieces/examples/setTitleAndSubtitle.ts @@ -1,10 +1,14 @@ -import { world } from '@minecraft/server'; +import { world, DimensionLocation } from "@minecraft/server"; -world.afterEvents.playerSpawn.subscribe((event) => { - event.player.onScreenDisplay.setTitle('You respawned', { - stayDuration: 100, - fadeInDuration: 2, - fadeOutDuration: 4, - subtitle: 'Try not to die next time!', - }); -}); +function setTitleAndSubtitle( + targetLocation: DimensionLocation +) { + const players = world.getPlayers(); + + players[0].onScreenDisplay.setTitle("Chapter 1", { + stayDuration: 100, + fadeInDuration: 2, + fadeOutDuration: 4, + subtitle: "Trouble in Block Town", + }); +} diff --git a/translate-pieces/examples/sheepShearedTest.js b/translate-pieces/examples/sheepShearedTest.js deleted file mode 100644 index 7bd2dec..0000000 --- a/translate-pieces/examples/sheepShearedTest.js +++ /dev/null @@ -1 +0,0 @@ -test.assertEntityHasComponent("minecraft:sheep", "minecraft:is_sheared", entityLoc, false); diff --git a/translate-pieces/examples/shootArrow.ts b/translate-pieces/examples/shootArrow.ts index ee400ef..3cc17fd 100644 --- a/translate-pieces/examples/shootArrow.ts +++ b/translate-pieces/examples/shootArrow.ts @@ -1,7 +1,15 @@ -import { world, Vector3 } from '@minecraft/server'; +import { DimensionLocation, EntityProjectileComponent } from "@minecraft/server"; -const location: Vector3 = { x: 0, y: -59, z: 0 }; // Replace with the coordinates of where you want to spawn the arrow -const velocity: Vector3 = { x: 0, y: 0, z: 5 }; -const arrow = world.getDimension('overworld').spawnEntity('minecraft:arrow', location); -const projectileComp = arrow.getComponent('minecraft:projectile'); -projectileComp?.shoot(velocity); +function shootArrow(targetLocation: DimensionLocation) { + const velocity = { x: 0, y: 1, z: 5 }; + + const arrow = targetLocation.dimension.spawnEntity("minecraft:arrow", { + x: targetLocation.x, + y: targetLocation.y + 2, + z: targetLocation.z, + }); + + const projectileComp = arrow.getComponent("minecraft:projectile") as EntityProjectileComponent; + + projectileComp?.shoot(velocity); +} diff --git a/translate-pieces/examples/showActionForm.ts b/translate-pieces/examples/showActionForm.ts new file mode 100644 index 0000000..5c54863 --- /dev/null +++ b/translate-pieces/examples/showActionForm.ts @@ -0,0 +1,26 @@ +import { world, DimensionLocation } from "@minecraft/server"; +import { ActionFormData, ActionFormResponse } from "@minecraft/server-ui"; + +function showActionForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const playerList = world.getPlayers(); + + if (playerList.length >= 1) { + const form = new ActionFormData() + .title("Test Title") + .body("Body text here!") + .button("btn 1") + .button("btn 2") + .button("btn 3") + .button("btn 4") + .button("btn 5"); + + form.show(playerList[0]).then((result: ActionFormResponse) => { + if (result.canceled) { + log("Player exited out of the dialog. Note that if the chat window is up, dialogs are automatically canceled."); + return -1; + } else { + log("Your result was: " + result.selection); + } + }); + } +} diff --git a/translate-pieces/examples/showBasicMessageForm.ts b/translate-pieces/examples/showBasicMessageForm.ts new file mode 100644 index 0000000..738c75f --- /dev/null +++ b/translate-pieces/examples/showBasicMessageForm.ts @@ -0,0 +1,30 @@ +import { world, DimensionLocation } from "@minecraft/server"; +import { MessageFormResponse, MessageFormData } from "@minecraft/server-ui"; + +function showBasicMessageForm( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + const players = world.getPlayers(); + + const messageForm = new MessageFormData() + .title("Message Form Example") + .body("This shows a simple example using §o§7MessageFormData§r.") + .button1("Button 1") + .button2("Button 2"); + + messageForm + .show(players[0]) + .then((formData: MessageFormResponse) => { + // player canceled the form, or another dialog was up and open. + if (formData.canceled || formData.selection === undefined) { + return; + } + + log(`You selected ${formData.selection === 0 ? "Button 1" : "Button 2"}`); + }) + .catch((error: Error) => { + log("Failed to show form: " + error); + return -1; + }); +} diff --git a/translate-pieces/examples/showBasicModalForm.ts b/translate-pieces/examples/showBasicModalForm.ts new file mode 100644 index 0000000..4f1f954 --- /dev/null +++ b/translate-pieces/examples/showBasicModalForm.ts @@ -0,0 +1,30 @@ +import { world, DimensionLocation } from "@minecraft/server"; +import { ModalFormData } from "@minecraft/server-ui"; + +function showBasicModalForm(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const players = world.getPlayers(); + + const modalForm = new ModalFormData().title("Example Modal Controls for §o§7ModalFormData§r"); + + modalForm.toggle("Toggle w/o default"); + modalForm.toggle("Toggle w/ default", true); + + modalForm.slider("Slider w/o default", 0, 50, 5); + modalForm.slider("Slider w/ default", 0, 50, 5, 30); + + modalForm.dropdown("Dropdown w/o default", ["option 1", "option 2", "option 3"]); + modalForm.dropdown("Dropdown w/ default", ["option 1", "option 2", "option 3"], 2); + + modalForm.textField("Input w/o default", "type text here"); + modalForm.textField("Input w/ default", "type text here", "this is default"); + + modalForm + .show(players[0]) + .then((formData) => { + players[0].sendMessage(`Modal form results: ${JSON.stringify(formData.formValues, undefined, 2)}`); + }) + .catch((error: Error) => { + log("Failed to show form: " + error); + return -1; + }); +} diff --git a/translate-pieces/examples/showFavoriteMonth.ts b/translate-pieces/examples/showFavoriteMonth.ts new file mode 100644 index 0000000..186cecd --- /dev/null +++ b/translate-pieces/examples/showFavoriteMonth.ts @@ -0,0 +1,24 @@ +import { world, DimensionLocation } from "@minecraft/server"; +import { ActionFormData, ActionFormResponse } from "@minecraft/server-ui"; + +function showFavoriteMonth(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const players = world.getPlayers(); + + if (players.length >= 1) { + const form = new ActionFormData() + .title("Months") + .body("Choose your favorite month!") + .button("January") + .button("February") + .button("March") + .button("April") + .button("May"); + + form.show(players[0]).then((response: ActionFormResponse) => { + if (response.selection === 3) { + log("I like April too!"); + return -1; + } + }); + } +} diff --git a/translate-pieces/examples/showTranslatedMessageForm.ts b/translate-pieces/examples/showTranslatedMessageForm.ts index 37766d1..1e70d4c 100644 --- a/translate-pieces/examples/showTranslatedMessageForm.ts +++ b/translate-pieces/examples/showTranslatedMessageForm.ts @@ -1,26 +1,30 @@ -import { world, Player } from '@minecraft/server'; -import { MessageFormData, MessageFormResponse } from '@minecraft/server-ui'; +import { world, DimensionLocation } from "@minecraft/server"; +import { MessageFormResponse, MessageFormData } from "@minecraft/server-ui"; -function showMessage(player: Player) { - const messageForm = new MessageFormData() - .title({ translate: 'permissions.removeplayer' }) - .body({ translate: 'accessibility.list.or.two', with: ['Player 1', 'Player 2'] }) - .button1('Player 1') - .button2('Player 2'); +function showTranslatedMessageForm( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + const players = world.getPlayers(); - messageForm - .show(player) - .then((formData: MessageFormResponse) => { - // player canceled the form, or another dialog was up and open. - if (formData.canceled || formData.selection === undefined) { - return; - } + const messageForm = new MessageFormData() + .title({ translate: "permissions.removeplayer" }) + .body({ translate: "accessibility.list.or.two", with: ["Player 1", "Player 2"] }) + .button1("Player 1") + .button2("Player 2"); - console.warn(`You selected ${formData.selection === 0 ? 'Player 1' : 'Player 2'}`); - }) - .catch((error: Error) => { - console.warn('Failed to show form: ' + error); - }); -}; + messageForm + .show(players[0]) + .then((formData: MessageFormResponse) => { + // player canceled the form, or another dialog was up and open. + if (formData.canceled || formData.selection === undefined) { + return; + } -showMessage(world.getAllPlayers()[0]); + log(`You selected ${formData.selection === 0 ? "Player 1" : "Player 2"}`); + }) + .catch((error: Error) => { + log("Failed to show form: " + error); + return -1; + }); +} diff --git a/translate-pieces/examples/simpleMobGameTest.ts b/translate-pieces/examples/simpleMobGameTest.ts new file mode 100644 index 0000000..4b4b8dd --- /dev/null +++ b/translate-pieces/examples/simpleMobGameTest.ts @@ -0,0 +1,17 @@ +import { Test, register } from "@minecraft/server-gametest"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function simpleMobGameTest(test: Test) { + const attackerId = MinecraftEntityTypes.Fox; + const victimId = MinecraftEntityTypes.Chicken; + + test.spawn(attackerId, { x: 5, y: 2, z: 5 }); + test.spawn(victimId, { x: 2, y: 2, z: 2 }); + + test.assertEntityPresentInArea(victimId, true); + + test.succeedWhen(() => { + test.assertEntityPresentInArea(victimId, false); + }); +} +register("StarterTests", "simpleMobTest", simpleMobGameTest).maxTicks(400).structureName("gametests:mediumglass"); diff --git a/translate-pieces/examples/simpleString.ts b/translate-pieces/examples/simpleString.ts deleted file mode 100644 index 0246d8c..0000000 --- a/translate-pieces/examples/simpleString.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { world } from '@minecraft/server'; - -// Displays "Hello, world!" -world.sendMessage('Hello, world!'); diff --git a/translate-pieces/examples/spawnAdultHorse.ts b/translate-pieces/examples/spawnAdultHorse.ts new file mode 100644 index 0000000..1477ec1 --- /dev/null +++ b/translate-pieces/examples/spawnAdultHorse.ts @@ -0,0 +1,10 @@ +import { DimensionLocation } from "@minecraft/server"; +import { Vector3Utils } from "@minecraft/math"; + +function spawnAdultHorse(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + log("Create a horse and triggering the ageable_grow_up event, ensuring the horse is created as an adult"); + targetLocation.dimension.spawnEntity( + "minecraft:horse", + Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 }) + ); +} diff --git a/translate-pieces/examples/spawnAdultPig.b52912dc.js b/translate-pieces/examples/spawnAdultPig.b52912dc.js deleted file mode 100644 index 0e1f5cf..0000000 --- a/translate-pieces/examples/spawnAdultPig.b52912dc.js +++ /dev/null @@ -1 +0,0 @@ -test.spawn("minecraft:pig", { x: 1.5, y: 2, z: 1.5 }); diff --git a/translate-pieces/examples/spawnAdultPig.ca50f0aa.js b/translate-pieces/examples/spawnAdultPig.ca50f0aa.js deleted file mode 100644 index 6cee5b2..0000000 --- a/translate-pieces/examples/spawnAdultPig.ca50f0aa.js +++ /dev/null @@ -1,2 +0,0 @@ -test.spawn("minecraft:pig", { x: 1, y: 2, z: 1 }); - diff --git a/translate-pieces/examples/spawnEmeralds.js b/translate-pieces/examples/spawnEmeralds.js deleted file mode 100644 index 0b33d82..0000000 --- a/translate-pieces/examples/spawnEmeralds.js +++ /dev/null @@ -1,5 +0,0 @@ -const oneEmerald = new ItemStack(MinecraftItemTypes.Emerald, 1, 0); -const fiveEmeralds = new ItemStack(MinecraftItemTypes.Emerald, 5, 0); - -test.spawnItem(oneEmerald, { x: 3.5, y: 3, z: 1.5 }); -test.spawnItem(fiveEmeralds, { x: 1.5, y: 3, z: 1.5 }); diff --git a/translate-pieces/examples/spawnFeatherItem.ts b/translate-pieces/examples/spawnFeatherItem.ts index bc6fef9..67d1677 100644 --- a/translate-pieces/examples/spawnFeatherItem.ts +++ b/translate-pieces/examples/spawnFeatherItem.ts @@ -1,8 +1,9 @@ -// Spawns a feather at a location -import { ItemStack, DimensionLocation } from '@minecraft/server'; -import { MinecraftItemTypes } from '@minecraft/vanilla-data'; +import { ItemStack, DimensionLocation } from "@minecraft/server"; +import { MinecraftItemTypes } from "@minecraft/vanilla-data"; -function spawnFeather(location: DimensionLocation) { - const featherItem = new ItemStack(MinecraftItemTypes.Feather, 1); - location.dimension.spawnItem(featherItem, location); +function spawnFeatherItem(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const featherItem = new ItemStack(MinecraftItemTypes.Feather, 1); + + targetLocation.dimension.spawnItem(featherItem, targetLocation); + log(`New feather created at ${targetLocation.x}, ${targetLocation.y}, ${targetLocation.z}!`); } diff --git a/translate-pieces/examples/spawnParticle.25a384c8.ts b/translate-pieces/examples/spawnParticle.25a384c8.ts new file mode 100644 index 0000000..3432822 --- /dev/null +++ b/translate-pieces/examples/spawnParticle.25a384c8.ts @@ -0,0 +1,16 @@ +import { MolangVariableMap, DimensionLocation } from "@minecraft/server"; + +function spawnParticle(targetLocation: DimensionLocation) { + for (let i = 0; i < 100; i++) { + const molang = new MolangVariableMap(); + + molang.setColorRGB("variable.color", { red: Math.random(), green: Math.random(), blue: Math.random() }); + + const newLocation = { + x: targetLocation.x + Math.floor(Math.random() * 8) - 4, + y: targetLocation.y + Math.floor(Math.random() * 8) - 4, + z: targetLocation.z + Math.floor(Math.random() * 8) - 4, + }; + targetLocation.dimension.spawnParticle("minecraft:colored_flame_particle", newLocation, molang); + } +} diff --git a/translate-pieces/examples/spawnParticle.4689acc9.ts b/translate-pieces/examples/spawnParticle.4689acc9.ts deleted file mode 100644 index bf1698a..0000000 --- a/translate-pieces/examples/spawnParticle.4689acc9.ts +++ /dev/null @@ -1,21 +0,0 @@ -// A function that spawns a particle at a random location near the target location for all players in the server -import { world, MolangVariableMap, DimensionLocation, Vector3 } from '@minecraft/server'; - -function spawnConfetti(location: DimensionLocation) { - for (let i = 0; i < 100; i++) { - const molang = new MolangVariableMap(); - - molang.setColorRGB('variable.color', { - red: Math.random(), - green: Math.random(), - blue: Math.random() - }); - - const newLocation: Vector3 = { - x: location.x + Math.floor(Math.random() * 8) - 4, - y: location.y + Math.floor(Math.random() * 8) - 4, - z: location.z + Math.floor(Math.random() * 8) - 4, - }; - location.dimension.spawnParticle('minecraft:colored_flame_particle', newLocation, molang); - } -} diff --git a/translate-pieces/examples/spawnPoisonedVillager.ts b/translate-pieces/examples/spawnPoisonedVillager.ts new file mode 100644 index 0000000..ce7a4fe --- /dev/null +++ b/translate-pieces/examples/spawnPoisonedVillager.ts @@ -0,0 +1,12 @@ +import { DimensionLocation } from "@minecraft/server"; +import { MinecraftEffectTypes } from "@minecraft/vanilla-data"; + +function spawnPoisonedVillager( + targetLocation: DimensionLocation +) { + const villagerType = "minecraft:villager_v2"; + const villager = targetLocation.dimension.spawnEntity(villagerType, targetLocation); + const duration = 20; + + villager.addEffect(MinecraftEffectTypes.Poison, duration, { amplifier: 1 }); +} diff --git a/translate-pieces/examples/spreadFromFaceTowardDirection.js b/translate-pieces/examples/spreadFromFaceTowardDirection.js deleted file mode 100644 index e147f55..0000000 --- a/translate-pieces/examples/spreadFromFaceTowardDirection.js +++ /dev/null @@ -1 +0,0 @@ -test.spreadFromFaceTowardDirection({ x: 1, y: 2, z: 1 }, Direction.south, Direction.down); diff --git a/translate-pieces/examples/swapItems.ts b/translate-pieces/examples/swapItems.ts deleted file mode 100644 index 1130dad..0000000 --- a/translate-pieces/examples/swapItems.ts +++ /dev/null @@ -1,11 +0,0 @@ -// A function that swaps an item from one slot of the player's inventory to another player's inventory -import { Player, EntityComponentTypes } from '@minecraft/server'; - -function swapBetweenPlayers(slotId: number, fromPlayer: Player, toPlayer: Player) { - const fromInventory = fromPlayer.getComponent(EntityComponentTypes.Inventory); - const toInventory = toPlayer.getComponent(EntityComponentTypes.Inventory); - - if (fromInventory && toInventory && fromInventory.container && toInventory.container) { - fromInventory.container.swapItems(slotId, slotId, toInventory.container); - } -} diff --git a/translate-pieces/examples/tagsQuery.ts b/translate-pieces/examples/tagsQuery.ts index 3f0c048..8945123 100644 --- a/translate-pieces/examples/tagsQuery.ts +++ b/translate-pieces/examples/tagsQuery.ts @@ -1,20 +1,20 @@ -import { EntityQueryOptions, DimensionLocation } from '@minecraft/server'; +import { EntityQueryOptions, DimensionLocation } from "@minecraft/server"; -function mobParty(targetLocation: DimensionLocation) { - const mobs = ['creeper', 'skeleton', 'sheep']; +function tagsQuery(targetLocation: DimensionLocation) { + const mobs = ["creeper", "skeleton", "sheep"]; - // create some sample mob data - for (let i = 0; i < 10; i++) { - const mobTypeId = mobs[i % mobs.length]; - const entity = targetLocation.dimension.spawnEntity(mobTypeId, targetLocation); - entity.addTag('mobparty.' + mobTypeId); - } + // create some sample mob data + for (let i = 0; i < 10; i++) { + const mobTypeId = mobs[i % mobs.length]; + const entity = targetLocation.dimension.spawnEntity(mobTypeId, targetLocation); + entity.addTag("mobparty." + mobTypeId); + } - const eqo: EntityQueryOptions = { - tags: ['mobparty.skeleton'], - }; + const eqo: EntityQueryOptions = { + tags: ["mobparty.skeleton"], + }; - for (const entity of targetLocation.dimension.getEntities(eqo)) { - entity.kill(); - } + for (const entity of targetLocation.dimension.getEntities(eqo)) { + entity.kill(); + } } diff --git a/translate-pieces/examples/teleport.ts b/translate-pieces/examples/teleport.ts new file mode 100644 index 0000000..20559a1 --- /dev/null +++ b/translate-pieces/examples/teleport.ts @@ -0,0 +1,15 @@ +import { system, DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function teleport(targetLocation: DimensionLocation) { + const cow = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Cow, targetLocation); + + system.runTimeout(() => { + cow.teleport( + { x: targetLocation.x + 2, y: targetLocation.y + 2, z: targetLocation.z + 2 }, + { + facingLocation: targetLocation, + } + ); + }, 20); +} diff --git a/translate-pieces/examples/teleportMovement.ts b/translate-pieces/examples/teleportMovement.ts index 97d5595..a4b0f59 100644 --- a/translate-pieces/examples/teleportMovement.ts +++ b/translate-pieces/examples/teleportMovement.ts @@ -1,21 +1,21 @@ -import { world, system } from '@minecraft/server'; +import { system, DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; -const overworld = world.getDimension('overworld'); -const targetLocation = { x: 0, y: 0, z: 0 }; +function teleportMovement(targetLocation: DimensionLocation) { + const pig = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Pig, targetLocation); -const pig = overworld.spawnEntity('minecraft:pig', targetLocation); - -let inc = 1; -const runId = system.runInterval(() => { + let inc = 1; + const runId = system.runInterval(() => { pig.teleport( - { x: targetLocation.x + inc / 4, y: targetLocation.y + inc / 4, z: targetLocation.z + inc / 4 }, - { - facingLocation: targetLocation, - }, + { x: targetLocation.x + inc / 4, y: targetLocation.y + inc / 4, z: targetLocation.z + inc / 4 }, + { + facingLocation: targetLocation, + } ); if (inc > 100) { - system.clearRun(runId); + system.clearRun(runId); } inc++; -}, 4); + }, 4); +} diff --git a/translate-pieces/examples/testIfButtonNotPressed.js b/translate-pieces/examples/testIfButtonNotPressed.js deleted file mode 100644 index d51190e..0000000 --- a/translate-pieces/examples/testIfButtonNotPressed.js +++ /dev/null @@ -1,3 +0,0 @@ -test.assertBlockState(buttonPos, (block) => { - return block.permutation.getProperty("button_pressed_bit") == 0; -}); diff --git a/translate-pieces/examples/testThatEntityIsFeatherItem.ts b/translate-pieces/examples/testThatEntityIsFeatherItem.ts new file mode 100644 index 0000000..7ef930e --- /dev/null +++ b/translate-pieces/examples/testThatEntityIsFeatherItem.ts @@ -0,0 +1,21 @@ +import { EntityItemComponent, EntityComponentTypes, DimensionLocation } from "@minecraft/server"; + +function testThatEntityIsFeatherItem( + log: (message: string, status?: number) => void, + targetLocation: DimensionLocation +) { + const items = targetLocation.dimension.getEntities({ + location: targetLocation, + maxDistance: 20, + }); + + for (const item of items) { + const itemComp = item.getComponent(EntityComponentTypes.Item) as EntityItemComponent; + + if (itemComp) { + if (itemComp.itemStack.typeId.endsWith("feather")) { + log("Success! Found a feather", 1); + } + } + } +} diff --git a/translate-pieces/examples/titleCountdown.ts b/translate-pieces/examples/titleCountdown.ts deleted file mode 100644 index 7e4f653..0000000 --- a/translate-pieces/examples/titleCountdown.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { world, system } from '@minecraft/server'; - -world.afterEvents.playerSpawn.subscribe(event => { - event.player.onScreenDisplay.setTitle('Get ready!', { - stayDuration: 220, - fadeInDuration: 2, - fadeOutDuration: 4, - subtitle: '10', - }); - - let countdown = 10; - - const intervalId = system.runInterval(() => { - countdown--; - event.player.onScreenDisplay.updateSubtitle(countdown.toString()); - - if (countdown == 0) { - system.clearRun(intervalId); - } - }, 20); -}); diff --git a/translate-pieces/examples/transferBetweenContainers.ts b/translate-pieces/examples/transferBetweenContainers.ts new file mode 100644 index 0000000..9016628 --- /dev/null +++ b/translate-pieces/examples/transferBetweenContainers.ts @@ -0,0 +1,25 @@ +import { world, EntityInventoryComponent, EntityComponentTypes, DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function transferBetweenContainers( + targetLocation: DimensionLocation +) { + const players = world.getAllPlayers(); + + const chestCart = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.ChestMinecart, { + x: targetLocation.x + 1, + y: targetLocation.y, + z: targetLocation.z, + }); + + if (players.length > 0) { + const fromPlayer = players[0]; + + const fromInventory = fromPlayer.getComponent(EntityComponentTypes.Inventory) as EntityInventoryComponent; + const toInventory = chestCart.getComponent(EntityComponentTypes.Inventory) as EntityInventoryComponent; + + if (fromInventory && toInventory && fromInventory.container && toInventory.container) { + fromInventory.container.transferItem(0, toInventory.container); + } + } +} diff --git a/translate-pieces/examples/transferItem.ts b/translate-pieces/examples/transferItem.ts deleted file mode 100644 index 06ed502..0000000 --- a/translate-pieces/examples/transferItem.ts +++ /dev/null @@ -1,11 +0,0 @@ -// A function that moves an item from one slot of the player's inventory to another player's inventory -import { Player, EntityComponentTypes } from '@minecraft/server'; - -function moveBetweenPlayers(slotId: number, fromPlayer: Player, toPlayer: Player) { - const fromInventory = fromPlayer.getComponent(EntityComponentTypes.Inventory); - const toInventory = toPlayer.getComponent(EntityComponentTypes.Inventory); - - if (fromInventory && toInventory && fromInventory.container && toInventory.container) { - fromInventory.container.transferItem(slotId, toInventory.container); - } -} diff --git a/translate-pieces/examples/translation.ts b/translate-pieces/examples/translation.ts deleted file mode 100644 index a0c8304..0000000 --- a/translate-pieces/examples/translation.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { world } from '@minecraft/server'; - -// Displays "First or Second" -const rawMessage = { translate: 'accessibility.list.or.two', with: ['First', 'Second'] }; -world.sendMessage(rawMessage); diff --git a/translate-pieces/examples/trapTick.ts b/translate-pieces/examples/trapTick.ts index 3db7266..3e193d0 100644 --- a/translate-pieces/examples/trapTick.ts +++ b/translate-pieces/examples/trapTick.ts @@ -1,16 +1,14 @@ -import { system, world } from '@minecraft/server'; +import { world, system } from "@minecraft/server"; -function printEveryMinute() { - try { - // Minecraft runs at 20 ticks per second. - if (system.currentTick % 1200 === 0) { - world.sendMessage('Another minute passes...'); - } - } catch (e) { - console.warn('Error: ' + e); +function trapTick() { + try { + // Minecraft runs at 20 ticks per second. + if (system.currentTick % 1200 === 0) { + world.sendMessage("Another minute passes..."); } + } catch (e) { + console.warn("Error: " + e); + } - system.run(printEveryMinute); + system.run(trapTick); } - -printEveryMinute(); diff --git a/translate-pieces/examples/triggerEvent.b473e4eb.ts b/translate-pieces/examples/triggerEvent.b473e4eb.ts new file mode 100644 index 0000000..565808a --- /dev/null +++ b/translate-pieces/examples/triggerEvent.b473e4eb.ts @@ -0,0 +1,8 @@ +import { DimensionLocation } from "@minecraft/server"; +import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; + +function triggerEvent(targetLocation: DimensionLocation) { + const creeper = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Creeper, targetLocation); + + creeper.triggerEvent("minecraft:start_exploding_forced"); +} diff --git a/translate-pieces/examples/triggerEvent.ts b/translate-pieces/examples/triggerEvent.e0d38a47.ts similarity index 100% rename from translate-pieces/examples/triggerEvent.ts rename to translate-pieces/examples/triggerEvent.e0d38a47.ts diff --git a/translate-pieces/examples/tripWireTripEvent.ts b/translate-pieces/examples/tripWireTripEvent.ts index d1f941e..f622558 100644 --- a/translate-pieces/examples/tripWireTripEvent.ts +++ b/translate-pieces/examples/tripWireTripEvent.ts @@ -1,28 +1,32 @@ -import { Vector3, world, BlockPermutation, TripWireTripAfterEvent, system } from '@minecraft/server'; +import { world, system, BlockPermutation, TripWireTripAfterEvent, DimensionLocation } from "@minecraft/server"; +import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; -const overworld = world.getDimension('overworld'); -const targetLocation: Vector3 = { x: 0, y: 0, z: 0 }; +function tripWireTripEvent(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + // set up a tripwire + const redstone = targetLocation.dimension.getBlock({ + x: targetLocation.x, + y: targetLocation.y - 1, + z: targetLocation.z, + }); + const tripwire = targetLocation.dimension.getBlock(targetLocation); -// set up a tripwire -const redstone = overworld.getBlock({ x: targetLocation.x, y: targetLocation.y - 1, z: targetLocation.z }); -const tripwire = overworld.getBlock(targetLocation); + if (redstone === undefined || tripwire === undefined) { + log("Could not find block at location."); + return -1; + } -if (redstone === undefined || tripwire === undefined) { - console.warn('Could not find block at location.'); -} else { + redstone.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.RedstoneBlock)); + tripwire.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.TripWire)); -redstone.setPermutation(BlockPermutation.resolve('redstone_block')); -tripwire.setPermutation(BlockPermutation.resolve('tripwire')); - -world.afterEvents.tripWireTrip.subscribe((tripWireTripEvent: TripWireTripAfterEvent) => { + world.afterEvents.tripWireTrip.subscribe((tripWireTripEvent: TripWireTripAfterEvent) => { const eventLoc = tripWireTripEvent.block.location; if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) { - console.warn( - 'Tripwire trip event at tick ' + - system.currentTick + - (tripWireTripEvent.sources.length > 0 ? ' by entity ' + tripWireTripEvent.sources[0].id : ''), - ); + log( + "Tripwire trip event at tick " + + system.currentTick + + (tripWireTripEvent.sources.length > 0 ? " by entity " + tripWireTripEvent.sources[0].id : "") + ); } -}); + }); } diff --git a/translate-pieces/examples/updateScoreboard.ts b/translate-pieces/examples/updateScoreboard.ts new file mode 100644 index 0000000..4fb0a6c --- /dev/null +++ b/translate-pieces/examples/updateScoreboard.ts @@ -0,0 +1,36 @@ +import { world, DisplaySlotId, ObjectiveSortOrder, DimensionLocation } from "@minecraft/server"; + +function updateScoreboard(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { + const scoreboardObjectiveId = "scoreboard_demo_objective"; + const scoreboardObjectiveDisplayName = "Demo Objective"; + + const players = world.getPlayers(); + + // Ensure a new objective. + let objective = world.scoreboard.getObjective(scoreboardObjectiveId); + + if (!objective) { + objective = world.scoreboard.addObjective(scoreboardObjectiveId, scoreboardObjectiveDisplayName); + } + + // get the scoreboard identity for player 0 + const player0Identity = players[0].scoreboardIdentity; + + if (player0Identity === undefined) { + log("Could not get a scoreboard identity for player 0."); + return -1; + } + + // initialize player score to 100; + objective.setScore(player0Identity, 100); + + world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, { + objective: objective, + sortOrder: ObjectiveSortOrder.Descending, + }); + + const playerScore = objective.getScore(player0Identity) ?? 0; + + // score should now be 110. + objective.setScore(player0Identity, playerScore + 10); +} diff --git a/translate-pieces/examples/updateSignText.ts b/translate-pieces/examples/updateSignText.ts new file mode 100644 index 0000000..01b6fbf --- /dev/null +++ b/translate-pieces/examples/updateSignText.ts @@ -0,0 +1,25 @@ +import { BlockSignComponent, BlockComponentTypes, DimensionLocation, RawMessage, RawText } from "@minecraft/server"; + +function updateSignText(targetLocation: DimensionLocation) { + const block = targetLocation.dimension.getBlock(targetLocation); + if (!block) { + console.warn("Could not find a block at specified location."); + return; + } + + const sign = block.getComponent(BlockComponentTypes.Sign) as BlockSignComponent; + if (sign) { + // RawMessage + const helloWorldMessage: RawMessage = { text: "Hello World" }; + sign.setText(helloWorldMessage); + + // RawText + const helloWorldText: RawText = { rawtext: [{ text: "Hello World" }] }; + sign.setText(helloWorldText); + + // Regular string + sign.setText("Hello World"); + } else { + console.warn("Could not find a sign component on the block."); + } +} diff --git a/translate-pieces/examples/villagerEffectTest.js b/translate-pieces/examples/villagerEffectTest.js deleted file mode 100644 index 8e8c77d..0000000 --- a/translate-pieces/examples/villagerEffectTest.js +++ /dev/null @@ -1,5 +0,0 @@ -test.assertEntityState( - villagerPos, - "minecraft:villager_v2", - (entity) => entity.getEffect(MinecraftEffectTypes.Regeneration).duration > 120 -); // At least 6 seconds remaining in the villagers' effect diff --git a/translate-pieces/examples/yeetEntity.ts b/translate-pieces/examples/yeetEntity.ts deleted file mode 100644 index e752067..0000000 --- a/translate-pieces/examples/yeetEntity.ts +++ /dev/null @@ -1,11 +0,0 @@ -// A function that throws entities up in the air -import { Entity } from '@minecraft/server'; - -function yeetEntity(entity: Entity) { - - // Zero out the entity's velocity before applying impulse - entity.clearVelocity(); - - // throw the zombie up in the air - entity.applyImpulse({ x: 0, y: 15, z: 0 }); -} diff --git a/translate-pieces/server-admin/functions/transferPlayer.d.ts b/translate-pieces/server-admin/functions/transferPlayer.d.ts new file mode 100644 index 0000000..eb98ad0 --- /dev/null +++ b/translate-pieces/server-admin/functions/transferPlayer.d.ts @@ -0,0 +1,17 @@ +/* IMPORT */ import { minecraftserver } from '../index'; + +/** + * @remarks + * Transfer player to another server. + * + * This function can't be called in read-only mode. + * + * @param player + * Player to transfer. + * @param host + * Host of the server to transfer to. + * @param port + * Port of the server to transfer to. + * @throws This function can throw errors. + */ +export function transferPlayer(player: minecraftserver.Player, host: string, port: number): void; \ No newline at end of file diff --git a/translate-pieces/server-admin/index.d.ts b/translate-pieces/server-admin/index.d.ts index 7470d84..8d9d340 100644 --- a/translate-pieces/server-admin/index.d.ts +++ b/translate-pieces/server-admin/index.d.ts @@ -1,7 +1,10 @@ import * as minecraftcommon from '../common'; +import * as minecraftserver from '../server'; /* PRIVATE */ export { minecraftcommon }; +/* PRIVATE */ export { minecraftserver }; export { SecretString } from './classes/SecretString'; export { ServerSecrets } from './classes/ServerSecrets'; export { ServerVariables } from './classes/ServerVariables'; +export { transferPlayer } from './functions/transferPlayer'; export { secrets } from './variables/secrets'; export { variables } from './variables/variables'; \ No newline at end of file diff --git a/translate-pieces/server-editor/interfaces/IModalToolContainer.d.ts b/translate-pieces/server-editor/interfaces/IModalToolContainer.d.ts index 962f713..e436077 100644 --- a/translate-pieces/server-editor/interfaces/IModalToolContainer.d.ts +++ b/translate-pieces/server-editor/interfaces/IModalToolContainer.d.ts @@ -8,6 +8,7 @@ export interface IModalToolContainer { */ readonly currentTools: IModalTool[]; addTool(params: ModalToolCreationParameters, action?: RegisteredAction): IModalTool; + focusToolInputContext(): void; getSelectedToolId(): string | undefined; removeTool(id: string): void; setSelectedToolId(id: string | undefined): void; diff --git a/translate-pieces/server-gametest/classes/RegistrationBuilder.d.ts b/translate-pieces/server-gametest/classes/RegistrationBuilder.d.ts index 21fde05..c88156a 100644 --- a/translate-pieces/server-gametest/classes/RegistrationBuilder.d.ts +++ b/translate-pieces/server-gametest/classes/RegistrationBuilder.d.ts @@ -150,6 +150,7 @@ export class RegistrationBuilder { * @returns * RegistrationBuilder object where additional configuration * methods can be called. + * @seeExample phantomsShouldFlyFromCats.ts */ structureName(structureName: string): RegistrationBuilder; /** @@ -164,6 +165,7 @@ export class RegistrationBuilder { * @returns * RegistrationBuilder object where additional configuration * methods can be called. + * @seeExample phantomsShouldFlyFromCats.ts */ tag(tag: string): RegistrationBuilder; } \ No newline at end of file diff --git a/translate-pieces/server-gametest/classes/Test.d.ts b/translate-pieces/server-gametest/classes/Test.d.ts index a50f089..038a850 100644 --- a/translate-pieces/server-gametest/classes/Test.d.ts +++ b/translate-pieces/server-gametest/classes/Test.d.ts @@ -59,7 +59,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample testIfButtonNotPressed.js */ assertBlockState(blockLocation: minecraftserver.Vector3, callback: (arg: minecraftserver.Block) => boolean): void; /** @@ -139,7 +138,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample horseArmorTest.js */ assertEntityHasArmor( entityTypeIdentifier: string, @@ -170,7 +168,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample sheepShearedTest.js */ assertEntityHasComponent( entityTypeIdentifier: string, @@ -265,6 +262,7 @@ export class Test { * * {@link GameTestError} * @seeExample simpleMobTest.ts 3a296de4 + * @seeExample simpleMobGameTest.ts */ assertEntityPresentInArea(entityTypeIdentifier: string, isPresent?: boolean): void; /** @@ -287,7 +285,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample villagerEffectTest.js */ assertEntityState( blockLocation: minecraftserver.Vector3, @@ -349,7 +346,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample findFeathers.js */ assertItemEntityCountIs( itemType: minecraftserver.ItemType | string, @@ -722,6 +718,7 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} + * @seeExample minibiomes.ts */ setBlockType(blockType: minecraftserver.BlockType | string, blockLocation: minecraftserver.Vector3): void; /** @@ -774,7 +771,9 @@ export class Test { * * {@link minecraftserver.GameTestError} * @seeExample simpleMobTest.ts 3a296de4 - * @seeExample spawnAdultPig.js ca50f0aa + * @seeExample simpleMobGameTest.ts + * @seeExample phantomsShouldFlyFromCats.ts + * @seeExample minibiomes.ts */ spawn(entityTypeIdentifier: string, blockLocation: minecraftserver.Vector3): minecraftserver.Entity; /** @@ -794,7 +793,6 @@ export class Test { * @throws This function can throw errors. * * {@link minecraftserver.GameTestError} - * @seeExample spawnAdultPig.js b52912dc */ spawnAtLocation(entityTypeIdentifier: string, location: minecraftserver.Vector3): minecraftserver.Entity; /** @@ -810,7 +808,6 @@ export class Test { * @throws This function can throw errors. * * {@link minecraftserver.GameTestError} - * @seeExample spawnEmeralds.js */ spawnItem(itemStack: minecraftserver.ItemStack, location: minecraftserver.Vector3): minecraftserver.Entity; /** @@ -882,7 +879,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample spreadFromFaceTowardDirection.js */ spreadFromFaceTowardDirection( blockLocation: minecraftserver.Vector3, @@ -966,7 +962,7 @@ export class Test { * Testing callback function that runs. If the function runs * successfully, the test is marked as a success. * @throws This function can throw errors. - * @seeExample simpleMobTest.ts 3a296de4 + * @seeExample simpleMobGameTest.ts */ succeedWhen(callback: () => void): void; /** @@ -1043,6 +1039,8 @@ export class Test { * specified type is present. If false, tests that an entity of * the specified type is not present. * @throws This function can throw errors. + * @seeExample phantomsShouldFlyFromCats.ts + * @seeExample minibiomes.ts */ succeedWhenEntityPresent( entityTypeIdentifier: string, diff --git a/translate-pieces/server-gametest/functions/register.d.ts b/translate-pieces/server-gametest/functions/register.d.ts index 15f36ed..adcbdb0 100644 --- a/translate-pieces/server-gametest/functions/register.d.ts +++ b/translate-pieces/server-gametest/functions/register.d.ts @@ -20,7 +20,7 @@ * Returns a {@link RegistrationBuilder} object where * additional options for this test can be specified via * builder methods. - * @seeExample simpleMobTest.ts 3a296de4 + * @seeExample simpleMobGameTest.ts */ export function register( testClassName: string, diff --git a/translate-pieces/server-net/classes/NetworkBeforeEvents.d.ts b/translate-pieces/server-net/classes/NetworkBeforeEvents.d.ts new file mode 100644 index 0000000..3adec85 --- /dev/null +++ b/translate-pieces/server-net/classes/NetworkBeforeEvents.d.ts @@ -0,0 +1,7 @@ +/* IMPORT */ import { PacketReceiveBeforeEventSignal, PacketSendBeforeEventSignal } from '../index'; + +export class NetworkBeforeEvents { + private constructor(); + readonly packetReceive: PacketReceiveBeforeEventSignal; + readonly packetSend: PacketSendBeforeEventSignal; +} \ No newline at end of file diff --git a/translate-pieces/server-net/classes/PacketReceiveBeforeEventSignal.d.ts b/translate-pieces/server-net/classes/PacketReceiveBeforeEventSignal.d.ts new file mode 100644 index 0000000..c60e931 --- /dev/null +++ b/translate-pieces/server-net/classes/PacketReceiveBeforeEventSignal.d.ts @@ -0,0 +1,24 @@ +/* IMPORT */ import { PacketEventOptions, PacketReceivedBeforeEvent } from '../index'; + +export class PacketReceiveBeforeEventSignal { + private constructor(); + /** + * @remarks + * This function can't be called in read-only mode. + * + * This function can be called in early-execution mode. + * + */ + subscribe( + callback: (arg: PacketReceivedBeforeEvent) => void, + options?: PacketEventOptions, + ): (arg: PacketReceivedBeforeEvent) => void; + /** + * @remarks + * This function can't be called in read-only mode. + * + * This function can be called in early-execution mode. + * + */ + unsubscribe(callback: (arg: PacketReceivedBeforeEvent) => void): void; +} \ No newline at end of file diff --git a/translate-pieces/server-net/classes/PacketReceivedBeforeEvent.d.ts b/translate-pieces/server-net/classes/PacketReceivedBeforeEvent.d.ts new file mode 100644 index 0000000..33229d0 --- /dev/null +++ b/translate-pieces/server-net/classes/PacketReceivedBeforeEvent.d.ts @@ -0,0 +1,29 @@ +/* IMPORT */ import { PacketId, minecraftserver } from '../index'; + +/** + * Sent as the server receives a network packet from a client. + * If cancelled, the server will not parse the network packet + * and will silently ignore it. + */ +export class PacketReceivedBeforeEvent { + private constructor(); + cancel: boolean; + /** + * @remarks + * The type of network packet. + * + */ + readonly packetId: PacketId; + /** + * @remarks + * The size of the network packet in bytes. + * + */ + readonly packetSize: number; + /** + * @remarks + * Which client sent the network packet to the game server. + * + */ + readonly sender?: minecraftserver.Player; +} \ No newline at end of file diff --git a/translate-pieces/server-net/classes/PacketSendBeforeEvent.d.ts b/translate-pieces/server-net/classes/PacketSendBeforeEvent.d.ts new file mode 100644 index 0000000..17ad3e0 --- /dev/null +++ b/translate-pieces/server-net/classes/PacketSendBeforeEvent.d.ts @@ -0,0 +1,23 @@ +/* IMPORT */ import { PacketId, minecraftserver } from '../index'; + +/** + * Sent as the server sends a network packet to clients. If + * cancelled, the server will not send the network packet to + * the receiving clients. + */ +export class PacketSendBeforeEvent { + private constructor(); + cancel: boolean; + /** + * @remarks + * The type of network packet. + * + */ + readonly packetId: PacketId; + /** + * @remarks + * Which clients the network packet is being sent to. + * + */ + readonly recipients: minecraftserver.Player[]; +} \ No newline at end of file diff --git a/translate-pieces/server-net/classes/PacketSendBeforeEventSignal.d.ts b/translate-pieces/server-net/classes/PacketSendBeforeEventSignal.d.ts new file mode 100644 index 0000000..d12d9de --- /dev/null +++ b/translate-pieces/server-net/classes/PacketSendBeforeEventSignal.d.ts @@ -0,0 +1,24 @@ +/* IMPORT */ import { PacketEventOptions, PacketSendBeforeEvent } from '../index'; + +export class PacketSendBeforeEventSignal { + private constructor(); + /** + * @remarks + * This function can't be called in read-only mode. + * + * This function can be called in early-execution mode. + * + */ + subscribe( + callback: (arg: PacketSendBeforeEvent) => void, + options?: PacketEventOptions, + ): (arg: PacketSendBeforeEvent) => void; + /** + * @remarks + * This function can't be called in read-only mode. + * + * This function can be called in early-execution mode. + * + */ + unsubscribe(callback: (arg: PacketSendBeforeEvent) => void): void; +} \ No newline at end of file diff --git a/translate-pieces/server-net/enums/PacketId.d.ts b/translate-pieces/server-net/enums/PacketId.d.ts new file mode 100644 index 0000000..562f1af --- /dev/null +++ b/translate-pieces/server-net/enums/PacketId.d.ts @@ -0,0 +1,208 @@ +/** + * Represents the unique type of network packet. + */ +export enum PacketId { + ActorEventPacket = 'ActorEventPacket', + ActorPickRequestPacket = 'ActorPickRequestPacket', + AddActorPacket = 'AddActorPacket', + AddBehaviorTreePacket = 'AddBehaviorTreePacket', + AddItemActorPacket = 'AddItemActorPacket', + AddPaintingPacket = 'AddPaintingPacket', + AddPlayerPacket = 'AddPlayerPacket', + AddVolumeEntityPacket = 'AddVolumeEntityPacket', + AgentActionEventPacket = 'AgentActionEventPacket', + AgentAnimationPacket = 'AgentAnimationPacket', + AnimateEntityPacket = 'AnimateEntityPacket', + AnimatePacket = 'AnimatePacket', + AnvilDamagePacket = 'AnvilDamagePacket', + AvailableActorIdentifiersPacket = 'AvailableActorIdentifiersPacket', + AvailableCommandsPacket = 'AvailableCommandsPacket', + AwardAchievementPacket = 'AwardAchievementPacket', + BiomeDefinitionList = 'BiomeDefinitionList', + BlockActorDataPacket = 'BlockActorDataPacket', + BlockEventPacket = 'BlockEventPacket', + BlockPickRequestPacket = 'BlockPickRequestPacket', + BookEditPacket = 'BookEditPacket', + BossEventPacket = 'BossEventPacket', + CameraAimAssistPacket = 'CameraAimAssistPacket', + CameraAimAssistPresetsPacket = 'CameraAimAssistPresetsPacket', + CameraInstructionPacket = 'CameraInstructionPacket', + CameraPacket = 'CameraPacket', + CameraPresetsPacket = 'CameraPresetsPacket', + CameraShakePacket = 'CameraShakePacket', + ChangeDimensionPacket = 'ChangeDimensionPacket', + ChangeMobPropertyPacket = 'ChangeMobPropertyPacket', + ChunkRadiusUpdatedPacket = 'ChunkRadiusUpdatedPacket', + ClientboundCloseFormPacket = 'ClientboundCloseFormPacket', + ClientboundDebugRendererPacket = 'ClientboundDebugRendererPacket', + ClientCacheBlobStatusPacket = 'ClientCacheBlobStatusPacket', + ClientCacheMissResponsePacket = 'ClientCacheMissResponsePacket', + ClientCacheStatusPacket = 'ClientCacheStatusPacket', + ClientToServerHandshakePacket = 'ClientToServerHandshakePacket', + CodeBuilderPacket = 'CodeBuilderPacket', + CodeBuilderSourcePacket = 'CodeBuilderSourcePacket', + CommandBlockUpdatePacket = 'CommandBlockUpdatePacket', + CommandOutputPacket = 'CommandOutputPacket', + CommandRequestPacket = 'CommandRequestPacket', + CompletedUsingItemPacket = 'CompletedUsingItemPacket', + CompressedBiomeDefinitionList = 'CompressedBiomeDefinitionList', + ContainerClosePacket = 'ContainerClosePacket', + ContainerOpenPacket = 'ContainerOpenPacket', + ContainerRegistryCleanupPacket = 'ContainerRegistryCleanupPacket', + ContainerSetDataPacket = 'ContainerSetDataPacket', + CorrectPlayerMovePredictionPacket = 'CorrectPlayerMovePredictionPacket', + CraftingDataPacket = 'CraftingDataPacket', + CreatePhotoPacket = 'CreatePhotoPacket', + CreativeContentPacket = 'CreativeContentPacket', + CurrentStructureFeaturePacket = 'CurrentStructureFeaturePacket', + DeathInfoPacket = 'DeathInfoPacket', + DebugInfoPacket = 'DebugInfoPacket', + DimensionDataPacket = 'DimensionDataPacket', + DisconnectPacket = 'DisconnectPacket', + EditorNetworkPacket = 'EditorNetworkPacket', + EducationSettingsPacket = 'EducationSettingsPacket', + EduUriResourcePacket = 'EduUriResourcePacket', + EmoteListPacket = 'EmoteListPacket', + EmotePacket = 'EmotePacket', + FeatureRegistryPacket = 'FeatureRegistryPacket', + GameRulesChangedPacket = 'GameRulesChangedPacket', + GameTestRequestPacket = 'GameTestRequestPacket', + GameTestResultsPacket = 'GameTestResultsPacket', + GuiDataPickItemPacket = 'GuiDataPickItemPacket', + HurtArmorPacket = 'HurtArmorPacket', + InteractPacket = 'InteractPacket', + InventoryContentPacket = 'InventoryContentPacket', + InventorySlotPacket = 'InventorySlotPacket', + InventoryTransactionPacket = 'InventoryTransactionPacket', + ItemComponentPacket = 'ItemComponentPacket', + ItemStackRequestPacket = 'ItemStackRequestPacket', + ItemStackResponse = 'ItemStackResponse', + JigsawStructureDataPacket = 'JigsawStructureDataPacket', + LabTablePacket = 'LabTablePacket', + LecternUpdatePacket = 'LecternUpdatePacket', + LegacyTelemetryEventPacket = 'LegacyTelemetryEventPacket', + LessonProgressPacket = 'LessonProgressPacket', + LevelChunkPacket = 'LevelChunkPacket', + LevelEventGenericPacket = 'LevelEventGenericPacket', + LevelEventPacket = 'LevelEventPacket', + LevelSoundEventPacket = 'LevelSoundEventPacket', + LevelSoundEventPacketV1 = 'LevelSoundEventPacketV1', + LevelSoundEventPacketV2 = 'LevelSoundEventPacketV2', + LoginPacket = 'LoginPacket', + MapCreateLockedCopyPacket = 'MapCreateLockedCopyPacket', + MapInfoRequestPacket = 'MapInfoRequestPacket', + MapItemDataPacket = 'MapItemDataPacket', + MobArmorEquipmentPacket = 'MobArmorEquipmentPacket', + MobEffectPacket = 'MobEffectPacket', + MobEquipmentPacket = 'MobEquipmentPacket', + ModalFormRequestPacket = 'ModalFormRequestPacket', + ModalFormResponsePacket = 'ModalFormResponsePacket', + MotionPredictionHintsPacket = 'MotionPredictionHintsPacket', + MoveActorAbsolutePacket = 'MoveActorAbsolutePacket', + MoveActorDeltaPacket = 'MoveActorDeltaPacket', + MovementEffectPacket = 'MovementEffectPacket', + MovePlayerPacket = 'MovePlayerPacket', + MultiplayerSettingsPacket = 'MultiplayerSettingsPacket', + NetworkChunkPublisherUpdatePacket = 'NetworkChunkPublisherUpdatePacket', + NetworkSettingsPacket = 'NetworkSettingsPacket', + NetworkStackLatencyPacket = 'NetworkStackLatencyPacket', + NpcDialoguePacket = 'NpcDialoguePacket', + NpcRequestPacket = 'NpcRequestPacket', + OnScreenTextureAnimationPacket = 'OnScreenTextureAnimationPacket', + OpenSignPacket = 'OpenSignPacket', + PacketViolationWarningPacket = 'PacketViolationWarningPacket', + PassengerJumpPacket = 'PassengerJumpPacket', + PhotoTransferPacket = 'PhotoTransferPacket', + PlayerActionPacket = 'PlayerActionPacket', + PlayerArmorDamagePacket = 'PlayerArmorDamagePacket', + PlayerAuthInputPacket = 'PlayerAuthInputPacket', + PlayerEnchantOptionsPacket = 'PlayerEnchantOptionsPacket', + PlayerFogPacket = 'PlayerFogPacket', + PlayerHotbarPacket = 'PlayerHotbarPacket', + PlayerInputPacket = 'PlayerInputPacket', + PlayerListPacket = 'PlayerListPacket', + PlayerSkinPacket = 'PlayerSkinPacket', + PlayerStartItemCooldownPacket = 'PlayerStartItemCooldownPacket', + PlayerToggleCrafterSlotRequestPacket = 'PlayerToggleCrafterSlotRequestPacket', + PlaySoundPacket = 'PlaySoundPacket', + PlayStatusPacket = 'PlayStatusPacket', + PositionTrackingDBClientRequestPacket = 'PositionTrackingDBClientRequestPacket', + PositionTrackingDBServerBroadcast = 'PositionTrackingDBServerBroadcast', + PurchaseReceiptPacket = 'PurchaseReceiptPacket', + RefreshEntitlementsPacket = 'RefreshEntitlementsPacket', + RemoveActorPacket = 'RemoveActorPacket', + RemoveObjectivePacket = 'RemoveObjectivePacket', + RemoveVolumeEntityPacket = 'RemoveVolumeEntityPacket', + RequestAbilityPacket = 'RequestAbilityPacket', + RequestChunkRadiusPacket = 'RequestChunkRadiusPacket', + RequestNetworkSettingsPacket = 'RequestNetworkSettingsPacket', + RequestPermissionsPacket = 'RequestPermissionsPacket', + ResourcePackChunkDataPacket = 'ResourcePackChunkDataPacket', + ResourcePackChunkRequestPacket = 'ResourcePackChunkRequestPacket', + ResourcePackClientResponsePacket = 'ResourcePackClientResponsePacket', + ResourcePackDataInfoPacket = 'ResourcePackDataInfoPacket', + ResourcePacksInfoPacket = 'ResourcePacksInfoPacket', + ResourcePackStackPacket = 'ResourcePackStackPacket', + RespawnPacket = 'RespawnPacket', + ScriptMessagePacket = 'ScriptMessagePacket', + ServerboundDiagnosticsPacket = 'ServerboundDiagnosticsPacket', + ServerboundLoadingScreenPacket = 'ServerboundLoadingScreenPacket', + ServerPlayerPostMovePositionPacket = 'ServerPlayerPostMovePositionPacket', + ServerSettingsRequestPacket = 'ServerSettingsRequestPacket', + ServerSettingsResponsePacket = 'ServerSettingsResponsePacket', + ServerStatsPacket = 'ServerStatsPacket', + ServerToClientHandshakePacket = 'ServerToClientHandshakePacket', + SetActorDataPacket = 'SetActorDataPacket', + SetActorLinkPacket = 'SetActorLinkPacket', + SetActorMotionPacket = 'SetActorMotionPacket', + SetCommandsEnabledPacket = 'SetCommandsEnabledPacket', + SetDefaultGameTypePacket = 'SetDefaultGameTypePacket', + SetDifficultyPacket = 'SetDifficultyPacket', + SetDisplayObjectivePacket = 'SetDisplayObjectivePacket', + SetHealthPacket = 'SetHealthPacket', + SetHudPacket = 'SetHudPacket', + SetLastHurtByPacket = 'SetLastHurtByPacket', + SetLocalPlayerAsInitializedPacket = 'SetLocalPlayerAsInitializedPacket', + SetMovementAuthorityPacket = 'SetMovementAuthorityPacket', + SetPlayerGameTypePacket = 'SetPlayerGameTypePacket', + SetPlayerInventoryOptionsPacket = 'SetPlayerInventoryOptionsPacket', + SetScoreboardIdentityPacket = 'SetScoreboardIdentityPacket', + SetScorePacket = 'SetScorePacket', + SetSpawnPositionPacket = 'SetSpawnPositionPacket', + SetTimePacket = 'SetTimePacket', + SettingsCommandPacket = 'SettingsCommandPacket', + SetTitlePacket = 'SetTitlePacket', + ShowCreditsPacket = 'ShowCreditsPacket', + ShowProfilePacket = 'ShowProfilePacket', + ShowStoreOfferPacket = 'ShowStoreOfferPacket', + SimpleEventPacket = 'SimpleEventPacket', + SimulationTypePacket = 'SimulationTypePacket', + SpawnExperienceOrbPacket = 'SpawnExperienceOrbPacket', + SpawnParticleEffectPacket = 'SpawnParticleEffectPacket', + StartGamePacket = 'StartGamePacket', + StopSoundPacket = 'StopSoundPacket', + StructureBlockUpdatePacket = 'StructureBlockUpdatePacket', + StructureTemplateDataExportPacket = 'StructureTemplateDataExportPacket', + StructureTemplateDataRequestPacket = 'StructureTemplateDataRequestPacket', + SubChunkPacket = 'SubChunkPacket', + SubChunkRequestPacket = 'SubChunkRequestPacket', + SubClientLoginPacket = 'SubClientLoginPacket', + SyncActorPropertyPacket = 'SyncActorPropertyPacket', + TakeItemActorPacket = 'TakeItemActorPacket', + TextPacket = 'TextPacket', + TickingAreasLoadStatusPacket = 'TickingAreasLoadStatusPacket', + ToastRequestPacket = 'ToastRequestPacket', + TransferPacket = 'TransferPacket', + TrimDataPacket = 'TrimDataPacket', + UnlockedRecipesPacket = 'UnlockedRecipesPacket', + UpdateAbilitiesPacket = 'UpdateAbilitiesPacket', + UpdateAdventureSettingsPacket = 'UpdateAdventureSettingsPacket', + UpdateAttributesPacket = 'UpdateAttributesPacket', + UpdateBlockPacket = 'UpdateBlockPacket', + UpdateBlockSyncedPacket = 'UpdateBlockSyncedPacket', + UpdateClientInputLocksPacket = 'UpdateClientInputLocksPacket', + UpdatePlayerGameTypePacket = 'UpdatePlayerGameTypePacket', + UpdateSoftEnumPacket = 'UpdateSoftEnumPacket', + UpdateSubChunkBlocksPacket = 'UpdateSubChunkBlocksPacket', + WSConnectPacket = 'WSConnectPacket', +} \ No newline at end of file diff --git a/translate-pieces/server-net/index.d.ts b/translate-pieces/server-net/index.d.ts index 90061b3..b5e16d8 100644 --- a/translate-pieces/server-net/index.d.ts +++ b/translate-pieces/server-net/index.d.ts @@ -1,10 +1,20 @@ import * as minecraftcommon from '../common'; +import * as minecraftserver from '../server'; import * as minecraftserveradmin from '../server-admin'; /* PRIVATE */ export { minecraftcommon }; +/* PRIVATE */ export { minecraftserver }; /* PRIVATE */ export { minecraftserveradmin }; export { HttpRequestMethod } from './enums/HttpRequestMethod'; +export { PacketId } from './enums/PacketId'; export { HttpClient } from './classes/HttpClient'; export { HttpHeader } from './classes/HttpHeader'; export { HttpRequest } from './classes/HttpRequest'; export { HttpResponse } from './classes/HttpResponse'; +export { NetworkBeforeEvents } from './classes/NetworkBeforeEvents'; +export { PacketReceiveBeforeEventSignal } from './classes/PacketReceiveBeforeEventSignal'; +export { PacketReceivedBeforeEvent } from './classes/PacketReceivedBeforeEvent'; +export { PacketSendBeforeEvent } from './classes/PacketSendBeforeEvent'; +export { PacketSendBeforeEventSignal } from './classes/PacketSendBeforeEventSignal'; +export { PacketEventOptions } from './interfaces/PacketEventOptions'; +export { beforeEvents } from './variables/beforeEvents'; export { http } from './variables/http'; \ No newline at end of file diff --git a/translate-pieces/server-net/interfaces/PacketEventOptions.d.ts b/translate-pieces/server-net/interfaces/PacketEventOptions.d.ts new file mode 100644 index 0000000..ce28f47 --- /dev/null +++ b/translate-pieces/server-net/interfaces/PacketEventOptions.d.ts @@ -0,0 +1,21 @@ +/* IMPORT */ import { PacketId } from '../index'; + +/** + * Options for events triggered by network packets. + */ +export interface PacketEventOptions { + /** + * @remarks + * If provided, packet IDs in this list will not trigger the + * event subscriptions. + * + */ + ignoredPacketIds?: PacketId[]; + /** + * @remarks + * If provided only packet IDs in this list will trigger the + * event subscriptions. + * + */ + monitoredPacketIds?: PacketId[]; +} \ No newline at end of file diff --git a/translate-pieces/server-net/variables/beforeEvents.d.ts b/translate-pieces/server-net/variables/beforeEvents.d.ts new file mode 100644 index 0000000..24a1500 --- /dev/null +++ b/translate-pieces/server-net/variables/beforeEvents.d.ts @@ -0,0 +1,3 @@ +/* IMPORT */ import { NetworkBeforeEvents } from '../index'; + +export const beforeEvents: NetworkBeforeEvents; \ No newline at end of file diff --git a/translate-pieces/server-ui/classes/ActionFormData.d.ts b/translate-pieces/server-ui/classes/ActionFormData.d.ts index 39470bf..78fa243 100644 --- a/translate-pieces/server-ui/classes/ActionFormData.d.ts +++ b/translate-pieces/server-ui/classes/ActionFormData.d.ts @@ -3,7 +3,8 @@ /** * Builds a simple player form with buttons that let the player * take action. - * @seeExample actionFormAskFavoriteMonth.ts + * @seeExample showActionForm.ts + * @seeExample showFavoriteMonth.ts */ export class ActionFormData { /** diff --git a/translate-pieces/server-ui/classes/ActionFormResponse.d.ts b/translate-pieces/server-ui/classes/ActionFormResponse.d.ts index 8e9d5f1..2b11762 100644 --- a/translate-pieces/server-ui/classes/ActionFormResponse.d.ts +++ b/translate-pieces/server-ui/classes/ActionFormResponse.d.ts @@ -3,7 +3,8 @@ /** * Returns data about the player results from a modal action * form. - * @seeExample actionFormAskFavoriteMonth.ts + * @seeExample showActionForm.ts + * @seeExample showFavoriteMonth.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class ActionFormResponse extends FormResponse { diff --git a/translate-pieces/server-ui/classes/MessageFormData.d.ts b/translate-pieces/server-ui/classes/MessageFormData.d.ts index 394ae6b..40fc78c 100644 --- a/translate-pieces/server-ui/classes/MessageFormData.d.ts +++ b/translate-pieces/server-ui/classes/MessageFormData.d.ts @@ -2,7 +2,8 @@ /** * Builds a simple two-button modal dialog. - * @seeExample messageFormSimple.ts + * @seeExample showBasicMessageForm.ts + * @seeExample showTranslatedMessageForm.ts */ export class MessageFormData { /** diff --git a/translate-pieces/server-ui/classes/MessageFormResponse.d.ts b/translate-pieces/server-ui/classes/MessageFormResponse.d.ts index 950675f..eb4ef75 100644 --- a/translate-pieces/server-ui/classes/MessageFormResponse.d.ts +++ b/translate-pieces/server-ui/classes/MessageFormResponse.d.ts @@ -3,7 +3,8 @@ /** * Returns data about the player results from a modal message * form. - * @seeExample messageFormSimple.ts + * @seeExample showBasicMessageForm.ts + * @seeExample showTranslatedMessageForm.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class MessageFormResponse extends FormResponse { diff --git a/translate-pieces/server-ui/classes/ModalFormData.d.ts b/translate-pieces/server-ui/classes/ModalFormData.d.ts index 4cf1122..11c7648 100644 --- a/translate-pieces/server-ui/classes/ModalFormData.d.ts +++ b/translate-pieces/server-ui/classes/ModalFormData.d.ts @@ -3,7 +3,7 @@ /** * Used to create a fully customizable pop-up form for a * player. - * @seeExample modalFormSimple.ts + * @seeExample showBasicModalForm.ts */ export class ModalFormData { /** diff --git a/translate-pieces/server-ui/classes/ModalFormResponse.d.ts b/translate-pieces/server-ui/classes/ModalFormResponse.d.ts index 9a0e710..4fdc569 100644 --- a/translate-pieces/server-ui/classes/ModalFormResponse.d.ts +++ b/translate-pieces/server-ui/classes/ModalFormResponse.d.ts @@ -2,7 +2,7 @@ /** * Returns data about player responses to a modal form. - * @seeExample modalFormSimple.ts + * @seeExample showBasicModalForm.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class ModalFormResponse extends FormResponse { diff --git a/translate-pieces/server-ui/package.d.ts b/translate-pieces/server-ui/package.d.ts index e423754..6b307de 100644 --- a/translate-pieces/server-ui/package.d.ts +++ b/translate-pieces/server-ui/package.d.ts @@ -13,7 +13,6 @@ * * {@link ModalFormData} allow for a more flexible * "questionnaire-style" list of controls that can be used to * take input. - * @seeExample createActionForm.js * * Manifest Details * ```json diff --git a/translate-pieces/server/classes/Block.d.ts b/translate-pieces/server/classes/Block.d.ts index 3b1879f..42d9dd8 100644 --- a/translate-pieces/server/classes/Block.d.ts +++ b/translate-pieces/server/classes/Block.d.ts @@ -301,7 +301,7 @@ export class Block { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} - * @seeExample check_block_tags.js d8a9d838 + * @seeExample checkBlockTags.ts */ hasTag(tag: string): boolean; /** diff --git a/translate-pieces/server/classes/BlockInventoryComponent.d.ts b/translate-pieces/server/classes/BlockInventoryComponent.d.ts index 7cb0f39..98b8b46 100644 --- a/translate-pieces/server/classes/BlockInventoryComponent.d.ts +++ b/translate-pieces/server/classes/BlockInventoryComponent.d.ts @@ -3,7 +3,7 @@ /** * Represents the inventory of a block in the world. Used with * blocks like chests. - * @seeExample place_items_in_chest.js + * @seeExample placeItemsInChest.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class BlockInventoryComponent extends BlockComponent { diff --git a/translate-pieces/server/classes/BlockPermutation.d.ts b/translate-pieces/server/classes/BlockPermutation.d.ts index 802b0a3..0de24bc 100644 --- a/translate-pieces/server/classes/BlockPermutation.d.ts +++ b/translate-pieces/server/classes/BlockPermutation.d.ts @@ -5,7 +5,7 @@ * properties (also sometimes called block state) which * describe a block (but does not belong to a specific {@link * Block}). - * @seeExample createTranslatedSign.ts + * @seeExample addTranslatedSign.ts 604a92ba */ export class BlockPermutation { private constructor(); @@ -61,7 +61,7 @@ export class BlockPermutation { * * @returns * Returns `true` if the permutation has the tag, else `false`. - * @seeExample check_block_tags.js 25c0e459 + * @seeExample checkBlockTags.ts */ hasTag(tag: string): boolean; /** diff --git a/translate-pieces/server/classes/BlockSignComponent.d.ts b/translate-pieces/server/classes/BlockSignComponent.d.ts index a0c6691..178d09a 100644 --- a/translate-pieces/server/classes/BlockSignComponent.d.ts +++ b/translate-pieces/server/classes/BlockSignComponent.d.ts @@ -2,9 +2,10 @@ /** * Represents a block that can display text on it. + * @seeExample addSign.ts * @seeExample addTwoSidedSign.ts - * @seeExample setSignText.ts - * @seeExample createTranslatedSign.ts + * @seeExample updateSignText.ts + * @seeExample addTranslatedSign.ts 604a92ba */ // @ts-ignore Class inheritance allowed for native defined classes export class BlockSignComponent extends BlockComponent { @@ -74,7 +75,6 @@ export class BlockSignComponent extends BlockComponent { * @throws * Throws if the provided message is greater than 512 * characters in length. - * @seeExample setSignText.ts */ setText(message: RawMessage | RawText | string, side?: SignSide): void; /** diff --git a/translate-pieces/server/classes/ChatSendAfterEventSignal.d.ts b/translate-pieces/server/classes/ChatSendAfterEventSignal.d.ts index 5a1ecd7..e148756 100644 --- a/translate-pieces/server/classes/ChatSendAfterEventSignal.d.ts +++ b/translate-pieces/server/classes/ChatSendAfterEventSignal.d.ts @@ -16,7 +16,6 @@ export class ChatSendAfterEventSignal { * * This function can be called in early-execution mode. * - * @seeExample custom_command.js */ subscribe(callback: (arg: ChatSendAfterEvent) => void): (arg: ChatSendAfterEvent) => void; /** diff --git a/translate-pieces/server/classes/ChatSendBeforeEventSignal.d.ts b/translate-pieces/server/classes/ChatSendBeforeEventSignal.d.ts index 4353a18..ecfe76d 100644 --- a/translate-pieces/server/classes/ChatSendBeforeEventSignal.d.ts +++ b/translate-pieces/server/classes/ChatSendBeforeEventSignal.d.ts @@ -4,6 +4,7 @@ * @beta * Manages callbacks that are connected to an event that fires * before chat messages are sent. + * @seeExample customCommand.ts */ export class ChatSendBeforeEventSignal { private constructor(); diff --git a/translate-pieces/server/classes/Container.d.ts b/translate-pieces/server/classes/Container.d.ts index 51ebb20..318b9a5 100644 --- a/translate-pieces/server/classes/Container.d.ts +++ b/translate-pieces/server/classes/Container.d.ts @@ -4,7 +4,7 @@ * Represents a container that can hold sets of items. Used * with entities such as Players, Chest Minecarts, Llamas, and * more. - * @seeExample containers.js + * @seeExample containers.ts */ export class Container { private constructor(); @@ -64,7 +64,7 @@ export class Container { * @throws * Throws if the container is invalid or if the `slot` index is * out of bounds. - * @seeExample getItem.ts + * @seeExample getFirstHotbarItem.ts */ getItem(slot: number): ItemStack | undefined; /** @@ -107,7 +107,7 @@ export class Container { * @throws * Throws if either this container or `toContainer` are invalid * or if the `fromSlot` or `toSlot` indices out of bounds. - * @seeExample moveItem.ts + * @seeExample moveBetweenContainers.ts */ moveItem(fromSlot: number, toSlot: number, toContainer: Container): void; /** @@ -142,7 +142,6 @@ export class Container { * @throws * Throws if either this container or `otherContainer` are * invalid or if the `slot` or `otherSlot` are out of bounds. - * @seeExample swapItems.ts */ swapItems(slot: number, otherSlot: number, otherContainer: Container): void; /** @@ -164,7 +163,7 @@ export class Container { * @throws * Throws if either this container or `toContainer` are invalid * or if the `fromSlot` or `toSlot` indices out of bounds. - * @seeExample transferItem.ts + * @seeExample transferBetweenContainers.ts */ transferItem(fromSlot: number, toContainer: Container): ItemStack | undefined; } \ No newline at end of file diff --git a/translate-pieces/server/classes/Dimension.d.ts b/translate-pieces/server/classes/Dimension.d.ts index 163a26b..3126c34 100644 --- a/translate-pieces/server/classes/Dimension.d.ts +++ b/translate-pieces/server/classes/Dimension.d.ts @@ -62,6 +62,8 @@ export class Dimension { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} + * @seeExample createExplosion.ts + * @seeExample createNoBlockExplosion.ts * @seeExample createExplosions.ts */ createExplosion(location: Vector3, radius: number, explosionOptions?: ExplosionOptions): boolean; @@ -209,8 +211,9 @@ export class Dimension { * @returns * An entity array. * @throws This function can throw errors. - * @seeExample checkFeatherNearby.ts + * @seeExample bounceSkeletons.ts * @seeExample tagsQuery.ts + * @seeExample testThatEntityIsFeatherItem.ts */ getEntities(options?: EntityQueryOptions): Entity[]; /** @@ -290,7 +293,6 @@ export class Dimension { * An error will be thrown if fade is less than 0.0. * An error will be thrown if pitch is less than 0.01. * An error will be thrown if volume is less than 0.0. - * @seeExample playMusicAndSound.ts */ playSound(soundId: string, location: Vector3, soundOptions?: WorldSoundOptions): void; /** @@ -414,8 +416,9 @@ export class Dimension { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} - * @seeExample createOldHorse.ts + * @seeExample spawnAdultHorse.ts * @seeExample quickFoxLazyDog.ts + * @seeExample triggerEvent.ts b473e4eb */ spawnEntity(identifier: string, location: Vector3, options?: SpawnEntityOptions): Entity; /** @@ -434,6 +437,7 @@ export class Dimension { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} + * @seeExample itemStacks.ts * @seeExample spawnFeatherItem.ts */ spawnItem(itemStack: ItemStack, location: Vector3): Entity; @@ -456,7 +460,7 @@ export class Dimension { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} - * @seeExample spawnParticle.ts 4689acc9 + * @seeExample spawnParticle.ts 25a384c8 */ spawnParticle(effectName: string, location: Vector3, molangVariables?: MolangVariableMap): void; } \ No newline at end of file diff --git a/translate-pieces/server/classes/Entity.d.ts b/translate-pieces/server/classes/Entity.d.ts index 0c6a4b2..6b8ea99 100644 --- a/translate-pieces/server/classes/Entity.d.ts +++ b/translate-pieces/server/classes/Entity.d.ts @@ -152,7 +152,7 @@ export class Entity { * amplifier are outside of the valid ranges, or if the effect * does not exist. * @throws This function can throw errors. - * @seeExample poisonVillager.ts + * @seeExample spawnPoisonedVillager.ts * @seeExample quickFoxLazyDog.ts */ addEffect(effectType: EffectType | string, duration: number, options?: EntityEffectOptions): Effect | undefined; @@ -169,6 +169,7 @@ export class Entity { * Returns true if the tag was added successfully. This can * fail if the tag already exists on the entity. * @throws This function can throw errors. + * @seeExample tagsQuery.ts */ addTag(tag: string): boolean; /** @@ -201,7 +202,7 @@ export class Entity { * @param vector * Impulse vector. * @throws This function can throw errors. - * @seeExample yeetEntity.ts + * @seeExample applyImpulse.ts */ applyImpulse(vector: Vector3): void; /** @@ -239,7 +240,7 @@ export class Entity { * This function can't be called in read-only mode. * * @throws This function can throw errors. - * @seeExample yeetEntity.ts + * @seeExample applyImpulse.ts */ clearVelocity(): void; /** @@ -256,7 +257,7 @@ export class Entity { * @returns * Returns whether the entity was on fire. * @throws This function can throw errors. - * @seeExample setEntityOnFire.ts + * @seeExample setOnFire.ts */ extinguishFire(useEffects?: boolean): boolean; /** @@ -482,6 +483,22 @@ export class Entity { * @seeExample tagsQuery.ts */ kill(): boolean; + /** + * @beta + * @remarks + * Sets the rotation of the entity to face a target location. + * Both pitch and yaw will be set, if applicable, such as for + * mobs where the pitch controls the head tilt and the yaw + * controls the body rotation. + * + * This function can't be called in read-only mode. + * + * @param targetLocation + * The target location that this entity should face/look + * towards. + * @throws This function can throw errors. + */ + lookAt(targetLocation: Vector3): void; /** * @remarks * Matches the entity against the passed in options. Uses the @@ -637,7 +654,7 @@ export class Entity { * is less than or equal to zero, the entity is wet or the * entity is immune to fire. * @throws This function can throw errors. - * @seeExample setEntityOnFire.ts + * @seeExample setOnFire.ts */ setOnFire(seconds: number, useEffects?: boolean): boolean; /** @@ -687,6 +704,7 @@ export class Entity { * @param teleportOptions * Options regarding the teleport operation. * @throws This function can throw errors. + * @seeExample teleport.ts * @seeExample teleportMovement.ts */ teleport(location: Vector3, teleportOptions?: TeleportOptions): void; @@ -705,7 +723,8 @@ export class Entity { * @throws * If the event is not defined in the definition of the entity, * an error will be thrown. - * @seeExample triggerEvent.ts + * @seeExample triggerEvent.ts e0d38a47 + * @seeExample triggerEvent.ts b473e4eb */ triggerEvent(eventName: string): void; /** diff --git a/translate-pieces/server/classes/EntityEquippableComponent.d.ts b/translate-pieces/server/classes/EntityEquippableComponent.d.ts index ccfea08..5d32371 100644 --- a/translate-pieces/server/classes/EntityEquippableComponent.d.ts +++ b/translate-pieces/server/classes/EntityEquippableComponent.d.ts @@ -4,7 +4,6 @@ * Provides access to a mob's equipment slots. This component * exists for all mob entities. * @seeExample givePlayerElytra.ts - * @seeExample givePlayerEquipment.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class EntityEquippableComponent extends EntityComponent { diff --git a/translate-pieces/server/classes/EntityItemComponent.d.ts b/translate-pieces/server/classes/EntityItemComponent.d.ts index 9b87c61..4b54892 100644 --- a/translate-pieces/server/classes/EntityItemComponent.d.ts +++ b/translate-pieces/server/classes/EntityItemComponent.d.ts @@ -5,7 +5,7 @@ * represents a free-floating item in the world. Lets you * retrieve the actual item stack contents via the itemStack * property. - * @seeExample checkFeatherNearby.ts + * @seeExample testThatEntityIsFeatherItem.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class EntityItemComponent extends EntityComponent { diff --git a/translate-pieces/server/classes/EntityOnFireComponent.d.ts b/translate-pieces/server/classes/EntityOnFireComponent.d.ts index 45f2f15..17b5af2 100644 --- a/translate-pieces/server/classes/EntityOnFireComponent.d.ts +++ b/translate-pieces/server/classes/EntityOnFireComponent.d.ts @@ -2,7 +2,7 @@ /** * When present on an entity, this entity is on fire. - * @seeExample setEntityOnFire.ts + * @seeExample setOnFire.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class EntityOnFireComponent extends EntityComponent { diff --git a/translate-pieces/server/classes/EntityRideableComponent.d.ts b/translate-pieces/server/classes/EntityRideableComponent.d.ts index f51e054..de4a8f4 100644 --- a/translate-pieces/server/classes/EntityRideableComponent.d.ts +++ b/translate-pieces/server/classes/EntityRideableComponent.d.ts @@ -3,6 +3,7 @@ /** * When added, this component adds the capability that an * entity can be ridden by another entity. + * @seeExample minibiomes.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class EntityRideableComponent extends EntityComponent { @@ -74,6 +75,7 @@ export class EntityRideableComponent extends EntityComponent { * @returns * True if the rider entity was successfully added. * @throws This function can throw errors. + * @seeExample minibiomes.ts */ addRider(rider: Entity): boolean; /** diff --git a/translate-pieces/server/classes/EntitySpawnAfterEvent.d.ts b/translate-pieces/server/classes/EntitySpawnAfterEvent.d.ts index 7fd07c0..bed6736 100644 --- a/translate-pieces/server/classes/EntitySpawnAfterEvent.d.ts +++ b/translate-pieces/server/classes/EntitySpawnAfterEvent.d.ts @@ -3,7 +3,7 @@ /** * Contains data related to an entity spawning within the * world. - * @seeExample logEntitySpawnEvents.ts + * @seeExample logEntitySpawnEvent.ts */ export class EntitySpawnAfterEvent { private constructor(); diff --git a/translate-pieces/server/classes/EntitySpawnAfterEventSignal.d.ts b/translate-pieces/server/classes/EntitySpawnAfterEventSignal.d.ts index 1d7f859..b908eda 100644 --- a/translate-pieces/server/classes/EntitySpawnAfterEventSignal.d.ts +++ b/translate-pieces/server/classes/EntitySpawnAfterEventSignal.d.ts @@ -3,7 +3,6 @@ /** * Registers a script-based event handler for handling what * happens when an entity spawns. - * @seeExample logEntitySpawnEvents.ts */ export class EntitySpawnAfterEventSignal { private constructor(); @@ -18,6 +17,7 @@ export class EntitySpawnAfterEventSignal { * * @param callback * Function that handles the spawn event. + * @seeExample logEntitySpawnEvent.ts */ subscribe(callback: (arg: EntitySpawnAfterEvent) => void): (arg: EntitySpawnAfterEvent) => void; /** diff --git a/translate-pieces/server/classes/InputInfo.d.ts b/translate-pieces/server/classes/InputInfo.d.ts index 74bcfee..b43d64a 100644 --- a/translate-pieces/server/classes/InputInfo.d.ts +++ b/translate-pieces/server/classes/InputInfo.d.ts @@ -1,4 +1,4 @@ -/* IMPORT */ import { InputMode, InvalidEntityError } from '../index'; +/* IMPORT */ import { InputMode, InvalidEntityError, minecraftcommon } from '../index'; /** * @beta @@ -12,6 +12,8 @@ export class InputInfo { * * @throws This property can throw when used. * + * {@link minecraftcommon.EngineError} + * * {@link InvalidEntityError} */ readonly lastInputModeUsed: InputMode; diff --git a/translate-pieces/server/classes/ItemDurabilityComponent.d.ts b/translate-pieces/server/classes/ItemDurabilityComponent.d.ts index 40464e9..9c3cfd5 100644 --- a/translate-pieces/server/classes/ItemDurabilityComponent.d.ts +++ b/translate-pieces/server/classes/ItemDurabilityComponent.d.ts @@ -4,6 +4,7 @@ * When present on an item, this item can take damage in the * process of being used. Note that this component only applies * to data-driven items. + * @seeExample giveHurtDiamondSword.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class ItemDurabilityComponent extends ItemComponent { diff --git a/translate-pieces/server/classes/ItemEnchantableComponent.d.ts b/translate-pieces/server/classes/ItemEnchantableComponent.d.ts index 2be0541..389240d 100644 --- a/translate-pieces/server/classes/ItemEnchantableComponent.d.ts +++ b/translate-pieces/server/classes/ItemEnchantableComponent.d.ts @@ -3,7 +3,6 @@ /** * When present on an item, this item can have enchantments * applied to it. - * @seeExample givePlayerIronFireSword.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class ItemEnchantableComponent extends ItemComponent { diff --git a/translate-pieces/server/classes/ItemStack.d.ts b/translate-pieces/server/classes/ItemStack.d.ts index 6fd258e..f675f99 100644 --- a/translate-pieces/server/classes/ItemStack.d.ts +++ b/translate-pieces/server/classes/ItemStack.d.ts @@ -2,7 +2,7 @@ /** * Defines a collection of items. - * @seeExample givePlayerIronFireSword.ts + * @seeExample itemStacks.ts * @seeExample givePlayerEquipment.ts * @seeExample spawnFeatherItem.ts */ @@ -144,7 +144,7 @@ export class ItemStack { * @returns * Returns the component if it exists on the item stack, * otherwise undefined. - * @seeExample durability.ts + * @seeExample giveHurtDiamondSword.ts */ getComponent(componentId: T): ItemComponentTypeMap[T] | undefined; /** @@ -266,7 +266,7 @@ export class ItemStack { * String list of block types that the item can destroy. * @throws * Throws if any of the provided block identifiers are invalid. - * @seeExample giveRestrictedPickaxe.ts + * @seeExample giveDestroyRestrictedPickaxe.ts */ setCanDestroy(blockIdentifiers?: string[]): void; /** @@ -282,7 +282,7 @@ export class ItemStack { * String list of block types that the item can be placed on. * @throws * Throws if any of the provided block identifiers are invalid. - * @seeExample giveRestrictedGoldBlock.ts + * @seeExample givePlaceRestrictedGoldBlock.ts */ setCanPlaceOn(blockIdentifiers?: string[]): void; /** diff --git a/translate-pieces/server/classes/PistonActivateAfterEventSignal.d.ts b/translate-pieces/server/classes/PistonActivateAfterEventSignal.d.ts index e7f5cd5..e3c48b7 100644 --- a/translate-pieces/server/classes/PistonActivateAfterEventSignal.d.ts +++ b/translate-pieces/server/classes/PistonActivateAfterEventSignal.d.ts @@ -2,7 +2,6 @@ /** * Manages callbacks that are connected to piston activations. - * @seeExample pistonAfterEvent.ts */ export class PistonActivateAfterEventSignal { private constructor(); @@ -12,6 +11,7 @@ export class PistonActivateAfterEventSignal { * * This function can be called in early-execution mode. * + * @seeExample pistonAfterEvent.ts */ subscribe(callback: (arg: PistonActivateAfterEvent) => void): (arg: PistonActivateAfterEvent) => void; /** diff --git a/translate-pieces/server/classes/Player.d.ts b/translate-pieces/server/classes/Player.d.ts index 8df20fb..1829fc3 100644 --- a/translate-pieces/server/classes/Player.d.ts +++ b/translate-pieces/server/classes/Player.d.ts @@ -216,6 +216,7 @@ export class Player extends Entity { * @param soundOptions * Additional optional options for the sound. * @throws This function can throw errors. + * @seeExample playMusicAndSound.ts */ playSound(soundId: string, soundOptions?: PlayerSoundOptions): void; /** @@ -266,7 +267,11 @@ export class Player extends Entity { * This method can throw if the provided {@link RawMessage} is * in an invalid format. For example, if an empty `name` string * is provided to `score`. - * @seeExample sendMessagesToPlayer.ts + * @seeExample nestedTranslation.ts + * @seeExample scoreWildcard.ts + * @seeExample sendBasicMessage.ts + * @seeExample sendPlayerMessages.ts + * @seeExample sendTranslatedMessage.ts */ sendMessage(message: (RawMessage | string)[] | RawMessage | string): void; /** diff --git a/translate-pieces/server/classes/Scoreboard.d.ts b/translate-pieces/server/classes/Scoreboard.d.ts index 59ad8ca..3112f05 100644 --- a/translate-pieces/server/classes/Scoreboard.d.ts +++ b/translate-pieces/server/classes/Scoreboard.d.ts @@ -2,6 +2,7 @@ /** * Contains objectives and participants for the scoreboard. + * @seeExample updateScoreboard.ts */ export class Scoreboard { private constructor(); @@ -12,6 +13,7 @@ export class Scoreboard { * This function can't be called in read-only mode. * * @throws This function can throw errors. + * @seeExample updateScoreboard.ts */ addObjective(objectiveId: string, displayName?: string): ScoreboardObjective; /** diff --git a/translate-pieces/server/classes/ScreenDisplay.d.ts b/translate-pieces/server/classes/ScreenDisplay.d.ts index afb23c1..74f0507 100644 --- a/translate-pieces/server/classes/ScreenDisplay.d.ts +++ b/translate-pieces/server/classes/ScreenDisplay.d.ts @@ -5,7 +5,7 @@ * showing up on the screen. * @seeExample setTitle.ts * @seeExample setTitleAndSubtitle.ts - * @seeExample titleCountdown.ts + * @seeExample countdown.ts */ export class ScreenDisplay { private constructor(); @@ -83,7 +83,7 @@ export class ScreenDisplay { * @throws This function can throw errors. * @seeExample setTitle.ts * @seeExample setTitleAndSubtitle.ts - * @seeExample titleCountdown.ts + * @seeExample countdown.ts */ setTitle(title: (RawMessage | string)[] | RawMessage | string, options?: TitleDisplayOptions): void; /** @@ -94,6 +94,7 @@ export class ScreenDisplay { * This function can't be called in read-only mode. * * @throws This function can throw errors. + * @seeExample countdown.ts */ updateSubtitle(subtitle: (RawMessage | string)[] | RawMessage | string): void; } \ No newline at end of file diff --git a/translate-pieces/server/classes/World.d.ts b/translate-pieces/server/classes/World.d.ts index 2eb92f8..fb57e5d 100644 --- a/translate-pieces/server/classes/World.d.ts +++ b/translate-pieces/server/classes/World.d.ts @@ -20,6 +20,7 @@ export class World { * of the world. Event callbacks are called immediately. Event * callbacks are executed in read-only mode. * + * @seeExample customCommand.ts */ readonly beforeEvents: WorldBeforeEvents; /** @@ -236,10 +237,6 @@ export class World { * This method can throw if the provided {@link RawMessage} is * in an invalid format. For example, if an empty `name` string * is provided to `score`. - * @seeExample nestedTranslation.ts - * @seeExample scoreWildcard.ts - * @seeExample simpleString.ts - * @seeExample translation.ts */ sendMessage(message: (RawMessage | string)[] | RawMessage | string): void; /** diff --git a/translate-pieces/server/classes/WorldBeforeEvents.d.ts b/translate-pieces/server/classes/WorldBeforeEvents.d.ts index a504e6e..c6feddd 100644 --- a/translate-pieces/server/classes/WorldBeforeEvents.d.ts +++ b/translate-pieces/server/classes/WorldBeforeEvents.d.ts @@ -15,6 +15,7 @@ export class WorldBeforeEvents { * This event is triggered after a chat message has been * broadcast or sent to players. * + * @seeExample customCommand.ts */ readonly chatSend: ChatSendBeforeEventSignal; /** diff --git a/translate-pieces/server/enums/InputMode.d.ts b/translate-pieces/server/enums/InputMode.d.ts index 6bc28e4..5e4fea1 100644 --- a/translate-pieces/server/enums/InputMode.d.ts +++ b/translate-pieces/server/enums/InputMode.d.ts @@ -27,10 +27,4 @@ export enum InputMode { * */ Touch = 'Touch', - /** - * @remarks - * Input type not detected. - * - */ - Undetermined = 'Undetermined', } \ No newline at end of file diff --git a/translate-pieces/server/interfaces/EntityQueryOptions.d.ts b/translate-pieces/server/interfaces/EntityQueryOptions.d.ts index b0d8559..bf40513 100644 --- a/translate-pieces/server/interfaces/EntityQueryOptions.d.ts +++ b/translate-pieces/server/interfaces/EntityQueryOptions.d.ts @@ -2,12 +2,14 @@ /** * Contains options for selecting entities within an area. - * @seeExample BlockConditional.ts - * @seeExample EntityPropertyOptions.ts - * @seeExample PlaySoundChained.ts - * @seeExample SendMessageAllPlayers.ts - * @seeExample SetScoreBoardChained.ts - * @seeExample SummonMobChained.ts + * @seeExample blockConditional.ts + * @seeExample findEntitiesHavingPropertyEqualsTo.ts + * @seeExample playSoundChained.ts + * @seeExample setScoreboardChained.ts + * @seeExample summonMobChained.ts + * @seeExample bounceSkeletons.ts + * @seeExample tagsQuery.ts + * @seeExample testThatEntityIsFeatherItem.ts */ // @ts-ignore Class inheritance allowed for native defined classes export interface EntityQueryOptions extends EntityFilter { diff --git a/translate-pieces/server/interfaces/ExplosionOptions.d.ts b/translate-pieces/server/interfaces/ExplosionOptions.d.ts index a56ac14..31327cc 100644 --- a/translate-pieces/server/interfaces/ExplosionOptions.d.ts +++ b/translate-pieces/server/interfaces/ExplosionOptions.d.ts @@ -3,6 +3,7 @@ /** * Additional configuration options for the {@link * Dimension.createExplosion} method. + * @seeExample createNoBlockExplosion.ts * @seeExample createExplosions.ts */ export interface ExplosionOptions { diff --git a/translate-pieces/server/interfaces/RawMessage.d.ts b/translate-pieces/server/interfaces/RawMessage.d.ts index b428c99..e9cb455 100644 --- a/translate-pieces/server/interfaces/RawMessage.d.ts +++ b/translate-pieces/server/interfaces/RawMessage.d.ts @@ -2,8 +2,9 @@ /** * Defines a JSON structure that is used for more flexible. - * @seeExample addTranslatedSign.ts + * @seeExample addTranslatedSign.ts 9d3a2d98 * @seeExample showTranslatedMessageForm.ts + * @seeExample addTranslatedSign.ts 604a92ba */ export interface RawMessage { /** diff --git a/translate-pieces/server/interfaces/TeleportOptions.d.ts b/translate-pieces/server/interfaces/TeleportOptions.d.ts index 9e49062..1914ed0 100644 --- a/translate-pieces/server/interfaces/TeleportOptions.d.ts +++ b/translate-pieces/server/interfaces/TeleportOptions.d.ts @@ -2,6 +2,7 @@ /** * Contains additional options for teleporting an entity. + * @seeExample teleport.ts * @seeExample teleportMovement.ts */ export interface TeleportOptions { diff --git a/translated/README.md b/translated/README.md index d47c5ae..e798167 100644 --- a/translated/README.md +++ b/translated/README.md @@ -17,9 +17,9 @@ NPM 包: |[@minecraft/server-gametest](https://www.npmjs.com/package/@minecraft/server-gametest)|`1.0.0-beta`| |[@minecraft/server-net](https://www.npmjs.com/package/@minecraft/server-net)|`1.0.0-beta`| |[@minecraft/server-ui](https://www.npmjs.com/package/@minecraft/server-ui)|`1.4.0-beta`| -|[@minecraft/vanilla-data](https://www.npmjs.com/package/@minecraft/vanilla-data)|`1.21.50-preview.20`| +|[@minecraft/vanilla-data](https://www.npmjs.com/package/@minecraft/vanilla-data)|`1.21.50-preview.24`| -游戏版本号:`1.21.50.20` +游戏版本号:`1.21.50.24` diff --git a/translated/package.json b/translated/package.json index ba49edf..fb15812 100644 --- a/translated/package.json +++ b/translated/package.json @@ -1,15 +1,15 @@ { "dependencies": { "@minecraft/common": "1.2.0", - "@minecraft/debug-utilities": "1.0.0-beta.1.21.50-preview.20", + "@minecraft/debug-utilities": "1.0.0-beta.1.21.50-preview.24", "@minecraft/math": "1.4.0", - "@minecraft/server": "1.17.0-beta.1.21.50-preview.20", - "@minecraft/server-admin": "1.0.0-beta.1.21.50-preview.20", - "@minecraft/server-editor": "0.1.0-beta.1.21.50-preview.20", - "@minecraft/server-gametest": "1.0.0-beta.1.21.50-preview.20", - "@minecraft/server-net": "1.0.0-beta.1.21.50-preview.20", - "@minecraft/server-ui": "1.4.0-beta.1.21.50-preview.20", - "@minecraft/vanilla-data": "1.21.50-preview.20" + "@minecraft/server": "1.17.0-beta.1.21.50-preview.24", + "@minecraft/server-admin": "1.0.0-beta.1.21.50-preview.24", + "@minecraft/server-editor": "0.1.0-beta.1.21.50-preview.24", + "@minecraft/server-gametest": "1.0.0-beta.1.21.50-preview.24", + "@minecraft/server-net": "1.0.0-beta.1.21.50-preview.24", + "@minecraft/server-ui": "1.4.0-beta.1.21.50-preview.24", + "@minecraft/vanilla-data": "1.21.50-preview.24" }, "overrides": { "@minecraft/debug-utilities": { diff --git a/translated/server-admin.d.ts b/translated/server-admin.d.ts index fb14e11..a3ad0e2 100644 --- a/translated/server-admin.d.ts +++ b/translated/server-admin.d.ts @@ -25,6 +25,7 @@ * */ import * as minecraftcommon from '@minecraft/common'; +import * as minecraftserver from '@minecraft/server'; /** * This represents a placeholder object that represents a * secret string. The contents of that string are not available @@ -84,6 +85,21 @@ export class ServerVariables { get(name: string): any | undefined; } +/** + * @remarks + * Transfer player to another server. + * + * This function can't be called in read-only mode. + * + * @param player + * Player to transfer. + * @param host + * Host of the server to transfer to. + * @param port + * Port of the server to transfer to. + * @throws This function can throw errors. + */ +export function transferPlayer(player: minecraftserver.Player, host: string, port: number): void; /** * @remarks * A globally available object that returns a list of diff --git a/translated/server-editor.d.ts b/translated/server-editor.d.ts index 80fa261..3b381f0 100644 --- a/translated/server-editor.d.ts +++ b/translated/server-editor.d.ts @@ -5047,6 +5047,7 @@ export interface IModalToolContainer { */ readonly currentTools: IModalTool[]; addTool(params: ModalToolCreationParameters, action?: RegisteredAction): IModalTool; + focusToolInputContext(): void; getSelectedToolId(): string | undefined; removeTool(id: string): void; setSelectedToolId(id: string | undefined): void; diff --git a/translated/server-gametest.d.ts b/translated/server-gametest.d.ts index a461f1a..1c7b49c 100644 --- a/translated/server-gametest.d.ts +++ b/translated/server-gametest.d.ts @@ -359,6 +359,7 @@ export class RegistrationBuilder { * @returns * RegistrationBuilder object where additional configuration * methods can be called. + * @seeExample phantomsShouldFlyFromCats.ts */ structureName(structureName: string): RegistrationBuilder; /** @@ -373,6 +374,7 @@ export class RegistrationBuilder { * @returns * RegistrationBuilder object where additional configuration * methods can be called. + * @seeExample phantomsShouldFlyFromCats.ts */ tag(tag: string): RegistrationBuilder; } @@ -1045,7 +1047,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample testIfButtonNotPressed.js */ assertBlockState(blockLocation: minecraftserver.Vector3, callback: (arg: minecraftserver.Block) => boolean): void; /** @@ -1125,7 +1126,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample horseArmorTest.js */ assertEntityHasArmor( entityTypeIdentifier: string, @@ -1156,7 +1156,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample sheepShearedTest.js */ assertEntityHasComponent( entityTypeIdentifier: string, @@ -1251,6 +1250,7 @@ export class Test { * * {@link GameTestError} * @seeExample simpleMobTest.ts 3a296de4 + * @seeExample simpleMobGameTest.ts */ assertEntityPresentInArea(entityTypeIdentifier: string, isPresent?: boolean): void; /** @@ -1273,7 +1273,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample villagerEffectTest.js */ assertEntityState( blockLocation: minecraftserver.Vector3, @@ -1335,7 +1334,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample findFeathers.js */ assertItemEntityCountIs( itemType: minecraftserver.ItemType | string, @@ -1708,6 +1706,7 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} + * @seeExample minibiomes.ts */ setBlockType(blockType: minecraftserver.BlockType | string, blockLocation: minecraftserver.Vector3): void; /** @@ -1760,7 +1759,9 @@ export class Test { * * {@link minecraftserver.GameTestError} * @seeExample simpleMobTest.ts 3a296de4 - * @seeExample spawnAdultPig.js ca50f0aa + * @seeExample simpleMobGameTest.ts + * @seeExample phantomsShouldFlyFromCats.ts + * @seeExample minibiomes.ts */ spawn(entityTypeIdentifier: string, blockLocation: minecraftserver.Vector3): minecraftserver.Entity; /** @@ -1780,7 +1781,6 @@ export class Test { * @throws This function can throw errors. * * {@link minecraftserver.GameTestError} - * @seeExample spawnAdultPig.js b52912dc */ spawnAtLocation(entityTypeIdentifier: string, location: minecraftserver.Vector3): minecraftserver.Entity; /** @@ -1796,7 +1796,6 @@ export class Test { * @throws This function can throw errors. * * {@link minecraftserver.GameTestError} - * @seeExample spawnEmeralds.js */ spawnItem(itemStack: minecraftserver.ItemStack, location: minecraftserver.Vector3): minecraftserver.Entity; /** @@ -1868,7 +1867,6 @@ export class Test { * @throws This function can throw errors. * * {@link GameTestError} - * @seeExample spreadFromFaceTowardDirection.js */ spreadFromFaceTowardDirection( blockLocation: minecraftserver.Vector3, @@ -1952,7 +1950,7 @@ export class Test { * Testing callback function that runs. If the function runs * successfully, the test is marked as a success. * @throws This function can throw errors. - * @seeExample simpleMobTest.ts 3a296de4 + * @seeExample simpleMobGameTest.ts */ succeedWhen(callback: () => void): void; /** @@ -2029,6 +2027,8 @@ export class Test { * specified type is present. If false, tests that an entity of * the specified type is not present. * @throws This function can throw errors. + * @seeExample phantomsShouldFlyFromCats.ts + * @seeExample minibiomes.ts */ succeedWhenEntityPresent( entityTypeIdentifier: string, @@ -2178,7 +2178,7 @@ export class GameTestError extends Error { * Returns a {@link RegistrationBuilder} object where * additional options for this test can be specified via * builder methods. - * @seeExample simpleMobTest.ts 3a296de4 + * @seeExample simpleMobGameTest.ts */ export function register( testClassName: string, diff --git a/translated/server-net.d.ts b/translated/server-net.d.ts index 8850130..04084a9 100644 --- a/translated/server-net.d.ts +++ b/translated/server-net.d.ts @@ -24,6 +24,7 @@ * */ import * as minecraftcommon from '@minecraft/common'; +import * as minecraftserver from '@minecraft/server'; import * as minecraftserveradmin from '@minecraft/server-admin'; export enum HttpRequestMethod { /** @@ -69,6 +70,215 @@ export enum HttpRequestMethod { Put = 'Put', } +/** + * Represents the unique type of network packet. + */ +export enum PacketId { + ActorEventPacket = 'ActorEventPacket', + ActorPickRequestPacket = 'ActorPickRequestPacket', + AddActorPacket = 'AddActorPacket', + AddBehaviorTreePacket = 'AddBehaviorTreePacket', + AddItemActorPacket = 'AddItemActorPacket', + AddPaintingPacket = 'AddPaintingPacket', + AddPlayerPacket = 'AddPlayerPacket', + AddVolumeEntityPacket = 'AddVolumeEntityPacket', + AgentActionEventPacket = 'AgentActionEventPacket', + AgentAnimationPacket = 'AgentAnimationPacket', + AnimateEntityPacket = 'AnimateEntityPacket', + AnimatePacket = 'AnimatePacket', + AnvilDamagePacket = 'AnvilDamagePacket', + AvailableActorIdentifiersPacket = 'AvailableActorIdentifiersPacket', + AvailableCommandsPacket = 'AvailableCommandsPacket', + AwardAchievementPacket = 'AwardAchievementPacket', + BiomeDefinitionList = 'BiomeDefinitionList', + BlockActorDataPacket = 'BlockActorDataPacket', + BlockEventPacket = 'BlockEventPacket', + BlockPickRequestPacket = 'BlockPickRequestPacket', + BookEditPacket = 'BookEditPacket', + BossEventPacket = 'BossEventPacket', + CameraAimAssistPacket = 'CameraAimAssistPacket', + CameraAimAssistPresetsPacket = 'CameraAimAssistPresetsPacket', + CameraInstructionPacket = 'CameraInstructionPacket', + CameraPacket = 'CameraPacket', + CameraPresetsPacket = 'CameraPresetsPacket', + CameraShakePacket = 'CameraShakePacket', + ChangeDimensionPacket = 'ChangeDimensionPacket', + ChangeMobPropertyPacket = 'ChangeMobPropertyPacket', + ChunkRadiusUpdatedPacket = 'ChunkRadiusUpdatedPacket', + ClientboundCloseFormPacket = 'ClientboundCloseFormPacket', + ClientboundDebugRendererPacket = 'ClientboundDebugRendererPacket', + ClientCacheBlobStatusPacket = 'ClientCacheBlobStatusPacket', + ClientCacheMissResponsePacket = 'ClientCacheMissResponsePacket', + ClientCacheStatusPacket = 'ClientCacheStatusPacket', + ClientToServerHandshakePacket = 'ClientToServerHandshakePacket', + CodeBuilderPacket = 'CodeBuilderPacket', + CodeBuilderSourcePacket = 'CodeBuilderSourcePacket', + CommandBlockUpdatePacket = 'CommandBlockUpdatePacket', + CommandOutputPacket = 'CommandOutputPacket', + CommandRequestPacket = 'CommandRequestPacket', + CompletedUsingItemPacket = 'CompletedUsingItemPacket', + CompressedBiomeDefinitionList = 'CompressedBiomeDefinitionList', + ContainerClosePacket = 'ContainerClosePacket', + ContainerOpenPacket = 'ContainerOpenPacket', + ContainerRegistryCleanupPacket = 'ContainerRegistryCleanupPacket', + ContainerSetDataPacket = 'ContainerSetDataPacket', + CorrectPlayerMovePredictionPacket = 'CorrectPlayerMovePredictionPacket', + CraftingDataPacket = 'CraftingDataPacket', + CreatePhotoPacket = 'CreatePhotoPacket', + CreativeContentPacket = 'CreativeContentPacket', + CurrentStructureFeaturePacket = 'CurrentStructureFeaturePacket', + DeathInfoPacket = 'DeathInfoPacket', + DebugInfoPacket = 'DebugInfoPacket', + DimensionDataPacket = 'DimensionDataPacket', + DisconnectPacket = 'DisconnectPacket', + EditorNetworkPacket = 'EditorNetworkPacket', + EducationSettingsPacket = 'EducationSettingsPacket', + EduUriResourcePacket = 'EduUriResourcePacket', + EmoteListPacket = 'EmoteListPacket', + EmotePacket = 'EmotePacket', + FeatureRegistryPacket = 'FeatureRegistryPacket', + GameRulesChangedPacket = 'GameRulesChangedPacket', + GameTestRequestPacket = 'GameTestRequestPacket', + GameTestResultsPacket = 'GameTestResultsPacket', + GuiDataPickItemPacket = 'GuiDataPickItemPacket', + HurtArmorPacket = 'HurtArmorPacket', + InteractPacket = 'InteractPacket', + InventoryContentPacket = 'InventoryContentPacket', + InventorySlotPacket = 'InventorySlotPacket', + InventoryTransactionPacket = 'InventoryTransactionPacket', + ItemComponentPacket = 'ItemComponentPacket', + ItemStackRequestPacket = 'ItemStackRequestPacket', + ItemStackResponse = 'ItemStackResponse', + JigsawStructureDataPacket = 'JigsawStructureDataPacket', + LabTablePacket = 'LabTablePacket', + LecternUpdatePacket = 'LecternUpdatePacket', + LegacyTelemetryEventPacket = 'LegacyTelemetryEventPacket', + LessonProgressPacket = 'LessonProgressPacket', + LevelChunkPacket = 'LevelChunkPacket', + LevelEventGenericPacket = 'LevelEventGenericPacket', + LevelEventPacket = 'LevelEventPacket', + LevelSoundEventPacket = 'LevelSoundEventPacket', + LevelSoundEventPacketV1 = 'LevelSoundEventPacketV1', + LevelSoundEventPacketV2 = 'LevelSoundEventPacketV2', + LoginPacket = 'LoginPacket', + MapCreateLockedCopyPacket = 'MapCreateLockedCopyPacket', + MapInfoRequestPacket = 'MapInfoRequestPacket', + MapItemDataPacket = 'MapItemDataPacket', + MobArmorEquipmentPacket = 'MobArmorEquipmentPacket', + MobEffectPacket = 'MobEffectPacket', + MobEquipmentPacket = 'MobEquipmentPacket', + ModalFormRequestPacket = 'ModalFormRequestPacket', + ModalFormResponsePacket = 'ModalFormResponsePacket', + MotionPredictionHintsPacket = 'MotionPredictionHintsPacket', + MoveActorAbsolutePacket = 'MoveActorAbsolutePacket', + MoveActorDeltaPacket = 'MoveActorDeltaPacket', + MovementEffectPacket = 'MovementEffectPacket', + MovePlayerPacket = 'MovePlayerPacket', + MultiplayerSettingsPacket = 'MultiplayerSettingsPacket', + NetworkChunkPublisherUpdatePacket = 'NetworkChunkPublisherUpdatePacket', + NetworkSettingsPacket = 'NetworkSettingsPacket', + NetworkStackLatencyPacket = 'NetworkStackLatencyPacket', + NpcDialoguePacket = 'NpcDialoguePacket', + NpcRequestPacket = 'NpcRequestPacket', + OnScreenTextureAnimationPacket = 'OnScreenTextureAnimationPacket', + OpenSignPacket = 'OpenSignPacket', + PacketViolationWarningPacket = 'PacketViolationWarningPacket', + PassengerJumpPacket = 'PassengerJumpPacket', + PhotoTransferPacket = 'PhotoTransferPacket', + PlayerActionPacket = 'PlayerActionPacket', + PlayerArmorDamagePacket = 'PlayerArmorDamagePacket', + PlayerAuthInputPacket = 'PlayerAuthInputPacket', + PlayerEnchantOptionsPacket = 'PlayerEnchantOptionsPacket', + PlayerFogPacket = 'PlayerFogPacket', + PlayerHotbarPacket = 'PlayerHotbarPacket', + PlayerInputPacket = 'PlayerInputPacket', + PlayerListPacket = 'PlayerListPacket', + PlayerSkinPacket = 'PlayerSkinPacket', + PlayerStartItemCooldownPacket = 'PlayerStartItemCooldownPacket', + PlayerToggleCrafterSlotRequestPacket = 'PlayerToggleCrafterSlotRequestPacket', + PlaySoundPacket = 'PlaySoundPacket', + PlayStatusPacket = 'PlayStatusPacket', + PositionTrackingDBClientRequestPacket = 'PositionTrackingDBClientRequestPacket', + PositionTrackingDBServerBroadcast = 'PositionTrackingDBServerBroadcast', + PurchaseReceiptPacket = 'PurchaseReceiptPacket', + RefreshEntitlementsPacket = 'RefreshEntitlementsPacket', + RemoveActorPacket = 'RemoveActorPacket', + RemoveObjectivePacket = 'RemoveObjectivePacket', + RemoveVolumeEntityPacket = 'RemoveVolumeEntityPacket', + RequestAbilityPacket = 'RequestAbilityPacket', + RequestChunkRadiusPacket = 'RequestChunkRadiusPacket', + RequestNetworkSettingsPacket = 'RequestNetworkSettingsPacket', + RequestPermissionsPacket = 'RequestPermissionsPacket', + ResourcePackChunkDataPacket = 'ResourcePackChunkDataPacket', + ResourcePackChunkRequestPacket = 'ResourcePackChunkRequestPacket', + ResourcePackClientResponsePacket = 'ResourcePackClientResponsePacket', + ResourcePackDataInfoPacket = 'ResourcePackDataInfoPacket', + ResourcePacksInfoPacket = 'ResourcePacksInfoPacket', + ResourcePackStackPacket = 'ResourcePackStackPacket', + RespawnPacket = 'RespawnPacket', + ScriptMessagePacket = 'ScriptMessagePacket', + ServerboundDiagnosticsPacket = 'ServerboundDiagnosticsPacket', + ServerboundLoadingScreenPacket = 'ServerboundLoadingScreenPacket', + ServerPlayerPostMovePositionPacket = 'ServerPlayerPostMovePositionPacket', + ServerSettingsRequestPacket = 'ServerSettingsRequestPacket', + ServerSettingsResponsePacket = 'ServerSettingsResponsePacket', + ServerStatsPacket = 'ServerStatsPacket', + ServerToClientHandshakePacket = 'ServerToClientHandshakePacket', + SetActorDataPacket = 'SetActorDataPacket', + SetActorLinkPacket = 'SetActorLinkPacket', + SetActorMotionPacket = 'SetActorMotionPacket', + SetCommandsEnabledPacket = 'SetCommandsEnabledPacket', + SetDefaultGameTypePacket = 'SetDefaultGameTypePacket', + SetDifficultyPacket = 'SetDifficultyPacket', + SetDisplayObjectivePacket = 'SetDisplayObjectivePacket', + SetHealthPacket = 'SetHealthPacket', + SetHudPacket = 'SetHudPacket', + SetLastHurtByPacket = 'SetLastHurtByPacket', + SetLocalPlayerAsInitializedPacket = 'SetLocalPlayerAsInitializedPacket', + SetMovementAuthorityPacket = 'SetMovementAuthorityPacket', + SetPlayerGameTypePacket = 'SetPlayerGameTypePacket', + SetPlayerInventoryOptionsPacket = 'SetPlayerInventoryOptionsPacket', + SetScoreboardIdentityPacket = 'SetScoreboardIdentityPacket', + SetScorePacket = 'SetScorePacket', + SetSpawnPositionPacket = 'SetSpawnPositionPacket', + SetTimePacket = 'SetTimePacket', + SettingsCommandPacket = 'SettingsCommandPacket', + SetTitlePacket = 'SetTitlePacket', + ShowCreditsPacket = 'ShowCreditsPacket', + ShowProfilePacket = 'ShowProfilePacket', + ShowStoreOfferPacket = 'ShowStoreOfferPacket', + SimpleEventPacket = 'SimpleEventPacket', + SimulationTypePacket = 'SimulationTypePacket', + SpawnExperienceOrbPacket = 'SpawnExperienceOrbPacket', + SpawnParticleEffectPacket = 'SpawnParticleEffectPacket', + StartGamePacket = 'StartGamePacket', + StopSoundPacket = 'StopSoundPacket', + StructureBlockUpdatePacket = 'StructureBlockUpdatePacket', + StructureTemplateDataExportPacket = 'StructureTemplateDataExportPacket', + StructureTemplateDataRequestPacket = 'StructureTemplateDataRequestPacket', + SubChunkPacket = 'SubChunkPacket', + SubChunkRequestPacket = 'SubChunkRequestPacket', + SubClientLoginPacket = 'SubClientLoginPacket', + SyncActorPropertyPacket = 'SyncActorPropertyPacket', + TakeItemActorPacket = 'TakeItemActorPacket', + TextPacket = 'TextPacket', + TickingAreasLoadStatusPacket = 'TickingAreasLoadStatusPacket', + ToastRequestPacket = 'ToastRequestPacket', + TransferPacket = 'TransferPacket', + TrimDataPacket = 'TrimDataPacket', + UnlockedRecipesPacket = 'UnlockedRecipesPacket', + UpdateAbilitiesPacket = 'UpdateAbilitiesPacket', + UpdateAdventureSettingsPacket = 'UpdateAdventureSettingsPacket', + UpdateAttributesPacket = 'UpdateAttributesPacket', + UpdateBlockPacket = 'UpdateBlockPacket', + UpdateBlockSyncedPacket = 'UpdateBlockSyncedPacket', + UpdateClientInputLocksPacket = 'UpdateClientInputLocksPacket', + UpdatePlayerGameTypePacket = 'UpdatePlayerGameTypePacket', + UpdateSoftEnumPacket = 'UpdateSoftEnumPacket', + UpdateSubChunkBlocksPacket = 'UpdateSubChunkBlocksPacket', + WSConnectPacket = 'WSConnectPacket', +} + /** * @seeExample simpleHttpRequest.ts */ @@ -260,4 +470,127 @@ export class HttpResponse { readonly status: number; } +export class NetworkBeforeEvents { + private constructor(); + readonly packetReceive: PacketReceiveBeforeEventSignal; + readonly packetSend: PacketSendBeforeEventSignal; +} + +export class PacketReceiveBeforeEventSignal { + private constructor(); + /** + * @remarks + * This function can't be called in read-only mode. + * + * This function can be called in early-execution mode. + * + */ + subscribe( + callback: (arg: PacketReceivedBeforeEvent) => void, + options?: PacketEventOptions, + ): (arg: PacketReceivedBeforeEvent) => void; + /** + * @remarks + * This function can't be called in read-only mode. + * + * This function can be called in early-execution mode. + * + */ + unsubscribe(callback: (arg: PacketReceivedBeforeEvent) => void): void; +} + +/** + * Sent as the server receives a network packet from a client. + * If cancelled, the server will not parse the network packet + * and will silently ignore it. + */ +export class PacketReceivedBeforeEvent { + private constructor(); + cancel: boolean; + /** + * @remarks + * The type of network packet. + * + */ + readonly packetId: PacketId; + /** + * @remarks + * The size of the network packet in bytes. + * + */ + readonly packetSize: number; + /** + * @remarks + * Which client sent the network packet to the game server. + * + */ + readonly sender?: minecraftserver.Player; +} + +/** + * Sent as the server sends a network packet to clients. If + * cancelled, the server will not send the network packet to + * the receiving clients. + */ +export class PacketSendBeforeEvent { + private constructor(); + cancel: boolean; + /** + * @remarks + * The type of network packet. + * + */ + readonly packetId: PacketId; + /** + * @remarks + * Which clients the network packet is being sent to. + * + */ + readonly recipients: minecraftserver.Player[]; +} + +export class PacketSendBeforeEventSignal { + private constructor(); + /** + * @remarks + * This function can't be called in read-only mode. + * + * This function can be called in early-execution mode. + * + */ + subscribe( + callback: (arg: PacketSendBeforeEvent) => void, + options?: PacketEventOptions, + ): (arg: PacketSendBeforeEvent) => void; + /** + * @remarks + * This function can't be called in read-only mode. + * + * This function can be called in early-execution mode. + * + */ + unsubscribe(callback: (arg: PacketSendBeforeEvent) => void): void; +} + +/** + * Options for events triggered by network packets. + */ +export interface PacketEventOptions { + /** + * @remarks + * If provided, packet IDs in this list will not trigger the + * event subscriptions. + * + */ + ignoredPacketIds?: PacketId[]; + /** + * @remarks + * If provided only packet IDs in this list will trigger the + * event subscriptions. + * + */ + monitoredPacketIds?: PacketId[]; +} + +export const beforeEvents: NetworkBeforeEvents; export const http: HttpClient; diff --git a/translated/server-ui.d.ts b/translated/server-ui.d.ts index 935f6c4..cd46bf4 100644 --- a/translated/server-ui.d.ts +++ b/translated/server-ui.d.ts @@ -21,7 +21,6 @@ * * {@link ModalFormData} allow for a more flexible * "questionnaire-style" list of controls that can be used to * take input. - * @seeExample createActionForm.js * * Manifest Details * ```json @@ -48,7 +47,8 @@ export enum FormRejectReason { /** * Builds a simple player form with buttons that let the player * take action. - * @seeExample actionFormAskFavoriteMonth.ts + * @seeExample showActionForm.ts + * @seeExample showFavoriteMonth.ts */ export class ActionFormData { /** @@ -88,7 +88,8 @@ export class ActionFormData { /** * Returns data about the player results from a modal action * form. - * @seeExample actionFormAskFavoriteMonth.ts + * @seeExample showActionForm.ts + * @seeExample showFavoriteMonth.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class ActionFormResponse extends FormResponse { @@ -123,7 +124,8 @@ export class FormResponse { /** * Builds a simple two-button modal dialog. - * @seeExample messageFormSimple.ts + * @seeExample showBasicMessageForm.ts + * @seeExample showTranslatedMessageForm.ts */ export class MessageFormData { /** @@ -170,7 +172,8 @@ export class MessageFormData { /** * Returns data about the player results from a modal message * form. - * @seeExample messageFormSimple.ts + * @seeExample showBasicMessageForm.ts + * @seeExample showTranslatedMessageForm.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class MessageFormResponse extends FormResponse { @@ -186,7 +189,7 @@ export class MessageFormResponse extends FormResponse { /** * Used to create a fully customizable pop-up form for a * player. - * @seeExample modalFormSimple.ts + * @seeExample showBasicModalForm.ts */ export class ModalFormData { /** @@ -251,7 +254,7 @@ export class ModalFormData { /** * Returns data about player responses to a modal form. - * @seeExample modalFormSimple.ts + * @seeExample showBasicModalForm.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class ModalFormResponse extends FormResponse { diff --git a/translated/server.d.ts b/translated/server.d.ts index ce1aeef..f6b10a8 100644 --- a/translated/server.d.ts +++ b/translated/server.d.ts @@ -1621,12 +1621,6 @@ export enum InputMode { * */ Touch = 'Touch', - /** - * @remarks - * Input type not detected. - * - */ - Undetermined = 'Undetermined', } /** @@ -2853,7 +2847,7 @@ export class Block { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} - * @seeExample check_block_tags.js d8a9d838 + * @seeExample checkBlockTags.ts */ hasTag(tag: string): boolean; /** @@ -3372,7 +3366,7 @@ export class BlockFluidContainerComponent extends BlockComponent { /** * Represents the inventory of a block in the world. Used with * blocks like chests. - * @seeExample place_items_in_chest.js + * @seeExample placeItemsInChest.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class BlockInventoryComponent extends BlockComponent { @@ -3426,7 +3420,7 @@ export class BlockLocationIterator implements Iterable { * properties (also sometimes called block state) which * describe a block (but does not belong to a specific {@link * Block}). - * @seeExample createTranslatedSign.ts + * @seeExample addTranslatedSign.ts 604a92ba */ export class BlockPermutation { private constructor(); @@ -3482,7 +3476,7 @@ export class BlockPermutation { * * @returns * Returns `true` if the permutation has the tag, else `false`. - * @seeExample check_block_tags.js 25c0e459 + * @seeExample checkBlockTags.ts */ hasTag(tag: string): boolean; /** @@ -3635,9 +3629,10 @@ export class BlockRecordPlayerComponent extends BlockComponent { /** * Represents a block that can display text on it. + * @seeExample addSign.ts * @seeExample addTwoSidedSign.ts - * @seeExample setSignText.ts - * @seeExample createTranslatedSign.ts + * @seeExample updateSignText.ts + * @seeExample addTranslatedSign.ts 604a92ba */ // @ts-ignore Class inheritance allowed for native defined classes export class BlockSignComponent extends BlockComponent { @@ -3707,7 +3702,6 @@ export class BlockSignComponent extends BlockComponent { * @throws * Throws if the provided message is greater than 512 * characters in length. - * @seeExample setSignText.ts */ setText(message: RawMessage | RawText | string, side?: SignSide): void; /** @@ -4256,7 +4250,6 @@ export class ChatSendAfterEventSignal { * * This function can be called in early-execution mode. * - * @seeExample custom_command.js */ subscribe(callback: (arg: ChatSendAfterEvent) => void): (arg: ChatSendAfterEvent) => void; /** @@ -4311,6 +4304,7 @@ export class ChatSendBeforeEvent { * @beta * Manages callbacks that are connected to an event that fires * before chat messages are sent. + * @seeExample customCommand.ts */ export class ChatSendBeforeEventSignal { private constructor(); @@ -4654,7 +4648,7 @@ export class CompoundBlockVolume { * Represents a container that can hold sets of items. Used * with entities such as Players, Chest Minecarts, Llamas, and * more. - * @seeExample containers.js + * @seeExample containers.ts */ export class Container { private constructor(); @@ -4714,7 +4708,7 @@ export class Container { * @throws * Throws if the container is invalid or if the `slot` index is * out of bounds. - * @seeExample getItem.ts + * @seeExample getFirstHotbarItem.ts */ getItem(slot: number): ItemStack | undefined; /** @@ -4757,7 +4751,7 @@ export class Container { * @throws * Throws if either this container or `toContainer` are invalid * or if the `fromSlot` or `toSlot` indices out of bounds. - * @seeExample moveItem.ts + * @seeExample moveBetweenContainers.ts */ moveItem(fromSlot: number, toSlot: number, toContainer: Container): void; /** @@ -4792,7 +4786,6 @@ export class Container { * @throws * Throws if either this container or `otherContainer` are * invalid or if the `slot` or `otherSlot` are out of bounds. - * @seeExample swapItems.ts */ swapItems(slot: number, otherSlot: number, otherContainer: Container): void; /** @@ -4814,7 +4807,7 @@ export class Container { * @throws * Throws if either this container or `toContainer` are invalid * or if the `fromSlot` or `toSlot` indices out of bounds. - * @seeExample transferItem.ts + * @seeExample transferBetweenContainers.ts */ transferItem(fromSlot: number, toContainer: Container): ItemStack | undefined; } @@ -5298,6 +5291,8 @@ export class Dimension { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} + * @seeExample createExplosion.ts + * @seeExample createNoBlockExplosion.ts * @seeExample createExplosions.ts */ createExplosion(location: Vector3, radius: number, explosionOptions?: ExplosionOptions): boolean; @@ -5445,8 +5440,9 @@ export class Dimension { * @returns * An entity array. * @throws This function can throw errors. - * @seeExample checkFeatherNearby.ts + * @seeExample bounceSkeletons.ts * @seeExample tagsQuery.ts + * @seeExample testThatEntityIsFeatherItem.ts */ getEntities(options?: EntityQueryOptions): Entity[]; /** @@ -5526,7 +5522,6 @@ export class Dimension { * An error will be thrown if fade is less than 0.0. * An error will be thrown if pitch is less than 0.01. * An error will be thrown if volume is less than 0.0. - * @seeExample playMusicAndSound.ts */ playSound(soundId: string, location: Vector3, soundOptions?: WorldSoundOptions): void; /** @@ -5650,8 +5645,9 @@ export class Dimension { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} - * @seeExample createOldHorse.ts + * @seeExample spawnAdultHorse.ts * @seeExample quickFoxLazyDog.ts + * @seeExample triggerEvent.ts b473e4eb */ spawnEntity(identifier: string, location: Vector3, options?: SpawnEntityOptions): Entity; /** @@ -5670,6 +5666,7 @@ export class Dimension { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} + * @seeExample itemStacks.ts * @seeExample spawnFeatherItem.ts */ spawnItem(itemStack: ItemStack, location: Vector3): Entity; @@ -5692,7 +5689,7 @@ export class Dimension { * {@link LocationInUnloadedChunkError} * * {@link LocationOutOfWorldBoundariesError} - * @seeExample spawnParticle.ts 4689acc9 + * @seeExample spawnParticle.ts 25a384c8 */ spawnParticle(effectName: string, location: Vector3, molangVariables?: MolangVariableMap): void; } @@ -6139,7 +6136,7 @@ export class Entity { * amplifier are outside of the valid ranges, or if the effect * does not exist. * @throws This function can throw errors. - * @seeExample poisonVillager.ts + * @seeExample spawnPoisonedVillager.ts * @seeExample quickFoxLazyDog.ts */ addEffect(effectType: EffectType | string, duration: number, options?: EntityEffectOptions): Effect | undefined; @@ -6156,6 +6153,7 @@ export class Entity { * Returns true if the tag was added successfully. This can * fail if the tag already exists on the entity. * @throws This function can throw errors. + * @seeExample tagsQuery.ts */ addTag(tag: string): boolean; /** @@ -6188,7 +6186,7 @@ export class Entity { * @param vector * Impulse vector. * @throws This function can throw errors. - * @seeExample yeetEntity.ts + * @seeExample applyImpulse.ts */ applyImpulse(vector: Vector3): void; /** @@ -6226,7 +6224,7 @@ export class Entity { * This function can't be called in read-only mode. * * @throws This function can throw errors. - * @seeExample yeetEntity.ts + * @seeExample applyImpulse.ts */ clearVelocity(): void; /** @@ -6243,7 +6241,7 @@ export class Entity { * @returns * Returns whether the entity was on fire. * @throws This function can throw errors. - * @seeExample setEntityOnFire.ts + * @seeExample setOnFire.ts */ extinguishFire(useEffects?: boolean): boolean; /** @@ -6469,6 +6467,22 @@ export class Entity { * @seeExample tagsQuery.ts */ kill(): boolean; + /** + * @beta + * @remarks + * Sets the rotation of the entity to face a target location. + * Both pitch and yaw will be set, if applicable, such as for + * mobs where the pitch controls the head tilt and the yaw + * controls the body rotation. + * + * This function can't be called in read-only mode. + * + * @param targetLocation + * The target location that this entity should face/look + * towards. + * @throws This function can throw errors. + */ + lookAt(targetLocation: Vector3): void; /** * @remarks * Matches the entity against the passed in options. Uses the @@ -6624,7 +6638,7 @@ export class Entity { * is less than or equal to zero, the entity is wet or the * entity is immune to fire. * @throws This function can throw errors. - * @seeExample setEntityOnFire.ts + * @seeExample setOnFire.ts */ setOnFire(seconds: number, useEffects?: boolean): boolean; /** @@ -6674,6 +6688,7 @@ export class Entity { * @param teleportOptions * Options regarding the teleport operation. * @throws This function can throw errors. + * @seeExample teleport.ts * @seeExample teleportMovement.ts */ teleport(location: Vector3, teleportOptions?: TeleportOptions): void; @@ -6692,7 +6707,8 @@ export class Entity { * @throws * If the event is not defined in the definition of the entity, * an error will be thrown. - * @seeExample triggerEvent.ts + * @seeExample triggerEvent.ts e0d38a47 + * @seeExample triggerEvent.ts b473e4eb */ triggerEvent(eventName: string): void; /** @@ -7161,7 +7177,6 @@ export class EntityDieAfterEventSignal { * Provides access to a mob's equipment slots. This component * exists for all mob entities. * @seeExample givePlayerElytra.ts - * @seeExample givePlayerEquipment.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class EntityEquippableComponent extends EntityComponent { @@ -7749,7 +7764,7 @@ export class EntityIsTamedComponent extends EntityComponent { * represents a free-floating item in the world. Lets you * retrieve the actual item stack contents via the itemStack * property. - * @seeExample checkFeatherNearby.ts + * @seeExample testThatEntityIsFeatherItem.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class EntityItemComponent extends EntityComponent { @@ -8334,7 +8349,7 @@ export class EntityNpcComponent extends EntityComponent { /** * When present on an entity, this entity is on fire. - * @seeExample setEntityOnFire.ts + * @seeExample setOnFire.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class EntityOnFireComponent extends EntityComponent { @@ -8644,6 +8659,7 @@ export class EntityRemoveBeforeEventSignal { /** * When added, this component adds the capability that an * entity can be ridden by another entity. + * @seeExample minibiomes.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class EntityRideableComponent extends EntityComponent { @@ -8715,6 +8731,7 @@ export class EntityRideableComponent extends EntityComponent { * @returns * True if the rider entity was successfully added. * @throws This function can throw errors. + * @seeExample minibiomes.ts */ addRider(rider: Entity): boolean; /** @@ -8818,7 +8835,7 @@ export class EntitySkinIdComponent extends EntityComponent { /** * Contains data related to an entity spawning within the * world. - * @seeExample logEntitySpawnEvents.ts + * @seeExample logEntitySpawnEvent.ts */ export class EntitySpawnAfterEvent { private constructor(); @@ -8841,7 +8858,6 @@ export class EntitySpawnAfterEvent { /** * Registers a script-based event handler for handling what * happens when an entity spawns. - * @seeExample logEntitySpawnEvents.ts */ export class EntitySpawnAfterEventSignal { private constructor(); @@ -8856,6 +8872,7 @@ export class EntitySpawnAfterEventSignal { * * @param callback * Function that handles the spawn event. + * @seeExample logEntitySpawnEvent.ts */ subscribe(callback: (arg: EntitySpawnAfterEvent) => void): (arg: EntitySpawnAfterEvent) => void; /** @@ -9682,6 +9699,8 @@ export class InputInfo { * * @throws This property can throw when used. * + * {@link minecraftcommon.EngineError} + * * {@link InvalidEntityError} */ readonly lastInputModeUsed: InputMode; @@ -10118,6 +10137,7 @@ export class ItemCooldownComponent extends ItemComponent { * When present on an item, this item can take damage in the * process of being used. Note that this component only applies * to data-driven items. + * @seeExample giveHurtDiamondSword.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class ItemDurabilityComponent extends ItemComponent { @@ -10197,7 +10217,6 @@ export class ItemDyeableComponent extends ItemComponent { /** * When present on an item, this item can have enchantments * applied to it. - * @seeExample givePlayerIronFireSword.ts */ // @ts-ignore Class inheritance allowed for native defined classes export class ItemEnchantableComponent extends ItemComponent { @@ -10496,7 +10515,7 @@ export class ItemReleaseUseAfterEventSignal { /** * Defines a collection of items. - * @seeExample givePlayerIronFireSword.ts + * @seeExample itemStacks.ts * @seeExample givePlayerEquipment.ts * @seeExample spawnFeatherItem.ts */ @@ -10638,7 +10657,7 @@ export class ItemStack { * @returns * Returns the component if it exists on the item stack, * otherwise undefined. - * @seeExample durability.ts + * @seeExample giveHurtDiamondSword.ts */ getComponent(componentId: T): ItemComponentTypeMap[T] | undefined; /** @@ -10760,7 +10779,7 @@ export class ItemStack { * String list of block types that the item can destroy. * @throws * Throws if any of the provided block identifiers are invalid. - * @seeExample giveRestrictedPickaxe.ts + * @seeExample giveDestroyRestrictedPickaxe.ts */ setCanDestroy(blockIdentifiers?: string[]): void; /** @@ -10776,7 +10795,7 @@ export class ItemStack { * String list of block types that the item can be placed on. * @throws * Throws if any of the provided block identifiers are invalid. - * @seeExample giveRestrictedGoldBlock.ts + * @seeExample givePlaceRestrictedGoldBlock.ts */ setCanPlaceOn(blockIdentifiers?: string[]): void; /** @@ -11576,7 +11595,6 @@ export class PistonActivateAfterEvent extends BlockEvent { /** * Manages callbacks that are connected to piston activations. - * @seeExample pistonAfterEvent.ts */ export class PistonActivateAfterEventSignal { private constructor(); @@ -11586,6 +11604,7 @@ export class PistonActivateAfterEventSignal { * * This function can be called in early-execution mode. * + * @seeExample pistonAfterEvent.ts */ subscribe(callback: (arg: PistonActivateAfterEvent) => void): (arg: PistonActivateAfterEvent) => void; /** @@ -11817,6 +11836,7 @@ export class Player extends Entity { * @param soundOptions * Additional optional options for the sound. * @throws This function can throw errors. + * @seeExample playMusicAndSound.ts */ playSound(soundId: string, soundOptions?: PlayerSoundOptions): void; /** @@ -11867,7 +11887,11 @@ export class Player extends Entity { * This method can throw if the provided {@link RawMessage} is * in an invalid format. For example, if an empty `name` string * is provided to `score`. - * @seeExample sendMessagesToPlayer.ts + * @seeExample nestedTranslation.ts + * @seeExample scoreWildcard.ts + * @seeExample sendBasicMessage.ts + * @seeExample sendPlayerMessages.ts + * @seeExample sendTranslatedMessage.ts */ sendMessage(message: (RawMessage | string)[] | RawMessage | string): void; /** @@ -13419,6 +13443,7 @@ export class ProjectileHitEntityAfterEventSignal { /** * Contains objectives and participants for the scoreboard. + * @seeExample updateScoreboard.ts */ export class Scoreboard { private constructor(); @@ -13429,6 +13454,7 @@ export class Scoreboard { * This function can't be called in read-only mode. * * @throws This function can throw errors. + * @seeExample updateScoreboard.ts */ addObjective(objectiveId: string, displayName?: string): ScoreboardObjective; /** @@ -13656,7 +13682,7 @@ export class ScoreboardScoreInfo { * showing up on the screen. * @seeExample setTitle.ts * @seeExample setTitleAndSubtitle.ts - * @seeExample titleCountdown.ts + * @seeExample countdown.ts */ export class ScreenDisplay { private constructor(); @@ -13734,7 +13760,7 @@ export class ScreenDisplay { * @throws This function can throw errors. * @seeExample setTitle.ts * @seeExample setTitleAndSubtitle.ts - * @seeExample titleCountdown.ts + * @seeExample countdown.ts */ setTitle(title: (RawMessage | string)[] | RawMessage | string, options?: TitleDisplayOptions): void; /** @@ -13745,6 +13771,7 @@ export class ScreenDisplay { * This function can't be called in read-only mode. * * @throws This function can throw errors. + * @seeExample countdown.ts */ updateSubtitle(subtitle: (RawMessage | string)[] | RawMessage | string): void; } @@ -14768,6 +14795,7 @@ export class World { * of the world. Event callbacks are called immediately. Event * callbacks are executed in read-only mode. * + * @seeExample customCommand.ts */ readonly beforeEvents: WorldBeforeEvents; /** @@ -14984,10 +15012,6 @@ export class World { * This method can throw if the provided {@link RawMessage} is * in an invalid format. For example, if an empty `name` string * is provided to `score`. - * @seeExample nestedTranslation.ts - * @seeExample scoreWildcard.ts - * @seeExample simpleString.ts - * @seeExample translation.ts */ sendMessage(message: (RawMessage | string)[] | RawMessage | string): void; /** @@ -15378,6 +15402,7 @@ export class WorldBeforeEvents { * This event is triggered after a chat message has been * broadcast or sent to players. * + * @seeExample customCommand.ts */ readonly chatSend: ChatSendBeforeEventSignal; /** @@ -16305,12 +16330,14 @@ export interface EntityHitInformation { /** * Contains options for selecting entities within an area. - * @seeExample BlockConditional.ts - * @seeExample EntityPropertyOptions.ts - * @seeExample PlaySoundChained.ts - * @seeExample SendMessageAllPlayers.ts - * @seeExample SetScoreBoardChained.ts - * @seeExample SummonMobChained.ts + * @seeExample blockConditional.ts + * @seeExample findEntitiesHavingPropertyEqualsTo.ts + * @seeExample playSoundChained.ts + * @seeExample setScoreboardChained.ts + * @seeExample summonMobChained.ts + * @seeExample bounceSkeletons.ts + * @seeExample tagsQuery.ts + * @seeExample testThatEntityIsFeatherItem.ts */ // @ts-ignore Class inheritance allowed for native defined classes export interface EntityQueryOptions extends EntityFilter { @@ -16480,6 +16507,7 @@ export interface EqualsComparison { /** * Additional configuration options for the {@link * Dimension.createExplosion} method. + * @seeExample createNoBlockExplosion.ts * @seeExample createExplosions.ts */ export interface ExplosionOptions { @@ -16818,8 +16846,9 @@ export interface RangeComparison { /** * Defines a JSON structure that is used for more flexible. - * @seeExample addTranslatedSign.ts + * @seeExample addTranslatedSign.ts 9d3a2d98 * @seeExample showTranslatedMessageForm.ts + * @seeExample addTranslatedSign.ts 604a92ba */ export interface RawMessage { /** @@ -17077,6 +17106,7 @@ export interface StructurePlaceOptions { /** * Contains additional options for teleporting an entity. + * @seeExample teleport.ts * @seeExample teleportMovement.ts */ export interface TeleportOptions {