Пример #1
0
    def create_polys(self, options=Map()):
        polys = self.polys
        data_so_far = self.data()

        sides = data_so_far.sides or 4

        if options.outside:
            corners, lines = helpers.corners_from_bounds(options.p1, options.p2, sides, self.center, self.radius, options.width, options.depth)
            polys.append(MCShape(["garden"], corners, data_so_far.copy(corner_vectors=corners, lines=lines)))
            options.p1, options.p2 = vg.rectangle_inner(options.p1, options.p2, 1)

        # Build Walls
        corners, lines = helpers.corners_from_bounds(options.p1, options.p2, sides, self.center, self.radius, options.width, options.depth)
        for i, l in enumerate(lines):
            facing = "front" if i == 1 else "side"
            # TODO: Pass in point where front door is, determine facing from that
            p = MCShape(["standing rectangle", "wall"], l, data_so_far.copy(height=self.height, facing=facing))
            polys.append(p)

        # Build Roof and Foundation
        roof_vectors = [vg.up(v, self.height) for v in corners]
        polys.append(MCShape(["flat rectangle", "roof"], roof_vectors, data_so_far.copy(corner_vectors=roof_vectors)))
        polys.insert(0, MCShape(["flat rectangle", "foundation"], [vg.up(v, -1) for v in corners],
                                data_so_far.copy(corner_vectors=corners)))

        self.corner_vectors = corners
        self.polys = polys
Пример #2
0
    def build(self):
        if self.style == "blacktop":
            color = block.OBSIDIAN.id
        else:
            color = block.DIRT.id

        for pos in self.blocks:
            helpers.create_block(pos, color)
Пример #3
0
    def create_polys(self, options=Map()):
        polys = self.polys or []
        data_so_far = self.data()

        options.outside = False
        sides = options.sides = 4
        castle_wall_height = options.castle_wall_height or 9
        castle_inner_wall_height = options.castle_inner_wall_height or 18

        p1 = vg.up(options.p1, 1)
        p2 = vg.up(options.p2, 1)

        width, null, depth = vg.dists(p1, p2)
        print("Castle starting points and dimensions", p1, p2, ":", width, "x", depth)
        if (width > 22) and (depth > 22):
            # keep moat width between 4 and 10
            if (width > 26) and (depth > 26):
                moat_width = round(min((width + depth / 2) - 26, 10))
            else:
                moat_width = 4

            # Build Moat
            p1, p2 = vg.rectangle_inner(p1, p2, moat_width / 2)
            corners, lines = helpers.corners_from_bounds(vg.up(p1, -1), vg.up(p2, -1), sides, self.center, self.radius,
                                                         options.width, options.depth)
            p = MCShape(["moat"], corners, data_so_far.copy(height=self.height))
            polys.append(p)

            p1, p2 = vg.rectangle_inner(p1, p2, (moat_width / 2) - 2)

        width, null, depth = vg.dists(p1, p2)
        print("- Castle tower points", p1, p2, " and dimensions:", width, "x", depth)
        if (width > 17) and (depth > 17):

            p1, p2 = vg.rectangle_inner(p1, p2, 2)
            corners, lines = helpers.corners_from_bounds(p1, p2, sides, self.center, self.radius,
                                                         options.width, options.depth)

            for i, l in enumerate(lines):
                facing = "front" if i == 1 else "side"
                p = MCShape(["standing rectangle", "castle_outer_wall"], l, data_so_far.copy(height=castle_wall_height, thickness=3, facing=facing))
                polys.append(p)

            for i, c in enumerate(corners):
                p = MCShape(["standing line", "castle_wall_tower"], [c], data_so_far.copy(height=castle_wall_height, radius=3, facing=facing))
                polys.append(p)

            p1, p2 = vg.rectangle_inner(p1, p2, 4)

        options.p1 = p1
        options.p2 = p2

        self.polys = polys

        # Call the Building's create_poly class to build walls and roof
        super(self.__class__, self).create_polys(options)
    def draw(self):
        for i, item in enumerate(self.blocks):
            if i == 0 and type(item.id) == Texture1D.Texture1D:
                item.id.reset_between_objects()

                if not item.id.options.bounds:
                    item.id.options.bounds = vg.bounds(self.blocks)

                # TODO: This won't reset Texture Gradients if there are multiple per Feature

            helpers.create_block(item.pos, item.id, item.data)
