#Sneak Growth

2 messages · Page 1 of 1 (latest)

rigid path
#

A simple code that helps when creating modpacks so as not to fill your modpack with things that are possible to do with kubejs

PlayerEvents.tick(event => {
    const player = event.player
    const level = player.level

    // List of known saplings
    const saplings = [
        "minecraft:oak_sapling",
        "minecraft:birch_sapling",
        "minecraft:spruce_sapling",
        "minecraft:jungle_sapling",
        "minecraft:acacia_sapling",
        "minecraft:dark_oak_sapling",
        "minecraft:mangrove_propagule"
    ]

    // Checks if the player is sneaking
    if (player.isShiftKeyDown()) {
        console.log(`[DEBUG] Player ${player.name} is sneaking.`)

        let pos = player.blockPosition()

        // Defines a 4x4x4 range around the player
        for (let x = -2; x <= 2; x++) {
            for (let y = -2; y <= 2; y++) {
                for (let z = -2; z <= 2; z++) {
                    let blockPos = pos.offset(x, y, z)
                    let blockState = level.getBlockState(blockPos)
                    let block = blockState.block

                    console.log(`[DEBUG] Checking block at ${blockPos.x}, ${blockPos.y}, ${blockPos.z}: ${block.id}`)

                    if (blockState.isAir()) continue

                    // Checks if it is a known sapling
                    if (saplings.includes(block.id)) {
                        console.log(`[DEBUG] Block ${block.id} at ${blockPos.x}, ${blockPos.y}, ${blockPos.z} is a sapling.`)

                        // Attempts to apply the bonemeal effect to the sapling
                        let success = blockState.randomTick(level, blockPos, level.random)

                        if (success) {
                            console.log(`[DEBUG] Bonemeal successfully applied to sapling ${block.id} at ${blockPos.x}, ${blockPos.y}, ${blockPos.z}.`)
                            player.swing()
                            server.runCommandSilent(`playsound minecraft:item.bone_meal.use block @a ${blockPos.x} ${blockPos.y} ${blockPos.z}`)
                        } else {
                            console.log(`[DEBUG] Sapling ${block.id} at ${blockPos.x}, ${blockPos.y}, ${blockPos.z} cannot use Bonemeal.`)
                        }
                    }
                }
            }
        }
    }
})
waxen karmaBOT
#

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