Beispiel #1
0
    def place(x, y, z, lcval, crustval, bathyval, doSchematics, r=None, g=None, b=None, ir=None):
        try:
            Terrain.terdict[lcval]
        except KeyError:
            print "lcval value %s not found!" % lcval
        (y, column, tree) = Terrain.terdict.get(lcval, Terrain.terdict[0])(x, y, z, crustval, bathyval, doSchematics)
        merged = [ (depth, (block, 0)) if type(block) is not tuple else (depth, block) for (depth, block) in column ]
        # y=0 is always bedrock
        blocks = [ (0, materialNamed('Bedrock')) ]
        datas = [ (0, 0) ]
        core = [ ((y - height(merged)), ('End Stone', 0)) ] + merged
        base = 0
        while core:
            (depth, (block, data)) = core.pop(0)
            [ blocks.append((y, materialNamed(block) if type(block) is str else block)) for y in xrange(base, base+depth) if y > 0 ]
            [ datas.append((y, data)) for y in xrange(base, base+depth) if y > 0 ]
            base += depth

        water = materialNamed('Water')
        water = water(0) if type(water) is tuple else water 
        iswater = (block == 'Water') if type(block) is str else (block == water)
        if haveOrthoColors and not(iswater):
            [block, data] = mcBlockData.nearest(r, g, b, ir, not(lcval >= 22 and lcval <=25))
            blocks[-1] = (blocks[-1][0], block)
            datas[-1] = (datas[-1][0], data)

        return blocks, datas, tree
Beispiel #2
0
 def place(x, y, z, lcval, crustval, bathyval, doSchematics):
     try:
         Terrain.terdict[lcval]
     except KeyError:
         print "lcval value %s not found!" % lcval
     (y, column,
      tree) = Terrain.terdict.get(lcval,
                                  Terrain.terdict[0])(x, y, z, crustval,
                                                      bathyval,
                                                      doSchematics)
     merged = [(depth, block) if isinstance(block, tuple) else
               (depth, (block, 0)) for (depth, block) in column]
     # y=0 is always bedrock
     blocks = [(0, materialNamed('Bedrock'))]
     datas = [(0, 0)]
     core = [((y - height(merged)), ('End Stone', 0))] + merged
     base = 0
     while core:
         (depth, (block, data)) = core.pop(0)
         [
             blocks.append((y, materialNamed(block) if isinstance(
                 block, basestring) else block))
             for y in xrange(base, base + depth) if y > 0
         ]
         [
             datas.append((y, data)) for y in xrange(base, base + depth)
             if y > 0
         ]
         base += depth
     return blocks, datas, tree
Beispiel #3
0
    def placeoreintile(tile):
        # strictly speaking, this should be in class Tile somehow
        oreobjs = dict([(ore.name, ore) for ore in oreObjs])
        tile.ores = dict([(name, list()) for name in oreobjs])

        for ore in oreobjs:
            extent = cbrt(oreobjs[ore].size)*2
            maxy = pow(2, oreobjs[ore].depth)
            numrounds = int(oreobjs[ore].rounds * (tile.size/16) * (tile.size/16))
            oreID = materialNamed(oreobjs[ore].name)
            for dummy in xrange(numrounds):
                orex = randint(0, tile.size)
                orey = randint(0, maxy)
                orez = randint(0, tile.size)
                coords = [orex+tile.mcoffsetx, orey, orez+tile.mcoffsetz]
                if (orex < extent or (tile.size-orex) < extent or orez < extent or (tile.size-orez) < extent):
                    try:
                        tile.ores[ore]
                    except KeyError:
                        tile.ores[ore] = []
                    tile.ores[ore].append(coords)
                else:
                    for x, y, z in oreobjs[ore](coords):
                        if tile.world.blockAt(x, y, z) == Ore.stoneID:
                            tile.world.setBlockAt(x, y, z, oreID)
Beispiel #4
0
 def placetreesinregion(trees, treeobjs, world):
     for tree in trees:
         coords = trees[tree]
         for coord in coords:
             (blocks, datas) = treeobjs[tree](coord)
             [world.setBlockAt(x, y, z, materialNamed(block)) for (x, y, z, block) in blocks if block != 'Air']
             [world.setBlockDataAt(x, y, z, data) for (x, y, z, data) in datas if data != 0]
