diff --git a/include/mcpp/mcpp.h b/include/mcpp/mcpp.h index a6ecbce..bb3e9b9 100644 --- a/include/mcpp/mcpp.h +++ b/include/mcpp/mcpp.h @@ -125,19 +125,18 @@ class MinecraftConnection { Chunk getBlocks(const Coordinate& loc1, const Coordinate& loc2); /** - * @brief Returns the height of the specific provided x and z coordinate + * @brief Returns the height of the specific provided 2D coordinate * * ***IMPORTANT:*** * DO NOT USE FOR LARGE AREAS, IT WILL BE VERY SLOW * USE getHeights() INSTEAD * - * Gets the y-value of the highest non-air block at the specified (x, z) + * Gets the y-value of the highest non-air block at the specified 2D * coordinate. - * @param x - * @param z + * @param loc 2D coordinate * @return Returns the integer y-height at the requested coordinate. */ - int getHeight(int x, int z); + int getHeight(Coordinate2D loc); /** * @brief Provides a scaled option of the getHeight call to allow for @@ -145,10 +144,11 @@ class MinecraftConnection { * * \par USE THIS instead of getHeight in a for loop. * - * @param loc1 - * @param loc2 + * @param loc1 1st corner of rectangle + * @param loc2 2nd corner of rectangle * @return Returns a vector of integers representing the 2D area of heights. */ - const HeightMap getHeights(const Coordinate& loc1, const Coordinate& loc2); + const HeightMap getHeights(const Coordinate2D& loc1, + const Coordinate2D& loc2); }; } // namespace mcpp diff --git a/include/mcpp/util.h b/include/mcpp/util.h index e738d8c..6a819ff 100644 --- a/include/mcpp/util.h +++ b/include/mcpp/util.h @@ -451,7 +451,7 @@ struct HeightMap { Iterator begin() { return Iterator(&raw_heights[0]); } Iterator end() { return Iterator(&raw_heights[_x_len * _z_len]); } - HeightMap(const Coordinate& loc1, const Coordinate& loc2, + HeightMap(const Coordinate2D& loc1, const Coordinate2D& loc2, const std::vector& heights); ~HeightMap(); @@ -469,10 +469,10 @@ struct HeightMap { /** * Get the height at a Minecraft coordinate if saved inside the height map - * @param loc: Coordinate in Minecraft world to access in the map + * @param loc: 2D coordinate in Minecraft world to access in the map * @return: height at specified coordinate */ - int get_worldspace(const Coordinate& loc) const; + int get_worldspace(const Coordinate2D& loc) const; /** * Fill a coordinate inplace with the highest y coordinate at the `loc`'s x @@ -494,13 +494,13 @@ struct HeightMap { int z_len() const; /** - * Gets the minimum coordinate in the HeightMap. - * @return the minimum coordinate in the HeightMap. + * Gets the minimum 2D coordinate in the HeightMap. + * @return the minimum 2D coordinate in the HeightMap. */ - Coordinate base_pt() const; + Coordinate2D base_pt() const; private: - Coordinate _base_pt; + Coordinate2D _base_pt; int _x_len; int _z_len; int* raw_heights; diff --git a/src/mcpp.cpp b/src/mcpp.cpp index cacad72..4bf6cdb 100644 --- a/src/mcpp.cpp +++ b/src/mcpp.cpp @@ -112,13 +112,14 @@ Chunk MinecraftConnection::getBlocks(const Coordinate& loc1, return Chunk{loc1, loc2, result}; } -int MinecraftConnection::getHeight(int x, int z) { - std::string returnValue = conn->sendReceiveCommand("world.getHeight", x, z); +int MinecraftConnection::getHeight(Coordinate2D loc) { + std::string returnValue = + conn->sendReceiveCommand("world.getHeight", loc.x, loc.z); return stoi(returnValue); } -const HeightMap MinecraftConnection::getHeights(const Coordinate& loc1, - const Coordinate& loc2) { +const HeightMap MinecraftConnection::getHeights(const Coordinate2D& loc1, + const Coordinate2D& loc2) { std::string returnValue = conn->sendReceiveCommand( "world.getHeights", loc1.x, loc1.z, loc2.x, loc2.z); diff --git a/src/util.cpp b/src/util.cpp index 9c47d88..e1c0f75 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -156,7 +156,7 @@ int Chunk::z_len() const { return this->_z_len; } Coordinate Chunk::base_pt() const { return this->_base_pt.clone(); } -HeightMap::HeightMap(const Coordinate& loc1, const Coordinate& loc2, +HeightMap::HeightMap(const Coordinate2D& loc1, const Coordinate2D& loc2, const std::vector& heights) { _base_pt = Coordinate{ std::min(loc1.x, loc2.x), @@ -203,7 +203,7 @@ int HeightMap::get(int x, int z) const { return raw_heights[x * _z_len + z]; } -int HeightMap::get_worldspace(const Coordinate& loc) const { +int HeightMap::get_worldspace(const Coordinate2D& loc) const { return get(loc.x - _base_pt.x, loc.z - _base_pt.z); } @@ -215,6 +215,6 @@ int HeightMap::x_len() const { return this->_x_len; } int HeightMap::z_len() const { return this->_z_len; } -Coordinate HeightMap::base_pt() const { return this->_base_pt.clone(); } +Coordinate2D HeightMap::base_pt() const { return this->_base_pt.clone(); } } // namespace mcpp