Skip to content

Commit b6407bc

Browse files
committed
clarified some comments
1 parent 37fa1b7 commit b6407bc

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/index.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
+* MCPEDL: https://mcpedl.com/debug-stick
77
+* GitHub: https://github.com/vytdev/debug-stick
88
+*
9-
+* Script last updated: 1.9.0 (r1.21.0)
9+
+* Script last updated: September 19, 2024
1010
+*
1111
+* Copyright (c) 2023-2024 VYT <https://vytdev.github.io>
1212
+* This project is licensed under the MIT License.
@@ -34,6 +34,9 @@ type BlockStateValue = boolean | number | string;
3434
const DEBUG_STICK_ID = "vyt:debug_stick";
3535

3636

37+
// Some event listeners. Listens for entityHitBkock
38+
// and itemUseOn events, which triggers an action onto
39+
// the debug stick
3740
world.afterEvents.entityHitBlock.subscribe((ev) => {
3841
if (ev.damagingEntity.typeId != "minecraft:player")
3942
return;
@@ -68,7 +71,7 @@ world.beforeEvents.itemUseOn.subscribe((ev) => {
6871
\*============================================================================*/
6972

7073
/**
71-
* Change a selected property
74+
* Change the selected property
7275
* @param player
7376
* @param block
7477
*/
@@ -80,12 +83,16 @@ function changeSelectedProperty(player: Player, block: Block) {
8083
if (!names.length && !block.type.canBeWaterlogged)
8184
return message(`${block.typeId} has no properties`, player);
8285

83-
let prop = getCurrentProperty(player, block.type.id);
86+
let prop = getCurrentProperty(player, block.typeId);
8487
let val: BlockStateValue;
8588

89+
// Increment for the next property
8690
prop = names[names.indexOf(prop) + 1];
8791
val = states[prop];
8892

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
8996
if (!prop) {
9097
if (block.type.canBeWaterlogged) {
9198
prop = "waterlogged";
@@ -97,13 +104,14 @@ function changeSelectedProperty(player: Player, block: Block) {
97104
}
98105
}
99106

100-
setCurrentProperty(player, block.type.id, prop);
107+
// Update the player's selection
108+
setCurrentProperty(player, block.typeId, prop);
101109

102110
message(`selected "${prop}" (${val})`, player);
103111
}
104112

105113
/**
106-
* Change a block property
114+
* Change a block property value
107115
* @param player
108116
* @param block
109117
*/
@@ -115,15 +123,18 @@ function updateBlockProperty(player: Player, block: Block) {
115123
if (!names.length && !block.type.canBeWaterlogged)
116124
return message(`${block.typeId} has no properties`, player);
117125

118-
let prop = getCurrentProperty(player, block.type.id);
126+
let prop = getCurrentProperty(player, block.typeId);
119127
let val: BlockStateValue;
120128

129+
// Ensure that the recorded block property selection
130+
// is available on the block
121131
if (prop == "waterlogged" ? !block.type.canBeWaterlogged : !names.includes(prop))
122132
prop = names[0];
123133

124134
if (!prop && block.type.canBeWaterlogged)
125-
prop = "waterlogged";
135+
prop = "waterlogged";
126136

137+
// Update the property value
127138
if (prop == "waterlogged") {
128139
val = !block.isWaterlogged;
129140
system.run(() => {
@@ -143,7 +154,8 @@ function updateBlockProperty(player: Player, block: Block) {
143154
});
144155
}
145156

146-
setCurrentProperty(player, block.type.id, prop);
157+
// Avoid some edge cases bugs
158+
setCurrentProperty(player, block.typeId, prop);
147159

148160
message(`"${prop}" to ${val}`, player);
149161
}
@@ -156,22 +168,22 @@ function updateBlockProperty(player: Player, block: Block) {
156168
function displayBlockInfo(player: Player, block: Block) {
157169
let info = "§l§b" + block.typeId + "§r";
158170

159-
// coordinates
171+
// The block's coordinates
160172
info += "\n§4" + block.x + " §a" + block.y + " §9" + block.z;
161173

162-
// matter state
174+
// Block's matter state
163175
info += "\n§7matter state§8: §e";
164176
if (block.isLiquid) info += "liquid";
165177
else if (block.isAir) info += "gas";
166178
else info += "solid";
167179

168-
// impassable
180+
// Whether the block is impassable
169181
info += "\n§7hard block§8: " + (block.isSolid ? "§ayes" : "§cno");
170182

171-
// redstone power
183+
// The block's emitted/recieved redstone power
172184
info += "\n§7redstone power§8: §c" + (block.getRedstonePower() ?? 0);
173185

174-
// block states
186+
// The block states
175187
Object.entries(block.permutation.getAllStates()).forEach(([k, v]) => {
176188
info += "\n§o§7" + k + "§r§8: ";
177189
if (typeof v == "string") info += "§e";
@@ -180,11 +192,11 @@ function displayBlockInfo(player: Player, block: Block) {
180192
info += v;
181193
});
182194

183-
// waterlog property
195+
// Waterlog property if available
184196
if (block.type.canBeWaterlogged)
185197
info += "\n§o§7waterlogged§r§8: §6" + block.isWaterlogged;
186198

187-
// block tags
199+
// Additional block tags
188200
block.getTags().forEach(v => info += "\n§d#" + v);
189201

190202
message(info, player);
@@ -247,7 +259,7 @@ function getPlayerByID(id: string): Player | undefined {
247259
/**
248260
* Get the currently selected property for a block given the
249261
* interacting player
250-
* @param stick The debug stick
262+
* @param player The player
251263
* @param block The block ID
252264
* @returns The current selected property or undefined
253265
*/
@@ -260,7 +272,7 @@ function getCurrentProperty(player: Player, block: string): string | undefined {
260272
/**
261273
* Change the currently selected property for a block given
262274
* the interacting player
263-
* @param stick The debug stick
275+
* @param player The player
264276
* @param block The block ID
265277
* @param val The new property name
266278
*/

0 commit comments

Comments
 (0)