This repository has been archived on 2024-06-13. You can view files and clone it, but cannot push or open issues or pull requests.
mcedit/filters/CreateSpawners.py
2012-10-25 00:09:56 -10:00

49 lines
1.4 KiB
Python

# 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_Compound
from pymclevel import TAG_Int
from pymclevel import TAG_Short
from pymclevel import TAG_Byte
from pymclevel import TAG_String
from pymclevel import TAG_Float
from pymclevel import TAG_Double
from pymclevel import TAG_List
from pymclevel import TileEntity
displayName = "Create Spawners"
inputs = (
("Include position data", False),
)
def perform(level, box, options):
includePos = options["Include position data"]
entitiesToRemove = []
for (chunk, slices, point) in level.getChunkSlices(box):
for entity in chunk.Entities:
x = int(entity["Pos"][0].value)
y = int(entity["Pos"][1].value)
z = int(entity["Pos"][2].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:
entitiesToRemove.append((chunk, entity))
level.setBlockAt(x, y, z, 52)
spawner = TileEntity.Create("MobSpawner")
TileEntity.setpos(spawner, (x, y, z))
spawner["Delay"] = TAG_Short(120)
spawner["SpawnData"] = entity
if not includePos:
del spawner["SpawnData"]["Pos"]
spawner["EntityId"] = entity["id"]
chunk.TileEntities.append(spawner)
for (chunk, entity) in entitiesToRemove:
chunk.Entities.remove(entity)