#Offhand item count going into negatives

30 messages · Page 1 of 1 (latest)

lusty herald
#

I'm using offHandItem.count-- to consume the offhand "repairing" ingredient every time i left click on a certain block and it works fine until you consume the last ingredient in the offhand which for some reason the game continues to "consume" the item into the negatives even though you ran out of the ingredient

BlockEvents.leftClicked('kubejs:reforging_station', event => {
    let offHandItem = event.player.getHeldItem('off_hand');
    let item = event.player.getHeldItem('main_hand');
    let pData = event.player.persistentData;
    if (pData.timestall != 1) {
        return;
    }
    pData.timestall = 0;
    event.server.schedule(1200, () => {
        pData.timestall = 1;
    });
    if (!air && (item.hasTag('kubejs:trinkets_gold') && event.player.offHandItem == 'minecraft:gold_ingot')) {
      event.server.runCommandSilent(`execute as ${event.player.username} run playsound minecraft:block.anvil.use block @s ${event.player.x} ${event.player.y} ${event.player.z} 0.5 0.5`);
    offHandItem.count--
    event.player.tell(offHandItem)
    }
})```
ornate sableBOT
#

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

grave wing
lusty herald
#

it only fixes itself once you update the offhand slot by putting something in there

golden falcon
#
e.player.sendInventoryUpdate()
lusty herald
#

oooo ok lemme try it

#

didnt work js BlockEvents.leftClicked('kubejs:reforging_station', event => { let offHandItem = event.player.getHeldItem('off_hand'); let item = event.player.getHeldItem('main_hand'); let pData = event.player.persistentData; let air = event.player.getMainHandItem().id == 'minecraft:air' if (pData.timestall != 1) { return; } event.player.sendInventoryUpdate() pData.timestall = 0; event.server.schedule(1200, () => { pData.timestall = 1; }); if (!air && (item.hasTag('kubejs:trinkets_gold') && event.player.offHandItem == 'minecraft:gold_ingot')) { event.server.runCommandSilent(`execute as ${event.player.username} run playsound minecraft:block.anvil.use block @s ${event.player.x} ${event.player.y} ${event.player.z} 0.5 0.5`); offHandItem.count-- event.player.tell(offHandItem) } })

#

did i put it in the right place?

grave wing
#

you should put it after the offHandItem.count-- afaik

lusty herald
#

aight

#

didnt work

#

hmm

grave wing
lusty herald
#

is it possible to define if you have more than 0 itemstack in your offhand as an if condition?

golden falcon
#

did u get an error?

lusty herald
#

no errors

grave wing
#

also why @ornate sable offline

lusty herald
#

aight leme try

lusty herald
#

thanks a lot lol

grave wing
lusty herald
#

oh guess i cant even close the ticket cause kubejs supports offline

grave wing
#

I can "close" the ticket

#

so that no one can send messages

#

if you want to

lusty herald
#

its all g

#

ill just wait til lat gets his box up and running XD