/*
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
 *
 * Copyright (c) 2015 - 2026 CCBlueX
 *
 * LiquidBounce is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * LiquidBounce is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
 */
package net.ccbluex.liquidbounce.features.module.modules.exploit.phase.modes

import net.ccbluex.liquidbounce.config.types.group.Mode
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
import net.ccbluex.liquidbounce.event.events.BlockShapeEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.tickHandler
import net.ccbluex.liquidbounce.features.module.modules.exploit.phase.ModulePhase
import net.ccbluex.liquidbounce.utils.entity.withStrafe
import net.minecraft.world.level.block.LiquidBlock
import net.minecraft.world.phys.shapes.Shapes

/**
 * @anticheat UNCP + Verus + "Watchdog"
 * @anticheatVersion 14.07.2025
 * @testedOn blocksmc.com
 * @author liquidsquid1
 */
object PhaseBlocksMC : Mode("BlocksMC") {

    override val parent: ModeValueGroup<*>
        get() = ModulePhase.mode

    private var spiderTicks = 1

    override fun enable() {
        spiderTicks = 1
        player.deltaMovement.y = 0.0
        super.enable()
    }

    @Suppress("unused")
    private val tickHandler = tickHandler {
        when (spiderTicks) {
            1 -> {
                if (mc.options.keyJump.isDown && !world.getBlockState(player.blockPosition()).isAir) {
                    player.deltaMovement.y = 0.42
                    spiderTicks++
                }
                player.setOnGround(true)
            }
            2 -> {
                player.deltaMovement.y = 0.33
                spiderTicks++
            }
            3 -> {
                player.deltaMovement.y = 0.25
                spiderTicks++
            }
        }

        if (spiderTicks > 3 || spiderTicks == 0) {
            spiderTicks = 1
        }
        player.noPhysics = true
        if (player.isShiftKeyDown) {
            player.deltaMovement = player.deltaMovement.withStrafe(speed = 0.179)
        }
    }

    @Suppress("unused")
    private val shapeHandler = handler<BlockShapeEvent> { event ->
        if (event.state.block is LiquidBlock) {
            return@handler
        }

        if (event.pos.y >= player.y) {
            event.shape = Shapes.empty()
        }
    }

}
