#Run JS function on specific item use (right click)

1 messages · Page 1 of 1 (latest)

fickle smelt
#

You can use the ItemUse event to listen for item interactions
also for running functions using commands, you can probably use the ScriptEventReceive event and the /scriptevent command

#
world.afterEvents.itemUse.subscribe((data) => {
    if (data.itemStack.typeId == "minecraft:stick") {
        data.source.sendMessage("Hello World!");
    };
});
#

and for the command thing

  • Command: /scriptevent test:say hello
system.afterEvents.scriptEventReceive.subscribe((data) => {
    if (data.id == "test:say") {
        world.sendMessage(data.message);
    };
});
mystic swift
fickle smelt
mystic swift
mystic swift
fickle smelt
mystic swift
#

So, I have to call structure command instead.

mystic swift
fickle smelt
mystic swift
#

Stable.

        {
              "module_name": "@minecraft/server",
              "version": "1.7.0"
        }
fickle smelt
#

Ah, that's why, the PlayerInteractWithBlock is only in beta currently but we might be able to use the ItemUseOn event

mystic swift
fickle smelt
mystic swift
#

Anyway, hmmm, so, it will work in 1.8.0-beta, right?
Okay, on my way to try it.

#

Okay, that's cool, it replaces the actual block.
Would it be possible to get location of the block player clicked at?

fickle smelt
#

data.block.location

mystic swift
fickle smelt
fickle smelt
#
player.runCommand(`/structure load nogard:start ${data.block.location.x} ${data.block.location.y} ${data.block.location.z} 0_degrees`);