#Loot Table For Block Right-Click Event

2 messages · Page 1 of 1 (latest)

wraith jay
#

I've got this script that allows me to right click on gravel/coarse dirt to harvest a random stone. I want to modify this so that I can assign probabilities to each stone rather than just random chance.

    const { player, block, server, hand, player: { mainHandItem, x, y, z } } = event

    const harvestable_rocks = [
        "havenpebbles:andesite_pebble",
        "havenpebbles:basalt_pebble",
        "havenpebbles:blackstone_pebble",
        "havenpebbles:calcite_pebble",
        "havenpebbles:deepslate_pebble",
        "havenpebbles:diorite_pebble",
        "havenpebbles:dripstone_pebble",
        "havenpebbles:granite_pebble",
        "havenpebbles:stone_pebble",
        "havenpebbles:netherrack_pebble",
        "havenpebbles:tuff_pebble"
    ];

    //Player must be using main hand
    if (hand == 'OFF_HAND') { return }

    //Only can harvest from dirt-like blocks with an empty hand
    if (mainHandItem == 'item.empty' && (block == 'minecraft:gravel' || block =='minecraft:coarse_dirt')) { 

        player.playSound('block.composter.ready')
        player.swingArm('main_hand')
        //Utils.server.tell()
    
        if (Math.random() >= 0.6) {
            block.popItemFromFace(Math.floor(Math.random() * 2) + 1 + 'x ' + harvestable_rocks[Math.floor((Math.random()*harvestable_rocks.length))], "up")
        }
    }

})```
glossy gateBOT
#

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