From 456ba183dad5a38f27194888fe9f92356e52f3fd Mon Sep 17 00:00:00 2001 From: James Seibel Date: Thu, 26 Aug 2021 20:28:48 -0500 Subject: [PATCH] Fix updating regions where LODs contain no blocks --- .../com/seibel/lod/builders/LodBuilder.java | 29 ++++------- .../com/seibel/lod/objects/LodRegion.java | 52 ++++++++++++++----- 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/seibel/lod/builders/LodBuilder.java b/src/main/java/com/seibel/lod/builders/LodBuilder.java index b5c25e3bb..b75ea7e8e 100644 --- a/src/main/java/com/seibel/lod/builders/LodBuilder.java +++ b/src/main/java/com/seibel/lod/builders/LodBuilder.java @@ -25,9 +25,9 @@ import com.seibel.lod.enums.DistanceGenerationMode; import com.seibel.lod.enums.LodDetail; import com.seibel.lod.handlers.LodConfig; import com.seibel.lod.objects.DataPoint; -import com.seibel.lod.objects.LevelPos.LevelPos; import com.seibel.lod.objects.LodDimension; import com.seibel.lod.objects.LodWorld; +import com.seibel.lod.objects.LevelPos.LevelPos; import com.seibel.lod.util.ColorUtil; import com.seibel.lod.util.LodThreadFactory; import com.seibel.lod.util.LodUtil; @@ -49,11 +49,11 @@ import net.minecraft.world.gen.Heightmap; /** * This object is in charge of creating Lod related objects. (specifically: Lod - * World, Dimension, Region, and Chunk objects) + * World, Dimension, and Region objects) * * @author Leonardo Amato * @author James Seibel - * @version 8-17-2021 + * @version 8-26-2021 */ public class LodBuilder { @@ -63,6 +63,11 @@ public class LodBuilder public static final int CHUNK_SECTION_HEIGHT = CHUNK_DATA_WIDTH; public static final Heightmap.Type DEFAULT_HEIGHTMAP = Heightmap.Type.WORLD_SURFACE_WG; + /** If no blocks are found in the area in determineBottomPointForArea return this */ + public static final short DEFAULT_DEPTH = -1; + /** If no blocks are found in the area in determineHeightPointForArea return this */ + public static final short DEFAULT_HEIGHT = -1; + /** * How wide LodDimensions should be in regions */ @@ -206,12 +211,6 @@ public class LodBuilder /** * Find the lowest valid point from the bottom. - * - * @param chunkSections - * @param startX - * @param startZ - * @param endX - * @param endZ */ private short determineBottomPointForArea(ChunkSection[] chunkSections, int startX, int startZ, int endX, int endZ) { @@ -247,7 +246,7 @@ public class LodBuilder } // we never found a valid LOD point - return -1; + return DEFAULT_DEPTH; } @@ -264,17 +263,9 @@ public class LodBuilder /** * Find the highest valid point from the Top - * - * @param chunkSections - * @param startX - * @param startZ - * @param endX - * @param endZ */ private short determineHeightPointForArea(ChunkSection[] chunkSections, int startX, int startZ, int endX, int endZ) { - - //blockState.getBlock().isAir(); int numberOfBlocksRequired = ((endX - startX) * (endZ - startZ) / 2); // search from the top down for (int section = chunkSections.length - 1; section >= 0; section--) @@ -306,7 +297,7 @@ public class LodBuilder } // we never found a valid LOD point - return -1; + return DEFAULT_HEIGHT; } diff --git a/src/main/java/com/seibel/lod/objects/LodRegion.java b/src/main/java/com/seibel/lod/objects/LodRegion.java index b7b4ad0b5..dc0009991 100644 --- a/src/main/java/com/seibel/lod/objects/LodRegion.java +++ b/src/main/java/com/seibel/lod/objects/LodRegion.java @@ -1,15 +1,18 @@ package com.seibel.lod.objects; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.seibel.lod.builders.LodBuilder; import com.seibel.lod.enums.DistanceGenerationMode; import com.seibel.lod.objects.LevelPos.LevelPos; import com.seibel.lod.util.LodUtil; + import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; -import java.io.Serializable; -import java.util.*; -import java.util.List; - /** * STANDARD TO FOLLOW * every coordinate called posX or posZ is a relative coordinate and not and absolute coordinate @@ -408,6 +411,7 @@ public class LodRegion implements Serializable { levelPos.performRegionModule(); int numberOfChildren = 0; + int numberOfVoidChildren = 0; byte minGenerationType = 5; int tempRed = 0; @@ -431,13 +435,24 @@ public class LodRegion implements Serializable levelPos.changeParameters(newDetailLevel, newPosX, newPosZ); if (hasDataBeenGenerated(levelPos)) { - numberOfChildren++; - - tempRed += colors[newDetailLevel][newPosX][newPosZ][0]; - tempGreen += colors[newDetailLevel][newPosX][newPosZ][1]; - tempBlue += colors[newDetailLevel][newPosX][newPosZ][2]; - tempHeight += height[newDetailLevel][newPosX][newPosZ]; - tempDepth += depth[newDetailLevel][newPosX][newPosZ]; + if (height[newDetailLevel][newPosX][newPosZ] != LodBuilder.DEFAULT_HEIGHT + && depth[newDetailLevel][newPosX][newPosZ] != LodBuilder.DEFAULT_DEPTH) + { + numberOfChildren++; + + tempRed += colors[newDetailLevel][newPosX][newPosZ][0]; + tempGreen += colors[newDetailLevel][newPosX][newPosZ][1]; + tempBlue += colors[newDetailLevel][newPosX][newPosZ][2]; + tempHeight += height[newDetailLevel][newPosX][newPosZ]; + tempDepth += depth[newDetailLevel][newPosX][newPosZ]; + } + else + { + // void children have the default height (most likely -1) + // and represent a LOD with no blocks in it + numberOfVoidChildren++; + } + minGenerationType = (byte) Math.min(minGenerationType, generationType[newDetailLevel][newPosX][newPosZ]); } } @@ -453,6 +468,18 @@ public class LodRegion implements Serializable generationType[detailLevel][posX][posZ] = minGenerationType; dataExistence[detailLevel][posX][posZ] = true; } + else if (numberOfVoidChildren > 0) + { + colors[detailLevel][posX][posZ][0] = (byte) 0; + colors[detailLevel][posX][posZ][1] = (byte) 0; + colors[detailLevel][posX][posZ][2] = (byte) 0; + + height[detailLevel][posX][posZ] = LodBuilder.DEFAULT_HEIGHT; + depth[detailLevel][posX][posZ] = LodBuilder.DEFAULT_DEPTH; + + generationType[detailLevel][posX][posZ] = minGenerationType; + dataExistence[detailLevel][posX][posZ] = true; + } } /** @@ -658,7 +685,8 @@ public class LodRegion implements Serializable return count; } - public String toString() + @Override + public String toString() { return getLevel(LodUtil.REGION_DETAIL_LEVEL).toString(); }