Act as an expert Minecraft Bedrock Add-on developer specializing in modern JavaScript Scripting API (@minecraft/server). I need a complete, error-free Behavior Pack (.mcpack) for Minecraft version 1.21.0+.
The add-on is a "Stealth Survival Flight" tool disguised as a piece of Flint. When a player crouches and right-clicks/long-presses with Flint, it toggles their ability to fly in Survival mode.
Please generate the manifest.json and main.js files based on these exact technical specifications to ensure it works perfectly on mobile:
1. Trigger Requirements
- Event Hook: Use
world.afterEvents.itemUse.subscribe. - Item Check: Check if the item used is exactly "minecraft:flint".
- Condition: Check if
player.isSneakingis true. If false, do nothing.
2. Robust Flight Toggle Logic
- Maintain an in-memory tracking system using a global
const flyingPlayers = new Set();. - To avoid "Player is not an operator" permission errors in Survival mode, do NOT use
player.runCommandAsync. Instead, route the command through the server dimension using:
player.dimension.runCommandAsync(ability "${player.name}" mayfly true/false);
- Toggle Logic:
- If the player's ID is in the Set: Remove them, turn mayfly to false, and send an action bar message. - If the player's ID is NOT in the Set: Add them, turn mayfly to true, and send an action bar message.
3. Syntax & Encoding Safeguards (Crucial)
- Text Formatting: Use the Unicode escape character
\u00A7for color codes instead of the raw section symbol (§) to prevent mobile text corruption. (e.g., "\u00A7a[System] Fly Mode: ON"). - Code Completeness: Ensure all brackets, parentheses, and event subscriptions are completely closed. Include a
world.afterEvents.playerLeavelistener to clean up disconnecting players from the Set.
Please output the full manifest.json and the complete, uncorrupted main.js script.
I’ll create this Stealth Survival Flight add-on behavior pack.
manifest.json:
{
"format_version": 2,
"header": {
"name": "Stealth Survival Flight",
"description": "Crouch + use Flint to toggle flight in Survival mode",
"uuid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"version": [1, 0, 0],
"min_engine_version": [1, 21, 0]
},
"modules": [
{
"type": "script",
"language": "javascript",
"uuid": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"entry": "scripts/main.js",
"version": [1, 0, 0]
}
],
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.13.0"
}
],
"capabilities": ["script_eval"]
}
scripts/main.js:
import { world, system } from "@minecraft/server";
const flyingPlayers = new Set();
world.afterEvents.itemUse.subscribe((event) => {
const { source: player, itemStack } = event;
if (!player || !itemStack) return;
if (itemStack.typeId !== "minecraft:flint") return;
if (!player.isSneaking) return;
const playerId = player.id;
if (flyingPlayers.has(playerId)) {
flyingPlayers.delete(playerId);
player.dimension.runCommandAsync(`ability "${player.name}" mayfly false`);
player.onScreenDisplay.setActionBar("\u00A7c[SSF] Fly: OFF");
} else {
flyingPlayers.add(playerId);
player.dimension.runCommandAsync(`ability "${player.name}" mayfly true`);
player.onScreenDisplay.setActionBar("\u00A7a[SSF] Fly: ON");
}
});
world.afterEvents.playerLeave.subscribe((event) => {
flyingPlayers.delete(event.playerId);
});
Directory structure to assemble:
StealthFlightFlint_BP/
├── manifest.json
└── scripts/
└── main.js
To build the .mcpack: zip the StealthFlightFlint_BP folder and rename the extension to .mcpack — or zip the folder’s contents directly and rename. Your choice.
No files in this session