# This will leave the top X layers of the selected area. # The area underneath will be set to Air or what the user chooses. # copied from topsoil.py - all credit to codewarrior0 (assuming he is the author) from numpy import zeros import itertools from pymclevel import alphaMaterials from pymclevel.level import extractHeights am = alphaMaterials #naturally occuring materials blocks = [ am.Grass, am.Dirt, am.Stone, am.Bedrock, am.Sand, am.Gravel, am.GoldOre, am.IronOre, am.CoalOre, am.LapisLazuliOre, am.DiamondOre, am.RedstoneOre, am.RedstoneOreGlowing, am.Netherrack, am.SoulSand, am.Clay, am.Glowstone ] blocktypes = [b.ID for b in blocks] def naturalBlockmask(): blockmask = zeros((256,), dtype='bool') blockmask[blocktypes] = True return blockmask inputs = ( ("Layers to keep", (1, 1, 128)), ("Fill under with:", alphaMaterials.Air), ) def perform(level, box, options): depth = options["Layers to keep"] blocktype = options["Fill under with:"] #compute a truth table that we can index to find out whether a block # is naturally occuring and should be considered in a heightmap blockmask = naturalBlockmask() #iterate through the slices of each chunk in the selection box for chunk, slices, point in level.getChunkSlices(box): # slicing the block array is straightforward. blocks will contain only # the area of interest in this chunk. blocks = chunk.Blocks[slices] data = chunk.Data[slices] # use indexing to look up whether or not each block in blocks is # naturally-occuring. these blocks will "count" for column height. maskedBlocks = blockmask[blocks] heightmap = extractHeights(maskedBlocks) for x, z in itertools.product(*map(xrange, heightmap.shape)): h = heightmap[x, z] # Take 'lowest point' through 'naturally occuring' # then subtract users 'depth' input and set it all as air blocks[x, z, 0:(h - depth)] = blocktype.ID data[x, z, 0:(h - depth)] = blocktype.blockData #remember to do this to make sure the chunk is saved chunk.chunkChanged()