Hardware Reference
In-Depth Information
11. Start a nested for loop that reads out the next line in the file and splits it when-
ever there is a comma. Be careful of the indentation here; the for has to be
indented two levels (one for the function and one for the for y loop) and the
code inside this for x loop needs to be indented three levels.
for x in range(sizex):
line = lines[lineidx]
lineidx = lineidx + 1
data = line.split(",")
12. Now start your third for loop that scans through each of the blocks in the line
just read and builds them inside Minecraft. The for z loop is indented three
levels and the body of the loop is indented four times so take very special care
of the indentation; otherwise you will end up with some very strange-shaped
objects!
for z in range(sizez):
blockid = int(data[z])
mc.setBlock(originx+x, originy+y, originz+z, blockid)
13. Finally, type in the lines of the main program, which are not indented at all.
These lines read the player position and then ask the print3D() function to
print your 3D object just to the side of where you are standing:
pos = mc.player.getTilePos()
print3D(FILENAME, pos.x+1, pos.y, pos.z+1)
Save your program and run it to see what happens! Run around to different locations
inside Minecraft and run the program. Every time you run the program, a hollow stone
cave should be built just near your player! FigureĀ 6-5 shows how easy it is to build lots
of stone caves very quickly.
CHALLENGE
Create some more CSV files with 3D objects in them, change the FILENAME
constant in the print3D.py program and run it to stamp your objects all over
your Minecraft world. As your objects become more sophisticated, think of
some different ways that you could design them before entering the numbers
into the file. You might find some way of drawing the objects in a spreadsheet
program. Or perhaps you could even buy a big box of plastic construction bricks
and design your objects in the physical world first, then take them apart layer by
layer and enter the block numbers into your CSV file.
Search WWH ::




Custom Search