Hello, could someone explain to me why my script isn't working? Every time I click on the block, nothing happens and no error appears. Here is the script:
import { world, system } from "@minecraft/server";
const CONVERSION_TIME = 1200;
const disinfectantBlockId = "erro:decontaminator";
const inputItemId = "sci:contaminated_syringe";
const outputItemId = "sci:empty_syringe";
let pendingConversions = [];
world.beforeEvents.itemUseOn.subscribe((event) => {
const { item, block, source } = event;
if (!item || !block || !source || block.typeId !== disinfectantBlockId) return;
if (item.typeId !== inputItemId) return;
try {
const location = block.getLocation();
source.runCommandAsync(`clear @s ${inputItemId} 0 1`);
pendingConversions.push({
position: location,
timeRemaining: CONVERSION_TIME
});
source.runCommandAsync(`playsound random.click @s ~ ~ ~ 1 1`);
} catch (e) {
console.warn("Erro:", e);
}
});
system.runInterval(() => {
for (let i = pendingConversions.length - 1; i >= 0; i--) {
const task = pendingConversions[i];
task.timeRemaining -= 1;
if (task.timeRemaining <= 0) {
try {
const { x, y, z } = task.position;
world.getDimension("overworld").runCommandAsync(
`summon item ${x + 0.5} ${y + 1} ${z + 0.5} item=${outputItemId}`
);
} catch (e) {
console.warn("Erro:", e);
}
pendingConversions.splice(i, 1);
}
}
}, 1);