@@ -22,7 +22,6 @@ import {
2222 world ,
2323 system ,
2424 ItemCustomComponent ,
25- ItemComponentMineBlockEvent ,
2625 ItemComponentUseOnEvent ,
2726} from "@minecraft/server" ;
2827
@@ -45,19 +44,9 @@ const DEBUG_STICK_ID = "vyt:debug_stick";
4544class DebugStickEvents implements ItemCustomComponent {
4645
4746 constructor ( ) {
48- this . onMineBlock = safeCallWrapper ( this . onMineBlock ) . bind ( this ) ;
4947 this . onUseOn = safeCallWrapper ( this . onUseOn ) . bind ( this ) ;
5048 }
5149
52- onMineBlock ( ev : ItemComponentMineBlockEvent ) {
53- if ( ev . source . typeId != "minecraft:player" )
54- return ;
55- const player = getPlayerByID ( ev . source . id ) ;
56- if ( ! player )
57- return ;
58- changeSelectedProperty ( player , ev . block ) ;
59- }
60-
6150 onUseOn ( ev : ItemComponentUseOnEvent ) {
6251 if ( ev . source . typeId != "minecraft:player" )
6352 return ;
@@ -72,13 +61,6 @@ class DebugStickEvents implements ItemCustomComponent {
7261}
7362
7463
75- system . beforeEvents . startup . subscribe ( ( ev ) => {
76- ev . itemComponentRegistry . registerCustomComponent (
77- DEBUG_STICK_ID , new DebugStickEvents ( ) ) ;
78- } ) ;
79-
80-
81-
8264// Players should not be able to break blocks using
8365// the debug stick in survival
8466//
@@ -87,9 +69,16 @@ world.beforeEvents.playerBreakBlock.subscribe(safeCallWrapper((ev) => {
8769 if ( ev . itemStack ?. typeId != DEBUG_STICK_ID )
8870 return ;
8971 ev . cancel = true ;
72+ changeSelectedProperty ( ev . player , ev . block ) ;
9073} ) ) ;
9174
9275
76+ system . beforeEvents . startup . subscribe ( ( ev ) => {
77+ ev . itemComponentRegistry . registerCustomComponent (
78+ DEBUG_STICK_ID , new DebugStickEvents ( ) ) ;
79+ } ) ;
80+
81+
9382/*============================================================================*\
9483+* Action functions
9584\*============================================================================*/
0 commit comments