const playerLastLeftClickedAt = {}
const playerLastLeftClickedTime = {}
const baseMiningInterval = 10
const bedrockItemPool = []
BlockEvents.leftClicked(event => {
const {block, block:{pos}, facing, player, player:{uuid, mainHandItem, age, inWater, headArmorItem, creative}, server} = event
if(creative) return;
const hashCode = uuid.hashCode()
const posHashCode = pos.hashCode()
if(playerLastLeftClickedAt[hashCode] == posHashCode) {
delete playerLastLeftClickedAt[hashCode]
}
else playerLastLeftClickedAt[hashCode] = posHashCode
if(isNaN(playerLastLeftClickedAt[hashCode])) return;
if(block.id != "securitycraft:reinforced_cobblestone") return;
if(!mainHandItem.hasTag("minecraft:pickaxes")) return;
const miningSpeed = getMiningSpeed(player)
const miningInterval = Math.max(Math.round(baseMiningInterval / miningSpeed), 1)
const randomSource = Utils.newRandom(hashCode + posHashCode + age ** 2)
const checkMining = server.scheduleRepeatingInTicks(Math.ceil(miningInterval / 2), _ => {
if(playerLastLeftClickedAt[hashCode] != posHashCode){
checkMining.clear()
delete checkMining
return
}
if(server.tickCount - playerLastLeftClickedTime[hashCode] < miningInterval) return;
const randomIndex = randomSource.nextInt(bedrockItemPool.length)
const popItem = bedrockItemPool[randomIndex].copy()
block.popItemFromFace(popItem, facing)
player.damageHeldItem("main_hand", 1)
if(headArmorItem.hasEnchantment("minecraft:aqua_affinity", 1) && inWater) player.damageEquipment("head", 1)
playerLastLeftClickedTime[hashCode] = server.tickCount
})
})```