#Damage held item when right clicking on a block

4 messages · Page 1 of 1 (latest)

lone estuary
#

Hi! So I'm trying to make it so I can make rpg-like ore nodes, where you right click them with a pickaxe and they turn into stone and give you the item from them. But I want the action to also do damage to the item. I have no idea what I'm doing, I know only basic CSS normally.

Behaviour expected:

  1. Player right click eg. diamond ore block with pickaxe
    2.Ore turns into stone
    3.Player recieves diamond form the ore
    4.Player's pickaxe takes durability damage

Actual behaviour:

  1. -||-
  2. -||-
  3. -||-
  4. Tool doesn't take durability damage

I also want to use some delay to bring back the ore after some time, but that's a future me concern and I need to look for answers for that before I ask.

Here's what I have (I copied bits and pieces from other solutions here):

BlockEvents.rightClicked('minecraft:coal_ore', event => {
    const { item, level, player, target, block, damage } = event 
    const { x, y, z } = player
    if (item.id == 'minecraft:stone_pickaxe') {
        //item.count--
        player.tell("WORKS");
        const itemEntity = level.createEntity('item');
        itemEntity.item = Item.of('minecraft:coal', 1);
        itemEntity.setPos(x + 1, y, z);
        itemEntity.spawn();
        event.block.set('stone');
        event.item.getDamageValue('damage');
        event.item.setDamageValue('damage', -1)
    }
})
torpid ruinBOT
#

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

lone estuary
#

Damage held item when right clicking on a block