#insert item from hand to custom block entity inventory

5 messages · Page 1 of 1 (latest)

stiff galleon
#
BlockEvents.rightClicked("kubejs:turret", event => {
    console.log("right clicked")
    let item = event.item
    let block = event.block
    console.log(item.id)
    if (item.id == "crusty_chunks:machine_gun_box") {
        // how do I insert the item into the block inventory?
    }
})

registry of the turret block

StartupEvents.registry('block', event => {
    event.create('turret', "cardinal")
    .texture('front', 'kubejs:block/turret_forward_face')

    .blockEntity(entityInfo => {
        entityInfo.inventory(1,1)
        entityInfo.serverTick(1, 0, entity => {
            let neighbourSignal = entity.level.hasNeighborSignal(entity.block.pos)
            if (neighbourSignal == true) {
                global.fire(entity)
            }
        })
    })
})
lusty martenBOT
#

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

sinful magnet
#

Probe shows event.block.inventory.insertItem as a method, have you tried that?

stiff galleon
#

reload_turret.js#7: Error in 'BlockEvents.rightClicked': TypeError: Cannot call method "insertItem" of null

sinful magnet
#

hmmm I'm not sure then, it seems odd that the block's inventory is null