Kopasz7

Biome tools

Oct 30th, 2012
1,375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.31 KB | None | 0 0
  1. from pymclevel import MCSchematic
  2. from pymclevel import TAG_Compound
  3. from pymclevel import TAG_Short
  4. from pymclevel import TAG_Byte
  5. from pymclevel import TAG_Byte_Array
  6. from pymclevel import TAG_String
  7. from numpy import zeros
  8. import random
  9.  
  10. displayName = "Biome tools"
  11.  
  12. inputs = (
  13.     ("Biome 1", ("Desert",
  14.                "Mushroom Island",
  15.                "Ocean",
  16.                "Plains",
  17.                "Mountains",
  18.                "Forest",
  19.                "Taiga",
  20.                "Swamp",
  21.                "River",
  22.                "Nether",
  23.                "Sky",
  24.                "Frozen Ocean",
  25.                "Frozen River",
  26.                "Ice Plains",
  27.                "Ice Mountains",
  28.                "Mushroom Shore",
  29.                "Beach",
  30.                "Desert Hills",
  31.                "Forest Hills",
  32.                "Taiga Hills",
  33.                "Mountains Edge",
  34.                "Jungle",
  35.                "Jungle Hills",
  36.                )),
  37.     ("Biome 2", ("Desert",
  38.                "Mushroom Island",
  39.                "Ocean",
  40.                "Plains",
  41.                "Mountains",
  42.                "Forest",
  43.                "Taiga",
  44.                "Swamp",
  45.                "River",
  46.                "Nether",
  47.                "Sky",
  48.                "Frozen Ocean",
  49.                "Frozen River",
  50.                "Ice Plains",
  51.                "Ice Mountains",
  52.                "Mushroom Shore",
  53.                "Beach",
  54.                "Desert Hills",
  55.                "Forest Hills",
  56.                "Taiga Hills",
  57.                "Mountains Edge",
  58.                "Jungle",
  59.                "Jungle Hills",
  60.                )),
  61.                ("Random", False),
  62.                ("Chance", (50, 0, 100)),
  63.                ("Outline check", False),
  64. )
  65.  
  66. biomes = {
  67.     "Ocean":0,
  68.     "Plains":1,
  69.     "Desert":2,
  70.     "Mountains":3,
  71.     "Forest":4,
  72.     "Taiga":5,
  73.     "Swamp":6,
  74.     "River":7,
  75.     "Nether":8,
  76.     "Sky":9,
  77.     "Frozen Ocean":10,
  78.     "Frozen River":11,
  79.     "Ice Plains":12,
  80.     "Ice Mountains":13,
  81.     "Mushroom Island":14,
  82.     "Mushroom Shore":15,
  83.     "Beach":16,
  84.     "Desert Hills":17,
  85.     "Forest Hills":18,
  86.     "Taiga Hills":19,
  87.     "Mountains Edge":20,
  88.     "Jungle":21,
  89.     "Jungle Hills":22,
  90.     }
  91.  
  92. def perform(level, box, options):
  93.     biome1 = biomes[options["Biome 1"]]
  94.     biome2 = biomes[options["Biome 2"]]
  95.     chance = options["Chance"]
  96.     opRandom = options["Random"]
  97.     opOutline = options["Outline check"]
  98.     if opRandom == True and opOutline == True:
  99.         createBiome = 1
  100.     elif opOutline:
  101.         createBiome = 2
  102.     elif opRandom:
  103.         createBiome = 3
  104.     else:
  105.         createBiome = 4
  106.     minx = int(box.minx/16)*16
  107.     minz = int(box.minz/16)*16
  108.  
  109.     for x in xrange(minx, box.maxx, 16):
  110.         for z in xrange(minz, box.maxz, 16):
  111.             chunk = level.getChunk(x / 16, z / 16)
  112.             chunk.decompress()
  113.             chunk.dirty = True
  114.             array = chunk.root_tag["Level"]["Biomes"].value
  115.  
  116.             chunkx = int(x/16)*16
  117.             chunkz = int(z/16)*16
  118.  
  119.             for bx in xrange(max(box.minx, chunkx), min(box.maxx, chunkx+16)):
  120.                 for bz in xrange(max(box.minz, chunkz), min(box.maxz, chunkz+16)):
  121.                     idx = 16*(bz-chunkz)+(bx-chunkx)
  122.                     if createBiome == 1:
  123.                         randomOutline(level, box, options, bx, y, bz, chance, array, idx, biome1, biome2)
  124.                     elif createBiome == 2:
  125.                         OutlineBiome(level, box, options, bx, bz, array, idx, biome1)
  126.                     elif createBiome == 3:
  127.                         randomBiome(level, box, options, chance, array, idx, biome1, biome2)
  128.                     else:
  129.                         setBiome(level, box, options, array, idx, biome1)
  130.             chunk.root_tag["Level"]["Biomes"].value = array
  131.  
  132. def randomGen():
  133.     return int(random.random() * 99) + 1
  134.  
  135. def OutlineBiome(level, box, options, bx, bz, array, idx, biome1):
  136.     ground = 0
  137.     for y in xrange(box.miny, box.maxy):
  138.         if level.blockAt(bx, y, bz) != 0:
  139.             ground = 1
  140.             break
  141.     if ground:
  142.         array[idx] = biome1
  143.  
  144. def randomBiome(level, box, options, chance, array, idx, biome1, biome2):
  145.     if randomGen() <= chance:
  146.         array[idx] = biome1
  147.     else:
  148.         array[idx] = biome2
  149.  
  150. def randomOutline(level, box, options, bx, y, bz, chance, array, idx, biome1, biome2):
  151.     for y in xrange(box.miny, box.maxy):
  152.         if level.blockAt(bx, y, bz) != 0:
  153.             ground = 1
  154.             break
  155.     if ground:
  156.         if randomGen() <= chance:
  157.             array[idx] = biome1
  158.         else:
  159.             array[idx] = biome2
  160.  
  161. def setBiome(level, box, options, array, idx, biome1):
  162.     array[idx] = biome1
Advertisement
Add Comment
Please, Sign In to add comment