package cz.jzitnik.game.handlers.rightclick;

import cz.jzitnik.game.annotations.RightClickLogic;
import cz.jzitnik.game.entities.Block;
import cz.jzitnik.game.Game;
import cz.jzitnik.tui.ScreenRenderer;

public class RightClickHandlerProvider {
    public static void handle(int x, int y, Game game, ScreenRenderer screenRenderer) {
        if (game.isMining()) {
            return;
        }

        game.getGameStates().clickX = x;
        game.getGameStates().clickY = y;

        var blocks = game.getWorld()[y][x];
        for (Block block : blocks) {
            if (block.getBlockId().equalsIgnoreCase("crafting_table")) {
                game.getGameStates().craftingTable.render(x, y);
                continue;
            }

            if (block.getData() != null && block.getData().getClass().isAnnotationPresent(RightClickLogic.class)
                    && block.getData() instanceof RightClickHandler handlerClass) {
                handlerClass.onBlockRightClick(x, y, game, screenRenderer);
            }
        }
    }
}
