#Force delete a block?

4 messages · Page 1 of 1 (latest)

sage pumice
#

Is there a way to force delete a block after the player has been mining it for a certain amount of ticks? I'm trying to make certain unbreakable blocks breakable from the securitycraft mod, but so far I haven't had any luck, they just refuse to break.

I found this script from another thread, but haven't had any luck modifying it to work for these blocks.

odd vectorBOT
#

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

sage pumice
#
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
    })
})```
grizzled olive
# sage pumice ```js const playerLastLeftClickedAt = {} const playerLastLeftClickedTime = {} co...

try

const playerLastLeftClickedAt = {}
const playerLastLeftClickedTime = {}
const miningInterval = 10

BlockEvents.leftClicked(event => {
    const {block, block:{pos}, player, player:{uuid, mainHandItem, creative}, server, level} = 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 checkMining = server.scheduleRepeatingInTicks(Math.ceil(miningInterval / 2), _ => {
        if(playerLastLeftClickedAt[hashCode] != posHashCode){
            checkMining.clear()
            delete checkMining
            return
        }
        if(server.tickCount - playerLastLeftClickedTime[hashCode] < miningInterval) return;
        level.destroyBlock(pos, false)
        player.damageHeldItem("main_hand", 1)
        playerLastLeftClickedTime[hashCode] = server.tickCount
    })
})