import math displayName = "Realistic Cave Lighting" inputs = ( ("Minimum Lighting Level", (8, 1, 14)), ("Only Light Spawnable Areas", True) ) TransparentBlocks = [0, 6, 8, 9, 10, 11, 18, 20, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 44, 46, 50, 51, 52, 53, 54, 55, 59, 60, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 75, 76, 77, 78, 79, 81, 83, 85, 89, 90, 92, 93, 94, 95, 96, 97, 101, 102, 104, 105, 106, 107, 108, 109, 111, 113, 114, 115, 116, 117, 118, 119, 120, 122, 126, 127] levelObj = None boxObj = None totalTorches = 1 totalX = 1 totalZ = 1 xDiff = 1 zDiff = 1 def perform(level, box, options): global levelObj, totalX, totalZ, xDiff, zDiff levelObj = level boxObj = box print(type(boxObj)) minLightingLevel = options["Minimum Lighting Level"] lightSpawns = options["Only Light Spawnable Areas"] totalX = box.maxx totalZ = box.maxz xDiff = box.maxx - box.minx zDiff = box.maxz - box.minz for x in xrange(box.minx, box.maxx): for z in xrange(box.minz, box.maxz): for y in reversed(xrange(box.miny, box.maxy)): block = level.blockAt(x, y, z) blockLight = level.blockLightAt(x, y, z) # If our current block is air, and less than the specified lighting level if (block == 0 and blockLight < minLightingLevel): if (lightSpawns): blockAbove = level.blockAt(x, y + 1, z) blockBelow = level.blockAt(x, y - 1, z) if (blockAbove == 0 and blockBelow not in TransparentBlocks): placeTorchNearby(x, y, z) else: placeTorchNearby(x, y, z) print 'Done!' def placeTorchNearby(x, y, z): torchDir = 1 supportBlock = levelObj.blockAt(x - 1, y, z) if (supportBlock not in TransparentBlocks): placeTorch(x, y, z, torchDir) return torchDir += 1 supportBlock = levelObj.blockAt(x + 1, y, z) if (supportBlock not in TransparentBlocks): placeTorch(x, y, z, torchDir) return torchDir += 1 supportBlock = levelObj.blockAt(x, y, z - 1) if (supportBlock not in TransparentBlocks): placeTorch(x, y, z, torchDir) return torchDir += 1 supportBlock = levelObj.blockAt(x, y, z + 1) if (supportBlock not in TransparentBlocks): placeTorch(x, y, z, torchDir) return torchDir += 1 supportBlock = levelObj.blockAt(x, y - 1, z) if (supportBlock not in TransparentBlocks): placeTorch(x, y, z, torchDir) return def placeTorch(x, y, z, direction): global totalTorches levelObj.setBlockAt(x, y, z, 50) levelObj.setBlockDataAt(x, y, z, direction) levelObj.generateLights() output = round(float(x) / totalX * 100) print 'Torch num ' + str(totalTorches) + ' Placed! ' + str(output) + '%' totalTorches += 1