package electrosphere.controls;

import org.joml.Vector3d;

import electrosphere.client.block.BlockChunkData;

/**
 * Utilities for dealing with cursors
 */
public class PlayerCursor {

    /**
     * Token for displaying cursor
     */
    public static final String CURSOR_TOKEN = "CURSOR";

    /**
     * Token for displaying block cursor
     */
    public static final String CURSOR_BLOCK_TOKEN = "CURSOR_BLOCK";
    
    /**
     * Clamps a real position to the nearest block
     * @param input The input real position
     * @return The real position clamped to the nearest block
     */
    public static Vector3d clampPositionToNearestBlock(Vector3d input){
        double x = 0;
        double y = 0;
        double z = 0;
        if(input.x % BlockChunkData.BLOCK_SIZE_MULTIPLIER >  BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0){
            x = input.x - input.x % 0.25 + BlockChunkData.BLOCK_SIZE_MULTIPLIER + BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0;
        } else {
            x = input.x - input.x % 0.25 + BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0;
        }
        if(input.y % BlockChunkData.BLOCK_SIZE_MULTIPLIER >  BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0){
            y = input.y - input.y % 0.25 + BlockChunkData.BLOCK_SIZE_MULTIPLIER + BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0;
        } else {
            y = input.y - input.y % 0.25 + BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0;
        }
        if(input.z % BlockChunkData.BLOCK_SIZE_MULTIPLIER >  BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0){
            z = input.z - input.z % 0.25 + BlockChunkData.BLOCK_SIZE_MULTIPLIER + BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0;
        } else {
            z = input.z - input.z % 0.25 + BlockChunkData.BLOCK_SIZE_MULTIPLIER / 2.0;
        }
        return new Vector3d(x,y,z);
    }

}
