Advertisement
WolfieMario

BatchReplace.py

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