#Is there a way to detect a charged crossbow being used?

1 messages · Page 1 of 1 (latest)

gritty flint
#

I have tried doing the following:

import { world } from "@minecraft/server";

world.afterEvents.itemStartUse.subscribe((e) => {
  let { itemStack, source } = e;

  if (itemStack.typeId != 'minecraft:crossbow') return;

  source.setDynamicProperty('adv:charging', true);
  source.sendMessage('charging');
})

world.afterEvents.itemStopUse.subscribe((e) => {
  let { itemStack, source } = e;

  if (itemStack.typeId != 'minecraft:crossbow') return;

  source.setDynamicProperty('adv:charging', false);
  source.sendMessage('charged');
})

world.afterEvents.itemUse.subscribe((e) => {
  let { itemStack, source } = e;

  if (itemStack.typeId != 'minecraft:crossbow') return;
  if (source.getDynamicProperty('adv:charging')) return;

  source.sendMessage(`used charged item!`);
})

..However, it seems like itemUse is being triggered before the itemStartUse event and is not enough time for the property adv:charging to be checked. Is there a way to delay the itemUse event to check if the player is charging for a crossbow, and if not, then run the code.

maiden raft
#

It might be setting/getting dynamic properties takes a bit more time than the time event fires between itemstartuseon and remission event.

gritty flint
#

that too. i tried directly checking if there's any item flag if the crossbow is charged or not. doesnt seem to be the case tho.

maiden raft
#

make a variable in js that stores this data ig

gritty flint
#

i tried debugging the response, itemUse afterEvent comes before anything else. so i dont think i can do much anything about that