Skip to content

Instantly share code, notes, and snippets.

@Azenet
Created March 24, 2013 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azenet/5231247 to your computer and use it in GitHub Desktop.
Save Azenet/5231247 to your computer and use it in GitHub Desktop.
Modification of SethBling's filter Find And Replace.
# coding unicode-escape
# 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
import re
displayName = "Find and Replace"
inputs = (
("Find", "string"),
("Replace", "string"),
("Case sensitive", False)
)
def perform(level, box, options):
find = options["Find"]
replace = options["Replace"]
isCaseSensitive = options["Case sensitive"]
for (chunk, slices, point) in level.getChunkSlices(box):
for t in chunk.TileEntities:
x = t["x"].value
y = t["y"].value
z = t["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:
if t["id"].value == "Sign":
for l in range(1, 5):
line = t["Text" + str(l)].value
if isCaseSensitive:
newline = line.replace(find, replace)
else:
newline_regex = re.compile(re.escape(find), re.IGNORECASE)
newline = newline_regex.sub(replace, line)
if line != newline:
t["Text" + str(l)] = TAG_String(newline)
chunk.dirty = True
if t["id"].value == "Control":
cmd = t["Command"].value
newcmd = cmd.replace(find, replace)
if isCaseSensitive:
newline = line.replace(find, replace)
else:
newline_regex = re.compile(re.escape(find), re.IGNORECASE)
newline = newline_regex.sub(replace, line)
if newcmd != cmd:
t["Command"] = TAG_String(newcmd)
chunk.dirty = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment