#Script Problem

1 messages · Page 1 of 1 (latest)

tough wigeon
#

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);
#

Sorry if it's a very silly mistake, I'm not very good with scripts

dry ibex
#

also dont use AI becouse it doesnt know minecraft script api

#

const { item, block, source } = event; item doesnt exist, its itemStack

const location = block.getLocation(); getLocation() isnt a thing

runCommandAsync is replaced with runCommand and also you should never use commadns when doing scripts

#

ask humans how to do theese things not AI

tough wigeon
#

Ok...

hallow wraith
#

Vibe coding with AI is only really good for a first draft, AI is pretty dumb. You have to double check everything when you're learning, or know what you're doing already and need something quick made that you can spot the errors in.

agile heart
#

isnt itemUseOn replaced with payerInteractWithBlock?