/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program 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 Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.bausystem.features.worldedit.mask.grid;

import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.math.BlockVector3;

public class GridMask implements Mask {

    private int x;
    private int y;
    private int z;
    private boolean and;

    public GridMask(int x, int y, int z, boolean and) {
        this.x = x;
        this.y = y;
        this.z = z;
        this.and = and;
    }

    @Override
    public boolean test(BlockVector3 vector) {
        if (and) {
            return vector.getBlockX() % x == 0 && vector.getBlockY() % y == 0 && vector.getBlockZ() % z == 0;
        } else {
            return vector.getBlockX() % x == 0 || vector.getBlockY() % y == 0 || vector.getBlockZ() % z == 0;
        }
    }

    @Override
    public Mask copy() {
        return new GridMask(x, y, z, and);
    }
}
