#my script is preventing my block from dropping

25 messages · Page 1 of 1 (latest)

past vault
#

im not sure what to do about this my code is

const randomBlocks = [
    'block_of_metal_scrap',
    // Add more block IDs as needed
];

BlockEvents.broken(event => {
    const { block, player, block: { id, x, y, z }, server } = event;
    if (id !== 'kubejs:block_of_metal_scrap') return;
    const randomBlock = randomBlocks[Math.floor(Math.random() * randomBlocks.length)];
    block.popItemFromFace(block.drops, 'up')
    server.scheduleInTicks(1, () => {
        server.runCommandSilent(`execute as ${player.username} run setblock ${x} ${y} ${z} ${randomBlock} replace`);
    });
    event.cancel()
});```
does anyone have an idea
indigo sphinxBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

olive ice
#

canceling the event means the block doesnt break

#

if it doesnt break, it doesnt drop loot, cuz "it was never broken"

past vault
#

ohh ok

olive ice
#

oh wait you have pop item hmmm

past vault
#

?

olive ice
#

block.popItemFromFace

past vault
#

yes i know

#

i know its the script cause if i remove it it drops

#

removing event.cancel()
makes it so the entire script stops working

olive ice
#

try this

const randomBlocks = [
    'block_of_metal_scrap',
    // Add more block IDs as needed
];

BlockEvents.broken('kubejs:block_of_metal_scrap', event => {
    const { block, player, block: { id, x, y, z }, server } = event;
    const randomBlock = randomBlocks[Math.floor(Math.random() * randomBlocks.length)];
    block.popItemFromFace(block.drops, 'up')
    //server.scheduleInTicks(1, () => {
    //    server.runCommandSilent(`execute as ${player.username} run setblock ${x} ${y} ${z} ${randomBlock} replace`);
    //});
    event.cancel()
});
past vault
#

i see that the js server.runCommandSilent(`execute as ${player.username} run setblock ${x} ${y} ${z} ${randomBlock} replace`); is slashed out that is how i was making the block regenerate witch is the point of my script

olive ice
#

the cancel should be the thing that stops it from breaking

past vault
#

when i remove it it doesnt regenerate

#

its seting the block before it can drop i think

olive ice
#

yeah none of this makes sense to me hmmm

#

someone else might know something i dont

past vault
#

okay

olive ice
#

the block shouldnt break if you have cancel

past vault
#

i want the block to regenerate and drop its loot table

#

i feel dumb rn lol dum

#

ya know waht im just gona /summon the fucking item

#

it drops in creative lol