66+* MCPEDL: https://mcpedl.com/debug-stick
77+* GitHub: https://github.com/vytdev/debug-stick
88+*
9- +* Script last updated: July 22 , 2025
9+ +* Script last updated: July 27 , 2025
1010+*
1111+* Copyright (c) 2023-2025 VYT <https://vytdev.github.io>
1212+* This project is licensed under the MIT License.
@@ -20,9 +20,7 @@ import {
2020 BlockStates ,
2121 LiquidType ,
2222 world ,
23- system ,
24- ItemCustomComponent ,
25- ItemComponentUseOnEvent ,
23+ system
2624} from "@minecraft/server" ;
2725
2826import {
@@ -40,31 +38,16 @@ type BlockStateValue = boolean | number | string;
4038const DEBUG_STICK_ID = "vyt:debug_stick" ;
4139
4240
41+ world . beforeEvents . playerInteractWithBlock . subscribe ( safeCallWrapper ( ( ev ) => {
42+ if ( ev . itemStack ?. typeId != DEBUG_STICK_ID )
43+ return ;
44+ ev . cancel = true ;
45+ if ( ev . player . isSneaking )
46+ displayBlockInfo ( ev . player , ev . block ) ;
47+ else
48+ updateBlockProperty ( ev . player , ev . block ) ;
49+ } ) ) ;
4350
44- class DebugStickEvents implements ItemCustomComponent {
45-
46- constructor ( ) {
47- this . onUseOn = safeCallWrapper ( this . onUseOn ) . bind ( this ) ;
48- }
49-
50- onUseOn ( ev : ItemComponentUseOnEvent ) {
51- if ( ev . source . typeId != "minecraft:player" )
52- return ;
53- const player = getPlayerByID ( ev . source . id ) ;
54- if ( ! player )
55- return ;
56- if ( player . isSneaking )
57- displayBlockInfo ( player , ev . block ) ;
58- else
59- updateBlockProperty ( player , ev . block ) ;
60- }
61- }
62-
63-
64- // Players should not be able to break blocks using
65- // the debug stick in survival
66- //
67- // TODO: explore other alternatives
6851world . beforeEvents . playerBreakBlock . subscribe ( safeCallWrapper ( ( ev ) => {
6952 if ( ev . itemStack ?. typeId != DEBUG_STICK_ID )
7053 return ;
@@ -73,12 +56,6 @@ world.beforeEvents.playerBreakBlock.subscribe(safeCallWrapper((ev) => {
7356} ) ) ;
7457
7558
76- system . beforeEvents . startup . subscribe ( ( ev ) => {
77- ev . itemComponentRegistry . registerCustomComponent (
78- DEBUG_STICK_ID , new DebugStickEvents ( ) ) ;
79- } ) ;
80-
81-
8259/*============================================================================*\
8360+* Action functions
8461\*============================================================================*/
@@ -188,17 +165,6 @@ async function message(msg: string, player: Player) {
188165 } ) ;
189166}
190167
191- /**
192- * Utility function to return a player class from an entity ID
193- * @param id The entity ID
194- * @returns Player instance or undefined
195- */
196- function getPlayerByID ( id : string ) : Player | undefined {
197- return world
198- . getAllPlayers ( )
199- . find ( v => v . id == id ) ;
200- }
201-
202168/**
203169 * Returns all the block states of a block.
204170 * @param block The block.
0 commit comments