From 6e2642868a65c73965541278b2619b36e6757901 Mon Sep 17 00:00:00 2001 From: CobaltXII Date: Fri, 4 Jan 2019 17:40:16 -0500 Subject: [PATCH] Implemented void plant_tree_accessor --- src/inc/generator.hpp | 153 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/src/inc/generator.hpp b/src/inc/generator.hpp index a6b644c..548833d 100644 --- a/src/inc/generator.hpp +++ b/src/inc/generator.hpp @@ -1,6 +1,159 @@ #include #include +// 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 +#include + // Generate a world using a seed. void generate_world(world* out, unsigned int seed)