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:
- 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:
- -||-
- -||-
- -||-
- 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)
}
})