Пример #5
0
    def __init__(self, pos=False, options=Map()):
        if not helpers.mc:
            helpers.mc = helpers.connect()

        self.seed = options.seed or vg.get_seed()
        vg.init_with_seed(self.seed)
        self.sides = options.sides or 4
        self.polys = []

        if options.p1 and options.p2:
            p1, p2 = vg.min_max_points(options.p1, options.p2)
            options.width = abs(p2.x - p1.x) - 2
            options.depth = abs(p2.z - p1.z) - 2
            options.radius = math.floor(min(options.width, options.depth) / 2)
            pos = V3(round((p1.x + p2.x) / 2), p1.y, round((p1.z + p2.z) / 2))
            if options.sides == 4:
                options.p1 = p1
                options.p2 = p2
        else:
            # If position isn't set, use the player position
            if pos is False:
                pos = helpers.my_tile_pos()

        # If "force_height" not passed in as an option, then pick height of the terrain at the x,z point
        # if not options.force_height:
        #     setattr(pos, "y", helpers.get_height(pos))

        self.options = options
        self.radius = options.radius or vg.rand_in_range(4, 10)
        self.options = choose_random_options(self.options)
        self.center = V3(pos.x, pos.y, pos.z)

        self.biome = "Plains"  # TODO: self.biome.title(options.biome or helpers.biome_at(pos))

        rand_max = min(max(math.ceil(self.radius * 2.5), 6), 40)  # keep buildings between 4-40 height
        self.height = options.height or vg.rand_in_range(4, rand_max)
        self.corner_vectors = []

        self.material = options.material or block.STONE.id
        self.material_edges = options.material_edges or block.IRON_BLOCK.id  # TODO: Change based on biome, have rand list

        self.name = options.name or self.biome + " house"

        # Create the walls and major polygons
        self.create_polys(options)
def add_cells_to_image(polys, colors, draw, zone_data=Map()):
    for poly_id, poly in enumerate(polys):

        lines = []
        for line_id, p1 in enumerate(poly):
            lines.append(p1[0])
            lines.append(p1[1])

        color = webcolors.rgb_to_hex(helpers.choose_one(colors))
        color = chroma.Color(color)

        if poly_id == zone_data.center_id:
            color -= chroma.Color(webcolors.name_to_hex('red'))
        elif poly_id in zone_data.city_zones_in_walls:
            color -= chroma.Color(webcolors.name_to_hex('white'))
        # elif poly_id in zone_data.first:
        #     color -= chroma.Color(webcolors.name_to_hex('green'))
        # elif poly_id in zone_data.second:
        #     color -= chroma.Color(webcolors.name_to_hex('yellow'))
        # elif poly_id in zone_data.third:
        #     color -= chroma.Color(webcolors.name_to_hex('brown'))
        # elif poly_id in zone_data.fourth:
        #     color -= chroma.Color(webcolors.name_to_hex('lightblue'))

        draw.polygon(lines, fill=color.hex)

    for poly_id, poly in enumerate(polys):
        for line_id, p1 in enumerate(poly):
            p2 = poly[(line_id + 1) % len(poly)]

            is_outer = False
            is_river = False

            for w_poly, w_id in zone_data.outer_walls:
                if w_poly == poly_id and w_id == line_id:
                    is_outer = True
                    break
            for r_poly, r_id in zone_data.river_edges:
                if r_poly == poly_id and r_id == line_id:
                    is_river = True
                    break

            if is_outer:
                draw.line((p1[0], p1[1], p2[0], p2[1]), fill='black', width=7)

            if is_river:
                draw.line((p1[0], p1[1], p2[0], p2[1]), fill='blue', width=9)
