Skip to content

Commit

Permalink
Merge branch 'rozukke:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
johnathanchann authored Aug 14, 2024
2 parents 29916a5 + 4a369b8 commit 62a69a5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ project(mcpp)

set(CMAKE_CXX_STANDARD 17)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_FLAGS "-Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

set(MCPP_SRC_DIR src)
set(MCPP_INC_DIR include/mcpp)

Expand Down
7 changes: 7 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Examples
A few small examples to show the capabilities of `mcpp`.

They should be compilable with something along the lines of `g++ -std=c++17 -o example example.cpp -lmcpp`
after you have installed the library.

Feel free to open a PR if you have an interesting usecase to include as part of the examples.
43 changes: 43 additions & 0 deletions example/pyramid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <algorithm>
#include <mcpp/block.h>
#include <mcpp/mcpp.h>
#include <mcpp/util.h>

// Change location here
mcpp::Coordinate ORIGIN{0, 0, 0};
int PYRAMID_HEIGHT = 50;

// Can declare globally
mcpp::MinecraftConnection mc;

void make_ring(mcpp::Coordinate base_pt, int side_len) {
// Flat plane
mc.setBlocks(base_pt, base_pt + mcpp::Coordinate(side_len, 0, side_len),
mcpp::Blocks::SANDSTONE);

// Air inside to make border
base_pt = base_pt + mcpp::Coordinate(1, 0, 1);
mc.setBlocks(base_pt,
base_pt + mcpp::Coordinate(side_len - 2, 0, side_len - 2),
mcpp::Blocks::AIR);
}

int main() {
int pyramid_base_len = PYRAMID_HEIGHT * 2;

// Get heights of build area
mcpp::HeightMap heights =
mc.getHeights(ORIGIN, ORIGIN + mcpp::Coordinate(pyramid_base_len, 0,
pyramid_base_len));

// Use minimum height of the area as the lowest point on the pyramid
int min_height = *std::min_element(heights.begin(), heights.end());

// Build rings, diminishing up to pyramid height
mcpp::Coordinate base_pt = heights.base_pt();
base_pt.y = min_height;
int side_len = pyramid_base_len;
for (int i = 0; i < PYRAMID_HEIGHT; i++) {
make_ring(base_pt + mcpp::Coordinate(i, i, i), side_len - (i * 2));
}
}

0 comments on commit 62a69a5

Please sign in to comment.