Improve color generation and fix Biome Only generation

This commit is contained in:
James Seibel
2021-08-09 22:25:49 -05:00
parent 2cc78c874b
commit 953c2b2e92
5 changed files with 170 additions and 77 deletions
@@ -35,10 +35,10 @@ public class LodBuilderConfig
/** default true */
public boolean useSolidBlocksInColorGen;
/** default settings for a normal chunk
* useHeightmap = false
* useBiomeColors = false
* useSolidBlocksInColorGen = true
/** default settings for a normal chunk <br>
* useHeightmap = false <br>
* useBiomeColors = false <br>
* useSolidBlocksInColorGen = true <br>
*/
public LodBuilderConfig()
{
@@ -50,7 +50,7 @@ import net.minecraft.world.gen.Heightmap;
* (specifically: Lod World, Dimension, Region, and Chunk objects)
*
* @author James Seibel
* @version 7-26-2021
* @version 8-9-2021
*/
public class LodChunkBuilder
{
@@ -417,7 +417,9 @@ public class LodChunkBuilder
}
else
{
colorInt = biome.getGrassColor(x, z);
Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
tmp = tmp.darker();
colorInt = LodUtil.colorToInt(tmp);
}
}
else
@@ -469,7 +471,9 @@ public class LodChunkBuilder
// block special cases
if (blockState == Blocks.AIR.defaultBlockState())
{
colorInt = biome.getGrassColor(x, z);
Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
tmp = tmp.darker();
colorInt = LodUtil.colorToInt(tmp);
}
else if (blockState == Blocks.MYCELIUM.defaultBlockState())
{
@@ -44,7 +44,7 @@ import net.minecraftforge.common.WorldWorkerManager;
* This object is used to create NearFarBuffer objects.
*
* @author James Seibel
* @version 8-7-2021
* @version 8-9-2021
*/
public class LodNodeBufferBuilder
{
@@ -176,7 +176,7 @@ public class LodNodeBufferBuilder
startX + // offset so the center LOD block is centered underneath the player
8; // I'm not sure what this is correcting exactly but with it the chunks line up.
// 8 works for LODs the size of chunks
double yOffset = 1; // TODO this offset should be done in the LOD generation
double yOffset = 0;
double zOffset = (LodQuadTreeNode.CHUNK_WIDTH * j) + startZ + 8;
LodQuadTreeNode lod = lodDim.getLodFromCoordinates(new ChunkPos(chunkX, chunkZ), LodQuadTreeNode.CHUNK_LEVEL);
@@ -22,17 +22,21 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.seibel.lod.enums.DistanceGenerationMode;
import com.seibel.lod.objects.LodChunk;
import com.seibel.lod.objects.LodDataPoint;
import com.seibel.lod.objects.LodQuadTreeDimension;
import com.seibel.lod.objects.LodQuadTreeNode;
import com.seibel.lod.objects.LodQuadTreeWorld;
import com.seibel.lod.util.LodUtil;
import net.minecraft.block.AbstractPlantBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FlowingFluidBlock;
import net.minecraft.block.BushBlock;
import net.minecraft.block.GrassBlock;
import net.minecraft.block.IGrowable;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.world.DimensionType;
import net.minecraft.world.IWorld;
import net.minecraft.world.biome.Biome;
@@ -40,6 +44,14 @@ import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.gen.Heightmap;
/**
* This object is in charge of creating Lod
* related objects.
* (specifically: Lod World, Dimension, Region, and Chunk objects)
*
* @author James Seibel
* @version 8-9-2021
*/
public class LodNodeBuilder {
private ExecutorService lodGenThreadPool = Executors.newSingleThreadExecutor();
@@ -137,9 +149,16 @@ public class LodNodeBuilder {
short height;
short depth;
/**TODO I HAVE TO RE-ADD THE HEIGHTMAP**/
height = determineHeightPointForArea(chunk.getSections(), startX, startZ, endX, endZ);
depth = determineBottomPointForArea(chunk.getSections(), startX, startZ, endX, endZ);
if (!config.useHeightmap)
{
height = determineHeightPointForArea(chunk.getSections(), startX, startZ, endX, endZ);
depth = determineBottomPointForArea(chunk.getSections(), startX, startZ, endX, endZ);
}
else
{
height = determineHeightPoint(chunk.getOrCreateHeightmapUnprimed(LodChunk.DEFAULT_HEIGHTMAP), startX, startZ, endX, endZ);
depth = 0;
}
return new LodQuadTreeNode(LodQuadTreeNode.CHUNK_LEVEL, chunk.getPos().x, chunk.getPos().z, new LodDataPoint(height, depth, color), DistanceGenerationMode.SERVER);
}
@@ -228,7 +247,7 @@ public class LodNodeBuilder {
// enough blocks in this
// layer to count as an
// LOD point
return (short) (y + (section * CHUNK_SECTION_HEIGHT));
return (short) (y + 1 + (section * CHUNK_SECTION_HEIGHT));
}
}
}
@@ -243,7 +262,6 @@ public class LodNodeBuilder {
/**
* Find the highest point from the Top
*/
@SuppressWarnings("unused")
private short determineHeightPoint(Heightmap heightmap,
int startX, int startZ, int endX, int endZ)
{
@@ -312,49 +330,15 @@ public class LodNodeBuilder {
if (config.useBiomeColors)
{
// the bit shift is equivalent to dividing by 4
Biome biome = chunk.getBiomes().getNoiseBiome(x >> 2, y + i * chunkSections.length >> 2, z >> 2);
if (biome.getBiomeCategory() == Biome.Category.OCEAN ||
biome.getBiomeCategory() == Biome.Category.RIVER)
{
if (config.useSolidBlocksInColorGen &&
blockState != Blocks.WATER.defaultBlockState())
{
// non-water block
colorInt = getColorForBlock(x, z, blockState, biome);
}
else
{
// water block
colorInt = biome.getWaterColor();
}
}
else if (biome.getBiomeCategory() == Biome.Category.EXTREME_HILLS)
{
colorInt = Blocks.STONE.defaultMaterialColor().col;
}
else if (biome.getBiomeCategory() == Biome.Category.ICY)
{
colorInt = LodUtil.colorToInt(Color.WHITE);
}
else if (biome.getBiomeCategory() == Biome.Category.THEEND)
{
colorInt = Blocks.END_STONE.defaultBlockState().materialColor.col;
}
else if (config.useSolidBlocksInColorGen)
{
colorInt = getColorForBlock(x, z, blockState, biome);
}
else
{
colorInt = biome.getGrassColor(x, z);
}
// I have no idea why I need to bit shift to the right, but
// if I don't the biomes don't show up correctly.
Biome biome = chunk.getBiomes().getNoiseBiome(x >> 2, y + 1 * chunkSections.length >> 2, z >> 2);
colorInt = getColorForBiome(x,z, biome);
}
else
{
// I have no idea why I need to bit shift to the right, but
// if I don't the biomes don't show up correctly.
// the bit shift is equivalent to dividing by 4
Biome biome = chunk.getBiomes().getNoiseBiome(x >> 2, y + i * chunkSections.length >> 2, z >> 2);
colorInt = getColorForBlock(x,z, blockState, biome);
}
@@ -389,30 +373,126 @@ public class LodNodeBuilder {
}
/**
/**
* Returns a color int for a given block.
*/
private int getColorForBlock(int x, int z, BlockState blockState, Biome biome)
{
int colorInt = 0;
// block special cases
if (blockState == Blocks.AIR.defaultBlockState())
{
Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
tmp = tmp.darker();
colorInt = LodUtil.colorToInt(tmp);
}
else if (blockState == Blocks.MYCELIUM.defaultBlockState())
{
colorInt = MaterialColor.COLOR_LIGHT_GRAY.col;
}
// plant life
else if (blockState.getBlock() instanceof LeavesBlock)
{
Color leafColor = LodUtil.intToColor(biome.getFoliageColor()).darker();
colorInt = LodUtil.colorToInt(leafColor);
}
else if (blockState.getBlock() instanceof GrassBlock ||
blockState.getBlock() instanceof AbstractPlantBlock ||
blockState.getBlock() instanceof BushBlock ||
blockState.getBlock() instanceof IGrowable)
{
Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
tmp = tmp.darker();
colorInt = LodUtil.colorToInt(tmp);
}
// water
else if (blockState.getBlock() == Blocks.WATER)
{
colorInt = biome.getWaterColor();
}
// everything else
else
{
colorInt = blockState.materialColor.col;
}
return colorInt;
}
/**
* Returns a color int for the given biome.
*/
private int getColorForBiome(int x, int z, Biome biome)
{
int colorInt = 0;
if (blockState == Blocks.AIR.defaultBlockState()) {
colorInt = biome.getGrassColor(x, z);
} else if (blockState.getBlock() instanceof LeavesBlock) {
Color leafColor = LodUtil.intToColor(biome.getFoliageColor()).darker();
colorInt = LodUtil.colorToInt(leafColor);
} else if (blockState.getBlock() instanceof GrassBlock) {
colorInt = biome.getGrassColor(x, z);
} else if (blockState.getBlock() instanceof FlowingFluidBlock) {
colorInt = biome.getWaterColor();
} else {
colorInt = blockState.materialColor.col;
}
return colorInt;
}
int colorInt = 0;
switch(biome.getBiomeCategory())
{
case NETHER:
colorInt = Blocks.BEDROCK.defaultBlockState().materialColor.col;
break;
case THEEND:
colorInt = Blocks.END_STONE.defaultBlockState().materialColor.col;
break;
case BEACH:
case DESERT:
colorInt = Blocks.SAND.defaultBlockState().materialColor.col;
break;
case EXTREME_HILLS:
colorInt = Blocks.STONE.defaultMaterialColor().col;
break;
case MUSHROOM:
colorInt = MaterialColor.COLOR_LIGHT_GRAY.col;
break;
case ICY:
colorInt = Blocks.SNOW.defaultMaterialColor().col;
break;
case MESA:
colorInt = Blocks.RED_SAND.defaultMaterialColor().col;
break;
case OCEAN:
case RIVER:
colorInt = biome.getWaterColor();
break;
case NONE:
case FOREST:
case TAIGA:
case JUNGLE:
case PLAINS:
case SAVANNA:
case SWAMP:
default:
Color tmp = LodUtil.intToColor(biome.getGrassColor(x, z));
tmp = tmp.darker();
colorInt = LodUtil.colorToInt(tmp);
break;
}
return colorInt;
}
/**
* Is the layer between the given X, Z, and dataIndex
* values a valid LOD point?
@@ -439,4 +519,13 @@ public class LodNodeBuilder {
return false;
}
}
@@ -378,7 +378,7 @@ public class LodNodeGenWorker implements IWorker
IceAndSnowFeature snowFeature = new IceAndSnowFeature(NoFeatureConfig.CODEC);
snowFeature.place(lodServerWorld, chunkGen, serverWorld.random, chunk.getPos().getWorldPosition(), null);
LodQuadTreeNode lod = lodNodeBuilder.generateLodNodeFromChunk(chunk, new LodBuilderConfig(true, true, false));
LodQuadTreeNode lod = lodNodeBuilder.generateLodNodeFromChunk(chunk, new LodBuilderConfig());
lodDim.addNode(lod);
}
@@ -505,7 +505,7 @@ public class LodNodeGenWorker implements IWorker
// generate a Lod like normal
LodQuadTreeNode lod = lodNodeBuilder.generateLodNodeFromChunk(chunk, new LodBuilderConfig(true, true, false));
LodQuadTreeNode lod = lodNodeBuilder.generateLodNodeFromChunk(chunk, new LodBuilderConfig());
lodDim.addNode(lod);
}