# Feel free to modify and use this filter however you wish. If you do,
# please give credit to SethBling.
# http://youtube.com/SethBling

from pymclevel import TAG_List
from pymclevel import TAG_Byte
from pymclevel import TAG_Int
from pymclevel import TAG_Compound
from pymclevel import TAG_Short
from pymclevel import TAG_Double
from pymclevel import TAG_String

displayName = "Change Spawner Properties"

inputs = (("Min Spawn Delay", 600),
		  ("Max Spawn Delay", 1200),
		  ("Current Spawn Delay", 120),
		  ("Spawn Count", 1),
		  ("Entity Cap", 6),
		  ("Detection Range", 16),
		  )

def perform(level, box, options):

	for (chunk, slices, point) in level.getChunkSlices(box):
		for e in chunk.TileEntities:
			if e["id"].value == "MobSpawner":
				x = e["x"].value
				y = e["y"].value
				z = e["z"].value
				
				if x >= box.minx and x < box.maxx and y >= box.miny and y < box.maxy and z >= box.minz and z < box.maxz:
					e["SpawnCount"] = TAG_Short(options["Spawn Count"])
					e["MinSpawnDelay"] = TAG_Short(options["Min Spawn Delay"])
					e["MaxSpawnDelay"] = TAG_Short(options["Max Spawn Delay"])
					e["Delay"] = TAG_Short(options["Current Spawn Delay"])
					e["MaxNearbyEntities"] = TAG_Short(options["Entity Cap"])
					e["RequiredPlayerRange"] = TAG_Short(options["Detection Range"])
					print e["EntityId"].value + " spawner at (" + str(x) + ", " + str(y) + ", " + str(z) + ") modified"
					chunk.dirty = True
