6
6
+* MCPEDL: https://mcpedl.com/debug-stick
7
7
+* GitHub: https://github.com/vytdev/debug-stick
8
8
+*
9
- +* Script last updated: 1.9.0 (r1.21.0)
9
+ +* Script last updated: September 19, 2024
10
10
+*
11
11
+* Copyright (c) 2023-2024 VYT <https://vytdev.github.io>
12
12
+* This project is licensed under the MIT License.
@@ -34,6 +34,9 @@ type BlockStateValue = boolean | number | string;
34
34
const DEBUG_STICK_ID = "vyt:debug_stick" ;
35
35
36
36
37
+ // Some event listeners. Listens for entityHitBkock
38
+ // and itemUseOn events, which triggers an action onto
39
+ // the debug stick
37
40
world . afterEvents . entityHitBlock . subscribe ( ( ev ) => {
38
41
if ( ev . damagingEntity . typeId != "minecraft:player" )
39
42
return ;
@@ -68,7 +71,7 @@ world.beforeEvents.itemUseOn.subscribe((ev) => {
68
71
\*============================================================================*/
69
72
70
73
/**
71
- * Change a selected property
74
+ * Change the selected property
72
75
* @param player
73
76
* @param block
74
77
*/
@@ -80,12 +83,16 @@ function changeSelectedProperty(player: Player, block: Block) {
80
83
if ( ! names . length && ! block . type . canBeWaterlogged )
81
84
return message ( `${ block . typeId } has no properties` , player ) ;
82
85
83
- let prop = getCurrentProperty ( player , block . type . id ) ;
86
+ let prop = getCurrentProperty ( player , block . typeId ) ;
84
87
let val : BlockStateValue ;
85
88
89
+ // Increment for the next property
86
90
prop = names [ names . indexOf ( prop ) + 1 ] ;
87
91
val = states [ prop ] ;
88
92
93
+ // We're probably at the end of the property names
94
+ // list, check if the 'waterlogged' property is
95
+ // available, or just go back at the start of the list
89
96
if ( ! prop ) {
90
97
if ( block . type . canBeWaterlogged ) {
91
98
prop = "waterlogged" ;
@@ -97,13 +104,14 @@ function changeSelectedProperty(player: Player, block: Block) {
97
104
}
98
105
}
99
106
100
- setCurrentProperty ( player , block . type . id , prop ) ;
107
+ // Update the player's selection
108
+ setCurrentProperty ( player , block . typeId , prop ) ;
101
109
102
110
message ( `selected "${ prop } " (${ val } )` , player ) ;
103
111
}
104
112
105
113
/**
106
- * Change a block property
114
+ * Change a block property value
107
115
* @param player
108
116
* @param block
109
117
*/
@@ -115,15 +123,18 @@ function updateBlockProperty(player: Player, block: Block) {
115
123
if ( ! names . length && ! block . type . canBeWaterlogged )
116
124
return message ( `${ block . typeId } has no properties` , player ) ;
117
125
118
- let prop = getCurrentProperty ( player , block . type . id ) ;
126
+ let prop = getCurrentProperty ( player , block . typeId ) ;
119
127
let val : BlockStateValue ;
120
128
129
+ // Ensure that the recorded block property selection
130
+ // is available on the block
121
131
if ( prop == "waterlogged" ? ! block . type . canBeWaterlogged : ! names . includes ( prop ) )
122
132
prop = names [ 0 ] ;
123
133
124
134
if ( ! prop && block . type . canBeWaterlogged )
125
- prop = "waterlogged" ;
135
+ prop = "waterlogged" ;
126
136
137
+ // Update the property value
127
138
if ( prop == "waterlogged" ) {
128
139
val = ! block . isWaterlogged ;
129
140
system . run ( ( ) => {
@@ -143,7 +154,8 @@ function updateBlockProperty(player: Player, block: Block) {
143
154
} ) ;
144
155
}
145
156
146
- setCurrentProperty ( player , block . type . id , prop ) ;
157
+ // Avoid some edge cases bugs
158
+ setCurrentProperty ( player , block . typeId , prop ) ;
147
159
148
160
message ( `"${ prop } " to ${ val } ` , player ) ;
149
161
}
@@ -156,22 +168,22 @@ function updateBlockProperty(player: Player, block: Block) {
156
168
function displayBlockInfo ( player : Player , block : Block ) {
157
169
let info = "§l§b" + block . typeId + "§r" ;
158
170
159
- // coordinates
171
+ // The block's coordinates
160
172
info += "\n§4" + block . x + " §a" + block . y + " §9" + block . z ;
161
173
162
- // matter state
174
+ // Block's matter state
163
175
info += "\n§7matter state§8: §e" ;
164
176
if ( block . isLiquid ) info += "liquid" ;
165
177
else if ( block . isAir ) info += "gas" ;
166
178
else info += "solid" ;
167
179
168
- // impassable
180
+ // Whether the block is impassable
169
181
info += "\n§7hard block§8: " + ( block . isSolid ? "§ayes" : "§cno" ) ;
170
182
171
- // redstone power
183
+ // The block's emitted/recieved redstone power
172
184
info += "\n§7redstone power§8: §c" + ( block . getRedstonePower ( ) ?? 0 ) ;
173
185
174
- // block states
186
+ // The block states
175
187
Object . entries ( block . permutation . getAllStates ( ) ) . forEach ( ( [ k , v ] ) => {
176
188
info += "\n§o§7" + k + "§r§8: " ;
177
189
if ( typeof v == "string" ) info += "§e" ;
@@ -180,11 +192,11 @@ function displayBlockInfo(player: Player, block: Block) {
180
192
info += v ;
181
193
} ) ;
182
194
183
- // waterlog property
195
+ // Waterlog property if available
184
196
if ( block . type . canBeWaterlogged )
185
197
info += "\n§o§7waterlogged§r§8: §6" + block . isWaterlogged ;
186
198
187
- // block tags
199
+ // Additional block tags
188
200
block . getTags ( ) . forEach ( v => info += "\n§d#" + v ) ;
189
201
190
202
message ( info , player ) ;
@@ -247,7 +259,7 @@ function getPlayerByID(id: string): Player | undefined {
247
259
/**
248
260
* Get the currently selected property for a block given the
249
261
* interacting player
250
- * @param stick The debug stick
262
+ * @param player The player
251
263
* @param block The block ID
252
264
* @returns The current selected property or undefined
253
265
*/
@@ -260,7 +272,7 @@ function getCurrentProperty(player: Player, block: string): string | undefined {
260
272
/**
261
273
* Change the currently selected property for a block given
262
274
* the interacting player
263
- * @param stick The debug stick
275
+ * @param player The player
264
276
* @param block The block ID
265
277
* @param val The new property name
266
278
*/
0 commit comments