def add_polys_to_image(polys, draw, colors, color=None, outline='brown'):
    for poly_id, poly in enumerate(polys):
        lines = []
        if type(poly) == Polygon:
            line = poly.exterior.coords
        else:
            line = poly

        for line_id, p1 in enumerate(line):
            lines.append(p1[0])
            lines.append(p1[1])

        if color is None:
            color_1 = webcolors.rgb_to_hex(helpers.choose_one(colors))
            color_1 = chroma.Color(color_1)
            color_1 -= chroma.Color(webcolors.name_to_hex('orange'))
            color_1 = color_1.hex
            draw.polygon(lines, fill=color_1, outline=outline)
        else:
            draw.polygon(lines, fill=color, outline=outline)
def city(size=0, layout="castle", farms=False, buildings=False, streets=True, castle=True):
    # Testing location numbers
    mid_point = V3(30, 0, 120)

    if size > 0:
        mid1 = V3(mid_point.x - size, mid_point.y, mid_point.z - size)
        mid2 = V3(mid_point.x + size, mid_point.y, mid_point.z + size)
    else:
        mid1, mid2 = V3(0, 0, 60), V3(50, 0, 110)
        size = 25

    helpers.prep(size+20)

    print("Building zone and street-map using layout:", layout)
    if layout == "castle":
        all_zones = build_castle_streetmap(mid1, mid2, Map(min_x=20, min_z=20))
    else:
        all_zones = vg.partition(mid1, mid2, Map(minx=20, minz=20))
    print("-", len(all_zones), "zones identified")

    farm_zones = []
    building_zones = []
    castle_zone = False

    # Sort zones
    for zone in all_zones:
        if zone.width < 8 or zone.depth < 8:
            farm_zones.append(zone)
        else:
            building_zones.append(zone)

    print("-", len(farm_zones), " farm zones identified")

    # Make the largest zone a castle
    if not castle_zone:
        largest = 0
        largest_index = -1
        for i, zone in enumerate(building_zones):
            size = (zone.width * zone.depth) + min(zone.width, zone.depth) ** 2
            if size > largest:
                largest = size
                largest_index = i
                castle_zone = zone
        building_zones.pop(largest_index)

    print("-", len(building_zones), " building zones identified")
    print("- Castle size", castle_zone.width, "width by", castle_zone.depth, "depth by", castle_zone.height, "height")

    # Turn zones into creations
    s = Streets(all_zones, Map(style="blacktop"))
    f = Farmzones(farm_zones)
    n = Neighborhoods(building_zones)
    c = Castle(options=castle_zone)

    z = [all_zones, farm_zones, building_zones, castle_zone]

    # Build the creations
    if streets: s.build()
    if farms: f.build()
    if buildings: n.build()
    if castle: c.build()

    class Temp:
        def __init__(self, s, f, n, c, z):
            self.s = s
            self.f = f
            self.n = n
            self.c = c
            self.zones = z

        def clear(self):
            self.s.clear()
            self.f.clear()
            self.n.clear()
            self.c.clear()

    return Temp(s=s, f=f, n=n, c=c, z=z)
from MCShape import MCShape
import mcpi.block as block
import Blocks

import MinecraftHelpers as helpers
import VoxelGraphics as vg
from Farmzones import Farmzones
from Castle import Castle, build_castle_streetmap
from Map import Map
from V3 import V3
from Building import Streets, Neighborhoods

# Load Plugin decorations and register them
from decorations import *

helpers.connect()


# --------------------------------------------------------------------
# City Building
# --------------------------------------------------------------------

