Comment, add interfaces to chunk classes

This commit is contained in:
austin 2023-06-13 18:59:56 -04:00
parent a8941c5de7
commit c69caeeab9
2 changed files with 57 additions and 14 deletions

View File

@ -1,5 +1,7 @@
package electrosphere.client.terrain.cache;
import org.joml.Vector3i;
import electrosphere.server.terrain.manager.ServerTerrainChunk;
/**
@ -50,10 +52,36 @@ public class ChunkData {
this.voxelWeight = voxelWeight;
}
/**
* Updates the value of a single voxel in the chunk
* @param localX The local position X
* @param localY The local position Y
* @param localZ The local position Z
* @param weight The weight to set it to
* @param type The type to set the voxel to
*/
public void updatePosition(int localX, int localY, int localZ, float weight, int type){
voxelWeight[localX][localY][localZ] = weight;
voxelType[localX][localY][localZ] = type;
}
/**
* 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 voxelWeight[localPosition.x][localPosition.y][localPosition.z];
}
/**
* Gets the type of a voxel at a position
* @param localPosition The local position
* @return The type of the specified voxel
*/
public int getType(Vector3i localPosition){
return voxelType[localPosition.x][localPosition.y][localPosition.z];
}
}

View File

@ -3,10 +3,12 @@ package electrosphere.server.terrain.manager;
import java.util.LinkedList;
import java.util.List;
import org.joml.Vector3i;
import electrosphere.server.terrain.models.TerrainModification;
/**
* Is a single subchunk of terrain on the server
* Is a single chunk of terrain on the server
*/
public class ServerTerrainChunk {
@ -56,20 +58,7 @@ public class ServerTerrainChunk {
}
}
}
// for(int weightX = 0; weightX < SUB_CHUNK_DIMENSION; weightX++){
// for(int weightZ = 0; weightZ < SUB_CHUNK_DIMENSION; weightZ++){
// weights[weightX][SUB_CHUNK_DIMENSION-1][weightZ] = 1;
// values[weightX][SUB_CHUNK_DIMENSION-1][weightZ] = 1;
// }
// }
// for(int weightX = 0; weightX < SUB_CHUNK_DIMENSION; weightX++){
// for(int weightZ = 0; weightZ < SUB_CHUNK_DIMENSION; weightZ++){
// weights[SUB_CHUNK_DIMENSION-1][weightX][weightZ] = 1;
// values[SUB_CHUNK_DIMENSION-1][weightX][weightZ] = 1;
// }
// }
ServerTerrainChunk rVal = new ServerTerrainChunk(worldX, worldY, worldZ, weights, values);
// rVal.addModification(new TerrainModification(x, y, 3, 3, 5));
return rVal;
}
@ -85,6 +74,14 @@ public class ServerTerrainChunk {
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 List<TerrainModification> getModifications() {
return modifications;
}
@ -102,6 +99,24 @@ public class ServerTerrainChunk {
values[modification.getVoxelPos().x][modification.getVoxelPos().y][modification.getVoxelPos().z] = modification.getValue();
weights[modification.getVoxelPos().x][modification.getVoxelPos().y][modification.getVoxelPos().z] = modification.getWeight();
}
/**
* 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 weights[localPosition.x][localPosition.y][localPosition.z];
}
/**
* Gets the type of a voxel at a position
* @param localPosition The local position
* @return The type of the specified voxel
*/
public int getType(Vector3i localPosition){
return values[localPosition.x][localPosition.y][localPosition.z];
}
}