From 6bf9e187e0793dbe1961f01bcda833ca4492a715 Mon Sep 17 00:00:00 2001 From: cola98765 Date: Thu, 16 Sep 2021 11:41:53 +0200 Subject: [PATCH 1/8] this breaks old file version system by simply ignoring the old files. --- .../lod/handlers/LodDimensionFileHandler.java | 148 +++++++----------- .../seibel/lod/objects/LevelContainer.java | 8 +- .../lod/objects/SingleLevelContainer.java | 61 ++++---- .../lod/objects/VerticalLevelContainer.java | 5 +- 4 files changed, 90 insertions(+), 132 deletions(-) diff --git a/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java b/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java index bab05d836..95536420c 100644 --- a/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java +++ b/src/main/java/com/seibel/lod/handlers/LodDimensionFileHandler.java @@ -17,11 +17,7 @@ */ package com.seibel.lod.handlers; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.concurrent.ExecutorService; @@ -57,7 +53,7 @@ public class LodDimensionFileHandler /** * .txt */ - private static final String FILE_EXTENSION = ".txt"; + private static final String FILE_EXTENSION = ".dat"; /** * detail-# */ @@ -79,11 +75,6 @@ public class LodDimensionFileHandler */ public static final int LOD_SAVE_FILE_VERSION = 6; - /** - * This is the string written before the file version - */ - private static final String LOD_FILE_VERSION_PREFIX = "lod_save_file_version"; - /** * Allow saving asynchronously, but never try to save multiple regions * at a time @@ -140,66 +131,50 @@ public class LodDimensionFileHandler // return anything continue; } - String data = ""; - BufferedReader bufferedReader = new BufferedReader(new FileReader(f)); - data = bufferedReader.readLine(); - int fileVersion = -1; + byte data[] = {0}; + long dataSize = f.length(); + dataSize -= 1; + if (dataSize > 0) { + try (InputStream inputStream = new BufferedInputStream(new FileInputStream(f))) { + int fileVersion = -1; + fileVersion = inputStream.read(); + // check if this file can be read by this file handler + if (fileVersion < LOD_SAVE_FILE_VERSION) { + // the file we are reading is an older version, + // close the reader and delete the file. + inputStream.close(); + f.delete(); + ClientProxy.LOGGER.info("Outdated LOD region file for region: (" + regionX + "," + regionZ + ") version found: " + fileVersion + + ", version requested: " + LOD_SAVE_FILE_VERSION + + " File was been deleted."); - if (data != null && !data.isEmpty()) - { - // try to get the file version - try - { - fileVersion = Integer.parseInt(data.substring(data.indexOf(' ')).trim()); - } catch (NumberFormatException | StringIndexOutOfBoundsException e) - { - // this file doesn't have a version - // keep the version as -1 - fileVersion = -1; + break; + } else if (fileVersion > LOD_SAVE_FILE_VERSION) { + // the file we are reading is a newer version, + // close the reader and ignore the file, we don't + // want to accidently delete anything the user may want. + inputStream.close(); + ClientProxy.LOGGER.info("Newer LOD region file for region: (" + regionX + "," + regionZ + ") version found: " + fileVersion + + ", version requested: " + LOD_SAVE_FILE_VERSION + + " this region will not be written to in order to protect the newer file."); + + break; + } + // this file is a readable version, begin reading the file + data = new byte[(int) dataSize]; + inputStream.read(data); + inputStream.close(); + } catch (IOException ex) { + ex.printStackTrace(); } - - // check if this file can be read by this file handler - if (fileVersion < LOD_SAVE_FILE_VERSION) - { - // the file we are reading is an older version, - // close the reader and delete the file. - bufferedReader.close(); - f.delete(); - ClientProxy.LOGGER.info("Outdated LOD region file for region: (" + regionX + "," + regionZ + ") version found: " + fileVersion + - ", version requested: " + LOD_SAVE_FILE_VERSION + - " File was been deleted."); - - break; - } else if (fileVersion > LOD_SAVE_FILE_VERSION) - { - // the file we are reading is a newer version, - // close the reader and ignore the file, we don't - // want to accidently delete anything the user may want. - bufferedReader.close(); - ClientProxy.LOGGER.info("Newer LOD region file for region: (" + regionX + "," + regionZ + ") version found: " + fileVersion + - ", version requested: " + LOD_SAVE_FILE_VERSION + - " this region will not be written to in order to protect the newer file."); - - break; - } - } else - { - // there is no data in this file - bufferedReader.close(); - break; } - - // this file is a readable version, begin reading the file - data = bufferedReader.readLine(); - - bufferedReader.close(); switch (region.getLodQualityMode()){ default: case HEIGHTMAP: region.addLevel(new SingleLevelContainer(data)); break; case MULTI_LOD: - region.addLevel(new VerticalLevelContainer(data)); + //region.addLevel(new VerticalLevelContainer(data)); break; } //region.addLevel(new SingleLevelContainer(data)); @@ -293,25 +268,13 @@ public class LodDimensionFileHandler // is the correct version. // (to make sure we don't overwrite a newer // version file if it exists) - - BufferedReader br = new BufferedReader(new FileReader(oldFile)); - String s = br.readLine(); int fileVersion = LOD_SAVE_FILE_VERSION; - - if (s != null && !s.isEmpty()) - { - // try to get the file version - try - { - fileVersion = Integer.parseInt(s.substring(s.indexOf(' ')).trim()); - } catch (NumberFormatException | StringIndexOutOfBoundsException e) - { - // this file doesn't have a correctly formated version - // just overwrite the file - } + try (InputStream inputStream = new BufferedInputStream(new FileInputStream(oldFile))) { + fileVersion = inputStream.read(); + inputStream.close(); + } catch (IOException ex) { + ex.printStackTrace(); } - br.close(); - // check if this file can be written to by the file handler if (fileVersion <= LOD_SAVE_FILE_VERSION) { @@ -327,17 +290,20 @@ public class LodDimensionFileHandler // the old file is good, now create a new save file File newFile = new File(fileName + TMP_FILE_EXTENSION); - FileWriter fw = new FileWriter(newFile); + try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(newFile));) { - // add the version of this file - fw.write(LOD_FILE_VERSION_PREFIX + " " + LOD_SAVE_FILE_VERSION + "\n"); + // add the version of this file + outputStream.write(LOD_SAVE_FILE_VERSION); - // add each LodChunk to the file - fw.write(region.getLevel(detailLevel).toDataString()); - fw.close(); + // add each LodChunk to the file + outputStream.write(region.getLevel(detailLevel).toDataString()); + outputStream.close(); - // overwrite the old file with the new one - Files.move(newFile.toPath(), oldFile.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); + // overwrite the old file with the new one + Files.move(newFile.toPath(), oldFile.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); + }catch (IOException ex) { + ex.printStackTrace(); + } } catch (Exception e) { ClientProxy.LOGGER.error("LOD file write error. Unable to write to [" + fileName + "] error [" + e.getMessage() + "]: "); @@ -370,10 +336,10 @@ public class LodDimensionFileHandler // or // ".\Super Flat\data" return dimensionDataSaveFolder.getCanonicalPath() + File.separatorChar + - lodQualityMode + File.separatorChar + - generationMode.toString() + File.separatorChar + - DETAIL_FOLDER_NAME_PREFIX + detailLevel + File.separatorChar + - FILE_NAME_PREFIX + "." + regionX + "." + regionZ + FILE_EXTENSION; + lodQualityMode + File.separatorChar + + generationMode.toString() + File.separatorChar + + DETAIL_FOLDER_NAME_PREFIX + detailLevel + File.separatorChar + + FILE_NAME_PREFIX + "." + regionX + "." + regionZ + FILE_EXTENSION; } catch (IOException | SecurityException e) { ClientProxy.LOGGER.warn("Unable to get the filename for the region [" + regionX + ", " + regionZ + "], error: [" + e.getMessage() + "], stacktrace: "); diff --git a/src/main/java/com/seibel/lod/objects/LevelContainer.java b/src/main/java/com/seibel/lod/objects/LevelContainer.java index 75a1c28e9..b03a293e7 100644 --- a/src/main/java/com/seibel/lod/objects/LevelContainer.java +++ b/src/main/java/com/seibel/lod/objects/LevelContainer.java @@ -1,11 +1,5 @@ package com.seibel.lod.objects; -import com.seibel.lod.util.LevelPosUtil; -import com.seibel.lod.util.LodUtil; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - public interface LevelContainer { public static final char VERTICAL_DATA_DELIMITER = '\t'; @@ -74,5 +68,5 @@ public interface LevelContainer * This will give the data to save in the file * @return data as a String */ - public String toDataString(); + public byte[] toDataString(); } diff --git a/src/main/java/com/seibel/lod/objects/SingleLevelContainer.java b/src/main/java/com/seibel/lod/objects/SingleLevelContainer.java index e85405f09..9fc1a2390 100644 --- a/src/main/java/com/seibel/lod/objects/SingleLevelContainer.java +++ b/src/main/java/com/seibel/lod/objects/SingleLevelContainer.java @@ -1,8 +1,7 @@ package com.seibel.lod.objects; -import com.seibel.lod.builders.LodBuilder; -import com.seibel.lod.enums.DistanceGenerationMode; import com.seibel.lod.util.*; +import java.util.Arrays; public class SingleLevelContainer implements LevelContainer { @@ -57,17 +56,13 @@ public class SingleLevelContainer implements LevelContainer return new SingleLevelContainer((byte) (getDetailLevel() - 1)); } - public SingleLevelContainer(String inputString) + public SingleLevelContainer(byte inputData[]) { int tempIndex; - int shift = 0; int index = 0; - int digit; - char currentChar; long newData; - currentChar = inputString.charAt(index); - digit = Character.digit(currentChar,16); - detailLevel = (byte) digit; + detailLevel = inputData[index]; + index++; size = (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel); this.data = new long[size][size]; for (int x = 0; x < size; x++) @@ -75,21 +70,17 @@ public class SingleLevelContainer implements LevelContainer for (int z = 0; z < size; z++) { newData = 0; - for(tempIndex = 0; tempIndex < 16; tempIndex++) - { - if(index+tempIndex >= inputString.length()) - break; - currentChar = inputString.charAt(index+tempIndex); - if(currentChar == DATA_DELIMITER){ - break; - } - shift = (15-tempIndex)*4; - digit = Character.digit(currentChar,16); - newData += ((((long) digit & 0xf)) << shift); - } - newData = newData >>> (shift); + if(inputData[index] == 0) + index++; + else if(index + 7 >= inputData.length) + break; + else { + for (tempIndex = 0; tempIndex < 8; tempIndex++) + newData += (((long) inputData[index + tempIndex]) & 0xff) << (8 * tempIndex); + index = index + 8; + } data[x][z] = newData; - index = index + tempIndex; + } } } @@ -125,22 +116,28 @@ public class SingleLevelContainer implements LevelContainer return DataPointUtil.doesItExist(getSingleData(posX, posZ)); } - public String toDataString() + public byte[] toDataString() { - StringBuilder stringBuilder = new StringBuilder(); - int size = (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel); - stringBuilder.append(detailLevel); - stringBuilder.append(DATA_DELIMITER); + int index = 0; + int tempIndex; + byte[] tempData = new byte[1 + (size * size * 8)]; + tempData[index] = detailLevel; + index++; for (int x = 0; x < size; x++) { for (int z = 0; z < size; z++) { - //Converting the dataToHex - stringBuilder.append(Long.toHexString(data[x][z])); - stringBuilder.append(DATA_DELIMITER); + if(data[x][z] == 0){ + tempData[index] = 0; + index++; + } else { + for (tempIndex = 0; tempIndex < 8; tempIndex++) + tempData[index + tempIndex] = (byte) (data[x][z] >>> (8 * tempIndex)); + index += 8; + } } } - return stringBuilder.toString(); + return Arrays.copyOfRange(tempData, 0, index); } @Override diff --git a/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java b/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java index 9a845780d..6c91f1dcc 100644 --- a/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java +++ b/src/main/java/com/seibel/lod/objects/VerticalLevelContainer.java @@ -114,9 +114,10 @@ public class VerticalLevelContainer implements LevelContainer addData(data,posX,posZ); } - public String toDataString() + public byte[] toDataString() { - return toString(); + byte[] temp = {}; + return temp; } @Override From b2aca276159c892d7ad3f6c3bbe1515255fbfcf7 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Thu, 16 Sep 2021 15:44:28 +0200 Subject: [PATCH 2/8] Added texture mean in lod builder --- .../com/seibel/lod/builders/LodBuilder.java | 87 +++++++++++++------ .../seibel/lod/wrappers/MinecraftWrapper.java | 8 +- 2 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/LodBuilder.java b/src/main/java/com/seibel/lod/builders/LodBuilder.java index acde5afa7..44122a640 100644 --- a/src/main/java/com/seibel/lod/builders/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBuilder.java @@ -18,6 +18,8 @@ package com.seibel.lod.builders; import java.awt.Color; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -33,6 +35,8 @@ import com.seibel.lod.wrappers.MinecraftWrapper; import net.minecraft.block.*; import net.minecraft.block.material.MaterialColor; +import net.minecraft.client.renderer.model.ModelManager; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; @@ -40,6 +44,7 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.DimensionType; import net.minecraft.world.IWorld; import net.minecraft.world.LightType; +import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraft.world.chunk.ChunkSection; import net.minecraft.world.chunk.IChunk; @@ -60,6 +65,7 @@ public class LodBuilder public static final int CHUNK_DATA_WIDTH = LodUtil.CHUNK_WIDTH; public static final int CHUNK_SECTION_HEIGHT = CHUNK_DATA_WIDTH; public static final Heightmap.Type DEFAULT_HEIGHTMAP = Heightmap.Type.WORLD_SURFACE_WG; + public static final ConcurrentMap colorMap= new ConcurrentHashMap<>(); /** * If no blocks are found in the area in determineBottomPointForArea return this @@ -286,7 +292,7 @@ public class LodBuilder yAbs = height - 1; // We search light on above air block - color = generateLodColor(chunk, config, xRel, yAbs, zRel); + color = generateLodColor(chunk, config, xRel, yAbs, zRel,blockPos ); depth = determineBottomPointFrom(chunk, config, xRel, zRel, yAbs, blockPos); blockPos.set(xAbs, yAbs + 1, zAbs); light = getLightValue(chunk, blockPos); @@ -420,7 +426,7 @@ public class LodBuilder yAbs = height - 1; // We search light on above air block - color = generateLodColor(chunk, config, xRel, yAbs, zRel); + color = generateLodColor(chunk, config, xRel, yAbs, zRel, blockPos); depth = determineBottomPoint(chunk, config, xRel, zRel, blockPos); blockPos.set(xAbs, yAbs + 1, zAbs); @@ -508,7 +514,7 @@ public class LodBuilder * Generate the color for the given chunk using biome water color, foliage * color, and grass color. */ - private int generateLodColor(IChunk chunk, LodBuilderConfig config, int xRel, int yAbs, int zRel) + private int generateLodColor(IChunk chunk, LodBuilderConfig config, int xRel, int yAbs, int zRel, BlockPos.Mutable blockPos) { ChunkSection[] chunkSections = chunk.getSections(); int colorInt = 0; @@ -529,12 +535,14 @@ public class LodBuilder // the bit shift is equivalent to dividing by 4 Biome biome = chunk.getBiomes().getNoiseBiome(xRel >> 2, yAbs >> 2, zRel >> 2); - colorInt = getColorForBlock(xRel, zRel, blockState, biome); + blockPos.set(chunk.getPos().getMinBlockX() + xRel, sectionIndex * CHUNK_DATA_WIDTH + yRel, chunk.getPos().getMinBlockZ() + zRel); + //colorInt = getColorTextureForBlock(blockState, blockPos); + colorInt = getColorForBlock(xRel, zRel, blockState, biome, blockPos); } if (colorInt == 0 && yAbs > 0) { //invisible case - colorInt = generateLodColor(chunk, config, xRel, yAbs - 1, zRel); + colorInt = generateLodColor(chunk, config, xRel, yAbs - 1, zRel, blockPos); } } return colorInt; @@ -559,10 +567,54 @@ public class LodBuilder return light; } + private int getColorTextureForBlock(BlockState blockState, BlockPos blockPos) + { + if(colorMap.containsKey(blockState.getBlock())) + return colorMap.get(blockState.getBlock()); + World world = MinecraftWrapper.INSTANCE.getPlayer().level; + TextureAtlasSprite texture = MinecraftWrapper.INSTANCE.getModelManager().getBlockModelShaper().getTexture(blockState, world, blockPos); + int count = 0; + int alpha = 0; + int red = 0; + int green = 0; + int blue = 0;; + int color = 0; + for(int i = 0 ; i < texture.getHeight(); i++) + { + for(int j = 0 ; j < texture.getWidth(); j++) + { + color = texture.getPixelRGBA(0,i,j); + //if(color != 0) + if(!texture.isTransparent(0,i,j)) + { + count++; + alpha += ColorUtil.getAlpha(color); + red += ColorUtil.getBlue(color); + green += ColorUtil.getGreen(color); + blue += ColorUtil.getRed(color); + + } + } + } + if(count == 0) + { + color = 0; + } + else + { + alpha /= count; + red /= count; + green /= count; + blue /= count; + color = ColorUtil.rgbToInt(alpha, red, green, blue); + } + colorMap.put(blockState.getBlock(), color); + return color; + } /** * Returns a color int for the given block. */ - private int getColorForBlock(int x, int z, BlockState blockState, Biome biome) + private int getColorForBlock(int x, int z, BlockState blockState, Biome biome, BlockPos blockPos) { int colorInt = 0; @@ -643,6 +695,7 @@ public class LodBuilder // everything else else { + //colorInt = getColorTextureForBlock(blockState,blockPos); colorInt = blockState.getBlock().defaultMaterialColor().col; } @@ -751,26 +804,4 @@ public class LodBuilder return false; } - - private boolean isLayerValidLodPoint(ChunkSection[] chunkSections, int sectionIndex, int y, int x, int z) - { - if (chunkSections[sectionIndex] == null) - { - // this section doesn't have any blocks, - // it is not a valid section - return false; - } else - { - if (chunkSections[sectionIndex].getBlockState(x, y, z) != null - && chunkSections[sectionIndex].getBlockState(x, y, z).getBlock() != Blocks.AIR - && chunkSections[sectionIndex].getBlockState(x, y, z).getBlock() != Blocks.CAVE_AIR - && chunkSections[sectionIndex].getBlockState(x, y, z).getBlock() != Blocks.BARRIER) - { - return true; - } - } - - return false; - } - } diff --git a/src/main/java/com/seibel/lod/wrappers/MinecraftWrapper.java b/src/main/java/com/seibel/lod/wrappers/MinecraftWrapper.java index 4d597da84..7f2e94094 100644 --- a/src/main/java/com/seibel/lod/wrappers/MinecraftWrapper.java +++ b/src/main/java/com/seibel/lod/wrappers/MinecraftWrapper.java @@ -12,6 +12,7 @@ import net.minecraft.client.multiplayer.ServerData; import net.minecraft.client.network.play.ClientPlayNetHandler; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.model.ModelManager; import net.minecraft.entity.Entity; import net.minecraft.profiler.IProfiler; import net.minecraft.server.integrated.IntegratedServer; @@ -78,7 +79,12 @@ public class MinecraftWrapper { return mc.options; } - + + public ModelManager getModelManager() + { + return mc.getModelManager(); + } + /** Measured in chunks */ public int getRenderDistance() { From fc4546538f2e39925a54471ad0469a4146f8d71d Mon Sep 17 00:00:00 2001 From: Leonardo Date: Thu, 16 Sep 2021 16:17:38 +0200 Subject: [PATCH 3/8] Reintroduced manual color for nether blocks --- .../com/seibel/lod/builders/LodBuilder.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/LodBuilder.java b/src/main/java/com/seibel/lod/builders/LodBuilder.java index 44122a640..92714b823 100644 --- a/src/main/java/com/seibel/lod/builders/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBuilder.java @@ -579,20 +579,22 @@ public class LodBuilder int green = 0; int blue = 0;; int color = 0; - for(int i = 0 ; i < texture.getHeight(); i++) + for(int k = 0 ; k < texture.getFrameCount(); k++) { - for(int j = 0 ; j < texture.getWidth(); j++) + for (int i = 0; i < texture.getHeight(); i++) { - color = texture.getPixelRGBA(0,i,j); - //if(color != 0) - if(!texture.isTransparent(0,i,j)) + for (int j = 0; j < texture.getWidth(); j++) { - count++; - alpha += ColorUtil.getAlpha(color); - red += ColorUtil.getBlue(color); - green += ColorUtil.getGreen(color); - blue += ColorUtil.getRed(color); + color = texture.getPixelRGBA(k, i, j); + if (!texture.isTransparent(k, i, j)) + { + count++; + alpha += ColorUtil.getAlpha(color); + red += ColorUtil.getBlue(color); + green += ColorUtil.getGreen(color); + blue += ColorUtil.getRed(color); + } } } } @@ -695,8 +697,9 @@ public class LodBuilder // everything else else { - //colorInt = getColorTextureForBlock(blockState,blockPos); - colorInt = blockState.getBlock().defaultMaterialColor().col; + colorInt = getColorTextureForBlock(blockState,blockPos); + //colorInt = blockState.materialColor.col; + //colorInt = blockState.getBlock().defaultMaterialColor().col; } return colorInt; From d911017112472ffec542cabaf4c8ccc6b8ecc54a Mon Sep 17 00:00:00 2001 From: Leonardo Date: Thu, 16 Sep 2021 17:11:08 +0200 Subject: [PATCH 4/8] new color for grass, leaf and water --- .../com/seibel/lod/builders/LodBuilder.java | 47 +++++-------------- .../java/com/seibel/lod/util/ColorUtil.java | 13 +++++ 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/LodBuilder.java b/src/main/java/com/seibel/lod/builders/LodBuilder.java index 92714b823..cf6d7314b 100644 --- a/src/main/java/com/seibel/lod/builders/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBuilder.java @@ -579,6 +579,7 @@ public class LodBuilder int green = 0; int blue = 0;; int color = 0; + System.out.println(blockState.getBlock().toString() + " " + texture.getFrameCount() + " " + texture.getHeight() + " " + texture.getWidth()); for(int k = 0 ; k < texture.getFrameCount(); k++) { for (int i = 0; i < texture.getHeight(); i++) @@ -628,10 +629,7 @@ public class LodBuilder Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z)); tmp = tmp.darker(); colorInt = LodUtil.colorToInt(tmp); - } else if (blockState == Blocks.STONE.defaultBlockState()) - { - colorInt = LodUtil.STONE_COLOR_INT; - } else if (blockState == Blocks.NETHERRACK.defaultBlockState()) + }else if (blockState == Blocks.NETHERRACK.defaultBlockState()) { colorInt = LodUtil.NETHERRACK_COLOR_INT; } else if (blockState == Blocks.WARPED_NYLIUM.defaultBlockState()) @@ -646,52 +644,33 @@ public class LodBuilder || blockState == Blocks.CRIMSON_ROOTS.defaultBlockState()) { colorInt = Blocks.NETHER_WART_BLOCK.defaultMaterialColor().col; - } else if (blockState == Blocks.TWISTING_VINES.defaultBlockState() - || blockState == Blocks.TWISTING_VINES_PLANT.defaultBlockState() - || blockState == Blocks.CRIMSON_FUNGUS.defaultBlockState() - || blockState == Blocks.CRIMSON_ROOTS.defaultBlockState()) + } else if (blockState.getBlock().equals(Blocks.TWISTING_VINES) + || blockState.equals(Blocks.TWISTING_VINES_PLANT) + || blockState == Blocks.WARPED_ROOTS.defaultBlockState() + || blockState == Blocks.WARPED_FUNGUS.defaultBlockState()) { - colorInt = Blocks.WARPED_WART_BLOCK.defaultMaterialColor().col; - } else if (blockState == Blocks.BEDROCK.defaultBlockState()) - { - colorInt = getColorForBiome(x, z, biome); - } else if (blockState == Blocks.MYCELIUM.defaultBlockState()) - { - colorInt = LodUtil.MYCELIUM_COLOR_INT; - } else if (blockState == Blocks.SOUL_TORCH.defaultBlockState() - || blockState == Blocks.SOUL_WALL_TORCH.defaultBlockState()) - { - colorInt = Blocks.WARPED_PLANKS.defaultMaterialColor().col; - } else if (blockState == Blocks.TORCH.defaultBlockState() - || blockState == Blocks.WALL_TORCH.defaultBlockState()) - { - colorInt = Blocks.OAK_PLANKS.defaultMaterialColor().col; - } else if (blockState == Blocks.REDSTONE_TORCH.defaultBlockState() - || blockState == Blocks.REDSTONE_WALL_TORCH.defaultBlockState()) - { - colorInt = Blocks.CRIMSON_PLANKS.defaultMaterialColor().col; + colorInt = Blocks.WARPED_NYLIUM.defaultMaterialColor().col; } // plant life else if (blockState.getBlock() instanceof LeavesBlock || blockState.getBlock() == Blocks.VINE) { - Color leafColor = LodUtil.intToColor(biome.getFoliageColor()).darker(); - leafColor = leafColor.darker(); - colorInt = LodUtil.colorToInt(leafColor); + int brightness = getColorTextureForBlock(blockState,blockPos); + colorInt = ColorUtil.changeBrightnessValue(biome.getFoliageColor(),brightness); } else if ((blockState.getBlock() instanceof GrassBlock || blockState.getBlock() instanceof AbstractPlantBlock || blockState.getBlock() instanceof BushBlock || blockState.getBlock() instanceof IGrowable) && !(blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM)) { - Color plantColor = LodUtil.intToColor(biome.getGrassColor(x, z)); - plantColor = plantColor.darker(); - colorInt = LodUtil.colorToInt(plantColor); + int brightness = getColorTextureForBlock(blockState,blockPos); + colorInt = ColorUtil.changeBrightnessValue(biome.getGrassColor(x, z),brightness); } // water else if (blockState.getBlock() == Blocks.WATER) { - colorInt = biome.getWaterColor(); + int brightness = getColorTextureForBlock(blockState,blockPos); + colorInt = ColorUtil.changeBrightnessValue(biome.getWaterColor(),brightness); } // everything else diff --git a/src/main/java/com/seibel/lod/util/ColorUtil.java b/src/main/java/com/seibel/lod/util/ColorUtil.java index e49f9e215..3b1806b3a 100644 --- a/src/main/java/com/seibel/lod/util/ColorUtil.java +++ b/src/main/java/com/seibel/lod/util/ColorUtil.java @@ -79,4 +79,17 @@ public class ColorUtil hsv[1], brightness).getRGB(); } + + /** + * Edit the given color as a HSV (Hue Saturation Value) color. + */ + public static int changeBrightnessValue(int color, int brightnessColor) + { + float[] hsv = Color.RGBtoHSB(getRed(color), getGreen(color), getBlue(color), null); + float brightness = Color.RGBtoHSB(getRed(brightnessColor), getGreen(brightnessColor), getBlue(brightnessColor), null)[2]; + return Color.getHSBColor( + hsv[0], // hue + hsv[1], + brightness).getRGB(); + } } From 6bc14fbb2d5ad02210b2d438c0b4fed41987fff3 Mon Sep 17 00:00:00 2001 From: cola98765 Date: Thu, 16 Sep 2021 18:12:22 +0200 Subject: [PATCH 5/8] brightness fix with real block colors TODO foliage --- src/main/java/com/seibel/lod/render/LodRenderer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/seibel/lod/render/LodRenderer.java b/src/main/java/com/seibel/lod/render/LodRenderer.java index 8241283f6..dcf587a04 100644 --- a/src/main/java/com/seibel/lod/render/LodRenderer.java +++ b/src/main/java/com/seibel/lod/render/LodRenderer.java @@ -575,10 +575,13 @@ public class LodRenderer float sunBrightness = lodDimension.dimension.hasSkyLight() ? mc.getSkyDarken(partialTicks) : 0.2f; sunBrightness = playerHasNightVision ? 1.0f : sunBrightness; - float gammaMultiplyer = (float) mc.getOptions().gamma - 0.5f; - float lightStrength = ((sunBrightness / 2f) - 0.2f) + (gammaMultiplyer * 0.3f); + float gamma = (float) mc.getOptions().gamma - 0.0f; + float dayEffect = (sunBrightness - 0.2f) * 1.25f; + float lightStrength = (gamma * 0.35f + 0.18f) * (1.0f - dayEffect) + dayEffect - 0.20f; //gamma * 0.2980392157f + 0.1647058824f + float blueLightStrength = (gamma * 0.48f + 0.32f) * (1.0f - dayEffect) + dayEffect - 0.20f; //gamma * 0.4235294118f + 0.2784313725f + + float lightAmbient[] = {lightStrength, lightStrength, blueLightStrength, 1.0f}; - float lightAmbient[] = {lightStrength, lightStrength, lightStrength, 1.0f}; // can be used for debugging // if (partialTicks < 0.005) From e23bbfcd91b5823efaa3d8c9c08ed0c6b645fdc5 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Thu, 16 Sep 2021 18:53:26 +0200 Subject: [PATCH 6/8] small changes --- .../com/seibel/lod/builders/LodBuilder.java | 82 +++++++++++-------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/LodBuilder.java b/src/main/java/com/seibel/lod/builders/LodBuilder.java index cf6d7314b..296735fa8 100644 --- a/src/main/java/com/seibel/lod/builders/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBuilder.java @@ -35,12 +35,9 @@ import com.seibel.lod.wrappers.MinecraftWrapper; import net.minecraft.block.*; import net.minecraft.block.material.MaterialColor; -import net.minecraft.client.renderer.model.ModelManager; import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.DimensionType; import net.minecraft.world.IWorld; import net.minecraft.world.LightType; @@ -65,7 +62,7 @@ public class LodBuilder public static final int CHUNK_DATA_WIDTH = LodUtil.CHUNK_WIDTH; public static final int CHUNK_SECTION_HEIGHT = CHUNK_DATA_WIDTH; public static final Heightmap.Type DEFAULT_HEIGHTMAP = Heightmap.Type.WORLD_SURFACE_WG; - public static final ConcurrentMap colorMap= new ConcurrentHashMap<>(); + public static final ConcurrentMap colorMap = new ConcurrentHashMap<>(); /** * If no blocks are found in the area in determineBottomPointForArea return this @@ -292,7 +289,7 @@ public class LodBuilder yAbs = height - 1; // We search light on above air block - color = generateLodColor(chunk, config, xRel, yAbs, zRel,blockPos ); + color = generateLodColor(chunk, config, xRel, yAbs, zRel, blockPos); depth = determineBottomPointFrom(chunk, config, xRel, zRel, yAbs, blockPos); blockPos.set(xAbs, yAbs + 1, zAbs); light = getLightValue(chunk, blockPos); @@ -530,14 +527,11 @@ public class LodBuilder int yRel = Math.floorMod(yAbs, CHUNK_SECTION_HEIGHT); if (chunkSections[sectionIndex] != null) { - BlockState blockState = chunkSections[sectionIndex].getBlockState(xRel, yRel, zRel); - // the bit shift is equivalent to dividing by 4 - Biome biome = chunk.getBiomes().getNoiseBiome(xRel >> 2, yAbs >> 2, zRel >> 2); blockPos.set(chunk.getPos().getMinBlockX() + xRel, sectionIndex * CHUNK_DATA_WIDTH + yRel, chunk.getPos().getMinBlockZ() + zRel); //colorInt = getColorTextureForBlock(blockState, blockPos); - colorInt = getColorForBlock(xRel, zRel, blockState, biome, blockPos); + colorInt = getColorForBlock(chunk, blockPos); } if (colorInt == 0 && yAbs > 0) { @@ -569,7 +563,7 @@ public class LodBuilder private int getColorTextureForBlock(BlockState blockState, BlockPos blockPos) { - if(colorMap.containsKey(blockState.getBlock())) + if (colorMap.containsKey(blockState.getBlock())) return colorMap.get(blockState.getBlock()); World world = MinecraftWrapper.INSTANCE.getPlayer().level; TextureAtlasSprite texture = MinecraftWrapper.INSTANCE.getModelManager().getBlockModelShaper().getTexture(blockState, world, blockPos); @@ -577,33 +571,37 @@ public class LodBuilder int alpha = 0; int red = 0; int green = 0; - int blue = 0;; + int blue = 0; + ; int color = 0; - System.out.println(blockState.getBlock().toString() + " " + texture.getFrameCount() + " " + texture.getHeight() + " " + texture.getWidth()); - for(int k = 0 ; k < texture.getFrameCount(); k++) + for (int k = 0; k < texture.getFrameCount(); k++) { for (int i = 0; i < texture.getHeight(); i++) { for (int j = 0; j < texture.getWidth(); j++) { - color = texture.getPixelRGBA(k, i, j); - if (!texture.isTransparent(k, i, j)) + if (texture.isTransparent(k, i, j)) { - count++; - alpha += ColorUtil.getAlpha(color); - red += ColorUtil.getBlue(color); - green += ColorUtil.getGreen(color); - blue += ColorUtil.getRed(color); - + if (blockState.getBlock() instanceof LeavesBlock) + color = 0; + else + continue; + } else + { + color = texture.getPixelRGBA(k, i, j); } + count++; + alpha += ColorUtil.getAlpha(color); + red += ColorUtil.getBlue(color); + green += ColorUtil.getGreen(color); + blue += ColorUtil.getRed(color); } } } - if(count == 0) + if (count == 0) { color = 0; - } - else + } else { alpha /= count; red /= count; @@ -614,13 +612,28 @@ public class LodBuilder colorMap.put(blockState.getBlock(), color); return color; } + /** * Returns a color int for the given block. */ - private int getColorForBlock(int x, int z, BlockState blockState, Biome biome, BlockPos blockPos) + private int getColorForBlock(IChunk chunk, BlockPos blockPos) { + + int xRel = blockPos.getX() - chunk.getPos().getMinBlockX(); + int zRel = blockPos.getZ() - chunk.getPos().getMinBlockZ(); + int x = blockPos.getX(); + int y = blockPos.getY(); + int z = blockPos.getZ(); + Biome biome = chunk.getBiomes().getNoiseBiome(xRel >> 2, y >> 2, zRel >> 2); + int brightness; + int red = 0; + int green = 0; + int blue = 0; + + BlockState blockState = chunk.getBlockState(blockPos); int colorInt = 0; + // block special cases if (blockState == Blocks.AIR.defaultBlockState() || blockState == Blocks.CAVE_AIR.defaultBlockState() @@ -629,7 +642,7 @@ public class LodBuilder Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z)); tmp = tmp.darker(); colorInt = LodUtil.colorToInt(tmp); - }else if (blockState == Blocks.NETHERRACK.defaultBlockState()) + } else if (blockState == Blocks.NETHERRACK.defaultBlockState()) { colorInt = LodUtil.NETHERRACK_COLOR_INT; } else if (blockState == Blocks.WARPED_NYLIUM.defaultBlockState()) @@ -639,7 +652,7 @@ public class LodBuilder { colorInt = LodUtil.CRIMSON_NYLIUM_COLOR_INT; } else if (blockState == Blocks.WEEPING_VINES.defaultBlockState() - || blockState == Blocks.WEEPING_VINES_PLANT.defaultBlockState() + || blockState == Blocks.WEEPING_VINES_PLANT.defaultBlockState() || blockState == Blocks.CRIMSON_FUNGUS.defaultBlockState() || blockState == Blocks.CRIMSON_ROOTS.defaultBlockState()) { @@ -656,27 +669,26 @@ public class LodBuilder // plant life else if (blockState.getBlock() instanceof LeavesBlock || blockState.getBlock() == Blocks.VINE) { - int brightness = getColorTextureForBlock(blockState,blockPos); - colorInt = ColorUtil.changeBrightnessValue(biome.getFoliageColor(),brightness); + brightness = getColorTextureForBlock(blockState, blockPos); + colorInt = ColorUtil.changeBrightnessValue(biome.getFoliageColor(), brightness); } else if ((blockState.getBlock() instanceof GrassBlock || blockState.getBlock() instanceof AbstractPlantBlock || blockState.getBlock() instanceof BushBlock || blockState.getBlock() instanceof IGrowable) && !(blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM)) { - int brightness = getColorTextureForBlock(blockState,blockPos); - colorInt = ColorUtil.changeBrightnessValue(biome.getGrassColor(x, z),brightness); + brightness = getColorTextureForBlock(blockState, blockPos); + colorInt = ColorUtil.changeBrightnessValue(biome.getGrassColor(x, z), brightness); } - // water else if (blockState.getBlock() == Blocks.WATER) { - int brightness = getColorTextureForBlock(blockState,blockPos); - colorInt = ColorUtil.changeBrightnessValue(biome.getWaterColor(),brightness); + brightness = getColorTextureForBlock(blockState, blockPos); + colorInt = ColorUtil.changeBrightnessValue(biome.getWaterColor(), brightness); } // everything else else { - colorInt = getColorTextureForBlock(blockState,blockPos); + colorInt = getColorTextureForBlock(blockState, blockPos); //colorInt = blockState.materialColor.col; //colorInt = blockState.getBlock().defaultMaterialColor().col; } From b6c350f6678c12fec9e9ccf206398912fecaf8ac Mon Sep 17 00:00:00 2001 From: cola98765 Date: Thu, 16 Sep 2021 22:21:04 +0200 Subject: [PATCH 7/8] colors are better than it were --- src/main/java/com/seibel/lod/builders/LodBuilder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/LodBuilder.java b/src/main/java/com/seibel/lod/builders/LodBuilder.java index 296735fa8..11c0f47d6 100644 --- a/src/main/java/com/seibel/lod/builders/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBuilder.java @@ -676,13 +676,15 @@ public class LodBuilder && !(blockState.getBlock() == Blocks.BROWN_MUSHROOM || blockState.getBlock() == Blocks.RED_MUSHROOM)) { brightness = getColorTextureForBlock(blockState, blockPos); - colorInt = ColorUtil.changeBrightnessValue(biome.getGrassColor(x, z), brightness); + //colorInt = ColorUtil.changeBrightnessValue(biome.getGrassColor(x, z), brightness); + colorInt = ColorUtil.applySaturationAndBrightnessMultipliers(biome.getGrassColor(x, z),1f,0.75f); } // water else if (blockState.getBlock() == Blocks.WATER) { brightness = getColorTextureForBlock(blockState, blockPos); - colorInt = ColorUtil.changeBrightnessValue(biome.getWaterColor(), brightness); + //colorInt = ColorUtil.changeBrightnessValue(biome.getWaterColor(), brightness); + colorInt = ColorUtil.applySaturationAndBrightnessMultipliers(biome.getWaterColor(),1f,0.75f); } // everything else From b008b70255ea324ea4b80e855c4ba16d4a99a6bb Mon Sep 17 00:00:00 2001 From: cola98765 Date: Fri, 17 Sep 2021 00:05:29 +0200 Subject: [PATCH 8/8] colors are better than it were... again --- src/main/java/com/seibel/lod/builders/LodBuilder.java | 2 +- src/main/java/com/seibel/lod/render/LodRenderer.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/LodBuilder.java b/src/main/java/com/seibel/lod/builders/LodBuilder.java index 11c0f47d6..2422883b1 100644 --- a/src/main/java/com/seibel/lod/builders/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBuilder.java @@ -677,7 +677,7 @@ public class LodBuilder { brightness = getColorTextureForBlock(blockState, blockPos); //colorInt = ColorUtil.changeBrightnessValue(biome.getGrassColor(x, z), brightness); - colorInt = ColorUtil.applySaturationAndBrightnessMultipliers(biome.getGrassColor(x, z),1f,0.75f); + colorInt = ColorUtil.applySaturationAndBrightnessMultipliers(biome.getGrassColor(x, z),1f,0.65f); } // water else if (blockState.getBlock() == Blocks.WATER) diff --git a/src/main/java/com/seibel/lod/render/LodRenderer.java b/src/main/java/com/seibel/lod/render/LodRenderer.java index dcf587a04..eb7899c29 100644 --- a/src/main/java/com/seibel/lod/render/LodRenderer.java +++ b/src/main/java/com/seibel/lod/render/LodRenderer.java @@ -577,8 +577,8 @@ public class LodRenderer sunBrightness = playerHasNightVision ? 1.0f : sunBrightness; float gamma = (float) mc.getOptions().gamma - 0.0f; float dayEffect = (sunBrightness - 0.2f) * 1.25f; - float lightStrength = (gamma * 0.35f + 0.18f) * (1.0f - dayEffect) + dayEffect - 0.20f; //gamma * 0.2980392157f + 0.1647058824f - float blueLightStrength = (gamma * 0.48f + 0.32f) * (1.0f - dayEffect) + dayEffect - 0.20f; //gamma * 0.4235294118f + 0.2784313725f + float lightStrength = (gamma * 0.34f - 0.01f) * (1.0f - dayEffect) + dayEffect - 0.20f; //gamma * 0.2980392157f + 0.1647058824f + float blueLightStrength = (gamma * 0.44f + 0.12f) * (1.0f - dayEffect) + dayEffect - 0.20f; //gamma * 0.4235294118f + 0.2784313725f float lightAmbient[] = {lightStrength, lightStrength, blueLightStrength, 1.0f};