package electrosphere.server.fluid.manager;


import org.joml.Vector3f;
import org.joml.Vector3i;


/**
 * Is a single chunk of terrain on the server
 */
public class ServerFluidChunk {


    int worldX, worldY, worldZ;
    float[][][] weights;
    float[][][] velocityX;
    float[][][] velocityY;
    float[][][] velocityZ;

    public ServerFluidChunk(
        int worldX,
        int worldY,
        int worldZ,
        float[][][] weights,
        float[][][] velocityX,
        float[][][] velocityY,
        float[][][] velocityZ
        ) {
        this.worldX = worldX;
        this.worldY = worldY;
        this.worldZ = worldZ;
        this.weights = weights;
        this.velocityX = velocityX;
        this.velocityY = velocityY;
        this.velocityZ = velocityZ;
    }

    public int getWorldX() {
        return worldX;
    }

    public int getWorldY() {
        return worldY;
    }

    public int getWorldZ() {
        return worldZ;
    }

    /**
     * Gets the world position of this terrain chunk as a joml Vector
     * @return The vector
     */
    public Vector3i getWorldPosition(){
        return new Vector3i(worldX,worldY,worldZ);
    }

    public float[][][] getWeights() {
        return weights;
    }

    /**
     * Gets the weight of a voxel at a poisiton
     * @param localPosition The local position
     * @return The weight of the specified voxel
     */
    public float getWeight(Vector3i localPosition){
        return getWeight(localPosition.x,localPosition.y,localPosition.z);
    }

    /**
     * Gets the weight of a voxel at a poisiton
     * @param x The x coordinate
     * @param y The y coordinate
     * @param z The z coordinate
     * @return The weight of the specified voxel
     */
    public float getWeight(int x, int y, int z){
        return weights[x][y][z];
    }

    //get velocity x
    public float[][][] getVelocityX() {
        return velocityX;
    }


    //set velocity x
    public void setVelocityX(float[][][] velocityX) {
        this.velocityX = velocityX;
    }

    //get velocity y
    public float[][][] getVelocityY() {
        return velocityY;
    }

    //set velocity y
    public void setVelocityY(float[][][] velocityY) {
        this.velocityY = velocityY;
    }


    //get velocity z
    public float[][][] getVelocityZ() {
        return velocityZ;
    }

    //set velocity z
    public void setVelocityZ(float[][][] velocityZ) {
        this.velocityZ = velocityZ;
    }

    //get a velocity at a given x, y and z as a Vector3f
    public Vector3f getVelocity(int x, int y, int z){
        return new Vector3f(velocityX[x][y][z],velocityY[x][y][z],velocityZ[x][y][z]);
    }

    //set a velocity at a given x, y, and z given three ints
    public void setVelocity(int x, int y, int z, float velX, float velY, float velZ){
        velocityX[x][y][z] = velX;
        velocityY[x][y][z] = velY;
        velocityZ[x][y][z] = velZ;
    }




}
