@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
987 lines • 52 kB
JSON
{
"buttonPushEvent": {
"description": "A simple button push before event. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/buttonpushaftereventsignal",
"prefix": ["mc"],
"body": [" // 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;",
" if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y + 1 && eventLoc.z === targetLocation.z) {",
" log('Button push event at tick ' + system.currentTick);",
" }",
" });"
]},
"leverActionEvent": {
"description": "A simple lever activate event. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/leveractionaftereventsignal",
"prefix": ["mc"],
"body": [" // 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);",
" }",
" });"
]},
"tripWireTripEvent": {
"description": "A basic tripwire event. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/tripwiretripaftereventsignal",
"prefix": ["mc"],
"body": [" // 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);",
" if (redstone === undefined || tripwire === undefined) {",
" log('Could not find block at location.');",
" return -1;",
" }",
" redstone.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.RedstoneBlock));",
" tripwire.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.TripWire));",
" world.afterEvents.tripWireTrip.subscribe((tripWireTripEvent: TripWireTripAfterEvent) => {",
" const eventLoc = tripWireTripEvent.block.location;",
" if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) {",
" log(",
" 'Tripwire trip event at tick ' +",
" system.currentTick +",
" (tripWireTripEvent.sources.length > 0 ? ' by entity ' + tripWireTripEvent.sources[0].id : '')",
" );",
" }",
" });"
]},
"addBlockColorCube": {
"description": "Creates a multicolored block out of different colors of wool. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blockpermutation/resolve",
"prefix": ["mc"],
"body": [" const allWoolBlocks: string[] = [",
" MinecraftBlockTypes.WhiteWool,",
" MinecraftBlockTypes.OrangeWool,",
" MinecraftBlockTypes.MagentaWool,",
" MinecraftBlockTypes.LightBlueWool,",
" MinecraftBlockTypes.YellowWool,",
" MinecraftBlockTypes.LimeWool,",
" MinecraftBlockTypes.PinkWool,",
" MinecraftBlockTypes.GrayWool,",
" MinecraftBlockTypes.LightGrayWool,",
" MinecraftBlockTypes.CyanWool,",
" MinecraftBlockTypes.PurpleWool,",
" MinecraftBlockTypes.BlueWool,",
" MinecraftBlockTypes.BrownWool,",
" MinecraftBlockTypes.GreenWool,",
" MinecraftBlockTypes.RedWool,",
" MinecraftBlockTypes.BlackWool,",
" ];",
" const cubeDim = 7;",
" 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]));",
" }",
" }",
" }"
]},
"checkBlockTags": {
"description": "Checks whether a specified block is dirt, wood, or stone. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/block/hastag",
"prefix": ["mc"],
"body": [" // 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')}`);",
" }"
]},
"containers": {
"description": "Creates some chests and containers and uses container transfer and swapping APIs. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/container",
"prefix": ["mc"],
"body": [" 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);",
" }"
]},
"placeItemsInChest": {
"description": "Creates a chest and places some items within it. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blockinventorycomponent",
"prefix": ["mc"],
"body": [" // 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));"
]},
"createExplosion": {
"description": "Creates an explosion in the world. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/createexplosion",
"prefix": ["mc"],
"body": [" log('Creating an explosion of radius 10.');",
" targetLocation.dimension.createExplosion(targetLocation, 10);"
]},
"createNoBlockExplosion": {
"description": "Creates an explosion in the world that does not impact blocks. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/createexplosion",
"prefix": ["mc"],
"body": [" 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 });"
]},
"createExplosions": {
"description": "Creates a fire explosion and an underwater explosion in the world. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/createexplosion",
"prefix": ["mc"],
"body": [" const explosionLoc = Vector3Utils.add(targetLocation, { x: 0.5, y: 0.5, z: 0.5 });",
" log('Creating an explosion of radius 15 that causes fire.');",
" targetLocation.dimension.createExplosion(explosionLoc, 15, { causesFire: 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 });"
]},
"itemStacks": {
"description": "Creates free-floating item stacks in the world. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemstack",
"prefix": ["mc"],
"body": [" 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);"
]},
"quickFoxLazyDog": {
"description": "Creates a fox and, well, a wolf with effects applied. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/spawnentity",
"prefix": ["mc"],
"body": [" const fox = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Fox, {",
" x: targetLocation.x + 1,",
" y: targetLocation.y + 2,",
" z: targetLocation.z + 3,",
" });",
" fox.addEffect(MinecraftEffectTypes.Speed, 10, {",
" amplifier: 2,",
" });",
" log('Created a fox.');",
" 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);"
]},
"incrementDynamicProperty": {
"description": "Increments a dynamic numeric persisted property. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world/getdynamicproperty",
"prefix": ["mc"],
"body": [" let number = world.getDynamicProperty('samplelibrary:number');",
" log('Current value is: ' + number);",
" if (number === undefined) {",
" number = 0;",
" }",
" if (typeof number !== 'number') {",
" log('Number is of an unexpected type.');",
" return -1;",
" }",
" world.setDynamicProperty('samplelibrary:number', number + 1);"
]},
"incrementDynamicPropertyInJsonBlob": {
"description": "Increments a dynamic numeric persisted property. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world/getdynamicproperty",
"prefix": ["mc"],
"body": [" let paintStr = world.getDynamicProperty('samplelibrary:longerjson');",
" let paint: { color: string; intensity: number } | undefined = undefined;",
" log('Current value is: ' + paintStr);",
" if (paintStr === undefined) {",
" paint = {",
" color: 'purple',",
" intensity: 0,",
" };",
" } else {",
" if (typeof paintStr !== 'string') {",
" log('Paint is of an unexpected type.');",
" return -1;",
" }",
" try {",
" paint = JSON.parse(paintStr);",
" } catch (e) {",
" log('Error parsing serialized struct.');",
" return -1;",
" }",
" }",
" if (!paint) {",
" 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",
" world.setDynamicProperty('samplelibrary:longerjson', paintStr);"
]},
"spawnPoisonedVillager": {
"description": "Spawns a villager and gives it a poison effect. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity/addeffect",
"prefix": ["mc"],
"body": [" const villagerType = 'minecraft:villager_v2<minecraft:ageable_grow_up>';",
" const villager = targetLocation.dimension.spawnEntity(villagerType, targetLocation);",
" const duration = 20;",
" villager.addEffect(MinecraftEffectTypes.Poison, duration, { amplifier: 1 });"
]},
"triggerEvent": {
"description": "Creates a creeper and then triggers an explosion. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/spawnentity",
"prefix": ["mc"],
"body": [" const creeper = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Creeper, targetLocation);",
" creeper.triggerEvent('minecraft:start_exploding_forced');"
]},
"applyImpulse": {
"description": "Creates a zombie and then applies an impulse. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity/applyimpulse",
"prefix": ["mc"],
"body": [" 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 });"
]},
"getFireworkVelocity": {
"description": "Gets a velocity of a firework. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity/getvelocity",
"prefix": ["mc"],
"body": [" const fireworkRocket = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.FireworksRocket, targetLocation);",
" system.runTimeout(() => {",
" const velocity = fireworkRocket.getVelocity();",
" log('Velocity of firework is: (x: ' + velocity.x + ', y:' + velocity.y + ', z:' + velocity.z + ')');",
" }, 5);"
]},
"applyDamageThenHeal": {
"description": "Applies damage, then heals an entity. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity/applydamage",
"prefix": ["mc"],
"body": [" const skelly = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Skeleton, targetLocation);",
" skelly.applyDamage(19); // skeletons have max damage of 20 so this is a near-death skeleton",
" 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);"
]},
"setOnFire": {
"description": "Sets an entity on fire. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity/setonfire",
"prefix": ["mc"],
"body": [" 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);"
]},
"teleport": {
"description": "Does a basic teleport action. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity/teleport",
"prefix": ["mc"],
"body": [" 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);"
]},
"teleportMovement": {
"description": "Does a basic movements with frequent teleport actions. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity/teleport",
"prefix": ["mc"],
"body": [" const pig = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Pig, targetLocation);",
" 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,",
" }",
" );",
" if (inc > 100) {",
" system.clearRun(runId);",
" }",
" inc++;",
" }, 4);"
]},
"shootArrow": {
"description": "Shoots an arrow. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityprojectilecomponent",
"prefix": ["mc"],
"body": [" 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);"
]},
"blockConditional": {
"description": "Spawns a salmon next to every fox, if the fox is standing on stone. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityqueryoptions",
"prefix": ["mc"],
"body": [" 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,",
" });",
" return block !== undefined && block.matches('minecraft:stone');",
" })",
" .forEach((entity) => {",
" targetLocation.dimension.spawnEntity('salmon', entity.location);",
" });"
]},
"findEntitiesHavingPropertyEqualsTo": {
"description": "Find entities having a property that is equals to a value. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityqueryoptions",
"prefix": ["mc"],
"body": [" // 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);"
]},
"playSoundChained": {
"description": "Plays a sound for every player, based on armor stands. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityqueryoptions",
"prefix": ["mc"],
"body": [" const targetPlayers = targetLocation.dimension.getPlayers();",
" const originEntities = targetLocation.dimension.getEntities({",
" type: 'armor_stand',",
" name: 'myArmorStand',",
" tags: ['dummyTag1'],",
" excludeTags: ['dummyTag2'],",
" });",
" originEntities.forEach((entity) => {",
" targetPlayers.forEach((player) => {",
" player.playSound('raid.horn');",
" });",
" });"
]},
"setScoreboardChained": {
"description": "Sets a scoreboard, based on the presence of armor stands. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityqueryoptions",
"prefix": ["mc"],
"body": [" 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);",
" }",
" });"
]},
"summonMobChained": {
"description": "Summons a mob near every player, based on a number of armor stands. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityqueryoptions",
"prefix": ["mc"],
"body": [" 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,",
" });",
" });",
" });"
]},
"bounceSkeletons": {
"description": "Amongst a set of entities, uses entity query to find specific entities and bounce them with applyKnockback. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/getentities",
"prefix": ["mc"],
"body": [" 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);",
" }",
" const eqo: EntityQueryOptions = {",
" type: 'skeleton',",
" };",
" for (const entity of targetLocation.dimension.getEntities(eqo)) {",
" entity.applyKnockback(0, 0, 0, 1);",
" }"
]},
"tagsQuery": {
"description": "Amongst a set of entities, uses entity query to find specific entities based on a tag. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/getentities",
"prefix": ["mc"],
"body": [" 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);",
" }",
" const eqo: EntityQueryOptions = {",
" tags: ['mobparty.skeleton'],",
" };",
" for (const entity of targetLocation.dimension.getEntities(eqo)) {",
" entity.kill();",
" }"
]},
"logEntitySpawnEvent": {
"description": "Registers and contains an entity spawned event handler. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityspawnaftereventsignal/subscribe",
"prefix": ["mc"],
"body": [" // 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<minecraft:ageable_grow_up>',",
" Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 })",
" );",
" }, 20);"
]},
"spawnAdultHorse": {
"description": "A simple function to create an adult horse. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/spawnentity",
"prefix": ["mc"],
"body": [" log('Create a horse and triggering the ageable_grow_up event, ensuring the horse is created as an adult');",
" targetLocation.dimension.spawnEntity(",
" 'minecraft:horse<minecraft:ageable_grow_up>',",
" Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 })",
" );"
]},
"givePlayerElytra": {
"description": "Gives a player an elytra. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityequipmentinventorycomponent",
"prefix": ["mc"],
"body": [" const players = world.getAllPlayers();",
" const equipment = players[0].getComponent(EntityComponentTypes.Equippable) as EntityEquippableComponent;",
" equipment?.setEquipment(EquipmentSlot.Chest, new ItemStack(MinecraftItemTypes.Elytra));",
" log('Player given Elytra');"
]},
"givePlayerEquipment": {
"description": "Give a player, and an armorstand, a full set of equipment. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemstack",
"prefix": ["mc"],
"body": [" 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));",
" }"
]},
"giveHurtDiamondSword": {
"description": "Gives a player a half-damaged diamond sword. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemstack/getcomponent",
"prefix": ["mc"],
"body": [" 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);",
" }",
" }"
]},
"giveDestroyRestrictedPickaxe": {
"description": "Gives a player a restricted pickaxe. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemstack/setcandestroy",
"prefix": ["mc"],
"body": [" 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);",
" }"
]},
"givePlaceRestrictedGoldBlock": {
"description": "Gives a player a restricted gold block. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemstack/setcanplaceon",
"prefix": ["mc"],
"body": [" 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);",
" }"
]},
"diamondAwesomeSword": {
"description": "Gives a player a diamond sword with custom lore text. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemstack/addlore",
"prefix": ["mc"],
"body": [" for (const player of world.getAllPlayers()) {",
" const diamondAwesomeSword = new ItemStack(MinecraftItemTypes.DiamondSword, 1);",
" diamondAwesomeSword.setLore(['§c§lDiamond Sword of Awesome§r', '+10 coolness', '§p+4 shiny§r']);",
" // hover over/select the item in your inventory to see the lore.",
" const inventory = player.getComponent(EntityComponentTypes.Inventory) as EntityInventoryComponent;",
" if (inventory === undefined || inventory.container === undefined) {",
" return;",
" }",
" inventory.container.setItem(0, diamondAwesomeSword);",
" }"
]},
"getFirstHotbarItem": {
"description": "Gets the first hotbar item. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/container/getitem",
"prefix": ["mc"],
"body": [" 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;",
" }"
]},
"moveBetweenContainers": {
"description": "Move an item between containers. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/container/moveitem",
"prefix": ["mc"],
"body": [" 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);",
" }",
" }"
]},
"swapBetweenContainers": {
"description": "Swap an item between containers. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/container/swapitem",
"prefix": ["mc"],
"body": [" 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.swapItems(0, 0, toInventory.container);",
" }",
" }"
]},
"transferBetweenContainers": {
"description": "Transfer an item between containers. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/container/transferitem",
"prefix": ["mc"],
"body": [" 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);",
" }",
" }"
]},
"playMusicAndSound": {
"description": "Plays some music and sound effects. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world/playmusic",
"prefix": ["mc"],
"body": [" const players = world.getPlayers();",
" const musicOptions: MusicOptions = {",
" fade: 0.5,",
" loop: true,",
" volume: 1.0,",
" };",
" world.playMusic('music.menu', musicOptions);",
" const worldSoundOptions: WorldSoundOptions = {",
" pitch: 0.5,",
" volume: 4.0,",
" };",
" world.playSound('ambient.weather.thunder', targetLocation, worldSoundOptions);",
" const playerSoundOptions: PlayerSoundOptions = {",
" pitch: 1.0,",
" volume: 1.0,",
" };",
" players[0].playSound('bucket.fill_water', playerSoundOptions);"
]},
"spawnParticle": {
"description": "Spawns a cloud of colored flame particles. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension/spawnparticle",
"prefix": ["mc"],
"body": [" 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);",
" }"
]},
"pistonAfterEvent": {
"description": "A simple piston after activate event. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/pistonactivateaftereventsignal/subscribe",
"prefix": ["mc"],
"body": [" // 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' : '')",
" );",
" }",
" });"
]},
"sendPlayerMessages": {
"description": "Sends player a number of diverse message types. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/player/sendmessage",
"prefix": ["mc"],
"body": [" 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);",
" }"
]},
"updateScoreboard": {
"description": "Creates and updates a scoreboard objective, plus a player score. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/scoreboard",
"prefix": ["mc"],
"body": [" 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);"
]},
"setTitle": {
"description": "Sets a title overlay on the player's screen. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/screendisplay",
"prefix": ["mc"],
"body": [" const players = world.getPlayers();",
" if (players.length > 0) {",
" players[0].onScreenDisplay.setTitle('§o§6Fancy Title§r');",
" }"
]},
"setTitleAndSubtitle": {
"description": "Sets a title and subtitle overlay on the player's screen. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/screendisplay",
"prefix": ["mc"],
"body": [" const players = world.getPlayers();",
" players[0].onScreenDisplay.setTitle('Chapter 1', {",
" stayDuration: 100,",
" fadeInDuration: 2,",
" fadeOutDuration: 4,",
" subtitle: 'Trouble in Block Town',",
" });"
]},
"countdown": {
"description": "Runs a countdown from 10 to 0. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/screendisplay",
"prefix": ["mc"],
"body": [" 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);"
]},
"sendBasicMessage": {
"description": "Sends a basic message. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/player/sendmessage",
"prefix": ["mc"],
"body": [" const players = world.getPlayers();",
" players[0].sendMessage('Hello World!');"
]},
"sendTranslatedMessage": {
"description": "Sends a translated message. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/player/sendmessage",
"prefix": ["mc"],
"body": [" const players = world.getPlayers();",
" players[0].sendMessage({ translate: 'authentication.welcome', with: ['Amazing Player 1'] });"
]},
"nestedTranslation": {
"description": "Sends a message with nested translation. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/player/sendmessage",
"prefix": ["mc"],
"body": [" // Displays 'Apple or Coal'",
" const rawMessage = {",
" translate: 'accessibility.list.or.two',",
" with: { rawtext: [{ translate: 'item.apple.name' }, { translate: 'item.coal.name' }] },",
" };",
" world.sendMessage(rawMessage);"
]},
"scoreWildcard": {
"description": "Sends a message with a wildcard score. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/player/sendmessage",
"prefix": ["mc"],
"body": [" // Displays the player's score for objective 'obj'. Each player will see their own score.",
" const rawMessage = { score: { name: '*', objective: 'obj' } };",
" world.sendMessage(rawMessage);"
]},
"showTranslatedMessageForm": {
"description": "Shows an example translated two-button dialog dialog. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/rawmessage",
"prefix": ["mc"],
"body": [" const players = world.getPlayers();",
" 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');",
" 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 ? 'Player 1' : 'Player 2'}`);",
" })",
" .catch((error: Error) => {",
" log('Failed to show form: ' + error);",
" return -1;",
" });"
]},
"addSign": {
"description": "Creates a single-sided simple sign. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blocksigncomponent",
"prefix": ["mc"],
"body": [" 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.`);"
]},
"addTranslatedSign": {
"description": "Creates a single-sided simple sign. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blockpermutation",
"prefix": ["mc"],
"body": [" 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] });"
]},
"addTwoSidedSign": {
"description": "Creates a two-sided sign with custom colors and a read-only status. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blocksigncomponent",
"prefix": ["mc"],
"body": [" const signBlock = targetLocation.dimension.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;",
" 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.');",
" }"
]},
"updateSignText": {
"description": "Updates sign text. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/blocksigncomponent",
"prefix": ["mc"],
"body": [" 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.');",
" }"
]},
"spawnFeatherItem": {
"description": "Creates a free-floating feather item in the world. See https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemstack",
"prefix": ["mc"],
"body": [" const featherItem = new ItemStack(MinecraftItemTypes.Feather, 1);",
" targetLocation.dimension.spawnItem(featherItem, targetLocation);",
" log(`New feather created at ${targetLocation.x}, ${targetLocation.y}, ${targetLocation.z}!`);"
]},
"testThatEntityIsFeatherItem": {
"description": "Tests whether there is a feath