Advertisement
WolfieMario

BatchReplace

Jun 26th, 2014
880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. # You may modify and distribute this filter however you wish,
  2. # but please give credit to WolfieMario.
  3.  
  4. displayName = "Batch Replace"
  5.  
  6. inputs = (
  7.     ("Batch block replacement filter by WolfieMario\n", "label"),
  8.     ("Usage: each conversion is a sequence of \"id:metadata\" values, separated by spaces. Conversions are separated by commas." +
  9.     " The final \"id:metadata\" value in a conversion represents what block to convert all preceding ones to." +
  10.     " For example, \"59:7 141:7 142:7 0, 2 110\" deletes all fully-grown wheat, potatoes, and carrots, and turns grass" +
  11.     " into mycelium. Note that the \":metadata\" is optional.", "label"),
  12.    
  13.     ("", ("string", "lines=5", "width=370", "value=")),
  14. )
  15.  
  16. def perform(level, box, options):
  17.     # Generate conversions
  18.     conversions = {}
  19.    
  20.     lines = options[""].split(",")
  21.     for l in lines:
  22.         tokens = l.split()
  23.         result = tokens.pop()
  24.         for t in tokens:
  25.             conversions[t] = result
  26.    
  27.     for x in xrange(box.minx, box.maxx):
  28.         for y in xrange(box.miny, box.maxy):
  29.             for z in xrange(box.minz, box.maxz):
  30.                 block = level.blockAt(x, y, z)
  31.                 data = level.blockDataAt(x, y, z)
  32.                
  33.                 key = str(block) + ":" + str(data)
  34.                 result = None
  35.                 if key in conversions:
  36.                     result = conversions[key]
  37.                 elif str(block) in conversions:
  38.                     result = conversions[str(block)]
  39.                
  40.                 if result:
  41.                     newData = result.split(":")
  42.                     level.setBlockAt(x, y, z, newData[0])
  43.                     if len(newData) > 1:
  44.                         level.setBlockDataAt(x, y, z, newData[1])
  45.    
  46.     level.markDirtyBox(box)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement