Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions pack/items/debug_stick.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"format_version": "1.20.20",
"format_version": "1.21.90",

"minecraft:item": {

Expand All @@ -11,15 +11,10 @@
},

"components": {
"minecraft:icon": {
"texture": "stick"
},
"minecraft:icon": "stick",
"minecraft:hand_equipped": true,
"minecraft:display_name": {
"value": "§dDebug Stick§r"
},
"minecraft:display_name": { "value": "§dDebug Stick§r" },
"minecraft:max_stack_size": 1,
"minecraft:can_destroy_in_creative": false,
"minecraft:glint": true
}
}
Expand Down
6 changes: 3 additions & 3 deletions pack/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"name": "Debug Stick",
"description": "Java §dDebug Stick§r ported to Minecraft: Bedrock Edition, by §bvytdev§r\nUse §a/give @s vyt:debug_stick§r or find it in the inventory screen to obtain the item.\n\nReport bugs here: §bhttps://github.com/vytdev/debug-stick/§r\nCopyright (c) 2023-2025 Vincent Yanzee J. Tan\nLicensed under the MIT License.",
"uuid": "21aadfa6-e27c-400c-c596-596021852939",
"version": "1.16.0",
"min_engine_version": [ 1, 21, 80 ]
"version": "1.17.0-beta",
"min_engine_version": [ 1, 21, 94 ]
},

"modules": [
Expand All @@ -29,7 +29,7 @@
"dependencies": [
{
"module_name": "@minecraft/server",
"version": "1.19.0"
"version": "2.0.0"
}
],

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"homepage": "https://github.com/vytdev/debug-stick#readme",
"dependencies": {
"@minecraft/server": "^1.19.0",
"@minecraft/server": "^2.0.0",
"typescript": "^5.4.5"
}
}
90 changes: 19 additions & 71 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
+* MCPEDL: https://mcpedl.com/debug-stick
+* GitHub: https://github.com/vytdev/debug-stick
+*
+* Script last updated: April 5, 2025
+* Script last updated: July 27, 2025
+*
+* Copyright (c) 2023-2025 VYT <https://vytdev.github.io>
+* This project is licensed under the MIT License.
Expand All @@ -18,7 +18,6 @@ import {
Player,
Block,
BlockStates,
ItemStack,
LiquidType,
world,
system
Expand All @@ -39,45 +38,21 @@ type BlockStateValue = boolean | number | string;
const DEBUG_STICK_ID = "vyt:debug_stick";


// Some event listeners. Listens for entityHitBkock
// and itemUseOn events, which triggers an action onto
// the debug stick
world.afterEvents.entityHitBlock.subscribe(safeCallWrapper((ev) => {
if (ev.damagingEntity.typeId != "minecraft:player")
return;
const player = getPlayerByID(ev.damagingEntity.id);
if (!player)
return;
if (!isHoldingDebugStick(player))
return;
changeSelectedProperty(player, ev.hitBlock);
}));


world.beforeEvents.itemUseOn.subscribe(safeCallWrapper((ev) => {
if (ev.source.typeId != "minecraft:player")
return;
world.beforeEvents.playerInteractWithBlock.subscribe(safeCallWrapper((ev) => {
if (ev.itemStack?.typeId != DEBUG_STICK_ID)
return;
ev.cancel = true;
const player = getPlayerByID(ev.source.id);
if (!player)
return;
if (player.isSneaking)
displayBlockInfo(player, ev.block);
if (ev.player.isSneaking)
displayBlockInfo(ev.player, ev.block);
else
updateBlockProperty(player, ev.block);
updateBlockProperty(ev.player, ev.block);
}));


// Players should not be able to break blocks using
// the debug stick in survival
//
// TODO: explore other alternatives
world.beforeEvents.playerBreakBlock.subscribe(safeCallWrapper((ev) => {
if (ev.itemStack?.typeId != DEBUG_STICK_ID)
return;
ev.cancel = true;
changeSelectedProperty(ev.player, ev.block);
}));


Expand Down Expand Up @@ -175,46 +150,19 @@ const record: Record<string, Record<string, string>> = {};
* @param msg The message
* @param player The player to message
*/
function message(msg: string, player: Player) {
return player
.runCommandAsync(
`titleraw @s actionbar {"rawtext":[{"text":${JSON.stringify(msg)}}]}`
);
}

/**
* Returns a player's currently held item
* @param player The player
* @returns ItemStack or undefined
*/
function getHeldItem(player: Player): ItemStack | undefined {
return player
.getComponent("minecraft:inventory")
.container
.getItem(player.selectedSlotIndex);
}

/**
* Queries whether a player is currently using the debug
* stick item
* @param player The player
* @returns true if the player currently holds the debug
* stick
*/
function isHoldingDebugStick(player: Player): boolean {
return getHeldItem(player)
?.typeId == DEBUG_STICK_ID;
}

/**
* Utility function to return a player class from an entity ID
* @param id The entity ID
* @returns Player instance or undefined
*/
function getPlayerByID(id: string): Player | undefined {
return world
.getAllPlayers()
.find(v => v.id == id);
async function message(msg: string, player: Player) {
return new Promise((res, rej) => {
system.run(() => {
try {
res(player.runCommand(
`titleraw @s actionbar {"rawtext":[{"text":${JSON.stringify(msg)}}]}`
));
}
catch (e) {
rej(e);
}
});
});
}

/**
Expand Down