コード例 #1
0
def setBlock(x, y, z, block, a="y", f="north", requirepunch=False):
    """Place a block at a defined location."""
    if block == "-":
        return
    if requirepunch and getBlock(x, y, z) in IGNORABLES:
        return

    waterlogged = "false"
    if WETNESSON \
            and getBlock(x, y, z) == "minecraft:water" \
            and block not in UNWETTABLE:
        for original, new in WETBLOCKS.items():
            if original in block:
                block = block.replace(original, new)
                waterlogged = "true"
                break

    fullblocks = [
        "[axis={axis}, waterlogged=" + waterlogged + "]", "[axis={axis}]",
        "[waterlogged=" + waterlogged + "]", "", "_planks"
    ]

    response = " "
    for addon in fullblocks:
        if not response.isnumeric():
            response = sB(x, y, z, (block + addon).format(axis=a, facing=f))
        else:
            return
    if not response.isnumeric():
        print("sB: " + response)
コード例 #2
0
def checkFreeSides(x, y, z, ignoreWater=True):
    """Determine which side is the most accessible."""
    sidecount = 0
    lastfree = None
    for dx, dz in ORTHFACTORS:
        if getBlock(x + dx, y, z + dz) in IGNORABLES \
                or (not ignoreWater
                    and getBlock(x + dx, y, z + dz) == "minecraft:water"):
            sidecount += 1
            lastfree = (dx, dz)
    return sidecount, lastfree
コード例 #3
0
 def placeStuds(self, x, y, z, amount=UNITSIZE - 1):
     """Place decorative studs at the appropriate position."""
     if getBlock(x, y, z) in IGNORABLES:
         return
     factor = findOuterWall(x, y, z)
     facing = factor2facing(factor)
     block = self.palette.palettify("{lightMat}_button[facing={facing}]")
     dx, dz = factor
     px, pz = perpabsfactor(factor)
     for i in range(amount):
         if getBlock(x + dx + i * px, y, z + dz + i * pz) in IGNORABLES:
             setBlock(x + dx + i * px, y, z + dz + i * pz, block, f=facing)
コード例 #4
0
    def punchDoor(self, xorig, yorig, zorig, axis):
        """Remove part of a wall to create a door."""
        x, y, z = xorig, yorig, zorig

        result = findAccessHeight(x, y, z)
        if not result:
            return
        h, stairsat = result
        y += h

        x, _, z = getWallMiddle(x, 0, z, axis)
        factor = findOuterWall(x, y, z)
        facing = factor2facing(factor)
        direction = factor2facing(invertfactor(factor))
        if getBlock(x - factor[0], y, z - factor[1]) not in IGNORABLES:
            if getBlock(x - factor[0], y, z - factor[1]) not in IGNORABLES:
                return
            y += 1

        if stairsat is not None:
            block = self.palette.palettify("{doorMat}_stairs[facing={facing}]")
            setBlock(x + stairsat[0],
                     y - 1,
                     z + stairsat[1],
                     block,
                     f=direction)
        if "fence" in getBlock(x, y, z):
            block = self.palette.palettify(
                "{doorMat}_fence_gate[facing={facing}]")
            setBlock(x, y, z, block, f=facing)
        else:
            block = self.palette.palettify(
                "{doorMat}_door[facing={facing}, half=")
            setBlock(x, y, z, block + "lower]", f=facing, requirepunch=True)
            setBlock(x,
                     y + 1,
                     z,
                     block + "upper]",
                     f=facing,
                     requirepunch=True)
        try:
            self.windows.remove((xorig, yorig, zorig))
        except ValueError:
            pass
コード例 #5
0
def findAccessHeight(x, y, z):
    """Discover the ideal position for a door."""
    check, laststairs = checkFreeSides(x, y, z)
    h = 0
    while check > 1:
        h -= 1
        check, laststairs = checkFreeSides(x, y + h, z)
    while check < 2:
        h += 1
        stairsat = laststairs
        check, laststairs = checkFreeSides(x, y + h, z)
    if (stairsat and getBlock(x + stairsat[0], y + h - 2, z + stairsat[1])
            in IGNORABLES):
        return None
    return h, stairsat
コード例 #6
0
def findOuterWall(x, y, z):
    """Determine the directional factor towards the outside of a wall."""
    # WARNING: cardinal directions are inverted for ease of use
    best = [-1, ()]
    for h in range(UNITHEIGHT + 1):
        if checkFreeSides(x, y + h, z, False)[0] > 0:
            y += h
            break
    for dx, dz in ORTHFACTORS:
        for h in range(UNITHEIGHT + 1):
            block = getBlock(x + dx, y + h, z + dz)
            if block not in IGNORABLES and block not in LIQUIDS:
                if h > best[0]:
                    best = h, (dx, dz)
                break
        else:
            return (dx, dz)
    if best[0] <= 0:
        return (0, 0)
    return best[1]
コード例 #7
0
def buildHouse(x1, y1, z1, x2, y2, z2):
    """Build a small house."""
    # floor
    interfaceUtils.fill(x1, y1, z1, x2 - 1, y1, z2 - 1, "cobblestone")

    # walls
    interfaceUtils.fill(x1 + 1, y1, z1, x2 - 2, y2, z1, "oak_planks")
    interfaceUtils.fill(x1 + 1, y1, z2 - 1, x2 - 2, y2, z2 - 1, "oak_planks")
    interfaceUtils.fill(x1, y1, z1 + 1, x1, y2, z2 - 2, "oak_planks")
    interfaceUtils.fill(x2 - 1, y1, z1 + 1, x2 - 1, y2, z2 - 2, "oak_planks")

    # corners
    interfaceUtils.fill(x1, y1, z1, x1, y2, z1, "oak_log")
    interfaceUtils.fill(x2 - 1, y1, z1, x2 - 1, y2, z1, "oak_log")
    interfaceUtils.fill(x1, y1, z2 - 1, x1, y2, z2 - 1, "oak_log")
    interfaceUtils.fill(x2 - 1, y1, z2 - 1, x2 - 1, y2, z2 - 1, "oak_log")

    # clear interior
    for y in range(y1 + 1, y2):
        for x in range(x1 + 1, x2 - 1):
            for z in range(z1 + 1, z2 - 1):
                # check what's at that place and only delete if not air
                if "air" not in interfaceUtils.getBlock(x, y, z):
                    interfaceUtils.setBlock(x, y, z, "air")

    # roof
    if x2 - x1 < z2 - z1:  # if the house is longer in Z-direction
        for i in range(0, (1 - x1 + x2) // 2):
            interfaceUtils.fill(x1 + i, y2 + i, z1, x2 - 1 - i, y2 + i, z2 - 1,
                                "bricks")
    else:
        # same as above but with x and z swapped
        for i in range(0, (1 - z1 + z2) // 2):
            interfaceUtils.fill(x1, y2 + i, z1 + i, x2 - 1, y2 + i, z2 - 1 - i,
                                "bricks")

    if interfaceUtils.isBuffering():
        interfaceUtils.sendBlocks()
コード例 #8
0
def findGround(x, z, y=127):
    """Determine the ground height (works in caves)."""
    while getBlock(x, y, z) in IGNORABLES:
        y -= 1
    return y
コード例 #9
0
 def getBlockAt(self, x, y_incr, z):
     y = y_incr + self.getHeightAt(x,z)
     return interfaceUtils.getBlock(x, y, z)
コード例 #10
0
ファイル: structures.py プロジェクト: lilmert/gdmc
    def buildPaths(self, build_map):
        mid_point = int((self._size - 1) / 2)
        l_switch = True
        l_side = (-1, 1)
        # bottom to top
        for j in range(-1, 2):
            x = self._builder._x
            z = self._builder._z + self._z + mid_point + j
            top = self._builder._x + self._builder._size
            while (x < top):
                if self._x <= x < (self._x+self._size):
                    x += 1
                else:
                    y = self._builder.getHeightAt(x, z)
                    block = self._builder.getBlockAt(x, -1, z)
                    if block == "minecraft:water":
                        self._builder.setBlockAt(x, -1, z, "oak_planks")
                        build_map.setBuildAt(x,z, 2)
                    else:
                        self._builder.setBlockAt(x, -1, z, "grass_path")
                        build_map.setBuildAt(x,z, 2)
                    
                    # clear above path
                    for y_i in range(10):
                        if interfaceUtils.getBlock(x, y + y_i, z) == "minecraft:oak_fence":
                            pass
                        else:
                            interfaceUtils.placeBlockBatched(x, y + y_i, z, "air")
                    
                    # build path lamps
                    if j == 0:
                        if (x % 7 == 0):
                            l_z = self._builder._z + self._z + mid_point + l_side[l_switch]
                            for ii in range(6):
                                interfaceUtils.placeBlockBatched(x, y+ii, l_z, "oak_fence")
                            interfaceUtils.placeBlockBatched(x, y+ii, z, "sea_lantern")
                            l_switch = not(l_switch)

                    x += 1
        
        # left to right
        for i in range(-1, 2):
            z = self._builder._z
            x = self._builder._x + self._x + mid_point + i
            bound = self._builder._z + self._builder._size
            while (z < bound):
                if self._z <= z < (self._z+self._size):
                    z += 1
                else:
                    y = self._builder.getHeightAt(x, z)
                    block = self._builder.getBlockAt(x, -1, z)
                    if block == "minecraft:water":
                        self._builder.setBlockAt(x, -1, z, "oak_planks")
                        build_map.setBuildAt(x,z, 2)
                    else:
                        self._builder.setBlockAt(x, -1, z, "grass_path")
                        build_map.setBuildAt(x,z, 2)
                    
                    # clear above path
                    for y_i in range(10):
                        if interfaceUtils.getBlock(x, y + y_i, z) == "minecraft:oak_fence":
                            pass
                        else:
                            interfaceUtils.placeBlockBatched(x, y + y_i, z, "air")
                    
                    # build path lamps
                    if i == 0:
                        if (z % 7 == 0):
                            l_x = self._builder._x + self._x + mid_point + l_side[l_switch]
                            for jj in range(6):
                                interfaceUtils.placeBlockBatched(l_x, y+jj, z, "oak_fence")
                            interfaceUtils.placeBlockBatched(x, y+jj, z, "sea_lantern")
                            l_switch = not(l_switch)
                    z += 1