Hardware Reference
In-Depth Information
4. Create some constants for the name of the CSV file you want to scan to and the
size of the area that you want to scan:
FILENAME = "tree.csv"
SIZEX = 5
SIZEY = 5
SIZEZ = 5
5. Define a scan3D() function. You will use this function in a later program, so
make sure it is named correctly:
def scan3D(filename, originx, originy, originz):
6. Open the file, but this time open it in write mode using the "w" file mode inside
the open() function:
f = open(filename, "w")
7. The first line of the file has to contain the metadata, so write the x y and z sizes
in the first line. See Digging into the Code to understand what the "\n" at the
end of the line is and why you need it.
f.write(str(SIZEX) + "," + str(SIZEY) + "," + str(SIZEZ)
+ "\n")
8. The scanner program is just the reverse of the printing program, again using
three nested loops. Here is this part of the program all in one go, so that it is easy
for you to get the indents correct. See Digging into the Code for an explanation
of how the comma-separated lines are created:
for y in range(SIZEY):
f.write("\n")
for x in range(SIZEX):
line = ""
for z in range(SIZEZ):
blockid = mc.getBlock(originx+x, originy+y,
originz+z)
if line != "":
line = line + ","
line = line + str(blockid)
f.write(line + "\n")
f.close()
9. Finally, the main program is not indented at all. This just reads the player position,
then calculates a cube space, where the player is standing at the centre of that
space, and asks the scan3D() function to scan that whole space to your CSV file.
pos = mc.player.getTilePos()
scan3D(FILENAME, pos.x-(SIZEX/2), pos.y, pos.z-(SIZEZ/2))
 
Search WWH ::




Custom Search