Exemple #1
0
def Main():
    mc = minecraft.Minecraft.create() 
    mc.player.setPos(35.5,34.0,-51.5)
    playerPos = mc.player.getPos()
    playerPos = minecraft.Vec3(int(playerPos.x),int(playerPos.y),int(playerPos.z))
    while int(playerPos.x)>32 and int(playerPos.x)<38 and int(playerPos.z)<-48 and int(playerPos.z)>-54 and int(playerPos.y)<37:
        if connected == False:
            break
        playerPos = mc.player.getPos()
        playerPos = minecraft.Vec3(int(playerPos.x),int(playerPos.y),int(playerPos.z))
        Find(int(playerPos.x), int(playerPos.z))
        time.sleep(.01)
    s.close()
    print "Connection closed"
Exemple #2
0
 def createApple(self):
     badApple = True
     #loop until an apple is created which doesnt collide with the boundary or the snake
     while (badApple == True):
         x = random.randrange(playingBottomLeft.x, playingTopRight.x)
         y = random.randrange(playingBottomLeft.y, playingTopRight.y)
         z = playingBottomLeft.z
         newApple = minecraft.Vec3(x, y, z)
         badApple = self.checkCollision(newApple)
     self.apple = newApple
     self.mc.setBlock(self.apple.x, self.apple.y, self.apple.z, block.GLOWING_OBSIDIAN)
Exemple #3
0
 def drawPlanet(self, mc):
     newVec3 = minecraft.Vec3(roundNo(self._st._x), roundNo(self._st._y),
                              ZPOSITION)
     #has the planet moved
     if (newVec3.x != self._lastVec3.x) or (
             newVec3.y != self._lastVec3.y) or (newVec3.z !=
                                                self._lastVec3.z):
         # clear last block
         self.drawPlanetInMC(mc, self._lastVec3, self._r, block.AIR)
         # draw new planet
         self.drawPlanetInMC(mc, newVec3, self._r, self._blockType)
         self._lastVec3 = newVec3
    def update(self):
        #Update the Bullet, should be called once per 'tick'
        # calculate new y velocity
        self.ticks += 1
        self.yVelocity = self.yStartVelocity + self.gravity * self.ticks

        # find the bullets new position
        newPos = minecraft.Vec3(
            self.currentPos.x + self.xVelocity,
            self.startPos.y + (self.yStartVelocity * self.ticks + 0.5 *
                               (self.gravity * pow(self.ticks, 2))),
            self.currentPos.z + self.zVelocity)
        #Has the bullet moved from its last drawn position
        # round the new position and compare it to the last drawn
        newDrawPos = minecraft.Vec3(int(round(newPos.x, 0)),
                                    int(round(newPos.y, 0)),
                                    int(round(newPos.z, 0)))
        movedBullet = True
        if matchVec3(newDrawPos, self.drawPos) == False:
            # if the bullet is moving to a block of air, move it, otherwise explode
            if self.mc.getBlock(newDrawPos.x, newDrawPos.y,
                                newDrawPos.z) == block.AIR:
                # clear the last drawn bullet
                self.clear()
                # move the draw position
                self.drawPos = minecraft.Vec3(newDrawPos.x, newDrawPos.y,
                                              newDrawPos.z)
                # draw the bullet
                self.draw()
            else:
                #exploded
                self.mcDrawing.drawSphere(newDrawPos, self.blastRadius,
                                          block.AIR)
                movedBullet = False
        #Update the current position
        self.currentPos = newPos

        return movedBullet
    def __init__(self, mc, position):

        #Constants
        self.lenghtOfGun = 5

        #Properties
        self.mc = mc
        self.position = position
        self.angle = 30
        self.direction = 0
        self.baseOfGun = minecraft.Vec3(position.x, position.y + 2, position.z)
        self.endOfGun = self.findEndOfGun()
        # minecraft drawing class
        self.mcDrawing = MinecraftDrawing(mc)
        # draw gun
        self.drawCannon()
        self.drawGun()
Exemple #6
0
    def __init__(self, blockType, initialState=None):
        if initialState != None:
            self._st = initialState
        else:
            # otherwise pick a random position and velocity
            self._st = State(float(random.randint(0, WIDTH)),
                             float(random.randint(0, HEIGHT)),
                             float(random.randint(0, 40) / 100.) - 0.2,
                             float(random.randint(0, 40) / 100.) - 0.2)

        self._r = 0.55

        self.setMassFromRadius()
        self._merged = False
        #MaOH - create a last vec3 which is representative of where the planet is now
        self._lastVec3 = minecraft.Vec3(roundNo(self._st._x),
                                        roundNo(self._st._y), ZPOSITION)
        self._blockType = blockType
