#on right click item uses twice, how to fix? also, i need to add requirement of click amount
32 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Paste version of server.log, world_interacting.js from @raw magnet
it was caused due it try to right click with all hands
to remove offhand you can do something like that
if (event.hand == "OFF_HAND") return;
they're both the same

also you probably want to change it to e.hand in this case since the var is e and not event
do you want it to have a random chance to fail or require a certain amount of right clicks for it to happen?
certain amount pls
try this js BlockEvents.rightClicked(e => { const { block, hand, player, facing } = e if (hand != "MAIN_HAND") return let item = player.mainHandItem if (item.count > 0 && item.id == 'minecraft:bone' && block.hasTag('forge:stone')) { if (!player.persistentData.KnapTime) player.persistentData.KnapTime = 0 if (player.persistentData.KnapTime >= 3) { block.popItemFromFace('kubejs:bone_shard', Math.random() * 2), facing player.swing() item.count-- player.persistentData.KnapTime = 0 } player.persistentData.KnapTime++ } })
hmmm, how strange. now bone shard drops always in one amount
It's like random doesn't work

try this js let random = (Math.random() * 2).toFixed(0) + 1 block.popItemFromFace(`${random}x kubejs:bone_shard`, facing)
and if that doesnt work then try this one js let random = (Math.random() * 2).toFixed(0) + 1 block.popItemFromFace(Item.of("kubejs:bone_shard", random), facing)
beforehand this isnt the right format for popitemfromface anyways js e.block.popItemFromFace('kubejs:bone_shard', Math.random() * 2), e.facing
try this one, i forgot to add the random definition line
.toFixed(0) should fix that, also adding a 1 so its never 0
its the name of the persistent data we're labeling on the player, it can be anything, i named it KnapTime to keep it consistent with the overal premise of the script so nobody gets confused
think of it as a custom nbt tag
after much agony, I finished the script
BlockEvents.rightClicked(e => {
if(e.player.mainHandItem.id == 'minecraft:bone') {
if (e.hand != 'MAIN_HAND') {
if (e.block.hasTag('forge:stone')) {
e.player.swing("main_hand", true)
if (!e.player.persistentData.bKnapTime) {
e.player.persistentData.bKnapTime = Math.floor(Math.random() * (7 - 3) + 3)
}
e.player.persistentData.bKnapTime--
if (e.player.persistentData.bKnapTime == 0) {
e.player.mainHandItem.count--
e.block.popItemFromFace(Item.of('kubejs:bone_shard', Math.floor(Math.random() * (3 - 1) + 1)), e.facing)
}
}
}
}
})