11#include " ../include/mcpp/mcpp.h"
2- #include " ../include/mcpp/util.h"
3-
4- #include < string_view>
52#include < string>
63#include < vector>
74
@@ -41,20 +38,20 @@ namespace mcpp {
4138 }
4239
4340 Coordinate MinecraftConnection::getPlayerPosition () {
44- // TODO remove currently required empty string that ensures formatting
41+ // TODO remove currently required empty string that ensures formatting
4542 std::string returnString = conn->sendReceiveCommand (" player.getPos" , " " );
4643 std::vector<int > parsedInts;
4744 splitCommaStringToInts (returnString, parsedInts);
4845 return Coordinate (parsedInts[0 ], parsedInts[1 ], parsedInts[2 ]);
4946 }
5047
51- // TODO tile variants of getPos and setPos
48+ // TODO tile variants of getPos and setPos
5249
5350
5451 void MinecraftConnection::setBlock (const Coordinate& loc,
5552 const BlockType& blockType) {
5653 conn->sendCommand (" world.setBlock" , loc.x , loc.y , loc.z , blockType.id ,
57- blockType.data );
54+ blockType.data );
5855 }
5956
6057
@@ -64,13 +61,13 @@ namespace mcpp {
6461 auto [x, y, z] = loc1;
6562 auto [x2, y2, z2] = loc2;
6663 conn->sendCommand (" world.setBlocks" , x, y, z, x2, y2, z2, blockType.id ,
67- blockType.data );
64+ blockType.data );
6865 }
6966
7067
7168 BlockType MinecraftConnection::getBlock (const Coordinate& loc) {
7269 std::string returnValue = conn->sendReceiveCommand (" world.getBlock" ,
73- loc.x , loc.y , loc.z );
70+ loc.x , loc.y , loc.z );
7471 return {std::stoi (returnValue)};
7572 }
7673
@@ -81,7 +78,7 @@ namespace mcpp {
8178 std::vector<int > parsedInts;
8279 splitCommaStringToInts (returnString, parsedInts);
8380
84- // data and id
81+ // Data and id
8582 return {parsedInts[0 ], parsedInts[1 ]};
8683 }
8784
@@ -90,10 +87,10 @@ namespace mcpp {
9087 MinecraftConnection::getBlocks (const Coordinate& loc1,
9188 const Coordinate& loc2) {
9289 std::string returnValue = conn->sendReceiveCommand (" world.getBlocks" ,
93- loc1.x , loc1.y ,
94- loc1.z ,
95- loc2.x , loc2.y ,
96- loc2.z );
90+ loc1.x , loc1.y ,
91+ loc1.z ,
92+ loc2.x , loc2.y ,
93+ loc2.z );
9794 std::stringstream ss (returnValue);
9895 std::string container;
9996 std::vector<BlockType> returnVector;
@@ -106,15 +103,15 @@ namespace mcpp {
106103 }
107104
108105
109- std::vector<std::vector<std::vector<BlockType>>>
106+ std::vector<std::vector<std::vector<BlockType>>>
110107 MinecraftConnection::getBlocksWithData (
111108 const Coordinate& loc1, const Coordinate& loc2) {
112109 std::string returnValue = conn->sendReceiveCommand (
113110 " world.getBlocksWithData" ,
114111 loc1.x , loc1.y , loc1.z ,
115112 loc2.x , loc2.y , loc2.z );
116113
117- // received in format 1,2;1,2;1,2 where 1,2 is a block of type 1 and data 2
114+ // Received in format 1,2;1,2;1,2 where 1,2 is a block of type 1 and data 2
118115 std::vector<BlockType> result;
119116 std::stringstream stream (returnValue);
120117
@@ -141,17 +138,17 @@ namespace mcpp {
141138
142139 int MinecraftConnection::getHeight (int x, int z) {
143140 std::string returnValue = conn->sendReceiveCommand (" world.getHeight" , x,
144- z);
141+ z);
145142 return stoi (returnValue);
146143 }
147144
148145
149- std::vector<std::vector<int >>
146+ std::vector<std::vector<int >>
150147 MinecraftConnection::getHeights (const Coordinate& loc1,
151- const Coordinate& loc2) {
148+ const Coordinate& loc2) {
152149 std::string returnValue = conn->sendReceiveCommand (" world.getHeights" ,
153- loc1.x , loc1.z ,
154- loc2.x , loc2.z );
150+ loc1.x , loc1.z ,
151+ loc2.x , loc2.z );
155152
156153 // Returned in format "1,2,3,4,5"
157154 std::vector<int > returnVector;
@@ -164,56 +161,53 @@ namespace mcpp {
164161 std::vector<std::vector<std::vector<BlockType>>>
165162 MinecraftConnection::unflattenBlocksArray (const Coordinate& loc1,
166163 const Coordinate& loc2,
167- const std::vector<BlockType>& inVector)
168- {
169- // initialise empty vector of correct size and shape
164+ const std::vector<BlockType>& inVector) {
165+ // Initialise empty vector of correct size and shape
170166 int y_len = abs (loc2.y - loc1.y ) + 1 ;
171167 int x_len = abs (loc2.x - loc1.x ) + 1 ;
172168 int z_len = abs (loc2.z - loc1.z ) + 1 ;
173- std::vector<std::vector<std::vector<BlockType>>> returnVector (
174- y_len,
175- std::vector<std::vector<BlockType>> (
176- x_len,
177- std::vector<BlockType> (
178- z_len,
179- BlockType (0 )
169+ std::vector<std::vector<std::vector<BlockType>>> returnVector (
170+ y_len,
171+ std::vector<std::vector<BlockType>>(
172+ x_len,
173+ std::vector<BlockType>(
174+ z_len,
175+ BlockType (0 )
176+ )
180177 )
181- )
182178 );
183179
184180 int index = 0 ;
185- for (int y=0 ; y < y_len; y++) {
186- for (int x=0 ; x < x_len; x++) {
187- for (int z=0 ; z < z_len; z++)
188- {
181+ for (int y = 0 ; y < y_len; y++) {
182+ for (int x = 0 ; x < x_len; x++) {
183+ for (int z = 0 ; z < z_len; z++) {
189184 returnVector[y][x][z] = inVector[index];
190185 index++;
191186 }
192187 }
193188 }
194189
195- return returnVector;
190+ return returnVector;
196191 }
197192
198193 std::vector<std::vector<int >>
199- MinecraftConnection::unflattenHeightsArray (const Coordinate& loc1, const Coordinate& loc2, const std::vector< int >& inVector)
200- {
201- // initialise empty vector of correct size and shape
194+ MinecraftConnection::unflattenHeightsArray (const Coordinate& loc1, const Coordinate& loc2,
195+ const std::vector< int >& inVector) {
196+ // Initialise empty vector of correct size and shape
202197 int x_len = abs (loc2.x - loc1.x ) + 1 ;
203198 int z_len = abs (loc2.z - loc1.z ) + 1 ;
204199
205- std::vector<std::vector<int >> returnVector (
206- x_len,
207- std::vector<int > (
208- z_len,
209- 0
210- )
200+ std::vector<std::vector<int >> returnVector (
201+ x_len,
202+ std::vector<int >(
203+ z_len,
204+ 0
205+ )
211206 );
212207
213208 int index = 0 ;
214- for (int x=0 ; x < x_len; x++) {
215- for (int z=0 ; z < z_len; z++)
216- {
209+ for (int x = 0 ; x < x_len; x++) {
210+ for (int z = 0 ; z < z_len; z++) {
217211 returnVector[x][z] = inVector[index];
218212 index++;
219213 }
0 commit comments