better world gen

This commit is contained in:
maxwes08
2025-09-29 10:55:37 +02:00
parent 9a61dfd74c
commit 38dccf0a84
7 changed files with 2653 additions and 22 deletions

View File

@@ -24,14 +24,17 @@
Initialize();
}
public void SetBlock(int x, int y, int z, Blocks block)
public void SetBlock(int x, int y, int z, Blocks block, bool updateMesh = true)
{
int i = GetBlockIndex(x, y, z);
if (i == -1) return;
_blocks[i] = block;
UpdateChunkMesh();
Renderer.MarkBuffersDirty();
if (updateMesh)
{
UpdateChunkMesh();
Renderer.MarkBuffersDirty();
}
}
public void SetBlockIndex(int i, Blocks block)
@@ -53,12 +56,20 @@
private void Initialize()
{
for (int i = 0; i < Size * Size; i++)
_blocks[i] = Blocks.Bedrock;
for (int i = Size * Size * 1; i < Size * Size * 15; i++)
_blocks[i] = Blocks.Stone;
for (int i = Size * Size * 15; i < Size * Size * 16; i++)
_blocks[i] = Blocks.Grass;
for (int x = 0; x < Size; x++)
{
for (int z = 0; z < Size; z++)
{
var position = GetWorldCoordinates(x, 0, z);
int height = Worldgen.GetHeight(position.x, position.z);
for (int y = 0; y < 256; y++)
{
Blocks block = Worldgen.GetBlock(y, height);
SetBlock(x, y, z, block, false);
}
}
}
UpdateChunkMesh();
}
@@ -72,6 +83,13 @@
return (x, y, z);
}
public (int x, int y, int z) GetWorldCoordinates(int x, int y, int z)
{
x += (Size * X);
z += (Size * Y);
return (x, y, z);
}
private int GetBlockIndex(int x, int y, int z)
{
if (x < 0 || x > 15 || y < 0 || y > 255 || z < 0 || z > 15)