Jason Scheirer avatar Jason Scheirer committed ec44b4f

Create resources

Comments (0)

Files changed (1)

 #! /usr/bin/env python
 
 import argparse
+import random
 
 import pymclevel
 
 import streets
 import gridder
 
+materials = pymclevel.namedMaterials['Alpha']
+
 class City(object):
     def __init__(self, grid, world, radius, block_length):
         self.grid = grid
         self.radius = radius
         self.block_length = block_length
         self.world_side_length = (((radius + 2) * 10) +
-                                   ((radius + 2) * 2 * block_length))
+                                   ((radius) * 2 * block_length))
         self.mclevel = pymclevel.mclevel.MCInfdevOldLevel(self.output,
-                create=True)
+                                                          create=True)
     def make_grass(self):
-        materials = pymclevel.namedMaterials['Alpha']
         Bedrock = materials.Bedrock
         Grass = materials.Grass
         Dirt = materials.Dirt
         Stone = materials.Stone
-        bedrockbox = pymclevel.mclevel.BoundingBox((-(self.world_side_length / 2),
+        bedrockbox = pymclevel.mclevel.BoundingBox((-(self.world_side_length/2),
                                                     0,
-                                                    -(self.world_side_length / 2)),
-                                                    (self.world_side_length,
+                                                    -(self.world_side_length/2)),
+                                                    (self.world_side_length
+                                                        + self.block_length,
                                                      1,
-                                                     self.world_side_length))
+                                                     self.world_side_length
+                                                        + self.block_length))
         # Spread out a bit so there's no seams on the edges 
         while not (bedrockbox.minx % 16 == 0):
             bedrockbox.minx -= 1
             bedrockbox.minz -= 1
         while not (bedrockbox.maxz % 16 == 0):
             bedrockbox.maxz += 1
+        print "WORLD IS", bedrockbox
+        print "IE", ((bedrockbox.maxcx-bedrockbox.mincx)*( bedrockbox.maxcz-bedrockbox.mincz), ((bedrockbox.mincx, bedrockbox.mincz), (bedrockbox.maxcx, bedrockbox.maxcz)))
         self.mclevel.createChunksInBox(bedrockbox)
         self.mclevel.fillBlocks(bedrockbox, Bedrock)
         bedrockbox.miny = 2
         self.mclevel.setPlayerSpawnPosition((-(self.world_side_length / 2) + 8,
                                             66,
                                             -(self.world_side_length / 2) + 8))
+    def make_ores(self, noisy = False):
+        choices = [materials.CoalOre,
+                   materials.DiamondOre,
+                   materials.GoldOre,
+                   materials.IronOre,
+                   materials.LapisLazuliOre,
+                   materials.RedstoneOre,
+                   materials.Air,
+                   materials.LavaStill,
+                   materials.WaterStill]
+        tlength = (self.radius ** 2) * (self.block_length ** 2)
+        for randpos in xrange(tlength):
+            x = random.randint(-(self.world_side_length / 2),
+                               (self.world_side_length / 2) - 10)
+            z = random.randint(-(self.world_side_length / 2),
+                               (self.world_side_length / 2) - 10)
+            y = random.randint(5, 40)
+            material = random.choice(choices)
+            for xoffset in xrange(2):
+                for zoffset in xrange(2):
+                    for yoffset in xrange(2):
+                        self.mclevel.setBlockAt(x + xoffset,
+                                                y + yoffset,
+                                                z + zoffset,
+                                                material.ID)
+            if noisy and randpos % 10 == 0:
+                print "    Placing resources {0}/{1}.".format(randpos
+                                                                if randpos
+                                                                else 1,
+                                                              tlength)
     def lay_streets(self, noisy = False):
         street_object = streets.StreetNetwork(self.grid,
                 (-(self.world_side_length / 2), -(self.world_side_length / 2)),
                     help='Length (in blocks) of a city street block')
 parser.add_argument('--nostreets', action='store_true', 
                     help="Don't include streets")
+parser.add_argument('--noresources', action='store_true', 
+                    help="Don't bury resources in city "
+                         "(stone all the way down)")
 parser.add_argument('--nobuildings', action='store_true', 
                     help="Don't include buildings")
 
     print "Making a flat space for city"
     new_city.make_grass()
 
+    if args.noresources:
+        print "Skipping resources"
+    else:
+        print "Burying resources"
+        new_city.make_ores(True)
+
     if args.nostreets:
         print "Skipping roads"
     else:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.