Beispiel #5
0
    def placeoreintile(tile):
        # strictly speaking, this should be in class Tile somehow
        oreobjs = dict([(ore.name, ore) for ore in oreObjs])
        tile.ores = dict([(name, list()) for name in oreobjs])

        for ore in oreobjs:
            extent = cbrt(oreobjs[ore].size) * 2
            maxy = pow(2, oreobjs[ore].depth)
            numrounds = int(oreobjs[ore].rounds * (tile.size / 16) *
                            (tile.size / 16))
            oreID = materialNamed(oreobjs[ore].name)
            for dummy in xrange(numrounds):
                orex = randint(0, tile.size)
                orey = randint(0, maxy)
                orez = randint(0, tile.size)
                coords = [orex + tile.mcoffsetx, orey, orez + tile.mcoffsetz]
                if (orex < extent or (tile.size - orex) < extent
                        or orez < extent or (tile.size - orez) < extent):
                    try:
                        tile.ores[ore]
                    except KeyError:
                        tile.ores[ore] = []
                    tile.ores[ore].append(coords)
                else:
                    for x, y, z in oreobjs[ore](coords):
                        if tile.world.blockAt(x, y, z) == Ore.stoneID:
                            tile.world.setBlockAt(x, y, z, oreID)
Beispiel #6
0
 def place(x, y, z, lcval, crustval, bathyval, doSchematics):
     try:
         Terrain.terdict[lcval]
     except KeyError:
         print "lcval value %s not found!" % lcval
     (y, column, tree) = Terrain.terdict.get(lcval, Terrain.terdict[0])(x, y, z, crustval, bathyval, doSchematics)
     merged = [ (depth, (block, 0)) if type(block) is not tuple else (depth, block) for (depth, block) in column ]
     # y=0 is always bedrock
     blocks = [ (0, materialNamed('Bedrock')) ]
     datas = [ (0, 0) ]
     core = [ ((y - height(merged)), ('End Stone', 0)) ] + merged
     base = 0
     while core:
         (depth, (block, data)) = core.pop(0)
         [ blocks.append((y, materialNamed(block) if type(block) is str else block)) for y in xrange(base, base+depth) if y > 0 ]
         [ datas.append((y, data)) for y in xrange(base, base+depth) if y > 0 ]
         base += depth
     return blocks, datas, tree
Beispiel #7
0
 def placetreesinregion(trees, treeobjs, world):
     for tree in trees:
         coords = trees[tree]
         for coord in coords:
             (blocks, datas) = treeobjs[tree](coord)
             [
                 world.setBlockAt(x, y, z, materialNamed(block))
                 for (x, y, z, block) in blocks if block != 'Air'
             ]
             [
                 world.setBlockDataAt(x, y, z, data)
                 for (x, y, z, data) in datas if data != 0
             ]
Beispiel #8
0
 def placetreeintile(tile, tree, mcx, mcy, mcz):
     coords = [mcx, mcy, mcz]
     myx = tile.mcoffsetx - mcx
     myz = tile.mcoffsetx - mcz
     if (myx < Tree.treeWidth+1 or (tile.size-myx) < Tree.treeWidth+1 or myz < Tree.treeWidth+1 or (tile.size-myz) < Tree.treeWidth+1):
         # tree is too close to the edge, plant it later
         try:
             tile.trees[tree]
         except KeyError:
             tile.trees[tree] = []
         tile.trees[tree].append(coords)
     else:
         # plant it now!
         (blocks, datas) = treeObjs[tree](coords)
         [tile.world.setBlockAt(x, y, z, materialNamed(block)) for (x, y, z, block) in blocks if block != 'Air']
         [tile.world.setBlockDataAt(x, y, z, data) for (x, y, z, data) in datas if data != 0]
Beispiel #9
0
 def placetreeintile(tile, tree, mcx, mcy, mcz):
     coords = [mcx, mcy, mcz]
     myx = tile.mcoffsetx - mcx
     myz = tile.mcoffsetx - mcz
     if (myx < Tree.treeWidth + 1 or (tile.size - myx) < Tree.treeWidth + 1
             or myz < Tree.treeWidth + 1
             or (tile.size - myz) < Tree.treeWidth + 1):
         # tree is too close to the edge, plant it later
         try:
             tile.trees[tree]
         except KeyError:
             tile.trees[tree] = []
         tile.trees[tree].append(coords)
     else:
         # plant it now!
         (blocks, datas) = treeObjs[tree](coords)
         [
             tile.world.setBlockAt(x, y, z, materialNamed(block))
             for (x, y, z, block) in blocks if block != 'Air'
         ]
         [
             tile.world.setBlockDataAt(x, y, z, data)
             for (x, y, z, data) in datas if data != 0
         ]
