Implemented void plant_tree_accessor

This commit is contained in:
CobaltXII
2019-01-04 17:40:16 -05:00
parent 5ac171d361
commit 6e2642868a

View File

@@ -1,6 +1,159 @@
#include <tuple>
#include <vector>
// Plant a tree.
void plant_tree_accessor(accessor* out, hitbox player, unsigned int x, unsigned int y, unsigned int z, block_id tree_leaf, block_id tree_log)
{
// It's grass, we may plant a tree if there are enough
// blocks available above the grass.
if (rand() % 2 == 0)
{
// Original tree.
if (!out->the_world->in_bounds(x, y - 6, z))
{
return;
}
// This is the trunk.
out->set_id_safe_if_air(x, y - 1, z, tree_log);
out->set_id_safe_if_air(x, y - 2, z, tree_log);
out->set_id_safe_if_air(x, y - 3, z, tree_log);
out->set_id_safe_if_air(x, y - 4, z, tree_log);
out->set_id_safe_if_air(x, y - 5, z, tree_log);
// This is the cross at the top.
out->set_id_safe_if_air(x, y - 6, z, tree_leaf);
out->set_id_safe_if_air(x - 1, y - 6, z, tree_leaf);
out->set_id_safe_if_air(x + 1, y - 6, z, tree_leaf);
out->set_id_safe_if_air(x, y - 6, z - 1, tree_leaf);
out->set_id_safe_if_air(x, y - 6, z + 1, tree_leaf);
// This is the square at the layer second from the
// top.
for (int j = -1; j <= 1; j++)
{
for (int k = -1; k <= 1; k++)
{
if (j == 0 && k == 0)
{
continue;
}
out->set_id_safe_if_air(x + j, y - 5, z + k, tree_leaf);
}
}
// These are the squares at the third and fourth
// layer from the top.
for (int j = -2; j <= 2; j++)
{
for (int k = -2; k <= 2; k++)
{
if (j == 0 && k == 0)
{
continue;
}
out->set_id_safe_if_air(x + j, y - 4, z + k, tree_leaf);
out->set_id_safe_if_air(x + j, y - 3, z + k, tree_leaf);
}
}
}
else
{
// Rounded tree.
if (!out->the_world->in_bounds(x, y - 7, z))
{
return;
}
// This is the trunk.
out->set_id_safe_if_air(x, y - 1, z, tree_log);
out->set_id_safe_if_air(x, y - 2, z, tree_log);
out->set_id_safe_if_air(x, y - 3, z, tree_log);
out->set_id_safe_if_air(x, y - 4, z, tree_log);
out->set_id_safe_if_air(x, y - 5, z, tree_log);
out->set_id_safe_if_air(x, y - 6, z, tree_log);
// This is the cross at the top.
out->set_id_safe_if_air(x, y - 7, z, tree_leaf);
out->set_id_safe_if_air(x - 1, y - 7, z, tree_leaf);
out->set_id_safe_if_air(x + 1, y - 7, z, tree_leaf);
out->set_id_safe_if_air(x, y - 7, z - 1, tree_leaf);
out->set_id_safe_if_air(x, y - 7, z + 1, tree_leaf);
// This is the square at the layer second from the
// top.
for (int j = -1; j <= 1; j++)
{
for (int k = -1; k <= 1; k++)
{
if (j == 0 && k == 0)
{
continue;
}
out->set_id_safe_if_air(x + j, y - 6, z + k, tree_leaf);
}
}
// These are the squares at the third and fourth
// layer from the top.
for (int j = -2; j <= 2; j++)
{
for (int k = -2; k <= 2; k++)
{
if (j == 0 && k == 0)
{
continue;
}
out->set_id_safe_if_air(x + j, y - 5, z + k, tree_leaf);
out->set_id_safe_if_air(x + j, y - 4, z + k, tree_leaf);
}
}
// This is the square at the fifth layer from the top.
// It has it's corners removed.
for (int j = -2; j <= 2; j++)
{
for (int k = -2; k <= 2; k++)
{
if (j == 0 && k == 0)
{
continue;
}
else if ((j == 2 && k == 2) || (j == 2 && k == -2) || (j == -2 && k == 2) || (j == -2 && k == -2))
{
continue;
}
out->set_id_safe_if_air(x + j, y - 3, z + k, tree_leaf);
}
}
}
}
#include <tuple>
#include <vector>
// Generate a world using a seed.
void generate_world(world* out, unsigned int seed)