Skip to content

Commit

Permalink
replace current tree generation with better one
Browse files Browse the repository at this point in the history
  • Loading branch information
InFTord committed May 26, 2023
1 parent d9d5b67 commit 390c93d
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions Obsidian/WorldData/Generators/Overworld/Features/Trees/BaseTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,24 @@ public virtual async Task<bool> TryGenerateTreeAsync(Vector origin, int heightOf

protected virtual async Task GenerateLeavesAsync(Vector origin, int heightOffset)
{
int topY = origin.Y + trunkHeight + heightOffset + 1;
for (int y = topY; y >= topY - 3; y--)
{
for (int x = origin.X - 2; x <= origin.X + 2; x++)
{
for (int z = origin.Z - 2; z <= origin.Z + 2; z++)
{
// Skip the top edges.
if (y == topY)
{
if (x != origin.X - 2 && x != origin.X + 2 && z != origin.Z - 2 && z != origin.Z + 2)
{
await helper.SetBlockAsync(x, y, z, this.leafBlock, chunk);
}
}
else
{
await helper.SetBlockAsync(x, y, z, this.leafBlock, chunk);
}
}
}
}

// Make leaves
for (int xx = -2; xx <= 2; xx++)
{
for (int zz = -2; zz <= 2; zz++)
{
await helper.SetBlockAsync(origin.X + xx, trunkHeight + origin.Y - 1, origin.Z + zz, this.leafBlock, chunk);
await helper.SetBlockAsync(origin.X + xx, trunkHeight + origin.Y, origin.Z + zz, this.leafBlock, chunk);

if (Math.Abs(xx) < 2 && Math.Abs(zz) < 2)
{
await helper.SetBlockAsync(origin.X + xx, trunkHeight + origin.Y + 1, origin.Z + zz, this.leafBlock, chunk);

if (xx == 0 || zz == 0)
await helper.SetBlockAsync(origin.X + xx, trunkHeight + origin.Y + 2, origin.Z + zz, this.leafBlock, chunk); }
}
}

}

protected virtual async Task GenerateTrunkAsync(Vector origin, int heightOffset)
Expand Down

0 comments on commit 390c93d

Please sign in to comment.