What does it mean to be a 21st Century Teacher… well, that’s a short and a long answer all wrapped up together. A bit like trying to find the printer cable in the box of cables that somewhere are attached to some interesting devices. The short answer is lots of change becoming lots of exciting new horizons! Continue reading
When automatically generating landscapes in Minecraft, it seems easy to get large flat areas by just using the setBlocks() part of the API, but what I wanted was depth, height and texture. I’d seen methods of using bump maps in 3d software, so I wondered if similar techniques could be used. After a bit of searching I came across the fantastic maps-for-free website which has a whole earth view in relief map format – and free, too! (Permission is granted to copy, distribute and/or modify the relief maps and the water layer under the terms of the GNU Free Documentation license, Version 1.2 or any later version published by the Free Software Foundation.).
I quickly copied a section, converted it into a JPEG file of reasonable dimensions and re-coloured the sea so that it was the darkest area. In order to simply convert this into a file that Python can use, I cheated and used jp2a again. This converts images into a set of ASCII characters. I read this into a Python and convert into a list The python program works its way through the list and using setBlocks() creates a stack of blocks whose height is related to the intensity of the image at that point. What’s really pleasing is how well the final landform came out. It’s possible to see the high lands of Dartmoor and Exmoor, Snowdonia and further North, as well as the flat areas of the Norfolk Broads (forgive me if my geography is a bit dodgy… they did try to sort me out at school!).
from mcpi import minecraft import commands mc = minecraft.Minecraft.create() mc.postToChat("Python is now in control!") #Output from jp2a: Default is " ...',;:clodxkO0KXNWM" #jp2a 18 values jp2ascale=" ",".","'",",",";",":","c","l","o","d","x","k","O","0","K","X","N","W","M" mcscale=80,82,79,1,4,98,98,98,98,98,98,98,98,98,14,15,16,17,49,98 blockset=8,82,79,1,4,98,98,98,98,98,98,98,98,98,14,15,16,17,49,98 wr_str = "ukmap.jpg" cmd = 'jp2a --width=255 --height=255 '+wr_str # create an operating system command line = commands.getoutput( cmd ) # send cmd as a command to the operating system and receive the result. list_line = line.rstrip().split("\n") # split the result from "figlet" into separate lines (right strip new line feeds) print "Your picture has been converted to" print line #list_line=" ...',;:clodxkO0KXNWM"," ...',;:clodxkO0KXNWM"," ...',;:clodxkO0KXNWM"," ...',;:clodxkO0KXNWM" startx,starty,startz = mc.player.getPos() #get the player's position startx=128 starty=-1 startz=128 for row in list_line: # one row at a time from list_line (the result from figlet) startz=startz-1 # work down from the top column=0 for letter in row: # work along each row - check each character. If it's a "#" then print a block else leave it as air column = column+1 blockheight=jp2ascale.index(letter) blocktype=blockset[blockheight] mc.setBlocks(startx-column,starty,startz,startx-column,starty+blockheight,startz,blocktype) print("All done!")