var $IntegerProperty = Java.loadClass("net.minecraft.world.level.block.state.properties.IntegerProperty")

StartupEvents.registry('block', (e) => {
    e.create('arrzenhanced:gamma_block')
    .displayName('Gamma Block')
    .mapColor('color_green')
    .soundType('amethyst')
    .hardness(5)
    .resistance(12.0)
    .requiresTool(true)
    .tagBlock('minecraft:mineable/pickaxe')
    .tagBlock('minecraft:needs_iron_tool')
    .textureAll('arrzenhanced:block/gamma_block')
    .blockEntity((c) => {
        c.serverTick(80, 0, (blockEntity) => {
            // runs every 80 ticks
            if (global.gammaBlockTick) {
                global.gammaBlockTick(blockEntity)
            }
        })
    })
})

global.gammaBlockTick = (blockEntity) => {
    let level = blockEntity.level
    let {x, y, z} = blockEntity
    level.getEntitiesWithin(AABB.of(
        x + 3,
        y + 3,
        z + 3,
        x - 3,
        y - 3,
        z - 3
    )).forEach(target => {
        if (!target?.potionEffects) return
        let gammaFx = target.potionEffects.getActive("arrzenhanced:gamma_radiation"),
        amp = 0
        if (gammaFx) {
            // target.tell(target.potionEffects.getActive("arrzenhanced:gamma_radiation").getAmplifier())
            amp = Number(target.potionEffects.getActive("arrzenhanced:gamma_radiation").getAmplifier())
            if (amp < 9) amp += 1
        }
        target.potionEffects.add("arrzenhanced:gamma_radiation", 30 * 20, amp, false, false)
    });
}