Beispiel #10
0
 def placeoreinregion(ores, oreobjs, world):
     for ore in ores:
         oreID = materialNamed(oreobjs[ore].name)
         for x, y, z in ores[ore]:
             if world.blockAt(x, y, z) == Ore.stoneID:
                 world.setBlockAt(x, y, z, oreID)
Beispiel #11
0
 def placeoreinregion(ores, oreobjs, world):
     for ore in ores:
         oreID = materialNamed(oreobjs[ore].name)
         for x, y, z in ores[ore]:
             if world.blockAt(x, y, z) == Ore.stoneID:
                 world.setBlockAt(x, y, z, oreID)
Beispiel #12
0
class Ore(object):
    """Each type of ore will be an instance of this class."""

    # what ID is stone?
    # we use 'end stone' actually since 'stone' might be in a schematic
    stoneID = materialNamed('End Stone')

    def __init__(self, name, depth=None, rounds=None, size=None):
        # nobody checks names
        # NB: ore names are block names too, consider fixing this
        self.name = name
        self.depth = depth
        self.rounds = rounds
        self.size = size

    def __call__(self, coords):
        # generate ellipsoid values based on parameters
        (mcx, mcy, mcz) = coords
        # start with random radius-like values
        x0 = randint(1, 4)
        y0 = randint(1, 4)
        z0 = randint(1, 4)
        v0 = 4 / 3 * pi * x0 * y0 * z0
        # scale to match volume and round up
        scale = cbrt(self.size / v0)
        x1 = int(round(scale * x0))
        y1 = int(round(scale * y0))
        z1 = int(round(scale * z0))
        # pre-calculate squares
        x2 = x1 * x1
        y2 = y1 * y1
        z2 = z1 * z1
        # generate ranges
        xr = xrange(-1 * x1, x1)
        yr = xrange(-1 * y1, y1)
        zr = xrange(-1 * z1, z1)
        # calculate ellipsoid
        oreCoords = [[mcx + x, mcy + y, mcz + z]
                     for x, y, z in product(xr, yr, zr)
                     if x * x / x2 + y * y / y2 + z * z / z2 <= 1]
        # if len(oreCoords) > self.size+2:
        #     print "warning: oreCoords larger than self.size -- %d > %d" % (len(oreCoords), self.size)
        # if len(oreCoords) < self.size-2:
        #     print "warning: oreCoords smaller than self.size -- %d < %d" % (len(oreCoords), self.size)
        return oreCoords

    @staticmethod
    def placeoreintile(tile):
        # strictly speaking, this should be in class Tile somehow
        oreobjs = dict([(ore.name, ore) for ore in oreObjs])
        tile.ores = dict([(name, list()) for name in oreobjs])

        for ore in oreobjs:
            extent = cbrt(oreobjs[ore].size) * 2
            maxy = pow(2, oreobjs[ore].depth)
            numrounds = int(oreobjs[ore].rounds * (tile.size / 16) *
                            (tile.size / 16))
            oreID = materialNamed(oreobjs[ore].name)
            for dummy in xrange(numrounds):
                orex = randint(0, tile.size)
                orey = randint(0, maxy)
                orez = randint(0, tile.size)
                coords = [orex + tile.mcoffsetx, orey, orez + tile.mcoffsetz]
                if (orex < extent or (tile.size - orex) < extent
                        or orez < extent or (tile.size - orez) < extent):
                    try:
                        tile.ores[ore]
                    except KeyError:
                        tile.ores[ore] = []
                    tile.ores[ore].append(coords)
                else:
                    for x, y, z in oreobjs[ore](coords):
                        if tile.world.blockAt(x, y, z) == Ore.stoneID:
                            tile.world.setBlockAt(x, y, z, oreID)

    @staticmethod
    def placeoreinregion(ores, oreobjs, world):
        for ore in ores:
            oreID = materialNamed(oreobjs[ore].name)
            for x, y, z in ores[ore]:
                if world.blockAt(x, y, z) == Ore.stoneID:
                    world.setBlockAt(x, y, z, oreID)