#how to get a block to interact with its gui

2 messages · Page 1 of 1 (latest)

rotund beacon
#

I'm not good at coding. I need an item from slots 1 and 2 to be removed from the anvil when I right click on the anvil. I don't understand how I can access the anvil for this and what method to use.
my code

BlockEvents.rightClicked('minecraft:anvil', event => {
    const { player, item, block, level } = event;
    
    // Проверяем что в руке булава
    if (item != 'minecraft:mace'){
        return;
    }

    const target = level.getBlockEntity(block);
    if (!target)
        return;
    

    const leftItem = target.getItem(0);
    const rightItem = target.getItem(1);
    

    if (leftItem.id == 'minecraft:netherite_ingot' &&
        rightItem.id == 'minecraft:netherite_ingot'){

        leftItem.count--
        rightItem.count--

        player.give(Item.of('minecraft:sandstone', 1));
    }


    event.cancel();

})
twilit whaleBOT
#

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