Exemple #7
0
 def move(self):
     newSegment = minecraft.Vec3(self.tail[0].x, self.tail[0].y,
                                 self.tail[0].z)
     if self.direction == "up":
         newSegment.y = newSegment.y + 1
     elif self.direction == "down":
         newSegment.y = newSegment.y - 1
     elif self.direction == "left":
         newSegment.x = newSegment.x - 1
     elif self.direction == "right":
         newSegment.x = newSegment.x + 1
     if (self.checkCollision(newSegment) == False):
         self.addSegment(newSegment)
         #have I eaten the apple?
         if (matchVec3(newSegment, self.apple) == True):
             #increase my lenght
             self.lenght = self.lenght + 2
             #increase my score
             self.score = self.score + 10
             #create a new apple
             self.createApple()
         return True
     else:
         #game over
         #flash snake head
         mc.setBlock(self.tail[0].x, self.tail[0].y, self.tail[0].z,
                     block.AIR)
         time.sleep(0.3)
         mc.setBlock(self.tail[0].x, self.tail[0].y, self.tail[0].z,
                     block.DIAMOND_BLOCK)
         time.sleep(0.3)
         mc.setBlock(self.tail[0].x, self.tail[0].y, self.tail[0].z,
                     block.AIR)
         time.sleep(0.3)
         mc.setBlock(self.tail[0].x, self.tail[0].y, self.tail[0].z,
                     block.DIAMOND_BLOCK)
         time.sleep(0.3)
         #show score
         mc.postToChat("Game over - score = " + str(self.score))
         time.sleep(5)
         mc.postToChat("www.stuffaboutcode.com")
         return False
Exemple #8
0
def roundVec3(vec3):
    return minecraft.Vec3(int(vec3.x), int(vec3.y), int(vec3.z))
Exemple #9
0
        #Find the difference between the player's position and the last position
        movementX = lastPlayerPos.x - playerPos.x
        movementZ = lastPlayerPos.z - playerPos.z

        #Has the player moved more than 0.2 in any horizontal (x,z) direction
        if ((movementX < -0.2) or (movementX > 0.2) or (movementZ < -0.2)
                or (movementZ > 0.2)):

            #Project players direction forward to the next square
            nextPlayerPos = playerPos
            # keep adding the movement to the players location till the next block is found
            while ((int(playerPos.x) == int(nextPlayerPos.x))
                   and (int(playerPos.z) == int(nextPlayerPos.z))):
                nextPlayerPos = minecraft.Vec3(nextPlayerPos.x - movementX,
                                               nextPlayerPos.y,
                                               nextPlayerPos.z - movementZ)

            #Is the block below the next player pos air, if so fill it in with TNT
            blockBelowPos = roundVec3(nextPlayerPos)
            #to resolve issues with negative positions
            if blockBelowPos.z < 0: blockBelowPos.z = blockBelowPos.z - 1
            if blockBelowPos.x < 0: blockBelowPos.x = blockBelowPos.x - 1
            blockBelowPos.y = blockBelowPos.y - 1
            if mc.getBlock(blockBelowPos) == block.AIR:
                mc.setBlock(blockBelowPos.x, blockBelowPos.y, blockBelowPos.z,
                            block.TNT)

            #Store players last position
            lastPlayerPos = playerPos
Exemple #10
0
        return False


#draws a vertical outline
def drawVerticalOutline(mc, x0, y0, x1, y1, z, blockType, blockData=0):
    mc.setBlocks(x0, y0, z, x0, y1, z, blockType, blockData)
    mc.setBlocks(x0, y1, z, x1, y1, z, blockType, blockData)
    mc.setBlocks(x1, y1, z, x1, y0, z, blockType, blockData)
    mc.setBlocks(x1, y0, z, x0, y0, z, blockType, blockData)


#main program
if __name__ == "__main__":

    #constants
    screenBottomLeft = minecraft.Vec3(-10, 4, 15)
    screenTopRight = minecraft.Vec3(10, 24, 15)
    playingBottomLeft = minecraft.Vec3(-10, 4, 14)
    playingTopRight = minecraft.Vec3(10, 24, 14)
    snakeStart = minecraft.Vec3(0, 5, 14)
    upControl = minecraft.Vec3(0, -1, 1)
    downControl = minecraft.Vec3(0, -1, -1)
    leftControl = minecraft.Vec3(-1, -1, 0)
    rightControl = minecraft.Vec3(1, -1, 0)
    middleControl = minecraft.Vec3(0, 0, 0)

    #Connect to minecraft by creating the minecraft object
    # - minecraft needs to be running and in a game
    mc = minecraft.Minecraft.create()

    #Post a message to the minecraft chat window
Exemple #11
0
mc.setBlock(playerPosition.x, playerPosition.y, playerPosition.z + 2, block.AIR)

playerIds = mc.getPlayerEntityIds()
playerId = min(playerIds)
entityId = 0

mc.postToChat("Break the glass block to speed boost with that mob.")
mc.postToChat('Choose a chicken for best results.')
mc.setBlock(playerPosition.x, playerPosition.y + 1, playerPosition.z + 1, block.GLASS)

while True: 
	try:
		entityId = entityId + 1
		if entityId < playerId:
			entityPosition = mc.entity.getPos(entityId)
			entityPosition = minecraft.Vec3(int(entityPosition.x), int(entityPosition.y), int(entityPosition.z))
			mc.postToChat('Mob ' + str(int(entityId)))
			mc.entity.setTilePos(entityId, playerPosition.x, playerPosition.y, playerPosition.z + 2)
			time.sleep(3)
			if mc.getBlock(playerPosition.x, playerPosition.y + 1, playerPosition.z + 1) == block.GLASS.id:
				mc.entity.setPos(entityId, entityPosition.x, entityPosition.y, entityPosition.z)
			else:
				break
		else:
			break

	except Exception:
		continue

mc.setBlocks(playerPosition.x - 1, playerPosition.y, playerPosition.z + 1, playerPosition.x + 1, playerPosition.y, playerPosition.z + 3, block.AIR)
Exemple #12
0
class buffer:
    """
   Double-buffer a voxel message for Minecraft.
   To improve performance, only changes are rendered.
   """
    anchor_position = minecraft.Vec3(0, 0, 0)
    last_message = ''
    offscreen = []
    onscreen = []

    def __init__(self, anchor_position):
        """
      Set everything up to render messages into the world
      at the given position.
      """
        self.anchor_position = anchor_position

    def render(self, message):
        """
      Put message into the off-screen buffer.
      """
        if message != self.last_message:  # Do nothing if the message has not changed.
            self.last_message = message  # For next time.

            self.offscreen = []  # Clear any previous use of the buffer.
            letter_offset = 0
            for letter in message:
                rendition = digit_dots[letter]
                line_offset = 0
                for line in rendition:
                    if len(self.offscreen) <= line_offset:
                        # Make space to store the drawing.
                        self.offscreen.append([])
                    dot_offset = 0
                    for dot in line:
                        if dot == '0':
                            self.offscreen[line_offset].append(block.ICE)
                        else:
                            self.offscreen[line_offset].append(block.AIR)
                        dot_offset += 1
                    for blank in range(dot_offset, 6):
                        # Expand short lines to the full width of 6 voxels.
                        self.offscreen[line_offset].append(block.AIR)
                    line_offset += 1
                letter_offset += 1

            # Clear the onscreen buffer.
            # Should only happen on the first call.
            # Assumption: message will always be the same size.
            # Assumption: render() is called before flip().
            if self.onscreen == []:
                # No onscreen copy - so make it the same size as the offscreen image. Fill with AIR voxels.
                line_offset = 0
                for line in self.offscreen:
                    self.onscreen.append([])
                    for dot in line:
                        self.onscreen[line_offset].append(block.AIR)
                    line_offset += 1

    def flip(self, client):
        """
      Put the off-screen buffer onto the screen.
      Only send the differences.
      Remember the new screen for next flip.
      """
        line_offset = 0
        for line in self.offscreen:
            dot_offset = 0
            for dot in line:
                if self.onscreen[line_offset][dot_offset] != dot:
                    self.onscreen[line_offset][dot_offset] = dot
                    client.setBlock(self.anchor_position.x + dot_offset,
                                    self.anchor_position.y - line_offset,
                                    self.anchor_position.z, dot)
                dot_offset += 1
            line_offset += 1
Exemple #13
0
        #clear hand
        drawMinuteHand(mc, clockCentre, lastTime.minute, block.AIR)
        #new hand
        drawMinuteHand(mc, clockCentre, time.minute, block.STONE)

    #draw second hand
    if (lastTime.second != time.second):
        #clear hand
        drawSecondHand(mc, clockCentre, lastTime.second, block.AIR)
        #new hand
        drawSecondHand(mc, clockCentre, time.second, block.WOOD_PLANKS)


if __name__ == "__main__":

    clockCentre = minecraft.Vec3(0, 30, 0)
    radius = 20
    print "STARTED"
    time.sleep(5)
    #Connect to minecraft by creating the minecraft object
    # - minecraft needs to be running and in a game
    mc = minecraft.Minecraft.create()

    #Post a message to the minecraft chat window
    mc.postToChat("Hi, Minecraft Analogue Clock, www.stuffaboutcode.com")

    time.sleep(2)

    lastTime = datetime.datetime.now()
    drawClock(mc, clockCentre, radius, lastTime)
    try:
 def do_start(self, args):
     "Start cannon and create it [start]"
     self.mc = minecraft.Minecraft.create()
     playerPos = self.mc.player.getTilePos()
     self.cannon = MinecraftCannon(
         self.mc, minecraft.Vec3(playerPos.x + 3, playerPos.y, playerPos.z))
    def findEndOfGun(self):
        x, y, z = findPointOnSphere(self.baseOfGun.x, self.baseOfGun.y,
                                    self.baseOfGun.z, self.lenghtOfGun,
                                    self.direction, self.angle)

        return minecraft.Vec3(x, y, z)
    def getLine(self, x1, y1, z1, x2, y2, z2):

        # return 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
    #             "Metal_Brushed1": [block.IRON_BLOCK,None],
    #             "Rouge3141": [block.WOOL.id,14],
    #             "roof": [block.WOOL.id,8],
    #             "Metal_Aluminum_Anodized": [block.IRON_BLOCK,None],
    #             "Translucent_Glass_Safety": [block.GLASS, None],
    #             "Translucent_Glass_Safety1": [block.GLASS, None],
    #             "Safety_Glass2": [block.GLASS, None],
    #             "Red": [block.WOOL.id,14],
    #             "goal_net1": [block.WOOL.id,0],
    #             "Black": [block.WOOL.id,15]}
    #SWAPYZ = False
    #vertices,textures,normals,faces, materials = load_obj("City_Ground-Notts.obj", DEFAULTBLOCK, MATERIALS)

    # Raspbery Pi
    COORDSSCALE = 1350
    STARTCOORD = minecraft.Vec3(-50, 0, 0)
    CLEARAREA1 = minecraft.Vec3(-100, 0, -100)
    CLEARAREA2 = minecraft.Vec3(100, 20, 10)
    DEFAULTBLOCK = [block.DIRT, None]
    MATERIALS = {
        "Default_Material": [block.WOOL.id, 0],
        "Material1": [block.WOOL.id, 5],
        "Goldenrod": [block.WOOL.id, 1],
        "0136_Charcoal": [block.WOOL.id, 7],
        "Gray61": [block.WOOL.id, 7],
        "Charcoal": [block.WOOL.id, 7],
        "Color_002": [block.WOOL.id, 8],
        "Color_008": [block.WOOL.id, 4],
        "Plastic_Green": [block.WOOL.id, 5],
        "MB_Pastic_White": [block.WOOL.id, 0],
        "IO_Shiny": [block.IRON_BLOCK, None],
Exemple #18
0
Run this in survival mode to get resources dropped by dead monsters.
Run it in an area at or close to sea level (y~0).
'''

import minecraft.minecraft as minecraft
import minecraft.block as block
import time

mc = minecraft.Minecraft.create()

if __name__ == '__main__':
    pos = mc.player.getTilePos()

    solid_block = block.COBBLESTONE

    highpos = minecraft.Vec3(pos.x + 2, pos.y + 28, pos.z + 2)

    mc.setBlock(highpos.x - 10, pos.y, highpos.z - 9, highpos.x + 11,
                highpos.y, highpos.z + 11, block.TORCH)

    #Whole Room, not hollowed
    mc.setBlocks(highpos.x - 9, highpos.y, highpos.z - 9, highpos.x + 10,
                 highpos.y + 6, highpos.z + 10, solid_block)
    #Hollow the top half (keep the cieling)
    mc.setBlocks(highpos.x - 8, highpos.y + 3, highpos.z - 8, highpos.x + 9,
                 highpos.y + 5, highpos.z + 9, block.AIR)
    #Water and Waterway
    mc.setBlocks(highpos.x, highpos.y + 1, highpos.z - 8, highpos.x + 1,
                 highpos.y + 2, highpos.z + 9, block.AIR)
    mc.setBlocks(highpos.x - 8, highpos.y + 1, highpos.z, highpos.x + 9,
                 highpos.y + 2, highpos.z + 1, block.AIR)
    #Post a message to the minecraft chat window 
    mc.postToChat("Hi, Minecraft API, the basics, what can you do? ")

    time.sleep(5)
    
    #Find out your players position
    playerPos = mc.player.getPos()
    mc.postToChat("Find your position - its x=" + str(playerPos.x) + ", y=" + str(playerPos.y) + ", z=" + str(playerPos.z))

    time.sleep(5)
    
    #Using your players position
    # - the players position is an x,y,z coordinate of floats (e.g. 23.59,12.00,-45.32)
    # - in order to use the players position in other commands we need integers (e.g. 23,12,-45)
    # - so round the players position
    playerPos = minecraft.Vec3(int(playerPos.x), int(playerPos.y), int(playerPos.z))

    #Changing your players position
    mc.postToChat("Move your player - 30 blocks UP!")
    time.sleep(2)
    mc.player.setPos(playerPos.x,playerPos.y + 30,playerPos.z)
    # - wait for you to fall!
    time.sleep(5)

    #Interacting with a block
    # - get the type block directly below you
    blockType =  mc.getBlock(playerPos.x,playerPos.y - 1,playerPos.z)
    mc.postToChat("Interact with blocks - the block below you is of type - " + str(blockType))

    time.sleep(5)
    
Exemple #20
0
#! /usr/bin/env python

import minecraft.minecraft as minecraft
import minecraft.block as block
import time

mc = minecraft.Minecraft.create()
if __name__ == '__main__':

    playerPosition = mc.player.getTilePos()
    playerPosition = minecraft.Vec3(int(playerPosition.x),
                                    int(playerPosition.y),
                                    int(playerPosition.z))

    mc.setBlock(playerPosition.x, playerPosition.y + 50, playerPosition.z,
                block.AIR)
    mc.player.setTilePos(playerPosition.x, playerPosition.y + 50,
                         playerPosition.z)
    mc.postToChat('WHEEEEEEEE!!')
    mc.setBlock(playerPosition.x, playerPosition.y + 2, playerPosition.z,
                block.WATER_STATIONARY)
    time.sleep(2.5)
    mc.setBlock(playerPosition.x, playerPosition.y + 2, playerPosition.z,
                block.AIR)
Exemple #21
0
    #BLOCKTYPE = block.GOLD_BLOCK
    #SWAPYZ = False
    #vertices,textures,normals,faces = load_obj("head.obj")

    # Cessna
    #COORDSSCALE = 2
    #STARTCOORD = minecraft.Vec3(-75, 25, -60)
    #CLEARAREA1 = minecraft.Vec3(-30, 15, -30)
    #CLEARAREA2 = minecraft.Vec3(-100, 65, -90)
    #BLOCKTYPE = block.WOOD_PLANKS
    #SWAPYZ = False
    #vertices,textures,normals,faces = load_obj("cessna.obj")

    # New York
    COORDSSCALE = 0.1
    STARTCOORD = minecraft.Vec3(-185, 0, 135)
    CLEARAREA1 = minecraft.Vec3(-130, 0, -130)
    CLEARAREA2 = minecraft.Vec3(130, 65, 130)
    BLOCKTYPE = block.IRON_BLOCK
    SWAPYZ = False
    vertices, textures, normals, faces = load_obj("NY_LIL.obj")

    print "obj file loaded"

    # clear a suitably large area
    mc.setBlocks(CLEARAREA1.x, CLEARAREA1.y, CLEARAREA1.z, CLEARAREA2.x,
                 CLEARAREA2.y, CLEARAREA2.z, block.AIR)
    time.sleep(10)

    # loop through faces
    for face in faces: