package cz.jzitnik.game.handlers.events.handlers.place;

import cz.jzitnik.game.Game;
import cz.jzitnik.game.annotations.PlaceEventHandler;
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
import cz.jzitnik.game.handlers.tooluse.handlers.HoeUse;
import cz.jzitnik.tui.ScreenRenderer;

public class FarmlandPlaceHandler {
    @PlaceEventHandler
    public void handle(ScreenRenderer screenRenderer, Game game, int x, int y) {
        var world = game.getWorld();

        if (world[y][x].stream().noneMatch(HoeUse::isBlock)) {
            return;
        }

        if (world[y + 1][x].stream().anyMatch(block -> block.getBlockId().equals("farmland"))) {
            world[y + 1][x].add(ItemBlockSupplier.getBlock("dirt"));
            world[y + 1][x].removeIf(block -> block.getBlockId().equals("farmland"));
        }
    }
}
