#damage item depending on block hardness
13 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
figured out how to damage the tool but block hardness or destroyspeed is still a mystery to me
bump
LOL
ForgeEvents.onEvent('net.minecraftforge.event.level.BlockEvent$BreakEvent', event => {
let player = event.getPlayer()
if ('minecraft:stone_pickaxe' == player.getMainHandItem()) {
let mainHandItemStack = player.getMainHandItem();
let newDamageValue = mainHandItemStack.getDamageValue() + 100;
mainHandItemStack.setDamageValue(newDamageValue);
}
})
Heres the solution using native script (change the damage value to whatever u want)
PUT IN STARTUP SCRIPT FOR THIS TO WORK
this is done using block break event in Forge
declaration: package: net.minecraftforge.event.level, class: BlockEvent, class: BreakEvent
no idea how kubejs events work cuz i cant find the damage value in the kubejs block break one
Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue!
This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.
Do you have any other questions regarding your issue? Feel free to ask!
Note: You should create a new post for unrelated issues.
this sadly isnt depending on block hardness. You can get the hardness with block.blockState.getDestroySpeed(level, pos)
Here's my solution:
BlockEvents.broken(e => {
const { server, player, block, level, block:{blockState, pos} } = e
if (global.carverItems.includes(player.getMainHandItem().id)) {
let hardness = blockState.getDestroySpeed(level, pos)
let durabilityDamage = hardness
let enchants = e.player.mainHandItem.enchantments
if(enchants) {
if ("minecraft:unbreaking" in enchants) {
let enchLevel = enchants["minecraft:unbreaking"]
let rolls = countSuccesses(hardness, enchLevel + 1)
durabilityDamage = rolls
}
}
player.mainHandItem.damageValue += Math.max(0, Math.ceil(durabilityDamage) - 1)
if (durabilityDamage >= 10) { // big durability damage warning
player.playNotifySound("minecraft:entity.item.break", "players", 1, 2)
}
}
console.log(block.id)
if (block.id == 'minecraft:obsidian' && global.carverItems.includes(player.getMainHandItem().id)) {
e.server.scheduleInTicks(0, () => e.block.set('kubejs:shattered_obsidian'))
}
})
function countSuccesses(count, sides) { // count = amount of throws, sides = sides of the dice
let successes = 0
for (let i = 0; i < count; i++) {
let roll = Math.floor(Math.random() * sides) + 1
if (roll == 1) successes++
}
return successes
}
(my custom pickaxes are called carvers)
i built in support for unbreaking
canceling a block breaking event (needed to set a new block) will result in the pickaxe not breaking, so i had to find a workaround for that
e.g.
block.set('kubejs:shattered_obsidian')
e.cancel()
results in the pickaxe not breaking, the workaround for this case is:
e.server.scheduleInTicks(0, () => e.block.set('kubejs:shattered_obsidian'))
Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue!
This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.
Do you have any other questions regarding your issue? Feel free to ask!
Note: You should create a new post for unrelated issues.