def city(size=0, layout="castle", farms=False, buildings=False, streets=True, castle=True):
    # Testing location numbers
    mid_point = V3(30, 0, 120)

    if size > 0:
        mid1 = V3(mid_point.x - size, mid_point.y, mid_point.z - size)
        mid2 = V3(mid_point.x + size, mid_point.y, mid_point.z + size)
    else:
        mid1, mid2 = V3(0, 0, 60), V3(50, 0, 110)
 def clear(self):
     for item in self.blocks:
         helpers.create_block(item.pos, block.AIR.id)
    def clear(self):
        for i, vec in enumerate(self.blocks):
            helpers.create_block(vec, block.GRASS.id)
            if vec == self.center:
                plus2 = vg.up(vec, 3)
                for v2 in vg.next_to(plus2):
                    helpers.create_block(v2.point, block.AIR.id)
                helpers.create_block(plus2, block.AIR.id)

        if self.crop in ["cane", "cactus"]:
            for p1 in self.blocks:
                helpers.create_block(vg.up(p1), block.AIR.id)
                helpers.create_block(vg.up(p1, 2), block.AIR.id)
                helpers.create_block(vg.up(p1, 3), block.AIR.id)
        elif self.crop in ["wheat", "carrot", "potato"]:
            for i, p1 in enumerate(self.blocks):
                if not vec == self.center:
                    helpers.create_block(vg.up(p1), block.AIR.id)
    def build(self):
        for i, vec in enumerate(self.blocks):
            if self.crop == "cane":
                if (vec.x % 3) == 0:
                    helpers.create_block(vec, block.WATER.id)
                else:
                    helpers.create_block(vec, block.DIRT.id)
            elif self.crop == "cactus":
                if ((vec.x + vec.z) % 2) == 0:
                    helpers.create_block(vec, block.AIR.id)
                else:
                    helpers.create_block(vec, block.SAND.id)
            else:
                # All other types of crops
                if vec == self.center:
                    helpers.create_block(vec, block.WATER.id)
                    plus2 = vg.up(vec, 3)
                    helpers.create_block(plus2, block.GLOWSTONE_BLOCK.id)
                    for v2 in vg.next_to(plus2):
                        helpers.create_block(v2.point, block.TORCH.id, v2.dir)
                else:
                    helpers.create_block(vec, block.FARMLAND.id)

        if self.crop == "cane":
            for i, vec in enumerate(self.blocks):
                if not (vec.x % 3) == 0:
                    canes = np.random.randint(1, 4)
                    helpers.create_block(vg.up(vec), block.SUGAR_CANE.id)
                    if canes > 1:
                        helpers.create_block(vg.up(vec, 2),
                                             block.SUGAR_CANE.id)
                    if canes > 2:
                        helpers.create_block(vg.up(vec, 3),
                                             block.SUGAR_CANE.id)
        elif self.crop == "cactus":
            for i, vec in enumerate(self.blocks):
                if ((vec.x + vec.z) % 2) == 1:
                    helpers.create_block(vec, block.SAND.id)
                    cacs = np.random.randint(1, 4)
                    helpers.create_block(vg.up(vec), block.CACTUS.id)
                    if cacs > 1:
                        helpers.create_block(vg.up(vec, 2), block.CACTUS.id)
                    if cacs > 2:
                        helpers.create_block(vg.up(vec, 3), block.CACTUS.id)
        elif self.crop == "wheat":
            for i, vec in enumerate(self.blocks):
                if not vec == self.center:
                    helpers.create_block(vg.up(vec), 59,
                                         np.random.randint(0, 8))
        elif self.crop == "carrot":
            for i, vec in enumerate(self.blocks):
                if not vec == self.center:
                    helpers.create_block(vg.up(vec), 141,
                                         np.random.randint(0, 8))
        elif self.crop == "potato":
            for i, vec in enumerate(self.blocks):
                if not vec == self.center:
                    helpers.create_block(vg.up(vec), 142,
                                         np.random.randint(0, 8))
Пример #13
0
 def clear(self):
     for pos in self.blocks:
         helpers.create_block(pos, block.GRASS.id)