Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///LIGHTING METHODS\\\
- private Vector3i[] getNeighbours(int x, int y, int z, boolean includeLightSourceAndChunkEdges){
- long startTime = System.nanoTime();
- Vector3i[] neighbours = new Vector3i[6];
- neighbours[0] = new Vector3i(x, y, z - 1);//north
- neighbours[1] = new Vector3i(x, y, z + 1);//south
- neighbours[2] = new Vector3i(x + 1, y, z);//east
- neighbours[3] = new Vector3i(x - 1, y, z);//west
- neighbours[4] = new Vector3i(x, y + 1, z);//up
- neighbours[5] = new Vector3i(x, y - 1, z);//down
- List<Vector3i> removePos = new ArrayList<>();
- for (int i = 0; i < 6; i++) {
- Vector3i p = neighbours[i];
- if(!includeLightSourceAndChunkEdges){
- if(p.x < 0 || p.y < 0 || p.z < 0) {
- removePos.add(p);
- continue;
- }
- if(p.x >= chunkSizeXZ || p.y >= chunkSizeY || p.z >= chunkSizeXZ) {
- removePos.add(p);
- continue;
- }
- Block block = GetBlock(p.x, p.y, p.z);
- if(block.blockType() == new BlockLight().blockType() || block.blockType() != new BlockAir().blockType()){
- removePos.add(p);
- continue;
- }
- }
- if(!hasNonAirNeighbour(p.x, p.y, p.z)){
- if(!hasNonAirNeighbourDiagonal(p.x, p.y, p.z)){
- removePos.add(p);
- continue;
- }
- }
- //Logger.info("Didnt remove: " + p.x + ", " + p.z);
- }
- Vector3i[] temp = new Vector3i[6 - removePos.size()];
- int c = 0;
- for (int n = 0; n < 6; n++) {
- Vector3i t = neighbours[n];
- if(removePos.contains(t))
- continue;
- temp[c] = t;
- c++;
- }
- long endTime = System.nanoTime() - startTime;
- if(endTime / 1000000 > 0) Logger.debug("Chunk(" + pos + ") -> getNeighbours(" + includeLightSourceAndChunkEdges + ") -> Execution Time: " + (endTime / 1000000) + "ms");
- return temp;
- }
- private byte getHighestNeighbourLightLevel(Vector3i[] neighbours){
- long startTime = System.nanoTime();
- byte lightLvl = 1;
- Vector3i neighbour;
- for (int i = 0; i < neighbours.length; i++) {
- neighbour = neighbours[i];
- byte tmpLvl = getLightLvl(neighbour.x, neighbour.y, neighbour.z);
- if(tmpLvl > lightLvl){
- lightLvl = tmpLvl;
- }
- }
- long endTime = System.nanoTime() - startTime;
- if(endTime / 1000000 > 0) Logger.debug("Chunk(" + pos + ") -> getHighestLightLevel() -> Execution Time: " + (endTime / 1000000) + "ms");
- return lightLvl;
- }
- private boolean hasNonAirNeighbour(int x, int y, int z){
- long startTime = System.nanoTime();
- Block block = GetBlock(x + 1, y, z);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x - 1, y, z);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x, y + 1, z);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x, y - 1, z);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x, y, z + 1);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x, y, z - 1);
- if(block.blockType() > 0)
- return true;
- long endTime = System.nanoTime() - startTime;
- if(endTime / 1000000 > 0) Logger.debug("Chunk(" + pos + ") -> hasNonAirNeighbour() -> Execution Time: " + (endTime / 1000000) + "ms");
- return false;
- }
- private boolean hasNonAirNeighbourDiagonal(int x, int y, int z){
- long startTime = System.nanoTime();
- Block block = GetBlock(x - 1, y + 1, z);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x - 1, y - 1, z);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x + 1, y - 1, z);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x + 1, y + 1, z);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x, y + 1, z + 1);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x, y - 1, z + 1);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x, y - 1, z - 1);
- if(block.blockType() > 0)
- return true;
- block = GetBlock(x, y + 1, z - 1);
- if(block.blockType() > 0)
- return true;
- long endTime = System.nanoTime() - startTime;
- if(endTime / 1000000 > 0) Logger.debug("Chunk(" + pos + ") -> hasNonAirNeighbourDiagonal() -> Execution Time: " + (endTime / 1000000) + "ms");
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement