예제 #1
0
    def __init__(self, x, y, z, blockType, blockData=0, tag=""):
        # persist data
        self.blockType = blockType
        self.blockData = blockData

        # store the positions
        # original pos
        self.originalPos = minecraft.Vec3(x, y, z)
        # relative pos - block position relatively to other shape blocks
        self.relativePos = minecraft.Vec3(x, y, z)
        # actual pos - actual block position in the world
        self.actualPos = minecraft.Vec3(x, y, z)

        # the tag system is used to give a particular block inside a shape meaning
        # e.g. for an animal shape you could tag the block which is its head
        self.tag = tag

        # the mc block object
        self.mcBlock = block.Block(blockType, blockData)
예제 #2
0
 def _copyBlocks(self, shapeBlocks):
     """
     Internal. copy a list of shapeBlocks to new objects, item level, as
     opposed to the expensive copy.deepcopy() or copy.copy()
     """
     newShapeBlocks = []
     for shapeBlock in shapeBlocks:
         newShapeBlock = ShapeBlock(shapeBlock.actualPos.x,
                                    shapeBlock.actualPos.y,
                                    shapeBlock.actualPos.z,
                                    shapeBlock.blockType,
                                    shapeBlock.blockData, shapeBlock.tag)
         newShapeBlock.originalPos = minecraft.Vec3(
             shapeBlock.originalPos.x, shapeBlock.originalPos.y,
             shapeBlock.originalPos.z)
         newShapeBlock.relativePos = minecraft.Vec3(
             shapeBlock.relativePos.x, shapeBlock.relativePos.y,
             shapeBlock.relativePos.z)
         newShapeBlocks.append(newShapeBlock)
     return newShapeBlocks
예제 #3
0
    def add(self, x, y, z):
        """
        add a single position to the list of points.

        :param int x:
            The x position.

        :param int y:
            The y position.

        :param int z:
            The z position.
        """
        self._points.append(minecraft.Vec3(x, y, z))
예제 #4
0
def angleToTextDirection(angle):
    direction = int(round((angle % 360) / 45))
    if direction == 0:
        return minecraft.Vec3(-1, 0, 0)
    elif direction == 1:
        return minecraft.Vec3(-1, 0, -1)
    elif direction == 2:
        return minecraft.Vec3(0, 0, -1)
    elif direction == 3:
        return minecraft.Vec3(1, 0, -1)
    elif direction == 4:
        return minecraft.Vec3(1, 0, 0)
    elif direction == 5:
        return minecraft.Vec3(1, 0, 1)
    elif direction == 6:
        return minecraft.Vec3(0, 0, 1)
    else:
        return minecraft.Vec3(-1, 0, 1)
예제 #5
0
 def __init__(self,
              mc,
              position=minecraft.Vec3(0, 0, 0),
              port=4711,
              offset_front=(1, 0),
              offset_left=(0, -1),
              offset_right=(0, 1)):
     # set defaults
     self.mc = mc
     # start position
     self.startposition = position
     # set turtle position
     self.position = position
     # set turtle angles
     self.heading = 0
     self.verticalheading = 0
     # set pen down
     self._pendown = True
     # set pen block to black wool
     self._penblock = block.Block(block.WOOL.id, 15)
     # flying to true
     self.flying = True
     # set speed
     self.turtlespeed = 6
     # create turtle
     self.showturtle = True
     # create drawing object
     self.mcDrawing = MinecraftDrawing(self.mc)
     # set turtle block
     self.turtleblock = block.Block(block.DIAMOND_BLOCK.id)
     # draw turtle
     self._drawTurtle(int(self.position.x), int(self.position.y),
                      int(self.position.y))
     # front, left, right of MinecraftTurtle
     self.offset_front = offset_front
     self.offset_left = offset_left
     self.offset_right = offset_right
예제 #6
0
    def getLine(self, x1, y1, z1, x2, y2, z2):
        """
        Returns all the points which would make up a line between 2 points as a list

        3d implementation of bresenham line algorithm

        :param int x1:
            The x position of the first point.

        :param int y1:
            The y position of the first point.

        :param int z1:
            The z position of the first point.

        :param int x2:
            The x position of the second point.

        :param int y2:
            The y position of the second point.

        :param int z2:
            The z position of the second point.
        """

        # return the maximum of 2 values
        def MAX(a, b):
            if a > b:
                return a
            else:
                return b

        # return step
        def ZSGN(a):
            if a < 0:
                return -1
            elif a > 0:
                return 1
            elif a == 0:
                return 0

        # list for vertices
        vertices = []

        # if the 2 points are the same, return single vertice
        if (x1 == x2 and y1 == y2 and z1 == z2):
            vertices.append(minecraft.Vec3(x1, y1, z1))

        # else get all points in edge
        else:

            dx = x2 - x1
            dy = y2 - y1
            dz = z2 - z1

            ax = abs(dx) << 1
            ay = abs(dy) << 1
            az = abs(dz) << 1

            sx = ZSGN(dx)
            sy = ZSGN(dy)
            sz = ZSGN(dz)

            x = x1
            y = y1
            z = z1

            # x dominant
            if (ax >= MAX(ay, az)):
                yd = ay - (ax >> 1)
                zd = az - (ax >> 1)
                loop = True
                while (loop):
                    vertices.append(minecraft.Vec3(x, y, z))
                    if (x == x2):
                        loop = False
                    if (yd >= 0):
                        y += sy
                        yd -= ax
                    if (zd >= 0):
                        z += sz
                        zd -= ax
                    x += sx
                    yd += ay
                    zd += az
            # y dominant
            elif (ay >= MAX(ax, az)):
                xd = ax - (ay >> 1)
                zd = az - (ay >> 1)
                loop = True
                while (loop):
                    vertices.append(minecraft.Vec3(x, y, z))
                    if (y == y2):
                        loop = False
                    if (xd >= 0):
                        x += sx
                        xd -= ay
                    if (zd >= 0):
                        z += sz
                        zd -= ay
                    y += sy
                    xd += ax
                    zd += az
            # z dominant
            elif (az >= MAX(ax, ay)):
                xd = ax - (az >> 1)
                yd = ay - (az >> 1)
                loop = True
                while (loop):
                    vertices.append(minecraft.Vec3(x, y, z))
                    if (z == z2):
                        loop = False
                    if (xd >= 0):
                        x += sx
                        xd -= az
                    if (yd >= 0):
                        y += sy
                        yd -= az
                    z += sz
                    xd += ax
                    yd += ay

        return vertices
예제 #7
0
 def _drawTurtle(self, x, y, z):
     # draw turtle
     self.mcDrawing.drawPoint3d(x, y, z, self.turtleblock.id,
                                self.turtleblock.data)
     lastDrawnTurtle = minecraft.Vec3(x, y, z)