1
0

Changing jungle trees a bit (#4823)

* switch range on jungle tree generation and renamed a confusing variable

* changed two numbers to match vanilla behaviour

* made jungle trees closer to vanilla behaviour

- matched variable names to new checkstyle
- made branch generation independent from noise at block position

* replaced random provider with Noise

* implemented changes suggested by peterbell10

* changed the way to determine the size of the leaves on branches

Co-authored-by: peterbell10 <peterbell10@live.co.uk>

Co-authored-by: 12xx12 <12xx12100@gmail.com>
Co-authored-by: peterbell10 <peterbell10@live.co.uk>
Co-authored-by: Alexander Harkness <me@bearbin.net>
This commit is contained in:
12xx12 2020-09-19 18:51:26 +02:00 committed by GitHub
parent 55672ca5b3
commit 1a211b6c46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@
#include "Globals.h" #include "Globals.h"
#include "Trees.h" #include "Trees.h"
#include "../BlockType.h" #include "../BlockType.h"
#include "../World.h"
@ -58,7 +59,7 @@ static const Vector3d & pickBranchDirection(const cNoise a_Noise, Vector3i a_Blo
} }
}; };
size_t index = static_cast<size_t>(a_Noise.IntNoise3DInt(a_BlockPos.x, a_BlockPos.y + a_Seq, a_BlockPos.z)) % directions.size(); size_t index = static_cast<size_t>(a_Noise.IntNoise3DInt(a_BlockPos * a_Seq)) % directions.size();
return directions[index]; return directions[index];
} }
@ -1266,11 +1267,12 @@ void GetLargeJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s
{2, 1, 2}, {2, 0, 2}, // East face {2, 1, 2}, {2, 0, 2}, // East face
}; };
int Height = 20 + (a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 11) % 12; int Height = 10 + ((a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * a_Seq)) / 11) % 20); // 10 < Height < 29
a_LogBlocks.reserve(static_cast<size_t>(Height) * 4); a_LogBlocks.reserve(static_cast<size_t>(Height) * 4);
a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO5Jungle) + ARRAYCOUNT(BigO4Jungle) + ARRAYCOUNT(BigO3Jungle) + static_cast<size_t>(Height) * 4 + 50); a_OtherBlocks.reserve(2 * ARRAYCOUNT(BigO5Jungle) + ARRAYCOUNT(BigO4Jungle) + ARRAYCOUNT(BigO3Jungle) + static_cast<size_t>(Height) * 4 + 50);
// Generates the main trunk
for (int i = 0; i < Height; i++) for (int i = 0; i < Height; i++)
{ {
a_LogBlocks.push_back(sSetBlock(a_BlockPos.addedY(i), E_BLOCK_LOG, E_META_LOG_JUNGLE)); a_LogBlocks.push_back(sSetBlock(a_BlockPos.addedY(i), E_BLOCK_LOG, E_META_LOG_JUNGLE));
@ -1288,7 +1290,6 @@ void GetLargeJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s
a_OtherBlocks.push_back(sSetBlock(a_BlockPos.addedXZ(VinesTrunk[j].x, VinesTrunk[j].z).addedY(i), E_BLOCK_VINES, VinesTrunk[j].Meta)); a_OtherBlocks.push_back(sSetBlock(a_BlockPos.addedXZ(VinesTrunk[j].x, VinesTrunk[j].z).addedY(i), E_BLOCK_VINES, VinesTrunk[j].Meta));
} }
} }
int hei = a_BlockPos.y + Height - 2;
// Prevent floating trees by placing dirt under them // Prevent floating trees by placing dirt under them
for (int i = 1; i < 5; i++) for (int i = 1; i < 5; i++)
@ -1299,26 +1300,41 @@ void GetLargeJungleTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s
a_OtherBlocks.push_back(sSetBlock(a_BlockPos.addedY(-i).addedXZ(1, 1), E_BLOCK_DIRT, E_META_DIRT_NORMAL)); a_OtherBlocks.push_back(sSetBlock(a_BlockPos.addedY(-i).addedXZ(1, 1), E_BLOCK_DIRT, E_META_DIRT_NORMAL));
} }
int numBranches = (a_Noise.IntNoise2DInt(a_BlockPos.x * a_Seq, a_BlockPos.z * a_Seq) / 11) % 3 + 1; int NumBranches = std::max(
int branchStartHeight = 8 + Height % 11; (a_Noise.IntNoise2DInt(a_BlockPos.x * a_Seq, a_BlockPos.z * a_Seq) / 10) % 4, // The Original Calculation
int branchInterval = (Height - branchStartHeight) / numBranches; FloorC(Height / 10.0f) // Just to assure that no massive trees spawn with just one branch
for (int i = branchStartHeight; i < (Height - 6); i += branchInterval) );
int BranchStartHeight = 6 + Height % 5; // 6 < BranchStartHeight < 10
int BranchInterval = (Height - 6 - BranchStartHeight) / NumBranches;
for (int i = BranchStartHeight; i < (Height - 6); i += BranchInterval) // Stop 6 blocks before reaching the top
{ {
// Get a direction for the trunk to go to. // Get a direction for the trunk to go to.
Vector3d BranchStartDirection = pickBranchDirection(a_Noise, a_BlockPos.addedY(i), a_Seq); Vector3d BranchStartDirection = pickBranchDirection(a_Noise, a_BlockPos.addedY(i), a_Seq);
Vector3d BranchDirection = pickBranchDirection(a_Noise, a_BlockPos.addedY(i * a_Seq), a_Seq) / 3; Vector3d BranchDirection = pickBranchDirection(a_Noise, a_BlockPos.addedY(i * a_Seq), a_Seq) / 3;
int BranchLength = 2 + a_Noise.IntNoise3DInt(a_BlockPos * a_Seq) % 2; int BranchLength = 2 + a_Noise.IntNoise3DInt(a_BlockPos * a_Seq) % 2;
Vector3i BranchEndPosition = GetTreeBranch(E_BLOCK_LOG, E_META_LOG_JUNGLE, a_BlockPos.addedY(i), BranchLength, BranchStartDirection, BranchDirection, a_LogBlocks).Floor(); Vector3i BranchEndPosition = GetTreeBranch(E_BLOCK_LOG, E_META_LOG_JUNGLE, a_BlockPos.addedY(i), BranchLength, BranchStartDirection, BranchDirection, a_LogBlocks).Floor();
// There's a chance that there is a third leaf level on a branch
if ((a_Noise.IntNoise3DInt(a_BlockPos.x * a_Seq, a_BlockPos.y * a_Seq, a_BlockPos.z * a_Seq) % 4) == 0) // A quarter chance
{
PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y, BranchEndPosition.z, a_OtherBlocks, BigO3, ARRAYCOUNT(BigO3), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE);
PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y + 1, BranchEndPosition.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE);
PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y + 2, BranchEndPosition.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE);
a_OtherBlocks.push_back(sSetBlock(BranchEndPosition.x, BranchEndPosition.y + 2, BranchEndPosition.z, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE));
}
else
{
PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y, BranchEndPosition.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y, BranchEndPosition.z, a_OtherBlocks, BigO2, ARRAYCOUNT(BigO2), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE);
PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y + 1, BranchEndPosition.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); PushCoordBlocks(BranchEndPosition.x, BranchEndPosition.y + 1, BranchEndPosition.z, a_OtherBlocks, BigO1, ARRAYCOUNT(BigO1), E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE);
a_OtherBlocks.push_back(sSetBlock(BranchEndPosition.x, BranchEndPosition.y + 1, BranchEndPosition.z, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE)); a_OtherBlocks.push_back(sSetBlock(BranchEndPosition.x, BranchEndPosition.y + 1, BranchEndPosition.z, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE));
} }
}
// Place the canopy. // Place the canopy.
int CanopyHeight = a_BlockPos.y + Height - 2;
for (size_t i = 0; i < ARRAYCOUNT(BigOJungleLayers); i++) for (size_t i = 0; i < ARRAYCOUNT(BigOJungleLayers); i++)
{ {
PushCoordBlocks(a_BlockPos.x, hei++, a_BlockPos.z, a_OtherBlocks, BigOJungleLayers[i].Coords, BigOJungleLayers[i].Count, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE); PushCoordBlocks(a_BlockPos.x, CanopyHeight++, a_BlockPos.z, a_OtherBlocks, BigOJungleLayers[i].Coords, BigOJungleLayers[i].Count, E_BLOCK_LEAVES, E_META_LEAVES_JUNGLE);
} }
} }