├── .github ├── dependabot.yml └── workflows │ ├── build.yml │ └── create-release.yml ├── .gitignore ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── SUPPORT.md ├── build-challenge ├── .env ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── ScoreSheet.md ├── behavior_packs │ └── buildchallenge │ │ ├── items │ │ └── heart.json │ │ ├── manifest.json │ │ ├── pack_icon.png │ │ └── structures │ │ └── challenge │ │ ├── options.mcstructure │ │ ├── viewtower.mcstructure │ │ ├── vote.mcstructure │ │ └── vote2.mcstructure ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── resource_packs │ └── buildchallenge │ │ ├── manifest.json │ │ ├── pack_icon.png │ │ ├── texts │ │ └── en_US.lang │ │ └── textures │ │ ├── item_texture.json │ │ └── items │ │ └── heart.png ├── scripts │ ├── Challenge.ts │ ├── ChallengePlayer.ts │ ├── Constants.ts │ ├── Log.ts │ ├── Team.ts │ ├── Track.ts │ ├── Utilities.ts │ └── main.ts ├── tsconfig.json └── worlds │ └── default │ ├── db │ ├── CURRENT │ └── MANIFEST-000002 │ ├── level.dat │ ├── level.dat_old │ ├── levelname.txt │ ├── world_behavior_packs.json │ ├── world_icon.jpeg │ └── world_resource_packs.json ├── custom-commands ├── .env ├── .mct │ └── prefs.mctp.json ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── behavior_packs │ └── mike_cc │ │ ├── manifest.json │ │ └── pack_icon.png ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── resource_packs │ └── mike_cc │ │ ├── manifest.json │ │ └── pack_icon.png ├── scripts │ └── main.ts └── tsconfig.json ├── custom-components ├── .env ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── behavior_packs │ └── custom_components │ │ ├── blocks │ │ └── strawberry_crop.block.json │ │ ├── items │ │ ├── sprayer_empty.json │ │ ├── sprayer_full.json │ │ ├── strawberry.json │ │ ├── strawberry_rotten.json │ │ └── strawberry_seeds.json │ │ ├── loot_tables │ │ ├── strawberry_crop.json │ │ ├── strawberry_grown_crop.json │ │ └── strawberry_rotten_crop.json │ │ ├── manifest.json │ │ └── pack_icon.png ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── resource_packs │ └── custom_components │ │ ├── manifest.json │ │ ├── models │ │ └── blocks │ │ │ └── crop.geo.json │ │ ├── pack_icon.png │ │ ├── texts │ │ └── en_US.lang │ │ └── textures │ │ ├── blocks │ │ ├── strawberry_0.png │ │ ├── strawberry_1.png │ │ ├── strawberry_2.png │ │ ├── strawberry_3.png │ │ ├── strawberry_4.png │ │ └── strawberry_5.png │ │ ├── item_texture.json │ │ ├── items │ │ ├── spray_can_empty.png │ │ ├── spray_can_full.png │ │ ├── strawberry.png │ │ ├── strawberry_rotten.png │ │ └── strawberry_seeds.png │ │ └── terrain_texture.json ├── scripts │ ├── CauseHungerOnConsumeComponent.ts │ ├── CropGrowthComponent.ts │ ├── GrownStrawberryCropComponent.ts │ ├── NightVisionConsumeComponent.ts │ ├── SprayerComponents.ts │ └── main.ts └── tsconfig.json ├── editor-basics ├── .env ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── behavior_packs │ └── editor-basics │ │ ├── manifest.json │ │ └── pack_icon.png ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── resource_packs │ └── editor-basics │ │ ├── manifest.json │ │ └── pack_icon.png ├── scripts │ ├── Basics.ts │ └── main.ts └── tsconfig.json ├── editor-multi ├── .env ├── .npmrc ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── behavior_packs │ └── editor-multi │ │ ├── manifest.json │ │ └── pack_icon.png ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── resource_packs │ └── editor-multi │ │ ├── manifest.json │ │ ├── pack_icon.png │ │ ├── texts │ │ └── en_US.lang │ │ └── textures │ │ ├── dye-brush.png │ │ ├── farm-generator.png │ │ ├── goto-mark.png │ │ ├── portal-generator.png │ │ └── tree-generator.png ├── scripts │ ├── camera-grapple.ts │ ├── dye-brush.ts │ ├── farm-generator.ts │ ├── goto-mark.ts │ ├── main.ts │ ├── portal-generator.ts │ ├── simple-locate-biome.ts │ ├── star-brush-shape.ts │ └── tree-generator.ts ├── tasks │ └── BuildSnippets.ts └── tsconfig.json ├── editor-script-box ├── .env ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── behavior_packs │ └── editor-script-box │ │ ├── manifest.json │ │ └── pack_icon.png ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── resource_packs │ └── editor-script-box │ │ ├── manifest.json │ │ └── pack_icon.png ├── scripts │ ├── ScriptBox.ts │ └── main.ts └── tsconfig.json ├── howto-gallery-betas ├── .env ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── behavior_packs │ └── howto-gallery-betas │ │ ├── manifest.json │ │ ├── pack_icon.png │ │ └── structures │ │ └── gametests │ │ ├── glass_cells.mcstructure │ │ ├── mediumglass.mcstructure │ │ └── minibiomes.mcstructure ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── scripts │ ├── Chat.ts │ ├── NetUse.ts │ ├── SampleManager.ts │ ├── Server-AdminSampleLibrary.ts │ ├── Server-GameTestSampleLibrary.ts │ ├── Server-NetSampleLibrary.ts │ ├── ServerAdmin.ts │ ├── ServerSampleLibrary.ts │ ├── SimpleGameTests.ts │ └── main.ts ├── tasks │ └── BuildSnippets.ts └── tsconfig.json ├── howto-gallery ├── .env ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── behavior_packs │ └── howto-gallery │ │ ├── manifest.json │ │ ├── pack_icon.png │ │ └── structures │ │ └── gametests │ │ ├── glass_cells.mcstructure │ │ ├── mediumglass.mcstructure │ │ └── minibiomes.mcstructure ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── scripts │ ├── BlockEvent.ts │ ├── Blocks.ts │ ├── Containers.ts │ ├── CreateExplosion.ts │ ├── CreateItemStacks.ts │ ├── CreateMobs.ts │ ├── DynamicProperties.ts │ ├── Effects.ts │ ├── Entities.ts │ ├── EntityQuery.ts │ ├── EntitySpawnEvent.ts │ ├── Equipment.ts │ ├── Items.ts │ ├── MusicAndSound.ts │ ├── Particles.ts │ ├── PistonActivateEvent.ts │ ├── Players.ts │ ├── SampleManager.ts │ ├── Scoreboard.ts │ ├── ScreenDisplay.ts │ ├── SendMessage.ts │ ├── Server-UISampleLibrary.ts │ ├── ServerSampleLibrary.ts │ ├── ServerUserInterface.ts │ ├── Signs.ts │ ├── SpawnItem.ts │ ├── SystemRun.ts │ └── main.ts ├── tasks │ └── BuildSnippets.ts └── tsconfig.json ├── package-lock.json ├── package.json ├── script-box ├── .env ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── behavior_packs │ └── script-box │ │ ├── manifest.json │ │ └── pack_icon.png ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── scripts │ ├── SampleManager.ts │ ├── ScriptBox.ts │ └── main.ts └── tsconfig.json ├── ts-starter-complete-cotta ├── .env ├── .prettierrc.json ├── .vscode │ ├── extensions.json │ ├── launch.json │ ├── settings.json │ └── tasks.json ├── README.md ├── behavior_packs │ └── cotta │ │ ├── manifest.json │ │ └── pack_icon.png ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── resource_packs │ └── cotta │ │ ├── manifest.json │ │ └── pack_icon.png ├── scripts │ ├── Utilities.ts │ └── main.ts └── tsconfig.json └── ts-starter ├── .env ├── .prettierrc.json ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── README.md ├── behavior_packs └── starter │ ├── manifest.json │ └── pack_icon.png ├── eslint.config.mjs ├── just.config.ts ├── package.json ├── resource_packs └── starter │ ├── manifest.json │ └── pack_icon.png ├── scripts └── main.ts └── tsconfig.json /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/build-challenge" 5 | schedule: 6 | interval: "monthly" 7 | groups: 8 | external: 9 | patterns: 10 | - "*" 11 | update-types: 12 | - "minor" 13 | 14 | - package-ecosystem: "npm" 15 | directory: "/custom-components" 16 | schedule: 17 | interval: "monthly" 18 | groups: 19 | external: 20 | patterns: 21 | - "*" 22 | update-types: 23 | - "minor" 24 | 25 | - package-ecosystem: "npm" 26 | directory: "/editor-basics" 27 | schedule: 28 | interval: "monthly" 29 | groups: 30 | external: 31 | patterns: 32 | - "*" 33 | update-types: 34 | - "minor" 35 | 36 | - package-ecosystem: "npm" 37 | directory: "/editor-script-box" 38 | schedule: 39 | interval: "monthly" 40 | groups: 41 | external: 42 | patterns: 43 | - "*" 44 | update-types: 45 | - "minor" 46 | 47 | - package-ecosystem: "npm" 48 | directory: "/howto-gallery" 49 | schedule: 50 | interval: "monthly" 51 | groups: 52 | external: 53 | patterns: 54 | - "*" 55 | update-types: 56 | - "minor" 57 | 58 | - package-ecosystem: "npm" 59 | directory: "/script-box" 60 | schedule: 61 | interval: "monthly" 62 | groups: 63 | external: 64 | patterns: 65 | - "*" 66 | update-types: 67 | - "minor" 68 | 69 | - package-ecosystem: "npm" 70 | directory: "/ts-starter" 71 | schedule: 72 | interval: "monthly" 73 | groups: 74 | external: 75 | patterns: 76 | - "*" 77 | update-types: 78 | - "minor" 79 | 80 | - package-ecosystem: "npm" 81 | directory: "/ts-starter-complete-cotta" 82 | schedule: 83 | interval: "monthly" 84 | groups: 85 | external: 86 | patterns: 87 | - "*" 88 | update-types: 89 | - "minor" 90 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | types: [opened, synchronize, reopened] 9 | branches: 10 | - main 11 | 12 | jobs: 13 | build: 14 | runs-on: windows-latest 15 | 16 | permissions: read-all 17 | 18 | strategy: 19 | matrix: 20 | node-version: [20] 21 | 22 | steps: 23 | - uses: actions/checkout@v4 24 | - name: Using Node.js ${{ matrix.node-version }} 25 | uses: actions/setup-node@v4 26 | with: 27 | node-version: ${{ matrix.node-version }} 28 | 29 | - name: Install 30 | run: npm ci 31 | - name: Build 32 | run: npm run mcaddon -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "eslint.experimental.useFlatConfig": true, 3 | "eslint.workingDirectories": [ 4 | { 5 | "pattern": "./build-challenge/*/" 6 | }, 7 | { 8 | "pattern": "./howto-gallery/*/" 9 | }, 10 | { 11 | "pattern": "./script-box/*/" 12 | }, 13 | { 14 | "pattern": "./ts-starter/*/" 15 | }, 16 | { 17 | "pattern": "./ts-starter-complete-cotta/*/" 18 | }, 19 | { 20 | "pattern": "./custom-components/*/" 21 | }, 22 | ] 23 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Project 2 | 3 | This project contains samples of [@minecraft/server](https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/minecraft-server) scripting APIs that are part of the Beta APIs experimental capability of Minecraft. For more information, see the [Minecraft: Bedrock Edition Creator Documentation](https://learn.microsoft.com/minecraft/creator/) 4 | 5 | ## Current Samples 6 | 7 | - [ts-starter](ts-starter/README.md) - A starter project that lets you use TypeScript, alongside a tutorial on how to use more `@minecraft/server` APIs. 8 | - [ts-starter-complete-cotta](ts-starter-complete-cotta/README.md) - A completed version of the `ts-starter` tutorial, featuring the Break the Cotta simple arena game. 9 | - [howto-gallery](howto-gallery/README.md) - A set of small code snippets that can be played back within the game. 10 | - [build-challenge](build-challenge/README.md) - A more complex starter script map with the ability to form teams that build structures, that can then be voted on. 11 | - [custom-components](custom-components/README.md) - An addon using block and item custom components to add a new strawberry crop and watering tool. 12 | 13 | ## Contributing 14 | 15 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 16 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 17 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 18 | 19 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide 20 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions 21 | provided by the bot. You will only need to do this once across all repos using our CLA. 22 | 23 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 24 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 25 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 26 | 27 | ## Trademarks 28 | 29 | This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft 30 | trademarks or logos is subject to and must follow 31 | [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). 32 | Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. 33 | Any use of third-party trademarks or logos are subject to those third-party's policies. 34 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | ## How to file issues and get help 4 | 5 | This project uses GitHub Issues to track bugs and feature requests. Please search the existing 6 | issues before filing new issues to avoid duplicates. For new issues, file your bug or 7 | feature request as a new Issue. 8 | 9 | For help and questions about using this project, please use GitHub Discussions to ask a question. 10 | 11 | ## Microsoft Support Policy 12 | 13 | Support for this project is limited to the resources listed above. 14 | -------------------------------------------------------------------------------- /build-challenge/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="buildchallenge" 2 | MINECRAFT_PRODUCT="BedrockUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /build-challenge/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /build-challenge/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /build-challenge/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.5.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "localRoot": "${workspaceFolder}/scripts/", 11 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 12 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 13 | "port": 19144 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /build-challenge/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "cand", 29 | "canonicalize", 30 | "chainmail", 31 | "chall", 32 | "CHARFONT", 33 | "chestplate", 34 | "Gamemode", 35 | "gametest", 36 | "gametests", 37 | "lerp", 38 | "minecart", 39 | "SCORESHEET", 40 | "shulker", 41 | "tock", 42 | "Tocks", 43 | "xtralarge", 44 | "zoglin" 45 | ], 46 | "editor.tabSize": 2, 47 | "eslint.experimental.useFlatConfig": true 48 | } 49 | -------------------------------------------------------------------------------- /build-challenge/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /build-challenge/behavior_packs/buildchallenge/items/heart.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.20.30", 3 | "minecraft:item": { 4 | "description": { 5 | "identifier": "bc:heart", 6 | "category": "Items" 7 | }, 8 | "components": { 9 | "minecraft:max_stack_size": 16, 10 | "minecraft:icon": { 11 | "texture": "bc:heart" 12 | }, 13 | "minecraft:display_name": { 14 | "value": "Heart Vote" 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /build-challenge/behavior_packs/buildchallenge/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Build Challenge", 5 | "description": "Host a build challenge within a survival world", 6 | "uuid": "cfe3d87b-8792-47f6-b4e0-67b251065ca9", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 21, 20] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Script resources", 13 | "language": "javascript", 14 | "type": "script", 15 | "uuid": "7ae54230-1350-4347-aec5-763676ee41e0", 16 | "version": [1, 0, 0], 17 | "entry": "scripts/main.js" 18 | } 19 | ], 20 | "dependencies": [ 21 | { 22 | "module_name": "@minecraft/server", 23 | "version": "1.13.0" 24 | }, 25 | { 26 | "module_name": "@minecraft/server-ui", 27 | "version": "1.2.0" 28 | }, 29 | { 30 | "uuid": "1103c416-7d50-4cf7-99c2-01decb358293", 31 | "version": [1, 0, 0] 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /build-challenge/behavior_packs/buildchallenge/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/behavior_packs/buildchallenge/pack_icon.png -------------------------------------------------------------------------------- /build-challenge/behavior_packs/buildchallenge/structures/challenge/options.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/behavior_packs/buildchallenge/structures/challenge/options.mcstructure -------------------------------------------------------------------------------- /build-challenge/behavior_packs/buildchallenge/structures/challenge/viewtower.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/behavior_packs/buildchallenge/structures/challenge/viewtower.mcstructure -------------------------------------------------------------------------------- /build-challenge/behavior_packs/buildchallenge/structures/challenge/vote.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/behavior_packs/buildchallenge/structures/challenge/vote.mcstructure -------------------------------------------------------------------------------- /build-challenge/behavior_packs/buildchallenge/structures/challenge/vote2.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/behavior_packs/buildchallenge/structures/challenge/vote2.mcstructure -------------------------------------------------------------------------------- /build-challenge/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /build-challenge/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "build-challenge", 3 | "version": "0.1.0", 4 | "productName": "Build Challenge", 5 | "description": "Host a build challenge within a survival world", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.6.2" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "mcaddon": "just-scripts mcaddon", 20 | "update-world": "just-scripts update-world", 21 | "pack-world": "just-scripts pack-world", 22 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 23 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 24 | }, 25 | "dependencies": { 26 | "@minecraft/server": "^1.14.0", 27 | "@minecraft/server-ui": "^1.3.0", 28 | "@minecraft/vanilla-data": "^1.21.20" 29 | }, 30 | "overrides": { 31 | "@minecraft/server-ui": { 32 | "@minecraft/server": "$@minecraft/server" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /build-challenge/resource_packs/buildchallenge/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Build challenge resource pack", 5 | "description": "Build challenge resource pack", 6 | "uuid": "1103c416-7d50-4cf7-99c2-01decb358293", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 21, 20] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Demo Resource Pack", 13 | "type": "resources", 14 | "uuid": "488b9027-02bc-4909-81c8-e2b20eb78757", 15 | "version": [1, 0, 0] 16 | } 17 | ], 18 | "dependencies": [ 19 | { 20 | "uuid": "cfe3d87b-8792-47f6-b4e0-67b251065ca9", 21 | "version": [1, 0, 0] 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /build-challenge/resource_packs/buildchallenge/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/resource_packs/buildchallenge/pack_icon.png -------------------------------------------------------------------------------- /build-challenge/resource_packs/buildchallenge/texts/en_US.lang: -------------------------------------------------------------------------------- 1 | item.bc:heart=Build Heart Vote -------------------------------------------------------------------------------- /build-challenge/resource_packs/buildchallenge/textures/item_texture.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource_pack_name": "custom_item_resource_pack", 3 | "texture_name": "atlas.items", 4 | "texture_data": { 5 | "bc:heart": { 6 | "textures": "textures/items/heart" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /build-challenge/resource_packs/buildchallenge/textures/items/heart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/resource_packs/buildchallenge/textures/items/heart.png -------------------------------------------------------------------------------- /build-challenge/scripts/Log.ts: -------------------------------------------------------------------------------- 1 | import { world, system } from "@minecraft/server"; 2 | 3 | export default class Log { 4 | static debug(name: string) { 5 | console.warn(name); 6 | 7 | // world.sendMessage("debug: " + name); 8 | } 9 | 10 | static debugAssert(condition: boolean, text?: string) { 11 | if (!condition) { 12 | let errorText = "Assertion failed"; 13 | 14 | if (text) { 15 | errorText += ": " + text; 16 | } 17 | 18 | Log.debug(errorText); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /build-challenge/scripts/Track.ts: -------------------------------------------------------------------------------- 1 | import { Vector3 } from "@minecraft/server"; 2 | 3 | export default class Track { 4 | from: Vector3; 5 | to: Vector3; 6 | facingAdjust: Vector3; 7 | constructor(newFrom: Vector3, newTo: Vector3, newFacingAdjust: Vector3) { 8 | this.from = newFrom; 9 | this.to = newTo; 10 | this.facingAdjust = newFacingAdjust; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /build-challenge/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { world, WorldInitializeAfterEvent } from "@minecraft/server"; 2 | import Challenge from "./Challenge.js"; 3 | 4 | const cv = new Challenge(); 5 | 6 | world.afterEvents.worldInitialize.subscribe(worldInit); 7 | 8 | function worldInit(event: WorldInitializeAfterEvent) { 9 | cv.init(); 10 | } 11 | -------------------------------------------------------------------------------- /build-challenge/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /build-challenge/worlds/default/db/CURRENT: -------------------------------------------------------------------------------- 1 | MANIFEST-000002 2 | -------------------------------------------------------------------------------- /build-challenge/worlds/default/db/MANIFEST-000002: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/worlds/default/db/MANIFEST-000002 -------------------------------------------------------------------------------- /build-challenge/worlds/default/level.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/worlds/default/level.dat -------------------------------------------------------------------------------- /build-challenge/worlds/default/level.dat_old: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/worlds/default/level.dat_old -------------------------------------------------------------------------------- /build-challenge/worlds/default/levelname.txt: -------------------------------------------------------------------------------- 1 | Build Challenge 2000 -------------------------------------------------------------------------------- /build-challenge/worlds/default/world_behavior_packs.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pack_id": "cfe3d87b-8792-47f6-b4e0-67b251065ca9", 4 | "version": [ 5 | 1, 6 | 0, 7 | 0 8 | ] 9 | } 10 | ] -------------------------------------------------------------------------------- /build-challenge/worlds/default/world_icon.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/build-challenge/worlds/default/world_icon.jpeg -------------------------------------------------------------------------------- /build-challenge/worlds/default/world_resource_packs.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "pack_id": "1103c416-7d50-4cf7-99c2-01decb358293", 4 | "version": [ 5 | 1, 6 | 0, 7 | 0 8 | ] 9 | } 10 | ] -------------------------------------------------------------------------------- /custom-commands/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="mike_cc" 2 | MINECRAFT_PRODUCT="PreviewUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" 4 | -------------------------------------------------------------------------------- /custom-commands/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /custom-commands/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /custom-commands/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.3.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "port": 19144, 7 | "request": "attach", 8 | "mode": "listen", 9 | "name": "Debug with Minecraft", 10 | "preLaunchTask": "build", 11 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 12 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /custom-commands/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "gametest", 29 | "gametests", 30 | "mcaddon" 31 | ], 32 | "editor.tabSize": 2, 33 | "eslint.experimental.useFlatConfig": true 34 | } -------------------------------------------------------------------------------- /custom-commands/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "dependsOrder": "sequence", 7 | "dependsOn": [ 8 | "minecraft: deploy" 9 | ] 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /custom-commands/behavior_packs/mike_cc/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "CustomCommands", 5 | "description": "TypeScript Starter", 6 | "uuid": "490cb58c-e6b1-4af2-8f48-433b96ae8dcd", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 21, 80] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Script resources", 13 | "language": "javascript", 14 | "type": "script", 15 | "uuid": "d6cc3ec1-f3d6-4ee1-9883-e01852a27c7a", 16 | "version": [1, 0, 0], 17 | "entry": "scripts/main.js" 18 | } 19 | ], 20 | "dependencies": [ 21 | { 22 | "module_name": "@minecraft/server", 23 | "version": "2.0.0-beta" 24 | }, 25 | { 26 | "uuid": "06f36430-433b-4315-a30f-02d41e54b078", 27 | "version": [1, 0, 0] 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /custom-commands/behavior_packs/mike_cc/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-commands/behavior_packs/mike_cc/pack_icon.png -------------------------------------------------------------------------------- /custom-commands/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | export default [ 5 | { 6 | files: ["scripts/**/*.ts"], 7 | languageOptions: { 8 | parser: tsParser, 9 | ecmaVersion: "latest", 10 | }, 11 | plugins: { 12 | ts, 13 | "minecraft-linting": minecraftLinting, 14 | }, 15 | rules: { 16 | "minecraft-linting/avoid-unnecessary-command": "error", 17 | }, 18 | }, 19 | ]; -------------------------------------------------------------------------------- /custom-commands/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import { 3 | BundleTaskParameters, 4 | CopyTaskParameters, 5 | bundleTask, 6 | cleanTask, 7 | cleanCollateralTask, 8 | copyTask, 9 | coreLint, 10 | mcaddonTask, 11 | setupEnvironment, 12 | ZipTaskParameters, 13 | STANDARD_CLEAN_PATHS, 14 | DEFAULT_CLEAN_DIRECTORIES, 15 | getOrThrowFromProcess, 16 | watchTask, 17 | } from "@minecraft/core-build-tasks"; 18 | import path from "path"; 19 | setupEnvironment(path.resolve(__dirname, ".env")); 20 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 21 | const bundleTaskOptions: BundleTaskParameters = { 22 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 23 | external: ["@minecraft/server", "@minecraft/server-ui"], 24 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 25 | minifyWhitespace: false, 26 | sourcemap: true, 27 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 28 | }; 29 | const copyTaskOptions: CopyTaskParameters = { 30 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 31 | copyToScripts: ["./dist/scripts"], 32 | copyToResourcePacks: [`./resource_packs/${projectName}`], 33 | }; 34 | const mcaddonTaskOptions: ZipTaskParameters = { 35 | ...copyTaskOptions, 36 | outputFile: `./dist/packages/${projectName}.mcaddon`, 37 | }; 38 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 39 | task("typescript", tscTask()); 40 | task("bundle", bundleTask(bundleTaskOptions)); 41 | task("build", series("typescript", "bundle")); 42 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 43 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 44 | task("clean", parallel("clean-local", "clean-collateral")); 45 | task("copyArtifacts", copyTask(copyTaskOptions)); 46 | task("package", series("clean-collateral", "copyArtifacts")); 47 | task( 48 | "local-deploy", 49 | watchTask( 50 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,tga,ogg,png}", "resource_packs/**/*.{json,lang,tga,ogg,png}"], 51 | series("clean-local", "build", "package") 52 | ) 53 | ); 54 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 55 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); -------------------------------------------------------------------------------- /custom-commands/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CustomCommands", 3 | "version": "0.1.0", 4 | "productName": "Minecraft TypeScript Starter Project", 5 | "description": "TypeScript Starter", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.2", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.5.4" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "mcaddon": "just-scripts mcaddon", 20 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 21 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 22 | }, 23 | "dependencies": { 24 | "@minecraft/server": "^2.0.0-beta.1.21.80-preview.27", 25 | "@minecraft/server-ui": "^2.0.0-beta.1.21.80-preview.22", 26 | "@minecraft/vanilla-data": "^1.21.62" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /custom-commands/resource_packs/mike_cc/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "CustomCommands", 5 | "description": "TypeScript Starter", 6 | "uuid": "06f36430-433b-4315-a30f-02d41e54b078", 7 | "version": [ 8 | 1, 9 | 0, 10 | 0 11 | ], 12 | "min_engine_version": [ 13 | 1, 14 | 21, 15 | 80 16 | ] 17 | }, 18 | "modules": [ 19 | { 20 | "description": "My Resource Pack", 21 | "type": "resources", 22 | "uuid": "0d36f7a8-e710-46ed-ac97-bef823020561", 23 | "version": [ 24 | 1, 25 | 0, 26 | 0 27 | ] 28 | } 29 | ], 30 | "dependencies": [ 31 | { 32 | "uuid": "490cb58c-e6b1-4af2-8f48-433b96ae8dcd", 33 | "version": [ 34 | 1, 35 | 0, 36 | 0 37 | ] 38 | } 39 | ] 40 | } -------------------------------------------------------------------------------- /custom-commands/resource_packs/mike_cc/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-commands/resource_packs/mike_cc/pack_icon.png -------------------------------------------------------------------------------- /custom-commands/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "moduleResolution": "Node", 5 | "module": "ES2020", 6 | "declaration": false, 7 | "noLib": false, 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "sourceMap": true, 11 | "pretty": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode": true, 15 | "allowUnusedLabels": true, 16 | "noImplicitAny": true, 17 | "noImplicitReturns": false, 18 | "noImplicitUseStrict": false, 19 | "outDir": "lib", 20 | "rootDir": ".", 21 | "baseUrl": "behavior_packs/", 22 | "listFiles": false, 23 | "noEmitHelpers": true, 24 | "skipLibCheck": true 25 | }, 26 | "include": [ 27 | "scripts/**/*" 28 | ], 29 | "exclude": [ 30 | "lib", 31 | "dist", 32 | "node_modules" 33 | ], 34 | "compileOnSave": false 35 | } -------------------------------------------------------------------------------- /custom-components/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="custom_components" 2 | MINECRAFT_PRODUCT="BedrockUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /custom-components/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /custom-components/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /custom-components/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /custom-components/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "gametest", 29 | "gametests", 30 | "mcaddon", 31 | "minecart", 32 | "shulker", 33 | "zoglin" 34 | ], 35 | "editor.tabSize": 2, 36 | "eslint.experimental.useFlatConfig": true 37 | } -------------------------------------------------------------------------------- /custom-components/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /custom-components/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | author: agriffin 4 | description: An addon using block and item custom components to add a new strawberry crop and watering tool. 5 | ms.author: agriffin@microsoft.com 6 | ms.date: 06/11/2024 7 | languages: 8 | - typescript 9 | products: 10 | - minecraft 11 | --- 12 | 13 | # Minecraft How-to Gallery 14 | 15 | This addon contains many code snippets that show how you can use custom components to create new logic for custom blocks and items. 16 | 17 | ## Prerequisites 18 | 19 | **Install Node.js tools, if you haven't already** 20 | 21 | We're going to use the package manager [npm](https://www.npmjs.com/package/npm) to get more tools to make the process of building our project easier. 22 | 23 | Visit [https://nodejs.org/](https://nodejs.org). 24 | 25 | Download the version with "LTS" next to the number and install it. (LTS stands for Long Term Support, if you're curious.) In the Node.js Windows installer, accept the installation defaults. You do not need to install any additional tools for Native compilation. 26 | 27 | **Install Visual Studio Code, if you haven't already** 28 | 29 | Visit the [Visual Studio Code website](https://code.visualstudio.com) and install Visual Studio Code. 30 | 31 | ## Getting Started 32 | 33 | 1. Use npm to install dependent modules: 34 | 35 | ```powershell 36 | npm i 37 | ``` 38 | 39 | 1. Use this shortcut command to open the project in Visual Studio Code: 40 | 41 | ```powershell 42 | code . 43 | ``` 44 | 45 | ### Chapter 2. Let's test the parts of our project 46 | 47 | Within the root folder (howto-gallery) of this sample, run this command: 48 | 49 | ```powershell 50 | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 51 | ``` 52 | 53 | Run this one to deploy in the game. 54 | 55 | ```powershell 56 | npm run local-deploy 57 | ``` 58 | 59 | Create an addon file to share. 60 | 61 | ```powershell 62 | npm run mcaddon 63 | ``` 64 | 65 | ## Manifest 66 | 67 | - [just.config.ts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/just.config.ts): This file contains build instructions for just-scripts, for building out TypeScript code. 68 | - [scripts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/scripts): This contains How to Gallery TypeScript files, that will be compiled and built into your projects. 69 | - [behavior_packs](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/behavior_packs): This contains resources and JSON files that define your behavior pack. 70 | -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/items/sprayer_empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.21.10", 3 | "minecraft:item": { 4 | "description": { 5 | "identifier": "starter:spray_can_empty" 6 | }, 7 | "components": { 8 | "minecraft:icon": "spray_can_empty", 9 | "minecraft:liquid_clipped": true, 10 | "minecraft:custom_components": [ 11 | "starter:gather_water" 12 | ] 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/items/sprayer_full.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.21.10", 3 | "minecraft:item": { 4 | "description": { 5 | "identifier": "starter:spray_can_full" 6 | }, 7 | "components": { 8 | "minecraft:icon": "spray_can_full", 9 | "minecraft:liquid_clipped": true, 10 | "minecraft:custom_components": [ 11 | "starter:spray_water" 12 | ], 13 | "minecraft:use_modifiers": { 14 | "use_duration": 1, 15 | "movement_modifier": 0.35 16 | }, 17 | "minecraft:use_animation": "drink" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/items/strawberry.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.21.10", 3 | "minecraft:item": { 4 | "description": { 5 | "menu_category": { 6 | "group": "itemGroup.name.crop", 7 | "category": "nature" 8 | }, 9 | "identifier": "starter:strawberry" 10 | }, 11 | "components": { 12 | "minecraft:icon": "strawberry", 13 | "minecraft:max_stack_size": 64, 14 | "minecraft:use_modifiers": { 15 | "use_duration": 1.6, 16 | "movement_modifier": 0.35 17 | }, 18 | "minecraft:food": { 19 | "can_always_eat": true, 20 | "nutrition": 1, 21 | "saturation_modifier": 0.5 22 | }, 23 | "minecraft:use_animation": "eat", 24 | "minecraft:custom_components": [ 25 | "starter:add_night_vision_on_consume" 26 | ] 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/items/strawberry_rotten.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.21.10", 3 | "minecraft:item": { 4 | "description": { 5 | "menu_category": { 6 | "group": "itemGroup.name.crop", 7 | "category": "nature" 8 | }, 9 | "identifier": "starter:strawberry_rotten" 10 | }, 11 | "components": { 12 | "minecraft:icon": "strawberry_rotten", 13 | "minecraft:max_stack_size": 64, 14 | "minecraft:use_modifiers": { 15 | "use_duration": 1.6, 16 | "movement_modifier": 0.35 17 | }, 18 | "minecraft:food": { 19 | "can_always_eat": true, 20 | "nutrition": 1, 21 | "saturation_modifier": 0.1 22 | }, 23 | "minecraft:custom_components": [ 24 | "starter:cause_hunger_on_eat" 25 | ], 26 | "minecraft:use_animation": "eat" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/items/strawberry_seeds.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.21.10", 3 | "minecraft:item": { 4 | "description": { 5 | "menu_category": { 6 | "group": "itemGroup.name.seed", 7 | "category": "nature" 8 | }, 9 | "identifier": "starter:strawberry_seeds" 10 | }, 11 | "components": { 12 | "minecraft:icon": "strawberry_seeds", 13 | "minecraft:max_stack_size": 64, 14 | "minecraft:block_placer": { 15 | "block": "starter:strawberry_crop" 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/loot_tables/strawberry_crop.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": [ 3 | { 4 | "rolls": 1, 5 | "entries": [ 6 | { 7 | "type": "item", 8 | "name": "starter:strawberry_seeds", 9 | "weight": 1, 10 | "functions": [ 11 | { 12 | "function": "set_count", 13 | "count": { 14 | "min": 1, 15 | "max": 1 16 | } 17 | }, 18 | { 19 | "function": "looting_enchant", 20 | "count": { 21 | "min": 0, 22 | "max": 1 23 | } 24 | } 25 | ] 26 | } 27 | ] 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/loot_tables/strawberry_grown_crop.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": [ 3 | { 4 | "rolls": 1, 5 | "entries": [ 6 | { 7 | "type": "item", 8 | "name": "starter:strawberry_seeds", 9 | "weight": 1, 10 | "functions": [ 11 | { 12 | "function": "set_count", 13 | "count": { 14 | "min": 1, 15 | "max": 2 16 | } 17 | }, 18 | { 19 | "function": "looting_enchant", 20 | "count": { 21 | "min": 0, 22 | "max": 1 23 | } 24 | } 25 | ] 26 | } 27 | ] 28 | }, 29 | { 30 | "rolls": 1, 31 | "entries": [ 32 | { 33 | "type": "item", 34 | "name": "starter:strawberry", 35 | "weight": 1, 36 | "functions": [ 37 | { 38 | "function": "set_count", 39 | "count": { 40 | "min": 3, 41 | "max": 5 42 | } 43 | }, 44 | { 45 | "function": "looting_enchant", 46 | "count": { 47 | "min": 1, 48 | "max": 2 49 | } 50 | } 51 | ] 52 | } 53 | ] 54 | } 55 | ] 56 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/loot_tables/strawberry_rotten_crop.json: -------------------------------------------------------------------------------- 1 | { 2 | "pools": [ 3 | { 4 | "rolls": 1, 5 | "entries": [ 6 | { 7 | "type": "item", 8 | "name": "starter:strawberry_seeds", 9 | "weight": 1, 10 | "functions": [ 11 | { 12 | "function": "set_count", 13 | "count": { 14 | "min": 1, 15 | "max": 2 16 | } 17 | }, 18 | { 19 | "function": "looting_enchant", 20 | "count": { 21 | "min": 0, 22 | "max": 1 23 | } 24 | } 25 | ] 26 | } 27 | ] 28 | }, 29 | { 30 | "rolls": 1, 31 | "entries": [ 32 | { 33 | "type": "item", 34 | "name": "starter:strawberry_rotten", 35 | "weight": 1, 36 | "functions": [ 37 | { 38 | "function": "set_count", 39 | "count": { 40 | "min": 3, 41 | "max": 5 42 | } 43 | }, 44 | { 45 | "function": "looting_enchant", 46 | "count": { 47 | "min": 2, 48 | "max": 3 49 | } 50 | } 51 | ] 52 | } 53 | ] 54 | } 55 | ] 56 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Custom components behavior pack", 5 | "description": "Custom components behavior pack", 6 | "uuid": "922f8c01-632f-4579-91c4-40101d578de7", 7 | "version": [ 8 | 1, 9 | 0, 10 | 0 11 | ], 12 | "min_engine_version": [ 13 | 1, 14 | 20, 15 | 30 16 | ] 17 | }, 18 | "modules": [ 19 | { 20 | "description": "Script resources", 21 | "language": "javascript", 22 | "type": "script", 23 | "uuid": "85c3bdf1-a82b-47f1-962f-90cb74c0f300", 24 | "version": [ 25 | 1, 26 | 0, 27 | 0 28 | ], 29 | "entry": "scripts/main.js" 30 | } 31 | ], 32 | "dependencies": [ 33 | { 34 | "module_name": "@minecraft/server", 35 | "version": "1.13.0" 36 | }, 37 | { 38 | "uuid": "7bd3b140-a9c0-42cb-aa56-0bdedc80e27b", 39 | "version": [ 40 | 1, 41 | 0, 42 | 0 43 | ] 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /custom-components/behavior_packs/custom_components/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/behavior_packs/custom_components/pack_icon.png -------------------------------------------------------------------------------- /custom-components/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /custom-components/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import { 3 | BundleTaskParameters, 4 | CopyTaskParameters, 5 | bundleTask, 6 | cleanTask, 7 | cleanCollateralTask, 8 | copyTask, 9 | coreLint, 10 | mcaddonTask, 11 | setupEnvironment, 12 | ZipTaskParameters, 13 | STANDARD_CLEAN_PATHS, 14 | DEFAULT_CLEAN_DIRECTORIES, 15 | getOrThrowFromProcess, 16 | watchTask, 17 | } from "@minecraft/core-build-tasks"; 18 | import path from "path"; 19 | 20 | // Setup env variables 21 | setupEnvironment(path.resolve(__dirname, ".env")); 22 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 23 | 24 | const bundleTaskOptions: BundleTaskParameters = { 25 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 26 | external: ["@minecraft/server", "@minecraft/server-ui"], 27 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 28 | minifyWhitespace: false, 29 | sourcemap: true, 30 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 31 | }; 32 | 33 | const copyTaskOptions: CopyTaskParameters = { 34 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 35 | copyToScripts: ["./dist/scripts"], 36 | copyToResourcePacks: [`./resource_packs/${projectName}`], 37 | }; 38 | 39 | const mcaddonTaskOptions: ZipTaskParameters = { 40 | ...copyTaskOptions, 41 | outputFile: `./dist/packages/${projectName}.mcaddon`, 42 | }; 43 | 44 | // Lint 45 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 46 | 47 | // Build 48 | task("typescript", tscTask()); 49 | task("bundle", bundleTask(bundleTaskOptions)); 50 | task("build", series("typescript", "bundle")); 51 | 52 | // Clean 53 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 54 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 55 | task("clean", parallel("clean-local", "clean-collateral")); 56 | 57 | // Package 58 | task("copyArtifacts", copyTask(copyTaskOptions)); 59 | task("package", series("clean-collateral", "copyArtifacts")); 60 | 61 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 62 | task( 63 | "local-deploy", 64 | watchTask( 65 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 66 | series("clean-local", "build", "package") 67 | ) 68 | ); 69 | 70 | // Mcaddon 71 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 72 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 73 | -------------------------------------------------------------------------------- /custom-components/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scripting-custom-component", 3 | "version": "0.1.0", 4 | "productName": "Minecraft TypeScript Custom Component", 5 | "description": "Minecraft TypeScript Custom Component", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.6.2" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "mcaddon": "just-scripts mcaddon", 20 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 21 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 22 | }, 23 | "dependencies": { 24 | "@minecraft/math": "^2.0.1", 25 | "@minecraft/server": "^1.14.0", 26 | "@minecraft/server-ui": "^1.3.0", 27 | "@minecraft/vanilla-data": "^1.21.20" 28 | }, 29 | "overrides": { 30 | "@minecraft/math": { 31 | "@minecraft/server": "$@minecraft/server" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Custom components resource pack", 5 | "description": "Custom components resource pack", 6 | "uuid": "7bd3b140-a9c0-42cb-aa56-0bdedc80e27b", 7 | "version": [ 8 | 1, 9 | 0, 10 | 0 11 | ], 12 | "min_engine_version": [ 13 | 1, 14 | 20, 15 | 30 16 | ] 17 | }, 18 | "modules": [ 19 | { 20 | "description": "My Resource Pack", 21 | "type": "resources", 22 | "uuid": "053c2173-2278-4a68-b55a-e101418b42c9", 23 | "version": [ 24 | 1, 25 | 0, 26 | 0 27 | ] 28 | } 29 | ], 30 | "dependencies": [ 31 | { 32 | "uuid": "922f8c01-632f-4579-91c4-40101d578de7", 33 | "version": [ 34 | 1, 35 | 0, 36 | 0 37 | ] 38 | } 39 | ] 40 | } -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/models/blocks/crop.geo.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": "1.21.10", 3 | "minecraft:geometry": [ 4 | { 5 | "description": { 6 | "identifier": "geometry.starter_crop_geo", 7 | "texture_width": 16, 8 | "texture_height": 16, 9 | "visible_bounds_width": 2, 10 | "visible_bounds_height": 2, 11 | "visible_bounds_offset": [ 12 | 0, 13 | 0, 14 | 0 15 | ] 16 | }, 17 | "bones": [ 18 | { 19 | "name": "world", 20 | "pivot": [ 21 | 0, 22 | 0, 23 | 0 24 | ], 25 | "cubes": [ 26 | { 27 | "origin": [ 28 | -8, 29 | -1, 30 | 0 31 | ], 32 | "size": [ 33 | 16, 34 | 16, 35 | 0 36 | ], 37 | "pivot": [ 38 | 0, 39 | -1, 40 | 0 41 | ], 42 | "rotation": [ 43 | 0, 44 | 45, 45 | 0 46 | ], 47 | "uv": [ 48 | 0, 49 | 0 50 | ] 51 | }, 52 | { 53 | "origin": [ 54 | -8, 55 | -1, 56 | 0 57 | ], 58 | "size": [ 59 | 16, 60 | 16, 61 | 0 62 | ], 63 | "pivot": [ 64 | 0, 65 | -1, 66 | 0 67 | ], 68 | "rotation": [ 69 | 0, 70 | -45, 71 | 0 72 | ], 73 | "uv": [ 74 | 0, 75 | 0 76 | ] 77 | } 78 | ] 79 | } 80 | ] 81 | } 82 | ] 83 | } -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/pack_icon.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/texts/en_US.lang: -------------------------------------------------------------------------------- 1 | item.starter:strawberry=Strawberry 2 | item.starter:strawberry_rotten=Rotten Strawberry 3 | item.starter:strawberry_seeds=Strawberry Seeds 4 | tile.starter:strawberry_crop.name=Strawberries 5 | -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/blocks/strawberry_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/blocks/strawberry_0.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/blocks/strawberry_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/blocks/strawberry_1.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/blocks/strawberry_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/blocks/strawberry_2.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/blocks/strawberry_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/blocks/strawberry_3.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/blocks/strawberry_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/blocks/strawberry_4.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/blocks/strawberry_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/blocks/strawberry_5.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/item_texture.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource_pack_name": "starter", 3 | "texture_name": "atlas.items", 4 | "texture_data": { 5 | "strawberry": { 6 | "textures": "textures/items/strawberry" 7 | }, 8 | "strawberry_rotten": { 9 | "textures": "textures/items/strawberry_rotten" 10 | }, 11 | "strawberry_seeds": { 12 | "textures": "textures/items/strawberry_seeds" 13 | }, 14 | "spray_can_empty": { 15 | "textures": "textures/items/spray_can_empty" 16 | }, 17 | "spray_can_full": { 18 | "textures": "textures/items/spray_can_full" 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/items/spray_can_empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/items/spray_can_empty.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/items/spray_can_full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/items/spray_can_full.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/items/strawberry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/items/strawberry.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/items/strawberry_rotten.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/items/strawberry_rotten.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/items/strawberry_seeds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/custom-components/resource_packs/custom_components/textures/items/strawberry_seeds.png -------------------------------------------------------------------------------- /custom-components/resource_packs/custom_components/textures/terrain_texture.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource_pack_name": "starter", 3 | "texture_name": "atlas.terrain", 4 | "padding": 8, 5 | "num_mip_levels": 4, 6 | "texture_data": { 7 | "strawberry_crop_0": { 8 | "textures": "textures/blocks/strawberry_0" 9 | }, 10 | "strawberry_crop_1": { 11 | "textures": "textures/blocks/strawberry_1" 12 | }, 13 | "strawberry_crop_2": { 14 | "textures": "textures/blocks/strawberry_2" 15 | }, 16 | "strawberry_crop_3": { 17 | "textures": "textures/blocks/strawberry_3" 18 | }, 19 | "strawberry_crop_4": { 20 | "textures": "textures/blocks/strawberry_4" 21 | }, 22 | "strawberry_crop_rotten": { 23 | "textures": "textures/blocks/strawberry_5" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /custom-components/scripts/CauseHungerOnConsumeComponent.ts: -------------------------------------------------------------------------------- 1 | import { ItemComponentConsumeEvent, ItemCustomComponent } from "@minecraft/server"; 2 | 3 | export class CauseHungerOnConsumeComponent implements ItemCustomComponent { 4 | onConsume(arg: ItemComponentConsumeEvent) { 5 | arg.source.addEffect("minecraft:hunger", 600); 6 | arg.source.applyDamage(0.5); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /custom-components/scripts/CropGrowthComponent.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Block, 3 | BlockComponentPlayerInteractEvent, 4 | BlockComponentRandomTickEvent, 5 | BlockCustomComponent, 6 | EntityInventoryComponent, 7 | Player, 8 | } from "@minecraft/server"; 9 | 10 | export class CropGrowthComponent implements BlockCustomComponent { 11 | static tryGrowBlock(block: Block) { 12 | const perm = block.permutation; 13 | const age = perm.getState("starter:crop_age"); 14 | if (age === undefined || typeof age !== "number") { 15 | return; 16 | } 17 | 18 | if (age === 5) { 19 | return; // already at max age 20 | } 21 | 22 | block.setPermutation(perm.withState("starter:crop_age", age + 1)); 23 | } 24 | 25 | static tryFertilize(block: Block, player: Player): boolean { 26 | const inventory = player.getComponent(EntityInventoryComponent.componentId) as EntityInventoryComponent; 27 | if (inventory === undefined) { 28 | return false; 29 | } 30 | 31 | const selectedItem = inventory.container?.getItem(player.selectedSlotIndex); 32 | if (selectedItem && selectedItem.typeId === "minecraft:bone_meal") { 33 | CropGrowthComponent.tryGrowBlock(block); 34 | selectedItem.amount--; 35 | inventory.container?.setItem(player.selectedSlotIndex, selectedItem); 36 | return true; 37 | } 38 | return false; 39 | } 40 | 41 | onRandomTick(arg: BlockComponentRandomTickEvent) { 42 | CropGrowthComponent.tryGrowBlock(arg.block); 43 | } 44 | 45 | // fertilization growth with bone meal 46 | onPlayerInteract(arg: BlockComponentPlayerInteractEvent) { 47 | if (arg.player === undefined) { 48 | return; 49 | } 50 | 51 | CropGrowthComponent.tryFertilize(arg.block, arg.player); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /custom-components/scripts/GrownStrawberryCropComponent.ts: -------------------------------------------------------------------------------- 1 | import { BlockComponentPlayerInteractEvent, BlockComponentTickEvent, BlockCustomComponent } from "@minecraft/server"; 2 | import { CropGrowthComponent } from "./CropGrowthComponent"; 3 | 4 | export class GrownStrawberryCropComponent implements BlockCustomComponent { 5 | onTick(arg: BlockComponentTickEvent) { 6 | CropGrowthComponent.tryGrowBlock(arg.block); 7 | } 8 | 9 | onPlayerInteract(arg: BlockComponentPlayerInteractEvent) { 10 | if (arg.player === undefined) { 11 | return; 12 | } 13 | 14 | // let player fertilize to rotten 15 | if (CropGrowthComponent.tryFertilize(arg.block, arg.player)) { 16 | return; 17 | } 18 | 19 | // otherwise harvest the block and replant it 20 | const pos = arg.block.location; 21 | arg.dimension.runCommand("loot spawn " + pos.x + " " + pos.y + " " + pos.z + " loot strawberry_grown_crop"); 22 | arg.block.setPermutation(arg.block.permutation.withState("starter:crop_age", 0)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /custom-components/scripts/NightVisionConsumeComponent.ts: -------------------------------------------------------------------------------- 1 | import { ItemComponentConsumeEvent, ItemCustomComponent } from "@minecraft/server"; 2 | 3 | export class NightVisionConsumeComponent implements ItemCustomComponent { 4 | onConsume(arg: ItemComponentConsumeEvent) { 5 | arg.source.addEffect("minecraft:night_vision", 600); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /custom-components/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { world, ItemComponentConsumeEvent } from "@minecraft/server"; 2 | import { GrownStrawberryCropComponent } from "./GrownStrawberryCropComponent"; 3 | import { CropGrowthComponent } from "./CropGrowthComponent"; 4 | import { CauseHungerOnConsumeComponent } from "./CauseHungerOnConsumeComponent"; 5 | import { sprayWater, gatherWater } from "./SprayerComponents"; 6 | 7 | world.beforeEvents.worldInitialize.subscribe((initEvent) => { 8 | // block 9 | initEvent.blockComponentRegistry.registerCustomComponent("starter:strawberry_grown", new GrownStrawberryCropComponent()); 10 | initEvent.blockComponentRegistry.registerCustomComponent("starter:crop_grow", new CropGrowthComponent()); 11 | 12 | // item 13 | initEvent.itemComponentRegistry.registerCustomComponent( 14 | "starter:cause_hunger_on_eat", 15 | new CauseHungerOnConsumeComponent() 16 | ); 17 | initEvent.itemComponentRegistry.registerCustomComponent("starter:spray_water", { 18 | onCompleteUse: sprayWater, 19 | }); 20 | initEvent.itemComponentRegistry.registerCustomComponent("starter:gather_water", { 21 | onUseOn: gatherWater, 22 | }); 23 | initEvent.itemComponentRegistry.registerCustomComponent("starter:add_night_vision_on_consume", { 24 | onConsume(arg: ItemComponentConsumeEvent) { 25 | arg.source.addEffect("minecraft:night_vision", 600); 26 | }, 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /custom-components/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /editor-basics/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="editor-basics" 2 | MINECRAFT_PRODUCT="PreviewUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /editor-basics/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /editor-basics/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /editor-basics/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /editor-basics/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "Elytra", 29 | "Equippable", 30 | "gametest", 31 | "gametests", 32 | "knockback", 33 | "mcaddon", 34 | "mcui", 35 | "minecart", 36 | "molang", 37 | "onfire", 38 | "samplelibrary", 39 | "scriptevent", 40 | "shulker", 41 | "skelly", 42 | "zoglin" 43 | ], 44 | "editor.tabSize": 2, 45 | "eslint.experimental.useFlatConfig": true 46 | } 47 | -------------------------------------------------------------------------------- /editor-basics/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /editor-basics/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | author: mammerla 4 | description: A comprehensive gallery of different samples of Minecraft coding behaviors. 5 | ms.author: mikeam@microsoft.com 6 | ms.date: 05/05/2022 7 | languages: 8 | - typescript 9 | products: 10 | - minecraft 11 | --- 12 | 13 | # Minecraft How-to Gallery 14 | 15 | This sample contains many code snippets that show how you can manipulate basic Minecraft behaviors. 16 | 17 | ## Prerequisites 18 | 19 | **Install Node.js tools, if you haven't already** 20 | 21 | We're going to use the package manager [npm](https://www.npmjs.com/package/npm) to get more tools to make the process of building our project easier. 22 | 23 | Visit [https://nodejs.org/](https://nodejs.org). 24 | 25 | Download the version with "LTS" next to the number and install it. (LTS stands for Long Term Support, if you're curious.) In the Node.js Windows installer, accept the installation defaults. You do not need to install any additional tools for Native compilation. 26 | 27 | **Install Visual Studio Code, if you haven't already** 28 | 29 | Visit the [Visual Studio Code website](https://code.visualstudio.com) and install Visual Studio Code. 30 | 31 | ## Getting Started 32 | 33 | 1. Use npm to install dependent modules: 34 | 35 | ```powershell 36 | npm i 37 | ``` 38 | 39 | 1. Use this shortcut command to open the project in Visual Studio Code: 40 | 41 | ```powershell 42 | code . 43 | ``` 44 | 45 | ### Chapter 2. Let's test the parts of our project 46 | 47 | Within the root folder (howto-gallery) of this sample, run this command: 48 | 49 | ```powershell 50 | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 51 | ``` 52 | 53 | Run this one to deploy in the game. 54 | 55 | ```powershell 56 | npm run local-deploy 57 | ``` 58 | 59 | Create an addon file to share. 60 | 61 | ```powershell 62 | npm run mcaddon 63 | ``` 64 | 65 | ## Manifest 66 | 67 | - [just.config.ts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/just.config.ts): This file contains build instructions for just-scripts, for building out TypeScript code. 68 | - [scripts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/scripts): This contains How to Gallery TypeScript files, that will be compiled and built into your projects. 69 | - [behavior_packs](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/behavior_packs): This contains resources and JSON files that define your behavior pack. 70 | -------------------------------------------------------------------------------- /editor-basics/behavior_packs/editor-basics/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Minecraft Editor Basics", 5 | "description": "A gallery of editor code snippets", 6 | "uuid": "2fb88d39-e589-4e49-a69f-f575f8705e5c", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 20, 0] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Script resources", 13 | "type": "script", 14 | "language": "javascript", 15 | "uuid": "df6523d1-4442-45c2-b33a-1c882d388683", 16 | "version": [1, 0, 0], 17 | "entry": "scripts/main.js" 18 | } 19 | ], 20 | "capabilities": ["editorExtension"], 21 | "dependencies": [ 22 | { 23 | "uuid": "b3d35b27-1827-4bff-bdf5-694942cfdd25", 24 | "version": [1, 0, 0] 25 | }, 26 | { 27 | "module_name": "@minecraft/server-editor", 28 | "version": "0.1.0-beta" 29 | }, 30 | { 31 | "module_name": "@minecraft/server", 32 | "version": "1.15.0-beta" 33 | }, 34 | { 35 | "module_name": "@minecraft/server-ui", 36 | "version": "1.4.0-beta" 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /editor-basics/behavior_packs/editor-basics/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-basics/behavior_packs/editor-basics/pack_icon.png -------------------------------------------------------------------------------- /editor-basics/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /editor-basics/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import path from "path"; 3 | 4 | import { 5 | bundleTask, 6 | BundleTaskParameters, 7 | CopyTaskParameters, 8 | cleanTask, 9 | cleanCollateralTask, 10 | copyTask, 11 | coreLint, 12 | mcaddonTask, 13 | setupEnvironment, 14 | ZipTaskParameters, 15 | STANDARD_CLEAN_PATHS, 16 | DEFAULT_CLEAN_DIRECTORIES, 17 | getOrThrowFromProcess, 18 | watchTask, 19 | } from "@minecraft/core-build-tasks"; 20 | 21 | // Setup env variables 22 | setupEnvironment(path.resolve(__dirname, ".env")); 23 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 24 | 25 | const bundleTaskOptions: BundleTaskParameters = { 26 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 27 | external: ["@minecraft/server", "@minecraft/server-gametest", "@minecraft/server-ui", "@minecraft/server-editor"], 28 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 29 | minifyWhitespace: false, 30 | sourcemap: true, 31 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 32 | }; 33 | 34 | const copyTaskOptions: CopyTaskParameters = { 35 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 36 | copyToScripts: ["./dist/scripts"], 37 | copyToResourcePacks: [`./resource_packs/${projectName}`], 38 | }; 39 | 40 | const mcaddonTaskOptions: ZipTaskParameters = { 41 | ...copyTaskOptions, 42 | outputFile: `./dist/packages/${projectName}.mcaddon`, 43 | }; 44 | 45 | // Lint 46 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 47 | 48 | // Build 49 | task("typescript", tscTask()); 50 | task("bundle", bundleTask(bundleTaskOptions)); 51 | task("build", series("typescript", "bundle")); 52 | 53 | // Clean 54 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 55 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 56 | task("clean", parallel("clean-local", "clean-collateral")); 57 | 58 | // Package 59 | task("copyArtifacts", copyTask(copyTaskOptions)); 60 | task("package", series("clean-collateral", "copyArtifacts")); 61 | 62 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 63 | task( 64 | "local-deploy", 65 | watchTask( 66 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 67 | series("clean-local", "build", "package") 68 | ) 69 | ); 70 | 71 | // Mcaddon 72 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 73 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 74 | -------------------------------------------------------------------------------- /editor-basics/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "editor-basics", 3 | "version": "0.1.0", 4 | "productName": "Minecraft Basic Editor Add-on", 5 | "description": "Minecraft Basic Editor Add-on", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.5.4" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "buildsnippets": "just-scripts buildSnippets", 20 | "mcaddon": "just-scripts mcaddon", 21 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 22 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 23 | }, 24 | "dependencies": { 25 | "@minecraft/math": "^2.0.1", 26 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25", 27 | "@minecraft/server-editor": "0.1.0-beta.1.21.60-preview.25", 28 | "@minecraft/server-ui": "1.4.0-beta.1.21.60-preview.25", 29 | "@minecraft/vanilla-data": "^1.21.20" 30 | }, 31 | "overrides": { 32 | "@minecraft/math": { 33 | "@minecraft/server": "$@minecraft/server" 34 | }, 35 | "@minecraft/server-gametest": { 36 | "@minecraft/server": "$@minecraft/server" 37 | }, 38 | "@minecraft/server-ui": { 39 | "@minecraft/server": "$@minecraft/server" 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /editor-basics/resource_packs/editor-basics/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Minecraft Editor Basics", 5 | "description": "A simple list of editor code snippets.", 6 | "uuid": "b3d35b27-1827-4bff-bdf5-694942cfdd25", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 20, 0] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Editor Basics", 13 | "type": "resources", 14 | "uuid": "9f6d66d2-5373-4798-a729-3bc154d4a81b", 15 | "version": [1, 0, 0] 16 | } 17 | ], 18 | "capabilities": ["editorExtension"], 19 | "dependencies": [ 20 | { 21 | "uuid": "2fb88d39-e589-4e49-a69f-f575f8705e5c", 22 | "version": [1, 0, 0] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /editor-basics/resource_packs/editor-basics/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-basics/resource_packs/editor-basics/pack_icon.png -------------------------------------------------------------------------------- /editor-basics/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { registerBasicsExtension as registerBasicsExtension } from "./Basics"; 2 | 3 | registerBasicsExtension(); 4 | -------------------------------------------------------------------------------- /editor-basics/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /editor-multi/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="editor-multi" 2 | MINECRAFT_PRODUCT="PreviewUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /editor-multi/.npmrc: -------------------------------------------------------------------------------- 1 | legacy-peer-deps=true -------------------------------------------------------------------------------- /editor-multi/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /editor-multi/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /editor-multi/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /editor-multi/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/dist": true, 25 | "**/lib": true, 26 | "**/.DS_Store": true, 27 | "**/node_modules": true 28 | }, 29 | "cSpell.words": [ 30 | "Elytra", 31 | "Equippable", 32 | "gametest", 33 | "gametests", 34 | "knockback", 35 | "mcaddon", 36 | "mcui", 37 | "minecart", 38 | "molang", 39 | "onfire", 40 | "samplelibrary", 41 | "scriptevent", 42 | "shulker", 43 | "skelly", 44 | "zoglin" 45 | ], 46 | "editor.tabSize": 2, 47 | "eslint.experimental.useFlatConfig": true 48 | } 49 | -------------------------------------------------------------------------------- /editor-multi/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /editor-multi/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | author: mammerla 4 | description: A comprehensive gallery of different examples of Minecraft Editor plugins. Based on https://github.com/Mojang/minecraft-editor-extension-starter-kit 5 | ms.author: mikeam@microsoft.com 6 | ms.date: 08/24/2024 7 | languages: 8 | - typescript 9 | products: 10 | - minecraft 11 | --- 12 | 13 | # Minecraft Editor Multiple Plugin Gallery 14 | 15 | This sample contains many code snippets that show how you can manipulate basic Minecraft behaviors. Based on https://github.com/Mojang/minecraft-editor-extension-starter-kit. 16 | 17 | ## Prerequisites 18 | 19 | **Install Node.js tools, if you haven't already** 20 | 21 | We're going to use the package manager [npm](https://www.npmjs.com/package/npm) to get more tools to make the process of building our project easier. 22 | 23 | Visit [https://nodejs.org/](https://nodejs.org). 24 | 25 | Download the version with "LTS" next to the number and install it. (LTS stands for Long Term Support, if you're curious.) In the Node.js Windows installer, accept the installation defaults. You do not need to install any additional tools for Native compilation. 26 | 27 | **Install Visual Studio Code, if you haven't already** 28 | 29 | Visit the [Visual Studio Code website](https://code.visualstudio.com) and install Visual Studio Code. 30 | 31 | ## Getting Started 32 | 33 | 1. Use npm to install dependent modules: 34 | 35 | ```powershell 36 | npm i 37 | ``` 38 | 39 | 1. Use this shortcut command to open the project in Visual Studio Code: 40 | 41 | ```powershell 42 | code . 43 | ``` 44 | 45 | ### Chapter 2. Let's test the parts of our project 46 | 47 | Within the root folder (howto-gallery) of this sample, run this command: 48 | 49 | ```powershell 50 | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 51 | ``` 52 | 53 | Run this one to deploy in the game. 54 | 55 | ```powershell 56 | npm run local-deploy 57 | ``` 58 | 59 | Create an addon file to share. 60 | 61 | ```powershell 62 | npm run mcaddon 63 | ``` 64 | 65 | ## Manifest 66 | 67 | - [just.config.ts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/just.config.ts): This file contains build instructions for just-scripts, for building out TypeScript code. 68 | - [scripts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/scripts): This contains Editor Plugin TypeScript files, that will be compiled and built into your projects. 69 | - [behavior_packs](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/behavior_packs): This contains resources and JSON files that define your behavior pack. 70 | -------------------------------------------------------------------------------- /editor-multi/behavior_packs/editor-multi/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Minecraft Editor Multiple Plugin", 5 | "description": "A gallery of editor code snippets", 6 | "uuid": "2fb88d39-e589-4e49-a69f-f575f8705e5c", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 20, 0] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Script resources", 13 | "type": "script", 14 | "language": "javascript", 15 | "uuid": "df6523d1-4442-45c2-b33a-1c882d388683", 16 | "version": [1, 0, 0], 17 | "entry": "scripts/main.js" 18 | } 19 | ], 20 | "capabilities": ["editorExtension"], 21 | "dependencies": [ 22 | { 23 | "uuid": "b3d35b27-1827-4bff-bdf5-694942cfdd25", 24 | "version": [1, 0, 0] 25 | }, 26 | { 27 | "module_name": "@minecraft/server-editor", 28 | "version": "0.1.0-beta" 29 | }, 30 | { 31 | "module_name": "@minecraft/server", 32 | "version": "1.15.0-beta" 33 | }, 34 | { 35 | "module_name": "@minecraft/server-ui", 36 | "version": "1.4.0-beta" 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /editor-multi/behavior_packs/editor-multi/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-multi/behavior_packs/editor-multi/pack_icon.png -------------------------------------------------------------------------------- /editor-multi/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /editor-multi/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import path from "path"; 3 | 4 | import { 5 | bundleTask, 6 | BundleTaskParameters, 7 | CopyTaskParameters, 8 | cleanTask, 9 | cleanCollateralTask, 10 | copyTask, 11 | coreLint, 12 | mcaddonTask, 13 | setupEnvironment, 14 | ZipTaskParameters, 15 | STANDARD_CLEAN_PATHS, 16 | DEFAULT_CLEAN_DIRECTORIES, 17 | getOrThrowFromProcess, 18 | watchTask, 19 | } from "@minecraft/core-build-tasks"; 20 | 21 | import { BuildSnippetsParameters, buildSnippets } from "./tasks/BuildSnippets"; 22 | 23 | // Setup env variables 24 | setupEnvironment(path.resolve(__dirname, ".env")); 25 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 26 | 27 | const bundleTaskOptions: BundleTaskParameters = { 28 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 29 | external: ["@minecraft/server", "@minecraft/server-gametest", "@minecraft/server-ui", "@minecraft/server-editor"], 30 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 31 | minifyWhitespace: false, 32 | sourcemap: true, 33 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 34 | }; 35 | 36 | const copyTaskOptions: CopyTaskParameters = { 37 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 38 | copyToScripts: ["./dist/scripts"], 39 | copyToResourcePacks: [`./resource_packs/${projectName}`], 40 | }; 41 | 42 | const mcaddonTaskOptions: ZipTaskParameters = { 43 | ...copyTaskOptions, 44 | outputFile: `./dist/packages/${projectName}.mcaddon`, 45 | }; 46 | 47 | // Lint 48 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 49 | 50 | // Build 51 | task("typescript", tscTask()); 52 | task("bundle", bundleTask(bundleTaskOptions)); 53 | task("build", series("typescript", "bundle")); 54 | 55 | // Clean 56 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 57 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 58 | task("clean", parallel("clean-local", "clean-collateral")); 59 | 60 | // Package 61 | task("copyArtifacts", copyTask(copyTaskOptions)); 62 | task("package", series("clean-collateral", "copyArtifacts")); 63 | 64 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 65 | task( 66 | "local-deploy", 67 | watchTask( 68 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 69 | series("clean-local", "build", "package") 70 | ) 71 | ); 72 | 73 | // Mcaddon 74 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 75 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 76 | 77 | task( 78 | "buildSnippets", 79 | buildSnippets({ 80 | scriptPaths: [`./scripts/`], 81 | targetFolderPath: "dist/snippets", 82 | }) 83 | ); 84 | -------------------------------------------------------------------------------- /editor-multi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "editor-multi", 3 | "version": "0.1.0", 4 | "productName": "Minecraft Multiple Editor Add-on", 5 | "description": "Minecraft Multiple Editor Add-on", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.5.4" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "buildsnippets": "just-scripts buildSnippets", 20 | "mcaddon": "just-scripts mcaddon", 21 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 22 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 23 | }, 24 | "dependencies": { 25 | "@minecraft/math": "^2.0.1", 26 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25", 27 | "@minecraft/server-editor": "0.1.0-beta.1.21.60-preview.25", 28 | "@minecraft/server-ui": "1.4.0-beta.1.21.60-preview.25", 29 | "@minecraft/vanilla-data": "^1.21.20" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /editor-multi/resource_packs/editor-multi/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Minecraft Editor Multiple Plugin", 5 | "description": "A simple list of editor code snippets.", 6 | "uuid": "b3d35b27-1827-4bff-bdf5-694942cfdd25", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 20, 0] 9 | }, 10 | "capabilities": ["editorExtension"], 11 | "modules": [ 12 | { 13 | "description": "Editor Basics", 14 | "type": "resources", 15 | "uuid": "9f6d66d2-5373-4798-a729-3bc154d4a81b", 16 | "version": [1, 0, 0] 17 | } 18 | ], 19 | "dependencies": [ 20 | { 21 | "uuid": "2fb88d39-e589-4e49-a69f-f575f8705e5c", 22 | "version": [1, 0, 0] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /editor-multi/resource_packs/editor-multi/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-multi/resource_packs/editor-multi/pack_icon.png -------------------------------------------------------------------------------- /editor-multi/resource_packs/editor-multi/textures/dye-brush.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-multi/resource_packs/editor-multi/textures/dye-brush.png -------------------------------------------------------------------------------- /editor-multi/resource_packs/editor-multi/textures/farm-generator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-multi/resource_packs/editor-multi/textures/farm-generator.png -------------------------------------------------------------------------------- /editor-multi/resource_packs/editor-multi/textures/goto-mark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-multi/resource_packs/editor-multi/textures/goto-mark.png -------------------------------------------------------------------------------- /editor-multi/resource_packs/editor-multi/textures/portal-generator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-multi/resource_packs/editor-multi/textures/portal-generator.png -------------------------------------------------------------------------------- /editor-multi/resource_packs/editor-multi/textures/tree-generator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-multi/resource_packs/editor-multi/textures/tree-generator.png -------------------------------------------------------------------------------- /editor-multi/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { registerCameraGrapple } from "./camera-grapple"; 2 | import { registerDyeBrushExtension } from "./dye-brush"; 3 | import { registerFarmGeneratorExtension } from "./farm-generator"; 4 | import { registerGotoMarkExtension } from "./goto-mark"; 5 | import { registerPortalGeneratorExtension } from "./portal-generator"; 6 | import { registerSimpleLocateBiomeExtension } from "./simple-locate-biome"; 7 | import { registerStarBrushExtension } from "./star-brush-shape"; 8 | import { registerTreeGeneratorExtension } from "./tree-generator"; 9 | 10 | registerCameraGrapple(); 11 | registerDyeBrushExtension(); 12 | registerFarmGeneratorExtension(); 13 | registerGotoMarkExtension(); 14 | registerPortalGeneratorExtension(); 15 | registerSimpleLocateBiomeExtension(); 16 | registerStarBrushExtension(); 17 | registerTreeGeneratorExtension(); 18 | -------------------------------------------------------------------------------- /editor-multi/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /editor-script-box/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="editor-script-box" 2 | MINECRAFT_PRODUCT="PreviewUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /editor-script-box/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /editor-script-box/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /editor-script-box/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /editor-script-box/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "Elytra", 29 | "gametest", 30 | "gametests", 31 | "knockback", 32 | "minecart", 33 | "molang", 34 | "onfire", 35 | "samplelibrary", 36 | "scriptevent", 37 | "shulker", 38 | "skelly", 39 | "zoglin" 40 | ], 41 | "editor.tabSize": 2, 42 | "eslint.experimental.useFlatConfig": true 43 | } -------------------------------------------------------------------------------- /editor-script-box/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /editor-script-box/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | author: mammerla 4 | description: A simple sandbox for experimenting with Minecraft coding behaviors. 5 | ms.author: mikeam@microsoft.com 6 | ms.date: 06/07/2023 7 | languages: 8 | - typescript 9 | products: 10 | - minecraft 11 | --- 12 | 13 | # Minecraft Editor Script Box 14 | 15 | This sample makes it easy to experiment with JavaScript code in the context of the Minecraft Edutir. Just add your code in the function at ScriptBox.ts, and this sample will add some infrastructure around it to make it easy to run that sample in within the editor experience. 16 | 17 | ## Prerequisites 18 | 19 | **Install Node.js tools, if you haven't already** 20 | 21 | We're going to use the package manager [npm](https://www.npmjs.com/package/npm) to get more tools to make the process of building our project easier. 22 | 23 | Visit [https://nodejs.org/](https://nodejs.org). 24 | 25 | Download the version with "LTS" next to the number and install it. (LTS stands for Long Term Support, if you're curious.) In the Node.js Windows installer, accept the installation defaults. You do not need to install any additional tools for Native compilation. 26 | 27 | **Install Visual Studio Code, if you haven't already** 28 | 29 | Visit the [Visual Studio Code website](https://code.visualstudio.com) and install Visual Studio Code. 30 | 31 | ## Getting Started 32 | 33 | 1. Use npm to install dependent modules: 34 | 35 | ```powershell 36 | npm i 37 | ``` 38 | 39 | 1. Use this shortcut command to open the project in Visual Studio Code: 40 | 41 | ```powershell 42 | code . 43 | ``` 44 | 45 | ### Chapter 2. Let's test the parts of our project 46 | 47 | Within the root folder (script-box) of this sample, run this command: 48 | 49 | ```powershell 50 | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 51 | ``` 52 | 53 | Run this one, too. 54 | 55 | ```powershell 56 | npm run local-deploy 57 | ``` 58 | 59 | Create an addon file to share. 60 | 61 | ```powershell 62 | npm run mcaddon 63 | ``` 64 | 65 | ## Manifest 66 | 67 | - [just.config.ts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/editor-script-box/just.config.ts): This file contains build instructions for just-scripts, for building out TypeScript code. 68 | - [scripts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/editor-script-box/scripts): This contains Script Box TypeScript files for the Editor, that will be compiled and built into your projects. 69 | - [behavior_packs](https://github.com/microsoft/minecraft-scripting-samples/blob/main/editor-script-box/behavior_packs): This contains resources and JSON files that define your behavior pack. 70 | -------------------------------------------------------------------------------- /editor-script-box/behavior_packs/editor-script-box/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Editor Script Box", 5 | "description": "A simple sample where you can add code in a framework", 6 | "uuid": "421d57b3-b40e-459f-aee9-adaf63f7895d", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 21, 0] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Script resources", 13 | "type": "script", 14 | "language": "javascript", 15 | "uuid": "72f31c51-c988-42ae-affc-c039dcf8a56f", 16 | "version": [1, 0, 0], 17 | "entry": "scripts/main.js" 18 | } 19 | ], 20 | "capabilities": ["editorExtension"], 21 | "dependencies": [ 22 | { 23 | "uuid": "1cbf2047-73a7-45e0-a2ee-6dfdf27a0685", 24 | "version": [1, 0, 0] 25 | }, 26 | { 27 | "module_name": "@minecraft/server-editor", 28 | "version": "0.1.0-beta" 29 | }, 30 | { 31 | "module_name": "@minecraft/server", 32 | "version": "1.15.0-beta" 33 | }, 34 | { 35 | "module_name": "@minecraft/server-ui", 36 | "version": "1.4.0-beta" 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /editor-script-box/behavior_packs/editor-script-box/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-script-box/behavior_packs/editor-script-box/pack_icon.png -------------------------------------------------------------------------------- /editor-script-box/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /editor-script-box/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import path from "path"; 3 | 4 | import { 5 | bundleTask, 6 | BundleTaskParameters, 7 | CopyTaskParameters, 8 | cleanTask, 9 | cleanCollateralTask, 10 | copyTask, 11 | coreLint, 12 | mcaddonTask, 13 | setupEnvironment, 14 | ZipTaskParameters, 15 | STANDARD_CLEAN_PATHS, 16 | DEFAULT_CLEAN_DIRECTORIES, 17 | getOrThrowFromProcess, 18 | watchTask, 19 | } from "@minecraft/core-build-tasks"; 20 | 21 | // Setup env variables 22 | setupEnvironment(path.resolve(__dirname, ".env")); 23 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 24 | 25 | const bundleTaskOptions: BundleTaskParameters = { 26 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 27 | external: ["@minecraft/server", "@minecraft/server-gametest", "@minecraft/server-ui", "@minecraft/server-editor"], 28 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 29 | minifyWhitespace: false, 30 | sourcemap: true, 31 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 32 | }; 33 | 34 | const copyTaskOptions: CopyTaskParameters = { 35 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 36 | copyToScripts: ["./dist/scripts"], 37 | copyToResourcePacks: [`./resource_packs/${projectName}`], 38 | }; 39 | 40 | const mcaddonTaskOptions: ZipTaskParameters = { 41 | ...copyTaskOptions, 42 | outputFile: `./dist/packages/${projectName}.mcaddon`, 43 | }; 44 | 45 | // Lint 46 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 47 | 48 | // Build 49 | task("typescript", tscTask()); 50 | task("bundle", bundleTask(bundleTaskOptions)); 51 | task("build", series("typescript", "bundle")); 52 | 53 | // Clean 54 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 55 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 56 | task("clean", parallel("clean-local", "clean-collateral")); 57 | 58 | // Package 59 | task("copyArtifacts", copyTask(copyTaskOptions)); 60 | task("package", series("clean-collateral", "copyArtifacts")); 61 | 62 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 63 | task( 64 | "local-deploy", 65 | watchTask( 66 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 67 | series("clean-local", "build", "package") 68 | ) 69 | ); 70 | 71 | // Mcaddon 72 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 73 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 74 | -------------------------------------------------------------------------------- /editor-script-box/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "editor-script-box", 3 | "version": "0.1.0", 4 | "productName": "Minecraft Editor Script Box Playground", 5 | "description": "Minecraft Editor Script Box Playground", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.6.2" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "mcaddon": "just-scripts mcaddon", 20 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 21 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 22 | }, 23 | "dependencies": { 24 | "@minecraft/math": "^2.0.1", 25 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25", 26 | "@minecraft/server-editor": "0.1.0-beta.1.21.60-preview.25", 27 | "@minecraft/server-ui": "^1.3.0", 28 | "@minecraft/vanilla-data": "^1.21.22" 29 | }, 30 | "overrides": { 31 | "@minecraft/math": { 32 | "@minecraft/server": "$@minecraft/server" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /editor-script-box/resource_packs/editor-script-box/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Editor Script Box", 5 | "description": "A simple list of editor code snippets.", 6 | "uuid": "1cbf2047-73a7-45e0-a2ee-6dfdf27a0685", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 21, 0] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Editor Script Box", 13 | "type": "resources", 14 | "uuid": "c3d4470c-4cd4-4f16-88b5-da3f21ae24e3", 15 | "version": [1, 0, 0] 16 | } 17 | ], 18 | "capabilities": ["editorExtension"], 19 | "dependencies": [ 20 | { 21 | "uuid": "421d57b3-b40e-459f-aee9-adaf63f7895d", 22 | "version": [1, 0, 0] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /editor-script-box/resource_packs/editor-script-box/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/editor-script-box/resource_packs/editor-script-box/pack_icon.png -------------------------------------------------------------------------------- /editor-script-box/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { registerExtension } from "./ScriptBox"; 2 | 3 | registerExtension(); 4 | -------------------------------------------------------------------------------- /editor-script-box/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /howto-gallery-betas/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="howto-gallery-betas" 2 | MINECRAFT_PRODUCT="PreviewUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /howto-gallery-betas/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /howto-gallery-betas/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /howto-gallery-betas/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /howto-gallery-betas/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "Elytra", 29 | "Equippable", 30 | "gametest", 31 | "gametests", 32 | "knockback", 33 | "mcaddon", 34 | "mcui", 35 | "minecart", 36 | "molang", 37 | "onfire", 38 | "samplelibrary", 39 | "scriptevent", 40 | "shulker", 41 | "skelly", 42 | "zoglin" 43 | ], 44 | "editor.tabSize": 2, 45 | "eslint.experimental.useFlatConfig": true 46 | } 47 | -------------------------------------------------------------------------------- /howto-gallery-betas/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /howto-gallery-betas/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | author: mammerla 4 | description: A gallery of different samples of Minecraft coding behaviors that use beta APIs. 5 | ms.author: mikeam@microsoft.com 6 | ms.date: 05/05/2022 7 | languages: 8 | - typescript 9 | products: 10 | - minecraft 11 | --- 12 | 13 | # Minecraft How-to Gallery (for Beta APIs and GameTest) 14 | 15 | This sample contains code snippets and gametests that show how you can manipulate Minecraft behaviors using currently-experimental APIs in Minecraft Bedrock Edition. 16 | 17 | ## Prerequisites 18 | 19 | **Install Node.js tools, if you haven't already** 20 | 21 | We're going to use the package manager [npm](https://www.npmjs.com/package/npm) to get more tools to make the process of building our project easier. 22 | 23 | Visit [https://nodejs.org/](https://nodejs.org). 24 | 25 | Download the version with "LTS" next to the number and install it. (LTS stands for Long Term Support, if you're curious.) In the Node.js Windows installer, accept the installation defaults. You do not need to install any additional tools for Native compilation. 26 | 27 | **Install Visual Studio Code, if you haven't already** 28 | 29 | Visit the [Visual Studio Code website](https://code.visualstudio.com) and install Visual Studio Code. 30 | 31 | ## Getting Started 32 | 33 | 1. Use npm to install dependent modules: 34 | 35 | ```powershell 36 | npm i 37 | ``` 38 | 39 | 1. Use this shortcut command to open the project in Visual Studio Code: 40 | 41 | ```powershell 42 | code . 43 | ``` 44 | 45 | ### Chapter 2. Let's test the parts of our project 46 | 47 | Within the root folder (howto-gallery) of this sample, run this command: 48 | 49 | ```powershell 50 | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 51 | ``` 52 | 53 | Run this one to deploy in the game. 54 | 55 | ```powershell 56 | npm run local-deploy 57 | ``` 58 | 59 | Create an addon file to share. 60 | 61 | ```powershell 62 | npm run mcaddon 63 | ``` 64 | 65 | ## Manifest 66 | 67 | - [just.config.ts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/just.config.ts): This file contains build instructions for just-scripts, for building out TypeScript code. 68 | - [scripts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/scripts): This contains How to Gallery TypeScript files, that will be compiled and built into your projects. 69 | - [behavior_packs](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/behavior_packs): This contains resources and JSON files that define your behavior pack. 70 | -------------------------------------------------------------------------------- /howto-gallery-betas/behavior_packs/howto-gallery-betas/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Minecraft JavaScript How-to Gallery (Beta APIs)", 5 | "description": "A gallery of code snippets that leverage beta APIs, and expose GameTests.", 6 | "uuid": "53b01267-861d-4938-866f-e26d2b80fd34", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 21, 40] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Script resources", 13 | "type": "script", 14 | "language": "javascript", 15 | "uuid": "90d45058-6abe-43dc-a478-9b497d7d1d0d", 16 | "version": [1, 0, 0], 17 | "entry": "scripts/main.js" 18 | } 19 | ], 20 | "dependencies": [ 21 | { 22 | "module_name": "@minecraft/server", 23 | "version": "1.17.0-beta" 24 | }, 25 | { 26 | "module_name": "@minecraft/server-ui", 27 | "version": "1.4.0-beta" 28 | }, 29 | { 30 | "module_name": "@minecraft/server-gametest", 31 | "version": "1.0.0-beta" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /howto-gallery-betas/behavior_packs/howto-gallery-betas/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/howto-gallery-betas/behavior_packs/howto-gallery-betas/pack_icon.png -------------------------------------------------------------------------------- /howto-gallery-betas/behavior_packs/howto-gallery-betas/structures/gametests/glass_cells.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/howto-gallery-betas/behavior_packs/howto-gallery-betas/structures/gametests/glass_cells.mcstructure -------------------------------------------------------------------------------- /howto-gallery-betas/behavior_packs/howto-gallery-betas/structures/gametests/mediumglass.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/howto-gallery-betas/behavior_packs/howto-gallery-betas/structures/gametests/mediumglass.mcstructure -------------------------------------------------------------------------------- /howto-gallery-betas/behavior_packs/howto-gallery-betas/structures/gametests/minibiomes.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/howto-gallery-betas/behavior_packs/howto-gallery-betas/structures/gametests/minibiomes.mcstructure -------------------------------------------------------------------------------- /howto-gallery-betas/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /howto-gallery-betas/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import path from "path"; 3 | 4 | import { 5 | bundleTask, 6 | BundleTaskParameters, 7 | CopyTaskParameters, 8 | cleanTask, 9 | cleanCollateralTask, 10 | copyTask, 11 | coreLint, 12 | mcaddonTask, 13 | setupEnvironment, 14 | ZipTaskParameters, 15 | STANDARD_CLEAN_PATHS, 16 | DEFAULT_CLEAN_DIRECTORIES, 17 | getOrThrowFromProcess, 18 | watchTask, 19 | } from "@minecraft/core-build-tasks"; 20 | 21 | import { BuildSnippetsParameters, buildSnippets } from "./tasks/BuildSnippets"; 22 | 23 | // Setup env variables 24 | setupEnvironment(path.resolve(__dirname, ".env")); 25 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 26 | 27 | const bundleTaskOptions: BundleTaskParameters = { 28 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 29 | external: ["@minecraft/server", "@minecraft/server-gametest", "@minecraft/server-ui"], 30 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 31 | minifyWhitespace: false, 32 | sourcemap: true, 33 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 34 | }; 35 | 36 | const copyTaskOptions: CopyTaskParameters = { 37 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 38 | copyToScripts: ["./dist/scripts"], 39 | }; 40 | 41 | const mcaddonTaskOptions: ZipTaskParameters = { 42 | ...copyTaskOptions, 43 | outputFile: `./dist/packages/${projectName}.mcaddon`, 44 | }; 45 | 46 | // Lint 47 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 48 | 49 | // Build 50 | task("typescript", tscTask()); 51 | task("bundle", bundleTask(bundleTaskOptions)); 52 | task("build", series("typescript", "bundle")); 53 | 54 | // Clean 55 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 56 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 57 | task("clean", parallel("clean-local", "clean-collateral")); 58 | 59 | // Package 60 | task("copyArtifacts", copyTask(copyTaskOptions)); 61 | task("package", series("clean-collateral", "copyArtifacts")); 62 | 63 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 64 | task( 65 | "local-deploy", 66 | watchTask( 67 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 68 | series("clean-local", "build", "package") 69 | ) 70 | ); 71 | 72 | // Mcaddon 73 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 74 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 75 | 76 | task( 77 | "buildSnippets", 78 | buildSnippets({ 79 | scriptPaths: [`./scripts/`], 80 | targetFolderPath: "dist/snippets", 81 | }) 82 | ); 83 | -------------------------------------------------------------------------------- /howto-gallery-betas/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "howto-gallery-betas", 3 | "version": "0.1.0", 4 | "productName": "Minecraft TypeScript How-to Gallery", 5 | "description": "Minecraft TypeScript How-to Gallery", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.5.4" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "buildsnippets": "just-scripts buildSnippets", 20 | "mcaddon": "just-scripts mcaddon", 21 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 22 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 23 | }, 24 | "dependencies": { 25 | "@minecraft/math": "^2.0.1", 26 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25", 27 | "@minecraft/server-admin": "1.0.0-beta.1.21.60-preview.25", 28 | "@minecraft/server-gametest": "1.0.0-beta.1.21.60-preview.25", 29 | "@minecraft/server-net": "1.0.0-beta.1.21.60-preview.25", 30 | "@minecraft/server-ui": "1.4.0-beta.1.21.60-preview.25", 31 | "@minecraft/vanilla-data": "^1.21.20" 32 | }, 33 | "overrides": { 34 | "@minecraft/math": { 35 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25" 36 | }, 37 | "@minecraft/server-gametest@1.0.0-beta.1.21.60-preview.25": { 38 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25" 39 | }, 40 | "@minecraft/server-ui@1.4.0-beta.1.21.60-preview.25": { 41 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /howto-gallery-betas/scripts/Chat.ts: -------------------------------------------------------------------------------- 1 | import { Vector3Utils } from "@minecraft/math"; 2 | import { BlockPermutation, DimensionLocation, world } from "@minecraft/server"; 3 | import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; 4 | 5 | /** 6 | * Implements a very basic command system using the experiment chatbefore event. 7 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 8 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/ChatSendBeforeEventSignal 10 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world#beforeEvents 11 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/WorldBeforeEvents#chatSend 12 | */ 13 | export function customCommand(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 14 | const chatCallback = world.beforeEvents.chatSend.subscribe((eventData) => { 15 | if (eventData.message.includes("cancel")) { 16 | // Cancel event if the message contains "cancel" 17 | eventData.cancel = true; 18 | } else { 19 | const args = eventData.message.split(" "); 20 | 21 | if (args.length > 0) { 22 | switch (args[0].toLowerCase()) { 23 | case "echo": 24 | // Send a modified version of chat message 25 | world.sendMessage(`Echo '${eventData.message.substring(4).trim()}'`); 26 | break; 27 | case "help": 28 | world.sendMessage(`Available commands: echo `); 29 | break; 30 | } 31 | } 32 | } 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /howto-gallery-betas/scripts/NetUse.ts: -------------------------------------------------------------------------------- 1 | import * as mc from "@minecraft/server"; 2 | import * as mcnet from "@minecraft/server-net"; 3 | 4 | /** 5 | * Updates score on a local server. 6 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 7 | * @param {mc.Location} location Location to center this sample code around. 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server-net/HttpRequest 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server-net/HttpHeader 10 | */ 11 | export async function updateScore(log: (message: string, status?: number) => void, targetLocation: mc.Vector3) { 12 | const req = new mcnet.HttpRequest("http://localhost:3000/updateScore"); 13 | 14 | req.body = JSON.stringify({ 15 | score: 22, 16 | }); 17 | 18 | req.method = mcnet.HttpRequestMethod.Post; 19 | req.headers = [ 20 | new mcnet.HttpHeader("Content-Type", "application/json"), 21 | new mcnet.HttpHeader("auth", "my-auth-token"), 22 | ]; 23 | 24 | await mcnet.http.request(req); 25 | } 26 | -------------------------------------------------------------------------------- /howto-gallery-betas/scripts/Server-AdminSampleLibrary.ts: -------------------------------------------------------------------------------- 1 | import * as mc from "@minecraft/server"; 2 | import * as mcsa from "@minecraft/server-admin"; 3 | import * as mcnet from "@minecraft/server-net"; // keep in for net samples 4 | 5 | import SampleManager from "./SampleManager"; 6 | 7 | import * as sdf1 from "./ServerAdmin"; 8 | 9 | const mojangServerAdminTestFuncs: { 10 | [name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>; 11 | } = { 12 | getPlayerProfile: [sdf1.getPlayerProfile], 13 | }; 14 | 15 | export function register(sampleManager: SampleManager) { 16 | sampleManager.registerSamples(mojangServerAdminTestFuncs); 17 | } 18 | -------------------------------------------------------------------------------- /howto-gallery-betas/scripts/Server-GameTestSampleLibrary.ts: -------------------------------------------------------------------------------- 1 | import * as mc from "@minecraft/server"; 2 | import * as gt from "@minecraft/server-gametest"; // keep in for gametest samples 3 | 4 | import SampleManager from "./SampleManager"; 5 | 6 | import * as sdf1 from "./SimpleGameTests"; 7 | 8 | const mojangGameTestFuncs: { 9 | [name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>; 10 | } = { 11 | runSimpleMobGameTest: [sdf1.runSimpleMobGameTest], 12 | runPhantomsShouldFlyFromCats: [sdf1.runPhantomsShouldFlyFromCats], 13 | runMinibiomes: [sdf1.runMinibiomes], 14 | }; 15 | 16 | export function register(sampleManager: SampleManager) { 17 | sampleManager.registerSamples(mojangGameTestFuncs); 18 | } 19 | -------------------------------------------------------------------------------- /howto-gallery-betas/scripts/Server-NetSampleLibrary.ts: -------------------------------------------------------------------------------- 1 | import * as mc from "@minecraft/server"; 2 | import * as mcnet from "@minecraft/server-net"; // keep in for net samples 3 | 4 | import SampleManager from "./SampleManager"; 5 | 6 | import * as sdf1 from "./NetUse"; 7 | 8 | const mojangNetAdminTestFuncs: { 9 | [name: string]: Array<(log: (message: string, status?: number) => void, location: mc.Vector3) => void>; 10 | } = { 11 | updateScore: [sdf1.updateScore], 12 | }; 13 | 14 | export function register(sampleManager: SampleManager) { 15 | sampleManager.registerSamples(mojangNetAdminTestFuncs); 16 | } 17 | -------------------------------------------------------------------------------- /howto-gallery-betas/scripts/ServerAdmin.ts: -------------------------------------------------------------------------------- 1 | import * as mc from "@minecraft/server"; 2 | import * as mcsa from "@minecraft/server-admin"; 3 | import * as mcnet from "@minecraft/server-net"; 4 | 5 | /** 6 | * Uses secrets and variables from dedicated server configuration files to further parameterize web requests. 7 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 8 | * @param {mc.Location} location Location to center this sample code around. 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server-admin/ServerSecrets 10 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server-admin/ServerVariables 11 | */ 12 | export async function getPlayerProfile(log: (message: string, status?: number) => void, targetLocation: mc.Vector3) { 13 | const serverUrl = mcsa.variables.get("serverEndpoint"); 14 | 15 | const req = new mcnet.HttpRequest(serverUrl + "getPlayerProfile"); 16 | 17 | req.body = JSON.stringify({ 18 | playerId: "johndoe", 19 | }); 20 | 21 | const authTokenSec = mcsa.secrets.get("authtoken"); 22 | 23 | if (!authTokenSec) { 24 | log("authtoken secret not defined.", -1); 25 | return; 26 | } 27 | 28 | req.method = mcnet.HttpRequestMethod.Post; 29 | req.headers = [new mcnet.HttpHeader("Content-Type", "application/json"), new mcnet.HttpHeader("auth", authTokenSec)]; 30 | 31 | await mcnet.http.request(req); 32 | } 33 | -------------------------------------------------------------------------------- /howto-gallery-betas/scripts/ServerSampleLibrary.ts: -------------------------------------------------------------------------------- 1 | import SampleManager from "./SampleManager"; 2 | 3 | import * as sdf1 from "./Chat"; 4 | import { DimensionLocation } from "@minecraft/server"; 5 | 6 | const mojangMinecraftFuncs: { 7 | [name: string]: Array<(log: (message: string, status?: number) => void, location: DimensionLocation) => void>; 8 | } = { 9 | chat: [sdf1.customCommand], 10 | }; 11 | 12 | export function register(sampleManager: SampleManager) { 13 | sampleManager.registerSamples(mojangMinecraftFuncs); 14 | } 15 | -------------------------------------------------------------------------------- /howto-gallery-betas/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import SampleManager from "./SampleManager"; 2 | import * as serverSampleLibrary from "./ServerSampleLibrary"; 3 | import * as mcgtsl from "./Server-GameTestSampleLibrary"; 4 | 5 | const sm = new SampleManager(); 6 | 7 | serverSampleLibrary.register(sm); 8 | mcgtsl.register(sm); 9 | -------------------------------------------------------------------------------- /howto-gallery-betas/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /howto-gallery/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="howto-gallery" 2 | MINECRAFT_PRODUCT="BedrockUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /howto-gallery/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /howto-gallery/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /howto-gallery/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /howto-gallery/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "Elytra", 29 | "Equippable", 30 | "gametest", 31 | "gametests", 32 | "knockback", 33 | "mcaddon", 34 | "mcui", 35 | "minecart", 36 | "molang", 37 | "onfire", 38 | "samplelibrary", 39 | "scriptevent", 40 | "shulker", 41 | "skelly", 42 | "zoglin" 43 | ], 44 | "editor.tabSize": 2, 45 | "eslint.experimental.useFlatConfig": true 46 | } 47 | -------------------------------------------------------------------------------- /howto-gallery/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /howto-gallery/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | author: mammerla 4 | description: A comprehensive gallery of different samples of Minecraft coding behaviors. 5 | ms.author: mikeam@microsoft.com 6 | ms.date: 05/05/2022 7 | languages: 8 | - typescript 9 | products: 10 | - minecraft 11 | --- 12 | 13 | # Minecraft How-to Gallery 14 | 15 | This sample contains many code snippets that show how you can manipulate basic Minecraft behaviors. 16 | 17 | ## Prerequisites 18 | 19 | **Install Node.js tools, if you haven't already** 20 | 21 | We're going to use the package manager [npm](https://www.npmjs.com/package/npm) to get more tools to make the process of building our project easier. 22 | 23 | Visit [https://nodejs.org/](https://nodejs.org). 24 | 25 | Download the version with "LTS" next to the number and install it. (LTS stands for Long Term Support, if you're curious.) In the Node.js Windows installer, accept the installation defaults. You do not need to install any additional tools for Native compilation. 26 | 27 | **Install Visual Studio Code, if you haven't already** 28 | 29 | Visit the [Visual Studio Code website](https://code.visualstudio.com) and install Visual Studio Code. 30 | 31 | ## Getting Started 32 | 33 | 1. Use npm to install dependent modules: 34 | 35 | ```powershell 36 | npm i 37 | ``` 38 | 39 | 1. Use this shortcut command to open the project in Visual Studio Code: 40 | 41 | ```powershell 42 | code . 43 | ``` 44 | 45 | ### Chapter 2. Let's test the parts of our project 46 | 47 | Within the root folder (howto-gallery) of this sample, run this command: 48 | 49 | ```powershell 50 | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 51 | ``` 52 | 53 | Run this one to deploy in the game. 54 | 55 | ```powershell 56 | npm run local-deploy 57 | ``` 58 | 59 | Create an addon file to share. 60 | 61 | ```powershell 62 | npm run mcaddon 63 | ``` 64 | 65 | ## Manifest 66 | 67 | - [just.config.ts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/just.config.ts): This file contains build instructions for just-scripts, for building out TypeScript code. 68 | - [scripts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/scripts): This contains How to Gallery TypeScript files, that will be compiled and built into your projects. 69 | - [behavior_packs](https://github.com/microsoft/minecraft-scripting-samples/blob/main/howto-gallery/behavior_packs): This contains resources and JSON files that define your behavior pack. 70 | -------------------------------------------------------------------------------- /howto-gallery/behavior_packs/howto-gallery/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Minecraft JavaScript How-to Gallery", 5 | "description": "A gallery and GameTest of many code snippets", 6 | "uuid": "7de074b8-9052-4b1c-9342-b5c4280269fa", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 20, 0] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Script resources", 13 | "type": "script", 14 | "language": "javascript", 15 | "uuid": "df6523d1-4442-45c2-b33a-1c882d388683", 16 | "version": [1, 0, 0], 17 | "entry": "scripts/main.js" 18 | } 19 | ], 20 | "dependencies": [ 21 | { 22 | "module_name": "@minecraft/server", 23 | "version": "1.10.0" 24 | }, 25 | { 26 | "module_name": "@minecraft/server-ui", 27 | "version": "1.1.0" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /howto-gallery/behavior_packs/howto-gallery/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/howto-gallery/behavior_packs/howto-gallery/pack_icon.png -------------------------------------------------------------------------------- /howto-gallery/behavior_packs/howto-gallery/structures/gametests/glass_cells.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/howto-gallery/behavior_packs/howto-gallery/structures/gametests/glass_cells.mcstructure -------------------------------------------------------------------------------- /howto-gallery/behavior_packs/howto-gallery/structures/gametests/mediumglass.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/howto-gallery/behavior_packs/howto-gallery/structures/gametests/mediumglass.mcstructure -------------------------------------------------------------------------------- /howto-gallery/behavior_packs/howto-gallery/structures/gametests/minibiomes.mcstructure: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/howto-gallery/behavior_packs/howto-gallery/structures/gametests/minibiomes.mcstructure -------------------------------------------------------------------------------- /howto-gallery/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /howto-gallery/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import path from "path"; 3 | 4 | import { 5 | bundleTask, 6 | BundleTaskParameters, 7 | CopyTaskParameters, 8 | cleanTask, 9 | cleanCollateralTask, 10 | copyTask, 11 | coreLint, 12 | mcaddonTask, 13 | setupEnvironment, 14 | ZipTaskParameters, 15 | STANDARD_CLEAN_PATHS, 16 | DEFAULT_CLEAN_DIRECTORIES, 17 | getOrThrowFromProcess, 18 | watchTask, 19 | } from "@minecraft/core-build-tasks"; 20 | 21 | import { BuildSnippetsParameters, buildSnippets } from "./tasks/BuildSnippets"; 22 | 23 | // Setup env variables 24 | setupEnvironment(path.resolve(__dirname, ".env")); 25 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 26 | 27 | const bundleTaskOptions: BundleTaskParameters = { 28 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 29 | external: ["@minecraft/server", "@minecraft/server-gametest", "@minecraft/server-ui"], 30 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 31 | minifyWhitespace: false, 32 | sourcemap: true, 33 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 34 | }; 35 | 36 | const copyTaskOptions: CopyTaskParameters = { 37 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 38 | copyToScripts: ["./dist/scripts"], 39 | }; 40 | 41 | const mcaddonTaskOptions: ZipTaskParameters = { 42 | ...copyTaskOptions, 43 | outputFile: `./dist/packages/${projectName}.mcaddon`, 44 | }; 45 | 46 | // Lint 47 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 48 | 49 | // Build 50 | task("typescript", tscTask()); 51 | task("bundle", bundleTask(bundleTaskOptions)); 52 | task("build", series("typescript", "bundle")); 53 | 54 | // Clean 55 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 56 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 57 | task("clean", parallel("clean-local", "clean-collateral")); 58 | 59 | // Package 60 | task("copyArtifacts", copyTask(copyTaskOptions)); 61 | task("package", series("clean-collateral", "copyArtifacts")); 62 | 63 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 64 | task( 65 | "local-deploy", 66 | watchTask( 67 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 68 | series("clean-local", "build", "package") 69 | ) 70 | ); 71 | 72 | // Mcaddon 73 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 74 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 75 | 76 | task( 77 | "buildSnippets", 78 | buildSnippets({ 79 | scriptPaths: [`./scripts/`], 80 | targetFolderPath: "dist/snippets", 81 | }) 82 | ); 83 | -------------------------------------------------------------------------------- /howto-gallery/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "howto-gallery", 3 | "version": "0.1.0", 4 | "productName": "Minecraft TypeScript How-to Gallery", 5 | "description": "Minecraft TypeScript How-to Gallery", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.6.2" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "buildsnippets": "just-scripts buildSnippets", 20 | "mcaddon": "just-scripts mcaddon", 21 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 22 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 23 | }, 24 | "dependencies": { 25 | "@minecraft/math": "^2.0.1", 26 | "@minecraft/server": "^1.14.0", 27 | "@minecraft/server-ui": "^1.3.0", 28 | "@minecraft/vanilla-data": "^1.21.31" 29 | }, 30 | "overrides": { 31 | "@minecraft/math": { 32 | "@minecraft/server": "$@minecraft/server" 33 | }, 34 | "@minecraft/server-gametest": { 35 | "@minecraft/server": "$@minecraft/server" 36 | }, 37 | "@minecraft/server-ui": { 38 | "@minecraft/server": "$@minecraft/server" 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /howto-gallery/scripts/CreateItemStacks.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation, ItemStack } from "@minecraft/server"; 2 | import { MinecraftItemTypes } from "@minecraft/vanilla-data"; 3 | 4 | /** 5 | * Creates free-floating item stacks in the world. 6 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 7 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemStack 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension#spawnitem 10 | */ 11 | export function itemStacks(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 12 | const oneItemLoc = { x: targetLocation.x + targetLocation.y + 3, y: 2, z: targetLocation.z + 1 }; 13 | const fiveItemsLoc = { x: targetLocation.x + 1, y: targetLocation.y + 2, z: targetLocation.z + 1 }; 14 | const diamondPickaxeLoc = { x: targetLocation.x + 2, y: targetLocation.y + 2, z: targetLocation.z + 4 }; 15 | 16 | const oneEmerald = new ItemStack(MinecraftItemTypes.Emerald, 1); 17 | const onePickaxe = new ItemStack(MinecraftItemTypes.DiamondPickaxe, 1); 18 | const fiveEmeralds = new ItemStack(MinecraftItemTypes.Emerald, 5); 19 | 20 | log(`Spawning an emerald at (${oneItemLoc.x}, ${oneItemLoc.y}, ${oneItemLoc.z})`); 21 | targetLocation.dimension.spawnItem(oneEmerald, oneItemLoc); 22 | 23 | log(`Spawning five emeralds at (${fiveItemsLoc.x}, ${fiveItemsLoc.y}, ${fiveItemsLoc.z})`); 24 | targetLocation.dimension.spawnItem(fiveEmeralds, fiveItemsLoc); 25 | 26 | log(`Spawning a diamond pickaxe at (${diamondPickaxeLoc.x}, ${diamondPickaxeLoc.y}, ${diamondPickaxeLoc.z})`); 27 | targetLocation.dimension.spawnItem(onePickaxe, diamondPickaxeLoc); 28 | } 29 | -------------------------------------------------------------------------------- /howto-gallery/scripts/CreateMobs.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation } from "@minecraft/server"; 2 | import { MinecraftEffectTypes, MinecraftEntityTypes } from "@minecraft/vanilla-data"; 3 | 4 | /** 5 | * Creates a fox and, well, a wolf with effects applied. 6 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 7 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension#spawnentity 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity#addeffect 10 | */ 11 | export function quickFoxLazyDog(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 12 | const fox = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Fox, { 13 | x: targetLocation.x + 1, 14 | y: targetLocation.y + 2, 15 | z: targetLocation.z + 3, 16 | }); 17 | 18 | fox.addEffect(MinecraftEffectTypes.Speed, 10, { 19 | amplifier: 2, 20 | }); 21 | log("Created a fox."); 22 | 23 | const wolf = targetLocation.dimension.spawnEntity(MinecraftEntityTypes.Wolf, { 24 | x: targetLocation.x + 4, 25 | y: targetLocation.y + 2, 26 | z: targetLocation.z + 3, 27 | }); 28 | wolf.addEffect(MinecraftEffectTypes.Slowness, 10, { 29 | amplifier: 2, 30 | }); 31 | wolf.isSneaking = true; 32 | log("Created a sneaking wolf.", 1); 33 | } 34 | -------------------------------------------------------------------------------- /howto-gallery/scripts/DynamicProperties.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation, world } from "@minecraft/server"; 2 | 3 | /** 4 | * Increments a dynamic numeric persisted property. 5 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 6 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 7 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world#getDynamicProperty 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world#setDynamicProperty 9 | */ 10 | export function incrementDynamicProperty( 11 | log: (message: string, status?: number) => void, 12 | targetLocation: DimensionLocation 13 | ) { 14 | let number = world.getDynamicProperty("samplelibrary:number"); 15 | 16 | log("Current value is: " + number); 17 | 18 | if (number === undefined) { 19 | number = 0; 20 | } 21 | 22 | if (typeof number !== "number") { 23 | log("Number is of an unexpected type."); 24 | return -1; 25 | } 26 | 27 | world.setDynamicProperty("samplelibrary:number", number + 1); 28 | } 29 | 30 | /** 31 | * Increments a dynamic numeric persisted property. 32 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 33 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 34 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world#getDynamicProperty 35 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world#setDynamicProperty 36 | */ 37 | export function incrementDynamicPropertyInJsonBlob( 38 | log: (message: string, status?: number) => void, 39 | targetLocation: DimensionLocation 40 | ) { 41 | let paintStr = world.getDynamicProperty("samplelibrary:longerjson"); 42 | let paint: { color: string; intensity: number } | undefined = undefined; 43 | 44 | log("Current value is: " + paintStr); 45 | 46 | if (paintStr === undefined) { 47 | paint = { 48 | color: "purple", 49 | intensity: 0, 50 | }; 51 | } else { 52 | if (typeof paintStr !== "string") { 53 | log("Paint is of an unexpected type."); 54 | return -1; 55 | } 56 | 57 | try { 58 | paint = JSON.parse(paintStr); 59 | } catch (e) { 60 | log("Error parsing serialized struct."); 61 | return -1; 62 | } 63 | } 64 | 65 | if (!paint) { 66 | log("Error parsing serialized struct."); 67 | return -1; 68 | } 69 | 70 | paint.intensity++; 71 | paintStr = JSON.stringify(paint); // be very careful to ensure your serialized JSON str cannot exceed limits 72 | world.setDynamicProperty("samplelibrary:longerjson", paintStr); 73 | } 74 | -------------------------------------------------------------------------------- /howto-gallery/scripts/Effects.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation } from "@minecraft/server"; 2 | import { MinecraftEffectTypes } from "@minecraft/vanilla-data"; 3 | 4 | /** 5 | * Spawns a villager and gives it a poison effect. 6 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 7 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/Entity#addEffect 9 | */ 10 | export function spawnPoisonedVillager( 11 | log: (message: string, status?: number) => void, 12 | targetLocation: DimensionLocation 13 | ) { 14 | const villagerType = "minecraft:villager_v2"; 15 | const villager = targetLocation.dimension.spawnEntity(villagerType, targetLocation); 16 | const duration = 20; 17 | 18 | villager.addEffect(MinecraftEffectTypes.Poison, duration, { amplifier: 1 }); 19 | } 20 | -------------------------------------------------------------------------------- /howto-gallery/scripts/EntityQuery.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation, EntityQueryOptions } from "@minecraft/server"; 2 | 3 | /** 4 | * Amongst a set of entities, uses entity query to find specific entities and bounce them with applyKnockback. 5 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 6 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 7 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension#getentities 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/EntityQueryOptions 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity#applyknockback 10 | */ 11 | export function bounceSkeletons(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 12 | const mobs = ["creeper", "skeleton", "sheep"]; 13 | 14 | // create some sample mob data 15 | for (let i = 0; i < 10; i++) { 16 | targetLocation.dimension.spawnEntity(mobs[i % mobs.length], targetLocation); 17 | } 18 | 19 | const eqo: EntityQueryOptions = { 20 | type: "skeleton", 21 | }; 22 | 23 | for (const entity of targetLocation.dimension.getEntities(eqo)) { 24 | entity.applyKnockback(0, 0, 0, 1); 25 | } 26 | } 27 | 28 | /** 29 | * Amongst a set of entities, uses entity query to find specific entities based on a tag. 30 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 31 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 32 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension#getentities 33 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/EntityQueryOptions 34 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity#kill 35 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entity#addtag 36 | */ 37 | export function tagsQuery(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 38 | const mobs = ["creeper", "skeleton", "sheep"]; 39 | 40 | // create some sample mob data 41 | for (let i = 0; i < 10; i++) { 42 | const mobTypeId = mobs[i % mobs.length]; 43 | const entity = targetLocation.dimension.spawnEntity(mobTypeId, targetLocation); 44 | entity.addTag("mobparty." + mobTypeId); 45 | } 46 | 47 | const eqo: EntityQueryOptions = { 48 | tags: ["mobparty.skeleton"], 49 | }; 50 | 51 | for (const entity of targetLocation.dimension.getEntities(eqo)) { 52 | entity.kill(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /howto-gallery/scripts/EntitySpawnEvent.ts: -------------------------------------------------------------------------------- 1 | import { Vector3Utils } from "@minecraft/math"; 2 | import { DimensionLocation, EntitySpawnAfterEvent, system, world } from "@minecraft/server"; 3 | 4 | /** 5 | * Registers and contains an entity spawned event handler. 6 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 7 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityspawnaftereventsignal#subscribe 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityspawnafterevent 10 | */ 11 | export function logEntitySpawnEvent( 12 | log: (message: string, status?: number) => void, 13 | targetLocation: DimensionLocation 14 | ) { 15 | // register a new function that is called when a new entity is created. 16 | world.afterEvents.entitySpawn.subscribe((entityEvent: EntitySpawnAfterEvent) => { 17 | if (entityEvent && entityEvent.entity) { 18 | log(`New entity of type ${entityEvent.entity.typeId} created!`, 1); 19 | } else { 20 | log(`The entity event did not work as expected.`, -1); 21 | } 22 | }); 23 | 24 | system.runTimeout(() => { 25 | targetLocation.dimension.spawnEntity( 26 | "minecraft:horse", 27 | Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 }) 28 | ); 29 | }, 20); 30 | } 31 | 32 | /** 33 | * A simple function to create an adult horse. 34 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 35 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 36 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension#spawnentity 37 | */ 38 | export function spawnAdultHorse(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 39 | log("Create a horse and triggering the ageable_grow_up event, ensuring the horse is created as an adult"); 40 | targetLocation.dimension.spawnEntity( 41 | "minecraft:horse", 42 | Vector3Utils.add(targetLocation, { x: 0, y: 1, z: 0 }) 43 | ); 44 | } 45 | -------------------------------------------------------------------------------- /howto-gallery/scripts/MusicAndSound.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation, MusicOptions, PlayerSoundOptions, world, WorldSoundOptions } from "@minecraft/server"; 2 | 3 | /** 4 | * Plays some music and sound effects. 5 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 6 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 7 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world#playmusic 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/world#playsound 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/player#playsound 10 | */ 11 | export function playMusicAndSound(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 12 | const players = world.getPlayers(); 13 | 14 | const musicOptions: MusicOptions = { 15 | fade: 0.5, 16 | loop: true, 17 | volume: 1.0, 18 | }; 19 | world.playMusic("music.menu", musicOptions); 20 | 21 | const worldSoundOptions: WorldSoundOptions = { 22 | pitch: 0.5, 23 | volume: 4.0, 24 | }; 25 | world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions); 26 | 27 | const playerSoundOptions: PlayerSoundOptions = { 28 | pitch: 1.0, 29 | volume: 1.0, 30 | }; 31 | 32 | players[0].playSound("bucket.fill_water", playerSoundOptions); 33 | } 34 | -------------------------------------------------------------------------------- /howto-gallery/scripts/Particles.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation, MolangVariableMap } from "@minecraft/server"; 2 | 3 | /** 4 | * Spawns a cloud of colored flame particles. 5 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 6 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 7 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension#spawnparticle 8 | */ 9 | export function spawnParticle(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 10 | for (let i = 0; i < 100; i++) { 11 | const molang = new MolangVariableMap(); 12 | 13 | molang.setColorRGB("variable.color", { red: Math.random(), green: Math.random(), blue: Math.random() }); 14 | 15 | const newLocation = { 16 | x: targetLocation.x + Math.floor(Math.random() * 8) - 4, 17 | y: targetLocation.y + Math.floor(Math.random() * 8) - 4, 18 | z: targetLocation.z + Math.floor(Math.random() * 8) - 4, 19 | }; 20 | targetLocation.dimension.spawnParticle("minecraft:colored_flame_particle", newLocation, molang); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /howto-gallery/scripts/PistonActivateEvent.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BlockPermutation, 3 | BlockPistonState, 4 | DimensionLocation, 5 | PistonActivateAfterEvent, 6 | system, 7 | world, 8 | } from "@minecraft/server"; 9 | import { MinecraftBlockTypes } from "@minecraft/vanilla-data"; 10 | 11 | /** 12 | * A simple piston after activate event. 13 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 14 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 15 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/pistonactivateaftereventsignal#subscribe 16 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/pistonactivateafterevent 17 | */ 18 | export function pistonAfterEvent(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 19 | // set up a couple of piston blocks 20 | const piston = targetLocation.dimension.getBlock(targetLocation); 21 | const button = targetLocation.dimension.getBlock({ 22 | x: targetLocation.x, 23 | y: targetLocation.y + 1, 24 | z: targetLocation.z, 25 | }); 26 | 27 | if (piston === undefined || button === undefined) { 28 | log("Could not find block at location."); 29 | return -1; 30 | } 31 | 32 | piston.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.Piston).withState("facing_direction", 3)); 33 | button.setPermutation(BlockPermutation.resolve(MinecraftBlockTypes.AcaciaButton).withState("facing_direction", 1)); 34 | 35 | world.afterEvents.pistonActivate.subscribe((pistonEvent: PistonActivateAfterEvent) => { 36 | const eventLoc = pistonEvent.piston.block.location; 37 | 38 | if (eventLoc.x === targetLocation.x && eventLoc.y === targetLocation.y && eventLoc.z === targetLocation.z) { 39 | log( 40 | "Piston event at " + 41 | system.currentTick + 42 | (pistonEvent.piston.isMoving ? " Moving" : "") + 43 | (pistonEvent.piston.state === BlockPistonState.Expanding ? " Expanding" : "") + 44 | (pistonEvent.piston.state === BlockPistonState.Expanded ? " Expanded" : "") + 45 | (pistonEvent.piston.state === BlockPistonState.Retracting ? " Retracting" : "") + 46 | (pistonEvent.piston.state === BlockPistonState.Retracted ? " Retracted" : "") 47 | ); 48 | } 49 | }); 50 | } 51 | -------------------------------------------------------------------------------- /howto-gallery/scripts/Players.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation, world } from "@minecraft/server"; 2 | 3 | /** 4 | * Sends player a number of diverse message types. 5 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 6 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 7 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/Player#sendMessage 8 | */ 9 | export function sendPlayerMessages(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 10 | for (const player of world.getAllPlayers()) { 11 | // Displays "First or Second" 12 | const rawMessage = { translate: "accessibility.list.or.two", with: ["First", "Second"] }; 13 | player.sendMessage(rawMessage); 14 | 15 | // Displays "Hello, world!" 16 | player.sendMessage("Hello, world!"); 17 | 18 | // Displays "Welcome, Amazing Player 1!" 19 | player.sendMessage({ translate: "authentication.welcome", with: ["Amazing Player 1"] }); 20 | 21 | // Displays the player's score for objective "obj". Each player will see their own score. 22 | const rawMessageWithScore = { score: { name: "*", objective: "obj" } }; 23 | player.sendMessage(rawMessageWithScore); 24 | 25 | // Displays "Apple or Coal" 26 | const rawMessageWithNestedTranslations = { 27 | translate: "accessibility.list.or.two", 28 | with: { rawtext: [{ translate: "item.apple.name" }, { translate: "item.coal.name" }] }, 29 | }; 30 | player.sendMessage(rawMessageWithNestedTranslations); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /howto-gallery/scripts/Scoreboard.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation, DisplaySlotId, ObjectiveSortOrder, world } from "@minecraft/server"; 2 | 3 | /** 4 | * Creates and updates a scoreboard objective, plus a player score. 5 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 6 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 7 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/Scoreboard 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/Scoreboard#addobjective 9 | */ 10 | export function updateScoreboard(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 11 | const scoreboardObjectiveId = "scoreboard_demo_objective"; 12 | const scoreboardObjectiveDisplayName = "Demo Objective"; 13 | 14 | const players = world.getPlayers(); 15 | 16 | // Ensure a new objective. 17 | let objective = world.scoreboard.getObjective(scoreboardObjectiveId); 18 | 19 | if (!objective) { 20 | objective = world.scoreboard.addObjective(scoreboardObjectiveId, scoreboardObjectiveDisplayName); 21 | } 22 | 23 | // get the scoreboard identity for player 0 24 | const player0Identity = players[0].scoreboardIdentity; 25 | 26 | if (player0Identity === undefined) { 27 | log("Could not get a scoreboard identity for player 0."); 28 | return -1; 29 | } 30 | 31 | // initialize player score to 100; 32 | objective.setScore(player0Identity, 100); 33 | 34 | world.scoreboard.setObjectiveAtDisplaySlot(DisplaySlotId.Sidebar, { 35 | objective: objective, 36 | sortOrder: ObjectiveSortOrder.Descending, 37 | }); 38 | 39 | const playerScore = objective.getScore(player0Identity) ?? 0; 40 | 41 | // score should now be 110. 42 | objective.setScore(player0Identity, playerScore + 10); 43 | } 44 | -------------------------------------------------------------------------------- /howto-gallery/scripts/Server-UISampleLibrary.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation } from "@minecraft/server"; 2 | import SampleManager from "./SampleManager"; 3 | 4 | import * as sdf1 from "./ServerUserInterface"; 5 | 6 | const mojangMinecraftUIFuncs: { 7 | [name: string]: Array<(log: (message: string, status?: number) => void, location: DimensionLocation) => void>; 8 | } = { 9 | showActionForm: [sdf1.showActionForm], 10 | showFavoriteMonth: [sdf1.showFavoriteMonth], 11 | showBasicMessageForm: [sdf1.showBasicMessageForm], 12 | showBasicModalForm: [sdf1.showBasicModalForm], 13 | showTranslatedMessageForm: [sdf1.showTranslatedMessageForm], 14 | }; 15 | 16 | export function register(sampleManager: SampleManager) { 17 | sampleManager.registerSamples(mojangMinecraftUIFuncs); 18 | } 19 | -------------------------------------------------------------------------------- /howto-gallery/scripts/SpawnItem.ts: -------------------------------------------------------------------------------- 1 | import { DimensionLocation, EntityComponentTypes, EntityItemComponent, ItemStack } from "@minecraft/server"; 2 | import { MinecraftItemTypes } from "@minecraft/vanilla-data"; 3 | 4 | /** 5 | * Creates a free-floating feather item in the world. 6 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 7 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 8 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/itemStack 9 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension#spawnitem 10 | */ 11 | export function spawnFeatherItem(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 12 | const featherItem = new ItemStack(MinecraftItemTypes.Feather, 1); 13 | 14 | targetLocation.dimension.spawnItem(featherItem, targetLocation); 15 | log(`New feather created at ${targetLocation.x}, ${targetLocation.y}, ${targetLocation.z}!`); 16 | } 17 | 18 | /** 19 | * Tests whether there is a feather nearby a spot. 20 | * @param {(message: string, status?: number) => void} log: Logger function. If status is positive, test is a success. If status is negative, test is a failure. 21 | * @param {DimensionLocation} targetLocation Location to center this sample code around. 22 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityitemcomponent 23 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/entityqueryoptions 24 | * @see https://learn.microsoft.com/minecraft/creator/scriptapi/minecraft/server/dimension#getentities 25 | */ 26 | export function testThatEntityIsFeatherItem( 27 | log: (message: string, status?: number) => void, 28 | targetLocation: DimensionLocation 29 | ) { 30 | const items = targetLocation.dimension.getEntities({ 31 | location: targetLocation, 32 | maxDistance: 20, 33 | }); 34 | 35 | for (const item of items) { 36 | const itemComp = item.getComponent(EntityComponentTypes.Item) as EntityItemComponent; 37 | 38 | if (itemComp) { 39 | if (itemComp.itemStack.typeId.endsWith("feather")) { 40 | log("Success! Found a feather", 1); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /howto-gallery/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import SampleManager from "./SampleManager"; 2 | import * as serverSampleLibrary from "./ServerSampleLibrary"; 3 | import * as serverUISampleLibrary from "./Server-UISampleLibrary"; 4 | 5 | const sm = new SampleManager(); 6 | 7 | serverSampleLibrary.register(sm); 8 | serverUISampleLibrary.register(sm); 9 | -------------------------------------------------------------------------------- /howto-gallery/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minecraft-scripting-samples", 3 | "workspaces": [ 4 | "*" 5 | ], 6 | "scripts": { 7 | "build": "npm run build -ws", 8 | "mcaddon": "npm run mcaddon -ws" 9 | }, 10 | "overrides": { 11 | "@minecraft/server-editor@0.1.0-beta.1.21.60-preview.25": { 12 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25" 13 | }, 14 | "@minecraft/server-ui@1.4.0-beta.1.21.60-preview.25": { 15 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25" 16 | }, 17 | "@minecraft/server-gametest@1.0.0-beta.1.21.60-preview.25": { 18 | "@minecraft/server": "1.18.0-beta.1.21.60-preview.25" 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /script-box/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="script-box" 2 | MINECRAFT_PRODUCT="BedrockUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /script-box/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /script-box/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /script-box/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /script-box/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "Elytra", 29 | "gametest", 30 | "gametests", 31 | "knockback", 32 | "minecart", 33 | "molang", 34 | "onfire", 35 | "samplelibrary", 36 | "scriptevent", 37 | "shulker", 38 | "skelly", 39 | "zoglin" 40 | ], 41 | "editor.tabSize": 2, 42 | "eslint.experimental.useFlatConfig": true 43 | } -------------------------------------------------------------------------------- /script-box/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /script-box/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | author: mammerla 4 | description: A simple sandbox for experimenting with Minecraft coding behaviors. 5 | ms.author: mikeam@microsoft.com 6 | ms.date: 06/07/2023 7 | languages: 8 | - typescript 9 | products: 10 | - minecraft 11 | --- 12 | 13 | # Minecraft Script Box 14 | 15 | This sample makes it easy to experiment with JavaScript code. Just add your code in the function at ScriptBox.ts, and this sample will add some infrastructure around it. 16 | 17 | ## Prerequisites 18 | 19 | **Install Node.js tools, if you haven't already** 20 | 21 | We're going to use the package manager [npm](https://www.npmjs.com/package/npm) to get more tools to make the process of building our project easier. 22 | 23 | Visit [https://nodejs.org/](https://nodejs.org). 24 | 25 | Download the version with "LTS" next to the number and install it. (LTS stands for Long Term Support, if you're curious.) In the Node.js Windows installer, accept the installation defaults. You do not need to install any additional tools for Native compilation. 26 | 27 | **Install Visual Studio Code, if you haven't already** 28 | 29 | Visit the [Visual Studio Code website](https://code.visualstudio.com) and install Visual Studio Code. 30 | 31 | ## Getting Started 32 | 33 | 1. Use npm to install dependent modules: 34 | 35 | ```powershell 36 | npm i 37 | ``` 38 | 39 | 1. Use this shortcut command to open the project in Visual Studio Code: 40 | 41 | ```powershell 42 | code . 43 | ``` 44 | 45 | ### Chapter 2. Let's test the parts of our project 46 | 47 | Within the root folder (script-box) of this sample, run this command: 48 | 49 | ```powershell 50 | Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass 51 | ``` 52 | 53 | Run this one, too. 54 | 55 | ```powershell 56 | npm run local-deploy 57 | ``` 58 | 59 | Create an addon file to share. 60 | 61 | ```powershell 62 | npm run mcaddon 63 | ``` 64 | 65 | ## Manifest 66 | 67 | - [just.config.ts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/script-box/just.config.ts): This file contains build instructions for just-scripts, for building out TypeScript code. 68 | - [scripts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/script-box/scripts): This contains Script Box TypeScript files, that will be compiled and built into your projects. 69 | - [behavior_packs](https://github.com/microsoft/minecraft-scripting-samples/blob/main/script-box/behavior_packs): This contains resources and JSON files that define your behavior pack. 70 | -------------------------------------------------------------------------------- /script-box/behavior_packs/script-box/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Script Box", 5 | "description": "A simple sample where you can add code in a framework", 6 | "uuid": "7de074b8-9052-4b1c-9342-b5c4280269fb", 7 | "version": [1, 0, 0], 8 | "min_engine_version": [1, 20, 0] 9 | }, 10 | "modules": [ 11 | { 12 | "description": "Script resources", 13 | "type": "script", 14 | "language": "javascript", 15 | "uuid": "df6523d1-4442-45c2-b33a-1c882d388684", 16 | "version": [1, 0, 0], 17 | "entry": "scripts/main.js" 18 | } 19 | ], 20 | "dependencies": [ 21 | { 22 | "module_name": "@minecraft/server", 23 | "version": "1.13.0" 24 | }, 25 | { 26 | "module_name": "@minecraft/server-ui", 27 | "version": "1.1.0" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /script-box/behavior_packs/script-box/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/script-box/behavior_packs/script-box/pack_icon.png -------------------------------------------------------------------------------- /script-box/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /script-box/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import { 3 | bundleTask, 4 | BundleTaskParameters, 5 | CopyTaskParameters, 6 | cleanTask, 7 | cleanCollateralTask, 8 | copyTask, 9 | coreLint, 10 | mcaddonTask, 11 | setupEnvironment, 12 | ZipTaskParameters, 13 | STANDARD_CLEAN_PATHS, 14 | DEFAULT_CLEAN_DIRECTORIES, 15 | getOrThrowFromProcess, 16 | watchTask, 17 | } from "@minecraft/core-build-tasks"; 18 | import path from "path"; 19 | 20 | // Setup env variables 21 | setupEnvironment(path.resolve(__dirname, ".env")); 22 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 23 | 24 | const bundleTaskOptions: BundleTaskParameters = { 25 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 26 | external: ["@minecraft/server", "@minecraft/server-gametest", "@minecraft/server-ui"], 27 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 28 | minifyWhitespace: false, 29 | sourcemap: true, 30 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 31 | }; 32 | 33 | const copyTaskOptions: CopyTaskParameters = { 34 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 35 | copyToScripts: ["./dist/scripts"], 36 | }; 37 | 38 | const mcaddonTaskOptions: ZipTaskParameters = { 39 | ...copyTaskOptions, 40 | outputFile: `./dist/packages/${projectName}.mcaddon`, 41 | }; 42 | 43 | // Lint 44 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 45 | 46 | // Build 47 | task("typescript", tscTask()); 48 | task("bundle", bundleTask(bundleTaskOptions)); 49 | task("build", series("typescript", "bundle")); 50 | 51 | // Clean 52 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 53 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 54 | task("clean", parallel("clean-local", "clean-collateral")); 55 | 56 | // Package 57 | task("copyArtifacts", copyTask(copyTaskOptions)); 58 | task("package", series("clean-collateral", "copyArtifacts")); 59 | 60 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 61 | task( 62 | "local-deploy", 63 | watchTask( 64 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 65 | series("clean-local", "build", "package") 66 | ) 67 | ); 68 | 69 | // Mcaddon 70 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 71 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 72 | -------------------------------------------------------------------------------- /script-box/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "script-box", 3 | "version": "0.1.0", 4 | "productName": "Minecraft Script Box Playground", 5 | "description": "Minecraft Script Box Playground", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.0.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.6.2" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "clean": "just-scripts clean", 18 | "local-deploy": "just-scripts local-deploy", 19 | "mcaddon": "just-scripts mcaddon", 20 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 21 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 22 | }, 23 | "dependencies": { 24 | "@minecraft/math": "^2.0.1", 25 | "@minecraft/server": "^1.14.0", 26 | "@minecraft/server-ui": "^1.3.0", 27 | "@minecraft/vanilla-data": "^1.21.20" 28 | }, 29 | "overrides": { 30 | "@minecraft/math": { 31 | "@minecraft/server": "$@minecraft/server" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /script-box/scripts/ScriptBox.ts: -------------------------------------------------------------------------------- 1 | import { world, DimensionLocation } from "@minecraft/server"; 2 | 3 | // When running a world with this behavior pack, type '/scriptevent sample:run' in chat to trigger this code. 4 | export function scriptBox(log: (message: string, status?: number) => void, targetLocation: DimensionLocation) { 5 | world.sendMessage("Hello world! Replace this line with your code."); 6 | } 7 | -------------------------------------------------------------------------------- /script-box/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import SampleManager from "./SampleManager"; 2 | import { scriptBox } from "./ScriptBox"; 3 | 4 | const sm = new SampleManager(); 5 | 6 | sm.registerSamples({ 7 | scriptBox: [scriptBox], 8 | }); 9 | -------------------------------------------------------------------------------- /script-box/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /ts-starter-complete-cotta/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="cotta" 2 | MINECRAFT_PRODUCT="BedrockUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /ts-starter-complete-cotta/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /ts-starter-complete-cotta/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /ts-starter-complete-cotta/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /ts-starter-complete-cotta/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "gametest", 29 | "gametests", 30 | "minecart", 31 | "shulker", 32 | "zoglin" 33 | ], 34 | "editor.tabSize": 2, 35 | "eslint.experimental.useFlatConfig": true 36 | } -------------------------------------------------------------------------------- /ts-starter-complete-cotta/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /ts-starter-complete-cotta/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | author: mammerla 4 | description: A basic Hello World example of developing Minecraft scripts using TypeScript and a build process. 5 | ms.author: mikeam@microsoft.com 6 | ms.date: 04/01/2022 7 | languages: 8 | - typescript 9 | products: 10 | - minecraft 11 | --- 12 | 13 | # Minecraft TypeScript Starter Project Complete (Break the Cotta Game) 14 | 15 | This is a completed version of the [../ts-starter/README.md](ts-starter) project. See also the [main tutorial article link](https://learn.microsoft.com/minecraft/creator/documents/scriptinggettingstarted). 16 | 17 | ## Prerequisites 18 | 19 | ### Install Node.js tools, if you haven't already 20 | 21 | We're going to use the package manager [npm](https://www.npmjs.com/package/npm) to get more tools to make the process of building our project easier. 22 | 23 | Visit [https://nodejs.org/](https://nodejs.org). 24 | 25 | Download the version with "LTS" next to the number and install it. (LTS stands for Long Term Support, if you're curious.) In the Node.js Windows installer, accept the installation defaults. You do not need to install any additional tools for Native compilation. 26 | 27 | ### Install Visual Studio Code, if you haven't already 28 | 29 | Visit the [Visual Studio Code website](https://code.visualstudio.com) and install Visual Studio Code. 30 | 31 | ## Manifest 32 | 33 | - [just.config.ts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/ts-starter-complete-cotta/just.config.ts): This file contains build instructions for the Starter Break the Cotta arena project. 34 | - [scripts](https://github.com/microsoft/minecraft-scripting-samples/blob/main/ts-starter-complete-cotta/scripts): This contains all of your TypeScript files, that will be compiled and built into your projects. 35 | - [behavior_packs](https://github.com/microsoft/minecraft-scripting-samples/blob/main/ts-starter-complete-cotta/behavior_packs): This contains resources and JSON files that define your behavior pack. 36 | -------------------------------------------------------------------------------- /ts-starter-complete-cotta/behavior_packs/cotta/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Cotta Behavior Pack", 5 | "description": "My TypeScript Project", 6 | "uuid": "79587552-f454-4cee-855e-652b7675c507", 7 | "version": [ 8 | 1, 9 | 0, 10 | 0 11 | ], 12 | "min_engine_version": [ 13 | 1, 14 | 20, 15 | 30 16 | ] 17 | }, 18 | "modules": [ 19 | { 20 | "description": "Script resources", 21 | "language": "javascript", 22 | "type": "script", 23 | "uuid": "530a69a2-11cc-4e69-9b13-bb99535184f5", 24 | "version": [ 25 | 1, 26 | 0, 27 | 0 28 | ], 29 | "entry": "scripts/main.js" 30 | } 31 | ], 32 | "dependencies": [ 33 | { 34 | "module_name": "@minecraft/server", 35 | "version": "1.8.0" 36 | }, 37 | { 38 | "uuid": "f0cc5ac5-24ff-40b1-870b-77b7730c3f3f", 39 | "version": [ 40 | 1, 41 | 0, 42 | 0 43 | ] 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /ts-starter-complete-cotta/behavior_packs/cotta/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/ts-starter-complete-cotta/behavior_packs/cotta/pack_icon.png -------------------------------------------------------------------------------- /ts-starter-complete-cotta/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /ts-starter-complete-cotta/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import { 3 | CopyTaskParameters, 4 | bundleTask, 5 | cleanTask, 6 | cleanCollateralTask, 7 | copyTask, 8 | coreLint, 9 | mcaddonTask, 10 | setupEnvironment, 11 | ZipTaskParameters, 12 | BundleTaskParameters, 13 | STANDARD_CLEAN_PATHS, 14 | DEFAULT_CLEAN_DIRECTORIES, 15 | getOrThrowFromProcess, 16 | watchTask, 17 | } from "@minecraft/core-build-tasks"; 18 | import path from "path"; 19 | 20 | // Setup env variables 21 | setupEnvironment(path.resolve(__dirname, ".env")); 22 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 23 | 24 | // You can use `npm run build:production` to build a "production" build that strips out statements labelled with "dev:". 25 | const isProduction = argv()['production']; 26 | 27 | const bundleTaskOptions: BundleTaskParameters = { 28 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 29 | external: ["@minecraft/server", "@minecraft/server-ui"], 30 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 31 | minifyWhitespace: false, 32 | sourcemap: true, 33 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 34 | dropLabels: isProduction ? ['dev'] : undefined 35 | }; 36 | 37 | const copyTaskOptions: CopyTaskParameters = { 38 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 39 | copyToScripts: ["./dist/scripts"], 40 | copyToResourcePacks: [`./resource_packs/${projectName}`], 41 | }; 42 | 43 | const mcaddonTaskOptions: ZipTaskParameters = { 44 | ...copyTaskOptions, 45 | outputFile: `./dist/packages/${projectName}.mcaddon`, 46 | }; 47 | 48 | // Lint 49 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 50 | 51 | // Build 52 | task("typescript", tscTask()); 53 | task("bundle", bundleTask(bundleTaskOptions)); 54 | task("build", series("typescript", "bundle")); 55 | 56 | // Clean 57 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 58 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 59 | task("clean", parallel("clean-local", "clean-collateral")); 60 | 61 | // Package 62 | task("copyArtifacts", copyTask(copyTaskOptions)); 63 | task("package", series("clean-collateral", "copyArtifacts")); 64 | 65 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 66 | task( 67 | "local-deploy", 68 | watchTask( 69 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 70 | series("clean-local", "build", "package") 71 | ) 72 | ); 73 | 74 | // Mcaddon 75 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 76 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 77 | -------------------------------------------------------------------------------- /ts-starter-complete-cotta/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scripting-starter-complete-cotta", 3 | "version": "0.1.0", 4 | "productName": "Minecraft TypeScript Starter Project", 5 | "description": "Minecraft TypeScript Starter Project", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.1.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.6.2" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "build:production": "just-scripts build --production", 18 | "clean": "just-scripts clean", 19 | "local-deploy": "just-scripts local-deploy", 20 | "mcaddon": "just-scripts mcaddon", 21 | "mcaddon:production": "just-scripts mcaddon --production", 22 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 23 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 24 | }, 25 | "dependencies": { 26 | "@minecraft/math": "^2.0.1", 27 | "@minecraft/server": "^1.14.0", 28 | "@minecraft/server-ui": "^1.3.0", 29 | "@minecraft/vanilla-data": "^1.21.20" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ts-starter-complete-cotta/resource_packs/cotta/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "Cotta resource pack", 5 | "description": "Cotta resource pack description", 6 | "uuid": "f0cc5ac5-24ff-40b1-870b-77b7730c3f3f", 7 | "version": [ 8 | 1, 9 | 0, 10 | 0 11 | ], 12 | "min_engine_version": [ 13 | 1, 14 | 20, 15 | 30 16 | ] 17 | }, 18 | "modules": [ 19 | { 20 | "description": "Cotta Resource Pack", 21 | "type": "resources", 22 | "uuid": "0c6c678e-367d-402a-80a0-53847181cd16", 23 | "version": [ 24 | 1, 25 | 0, 26 | 0 27 | ] 28 | } 29 | ], 30 | "dependencies": [ 31 | { 32 | "uuid": "79587552-f454-4cee-855e-652b7675c507", 33 | "version": [ 34 | 1, 35 | 0, 36 | 0 37 | ] 38 | } 39 | ] 40 | } -------------------------------------------------------------------------------- /ts-starter-complete-cotta/resource_packs/cotta/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/ts-starter-complete-cotta/resource_packs/cotta/pack_icon.png -------------------------------------------------------------------------------- /ts-starter-complete-cotta/scripts/Utilities.ts: -------------------------------------------------------------------------------- 1 | import { world, BlockPermutation } from "@minecraft/server"; 2 | import { MinecraftDimensionTypes } from "@minecraft/vanilla-data"; 3 | 4 | export default class Utilities { 5 | static fillBlock( 6 | blockPerm: BlockPermutation, 7 | xFrom: number, 8 | yFrom: number, 9 | zFrom: number, 10 | xTo: number, 11 | yTo: number, 12 | zTo: number 13 | ) { 14 | const overworld = world.getDimension(MinecraftDimensionTypes.Overworld); 15 | 16 | for (let i = xFrom; i <= xTo; i++) { 17 | for (let j = yFrom; j <= yTo; j++) { 18 | for (let k = zFrom; k <= zTo; k++) { 19 | overworld.getBlock({ x: i, y: j, z: k })?.setPermutation(blockPerm); 20 | } 21 | } 22 | } 23 | } 24 | 25 | static fourWalls( 26 | perm: BlockPermutation, 27 | xFrom: number, 28 | yFrom: number, 29 | zFrom: number, 30 | xTo: number, 31 | yTo: number, 32 | zTo: number 33 | ) { 34 | const overworld = world.getDimension(MinecraftDimensionTypes.Overworld); 35 | 36 | for (let i = xFrom; i <= xTo; i++) { 37 | for (let k = yFrom; k <= yTo; k++) { 38 | overworld.getBlock({ x: i, y: k, z: zFrom })?.setPermutation(perm); 39 | overworld.getBlock({ x: i, y: k, z: zTo })?.setPermutation(perm); 40 | } 41 | } 42 | 43 | for (let j = zFrom + 1; j < zTo; j++) { 44 | for (let k = yFrom; k <= yTo; k++) { 45 | overworld.getBlock({ x: xFrom, y: k, z: j })?.setPermutation(perm); 46 | overworld.getBlock({ x: xTo, y: k, z: j })?.setPermutation(perm); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ts-starter-complete-cotta/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } -------------------------------------------------------------------------------- /ts-starter/.env: -------------------------------------------------------------------------------- 1 | PROJECT_NAME="starter" 2 | MINECRAFT_PRODUCT="BedrockUWP" 3 | CUSTOM_DEPLOYMENT_PATH="" -------------------------------------------------------------------------------- /ts-starter/.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "semi": true, 5 | "singleQuote": false, 6 | "bracketSpacing": true, 7 | "arrowParens": "always", 8 | "printWidth": 120, 9 | "endOfLine": "auto" 10 | } -------------------------------------------------------------------------------- /ts-starter/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "esbenp.prettier-vscode", 4 | "blockceptionltd.blockceptionvscodeminecraftbedrockdevelopmentextension", 5 | "mojang-studios.minecraft-debugger" 6 | ] 7 | } -------------------------------------------------------------------------------- /ts-starter/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "type": "minecraft-js", 6 | "request": "attach", 7 | "name": "Debug with Minecraft", 8 | "mode": "listen", 9 | "preLaunchTask": "build", 10 | "sourceMapRoot": "${workspaceFolder}/dist/debug/", 11 | "generatedSourceRoot": "${workspaceFolder}/dist/scripts/", 12 | "port": 19144 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /ts-starter/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[javascript]": { 3 | "editor.defaultFormatter": "esbenp.prettier-vscode" 4 | }, 5 | "[typescript]": { 6 | "editor.defaultFormatter": "esbenp.prettier-vscode" 7 | }, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | }, 11 | "[json]": { 12 | "editor.defaultFormatter": "esbenp.prettier-vscode" 13 | }, 14 | "git.ignoreLimitWarning": true, 15 | "editor.formatOnSave": true, 16 | "search.exclude": { 17 | "**/.git": true, 18 | "**/node_modules": true, 19 | "**/dist": true, 20 | "**/lib": true 21 | }, 22 | "files.exclude": { 23 | "**/.git": true, 24 | "**/.DS_Store": true, 25 | "**/node_modules": true 26 | }, 27 | "cSpell.words": [ 28 | "gametest", 29 | "gametests", 30 | "mcaddon", 31 | "minecart", 32 | "shulker", 33 | "zoglin" 34 | ], 35 | "editor.tabSize": 2, 36 | "eslint.experimental.useFlatConfig": true 37 | } -------------------------------------------------------------------------------- /ts-starter/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "build", 6 | "type": "shell", 7 | "command": "npm run build" 8 | }, 9 | { 10 | "label": "deploy", 11 | "type": "shell", 12 | "command": "npm run local-deploy" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /ts-starter/behavior_packs/starter/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "My script behavior pack", 5 | "description": "My behavior pack description", 6 | "uuid": "14e467b4-e3aa-49d3-8352-f8439fd7b2ee", 7 | "version": [ 8 | 1, 9 | 0, 10 | 0 11 | ], 12 | "min_engine_version": [ 13 | 1, 14 | 20, 15 | 30 16 | ] 17 | }, 18 | "modules": [ 19 | { 20 | "description": "Script resources", 21 | "language": "javascript", 22 | "type": "script", 23 | "uuid": "7c7e693f-99f4-41a9-95e0-1f57b37e1e12", 24 | "version": [ 25 | 1, 26 | 0, 27 | 0 28 | ], 29 | "entry": "scripts/main.js" 30 | } 31 | ], 32 | "dependencies": [ 33 | { 34 | "module_name": "@minecraft/server", 35 | "version": "1.8.0" 36 | }, 37 | { 38 | "uuid": "2d7ed858-97eb-48a0-b180-7c80d1ce9a48", 39 | "version": [ 40 | 1, 41 | 0, 42 | 0 43 | ] 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /ts-starter/behavior_packs/starter/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/ts-starter/behavior_packs/starter/pack_icon.png -------------------------------------------------------------------------------- /ts-starter/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import minecraftLinting from "eslint-plugin-minecraft-linting"; 2 | import tsParser from "@typescript-eslint/parser"; 3 | import ts from "@typescript-eslint/eslint-plugin"; 4 | 5 | export default [ 6 | { 7 | files: ["scripts/**/*.ts"], 8 | languageOptions: { 9 | parser: tsParser, 10 | ecmaVersion: "latest", 11 | }, 12 | plugins: { 13 | ts, 14 | "minecraft-linting": minecraftLinting, 15 | }, 16 | rules: { 17 | "minecraft-linting/avoid-unnecessary-command": "error", 18 | }, 19 | }, 20 | ]; 21 | -------------------------------------------------------------------------------- /ts-starter/just.config.ts: -------------------------------------------------------------------------------- 1 | import { argv, parallel, series, task, tscTask } from "just-scripts"; 2 | import { 3 | BundleTaskParameters, 4 | CopyTaskParameters, 5 | bundleTask, 6 | cleanTask, 7 | cleanCollateralTask, 8 | copyTask, 9 | coreLint, 10 | mcaddonTask, 11 | setupEnvironment, 12 | ZipTaskParameters, 13 | STANDARD_CLEAN_PATHS, 14 | DEFAULT_CLEAN_DIRECTORIES, 15 | getOrThrowFromProcess, 16 | watchTask, 17 | } from "@minecraft/core-build-tasks"; 18 | import path from "path"; 19 | 20 | // Setup env variables 21 | setupEnvironment(path.resolve(__dirname, ".env")); 22 | const projectName = getOrThrowFromProcess("PROJECT_NAME"); 23 | 24 | // You can use `npm run build:production` to build a "production" build that strips out statements labelled with "dev:". 25 | const isProduction = argv()['production']; 26 | 27 | const bundleTaskOptions: BundleTaskParameters = { 28 | entryPoint: path.join(__dirname, "./scripts/main.ts"), 29 | external: ["@minecraft/server", "@minecraft/server-ui"], 30 | outfile: path.resolve(__dirname, "./dist/scripts/main.js"), 31 | minifyWhitespace: false, 32 | sourcemap: true, 33 | outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), 34 | dropLabels: isProduction ? ['dev'] : undefined 35 | }; 36 | 37 | const copyTaskOptions: CopyTaskParameters = { 38 | copyToBehaviorPacks: [`./behavior_packs/${projectName}`], 39 | copyToScripts: ["./dist/scripts"], 40 | copyToResourcePacks: [`./resource_packs/${projectName}`], 41 | }; 42 | 43 | const mcaddonTaskOptions: ZipTaskParameters = { 44 | ...copyTaskOptions, 45 | outputFile: `./dist/packages/${projectName}.mcaddon`, 46 | }; 47 | 48 | // Lint 49 | task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); 50 | 51 | // Build 52 | task("typescript", tscTask()); 53 | task("bundle", bundleTask(bundleTaskOptions)); 54 | task("build", series("typescript", "bundle")); 55 | 56 | // Clean 57 | task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); 58 | task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); 59 | task("clean", parallel("clean-local", "clean-collateral")); 60 | 61 | // Package 62 | task("copyArtifacts", copyTask(copyTaskOptions)); 63 | task("package", series("clean-collateral", "copyArtifacts")); 64 | 65 | // Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. 66 | task( 67 | "local-deploy", 68 | watchTask( 69 | ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], 70 | series("clean-local", "build", "package") 71 | ) 72 | ); 73 | 74 | // Mcaddon 75 | task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); 76 | task("mcaddon", series("clean-local", "build", "createMcaddonFile")); 77 | -------------------------------------------------------------------------------- /ts-starter/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scripting-starter", 3 | "version": "0.1.0", 4 | "productName": "Minecraft TypeScript Starter Project", 5 | "description": "Minecraft TypeScript Starter Project", 6 | "private": true, 7 | "devDependencies": { 8 | "@minecraft/core-build-tasks": "^4.1.0", 9 | "eslint-plugin-minecraft-linting": "^2.0.1", 10 | "source-map": "^0.7.4", 11 | "ts-node": "^10.9.1", 12 | "typescript": "^5.5.4" 13 | }, 14 | "scripts": { 15 | "lint": "just-scripts lint", 16 | "build": "just-scripts build", 17 | "build:production": "just-scripts build --production", 18 | "clean": "just-scripts clean", 19 | "local-deploy": "just-scripts local-deploy", 20 | "mcaddon": "just-scripts mcaddon", 21 | "mcaddon:production": "just-scripts mcaddon --production", 22 | "enablemcloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-1958404141-86561845-1752920682-3514627264-368642714-62675701-733520436", 23 | "enablemcpreviewloopback": "CheckNetIsolation.exe LoopbackExempt -a -p=S-1-15-2-424268864-5579737-879501358-346833251-474568803-887069379-4040235476" 24 | }, 25 | "dependencies": { 26 | "@minecraft/math": "^2.0.1", 27 | "@minecraft/server": "^1.13.0", 28 | "@minecraft/server-ui": "^1.2.0", 29 | "@minecraft/vanilla-data": "^1.21.20" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /ts-starter/resource_packs/starter/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "format_version": 2, 3 | "header": { 4 | "name": "My resource pack", 5 | "description": "My resource pack description", 6 | "uuid": "2d7ed858-97eb-48a0-b180-7c80d1ce9a48", 7 | "version": [ 8 | 1, 9 | 0, 10 | 0 11 | ], 12 | "min_engine_version": [ 13 | 1, 14 | 20, 15 | 30 16 | ] 17 | }, 18 | "modules": [ 19 | { 20 | "description": "My Resource Pack", 21 | "type": "resources", 22 | "uuid": "503fe660-142b-46a2-8fec-34a54e944720", 23 | "version": [ 24 | 1, 25 | 0, 26 | 0 27 | ] 28 | } 29 | ], 30 | "dependencies": [ 31 | { 32 | "uuid": "14e467b4-e3aa-49d3-8352-f8439fd7b2ee", 33 | "version": [ 34 | 1, 35 | 0, 36 | 0 37 | ] 38 | } 39 | ] 40 | } -------------------------------------------------------------------------------- /ts-starter/resource_packs/starter/pack_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/minecraft-scripting-samples/754b14467dd1271f176e2bafb8bb346caf567cf2/ts-starter/resource_packs/starter/pack_icon.png -------------------------------------------------------------------------------- /ts-starter/scripts/main.ts: -------------------------------------------------------------------------------- 1 | import { world, system } from "@minecraft/server"; 2 | 3 | function mainTick() { 4 | if (system.currentTick % 100 === 0) { 5 | world.sendMessage("Hello starter! Tick: " + system.currentTick); 6 | } 7 | 8 | system.run(mainTick); 9 | } 10 | 11 | system.run(mainTick); 12 | -------------------------------------------------------------------------------- /ts-starter/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions":{ 3 | "target":"es6", 4 | "moduleResolution":"Node", 5 | "module": "ES2020", 6 | "declaration":false, 7 | "noLib":false, 8 | "emitDecoratorMetadata":true, 9 | "experimentalDecorators":true, 10 | "sourceMap":true, 11 | "pretty":true, 12 | "forceConsistentCasingInFileNames": true, 13 | "strict": true, 14 | "allowUnreachableCode":true, 15 | "allowUnusedLabels":true, 16 | "noImplicitAny":true, 17 | "noImplicitReturns":false, 18 | "noImplicitUseStrict":false, 19 | "outDir":"lib", 20 | "rootDir": ".", 21 | "baseUrl":"behavior_packs/", 22 | "listFiles":false, 23 | "noEmitHelpers":true, 24 | "skipLibCheck": true 25 | }, 26 | "include":[ 27 | "scripts/**/*" 28 | ], 29 | "exclude": ["lib", "dist", "node_modules"], 30 | "compileOnSave":false 31 | } --------------------------------------------------------------------------------