def __init__(self, x, y, z, blockType, blockData=0): #persist data self.blockType = blockType self.blockData = blockData #store the positions # 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 mc block object self.mcBlock = block.Block(blockType, blockData)
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
def drawCube(mcDrawing): # Cube COORDSSCALE = 10 STARTCOORD = minecraft.Vec3(0, 10, 0) CLEARAREA1 = minecraft.Vec3(-10, 0, -10) CLEARAREA2 = minecraft.Vec3(10, 20, 10) DEFAULTBLOCK = [block.STONE, None] MATERIALS = {} SWAPYZ = False vertices, textures, normals, faces, materials = load_obj( "cube.obj", DEFAULTBLOCK, MATERIALS) print("obj file loaded") doDrawing(faces, vertices, materials, mcDrawing, COORDSSCALE, STARTCOORD, CLEARAREA1, CLEARAREA2, SWAPYZ)
def drawBeijingTemple(mcDrawing): mc = minecraft.Minecraft.create() pos = mc.player.getTilePos() STARTCOORD = minecraft.Vec3(pos.x, pos.y, pos.z) CLEARAREA1 = minecraft.Vec3(pos.x - 100, pos.y, pos.z - 100) CLEARAREA2 = minecraft.Vec3(pos.x + 100, pos.y + 100, pos.z + 100) DEFAULTBLOCK = [block.DIRT, None] COORDSSCALE = 10 MATERIALS = {} SWAPYZ = False vertices, textures, normals, faces, materials = load_obj( "BeijingTemple.obj", DEFAULTBLOCK, MATERIALS) print("obj file loaded") doDrawing(faces, vertices, materials, mcDrawing, COORDSSCALE, STARTCOORD, CLEARAREA1, CLEARAREA2, SWAPYZ)
def theHoles(arenaPos, holesZPos): #create connection to minecraft mc = minecraft.Minecraft.create() #constants HOLES = 15 HOLESWIDTH = 3 while not gameOver: #create random holes which open up for a few seconds, close, then change to a different set of holes holes = [] #find some random holes for count in range(0, HOLES): x = random.randint(arenaPos.x, arenaPos.x + ARENAX) z = random.randint(arenaPos.z + holesZPos, arenaPos.z + holesZPos + HOLESWIDTH) holes.append(minecraft.Vec3(x, arenaPos.y, z)) #turn the holes black before opening them up for hole in holes: mc.setBlock(hole.x, hole.y, hole.z, block.WOOL.id, 15) time.sleep(0.25) #open up the holes for hole in holes: mc.setBlocks(hole.x, hole.y, hole.z, hole.x, hole.y - 2, hole.z, block.AIR.id) time.sleep(2) #close up the holes for hole in holes: mc.setBlocks(hole.x, hole.y, hole.z, hole.x, hole.y - 2, hole.z, block.GRASS.id) time.sleep(0.25)
def setupBoard(self, playerPos, width, depth): # Draw the game board, two blocks back from where we are standing x, y, z = playerPos.x, playerPos.y, playerPos.z z = z - 2 x = x - 2 y = y - 1 mc.setBlocks(x - 10, y, z + 3, x + width + 5, y + 10, z - depth - 5, block.AIR.id) mc.setBlocks(x - 5, y - 1, z + 3, x + width + 2, y - 1, z - depth - 5, block.GRASS.id) # 11 is blue wool, change it as you wish mc.setBlocks(x, y, z, x + width, y, z - depth, block.WOOL.id, 11) # score board is set back two blocks from the end of the board mc.setBlocks(x, y, z - depth - 2, x + width, y + 9, z - depth - 2, block.WOOL, 0) # Now for the grid of mole holes, separated by one block of wool for i in range(1, width + 1, 2): for j in range(1, depth - 1, 2): mc.setBlock(x + i, y, z - j, block.STONE.id) # The moles will appear one block above the stone blocks # Store the coordinates in a list, as of possible targets for the player # the coordinates are converted into a single variable target = minecraft.Vec3(x + i, y + 1, z - j) self.targetList.append(target) self.emptyMoles = self.targetList for mymole in self.emptyMoles: print(mymole)
def theRiver(arenaPos, riverZPos): mc = minecraft.Minecraft.create() # констатнты реки RIVERWIDTH = 4 BRIDGEWIDTH = 2 # создаем реку mc.setBlocks(arenaPos.x, arenaPos.y - 2, arenaPos.z + riverZPos, arenaPos.x + ARENAX, arenaPos.y, arenaPos.z + riverZPos + RIVERWIDTH - 1, block.AIR.id) # наполняем реку mc.setBlocks(arenaPos.x, arenaPos.y - 2, arenaPos.z + riverZPos, arenaPos.x + ARENAX, arenaPos.y - 2, arenaPos.z + riverZPos + RIVERWIDTH - 1, block.WATER.id) # создаем мост bridgePos = minecraft.Vec3(arenaPos.x, arenaPos.y, arenaPos.z + riverZPos + 1) bridgeBlocks = [] for x in range(0, BRIDGEWIDTH): for z in range(0, RIVERWIDTH - 2): bridgeBlocks.append( minecraftstuff.ShapeBlock(x, 0, z, block.WOOD_PLANKS.id)) bridgeShape = minecraftstuff.MinecraftShape(mc, bridgePos, bridgeBlocks) # перемещаем мост влевло-вправо steps = ARENAX - BRIDGEWIDTH while not gameOver: for left in range(0, steps): bridgeShape.moveBy(1, 0, 0) time.sleep(1) for right in range(0, steps): bridgeShape.moveBy(-1, 0, 0) time.sleep(1)
def theHoles(arenaPos, holesZPos): mc = minecraft.Minecraft.create() # константы ям HOLES = 15 HOLESWIDTH = 3 while not gameOver: # создадим ямы которые генерируются случайным образом, а затем исчезают holes = [] # генерим координаты ям for count in range(0, HOLES): x = random.randint(arenaPos.x, arenaPos.x + ARENAX) z = random.randint(arenaPos.z + holesZPos, arenaPos.z + holesZPos + HOLESWIDTH) holes.append(minecraft.Vec3(x, arenaPos.y, z)) # перед тем как открыть яму зачерняем область for hole in holes: mc.setBlock(hole.x, hole.y, hole.z, block.WOOL.id, 15) time.sleep(0.25) # открываем яму for hole in holes: mc.setBlocks(hole.x, hole.y, hole.z, hole.x, hole.y - 2, hole.z, block.AIR.id) time.sleep(2) # закрываем яму for hole in holes: mc.setBlocks(hole.x, hole.y, hole.z, hole.x, hole.y - 2, hole.z, block.GRASS.id) time.sleep(0.25)
def restore(self, dict): for attribute in Turtle.QUICK_SAVE: setattr(self, attribute, dict[attribute]) p = dict['position'] self.position = minecraft.Vec3(p[0], p[1], p[2]) self.positionOut() self.directionOut()
def doDrawing(faces, vertices, materials, mcDrawing, scale, startCoord, clearArea1, clearArea2, swapYZ): mc.setBlocks(clearArea1.x, clearArea1.y, clearArea1.z, clearArea2.x, clearArea2.y, clearArea2.z, block.AIR) waitSeconds = 30 print("Finish area clearant. sleep %d seconds...." % waitSeconds) time.sleep(waitSeconds) print("Finish sleeping") faceCount = 0 # loop through faces for face in faces: faceVertices = [] # loop through vertex's in face and call drawFace function for vertex in face: #strip co-ords from vertex line vertexX, vertexY, vertexZ = getVertexXYZ(vertices[vertex[0]], scale, startCoord, swapYZ) faceVertices.append(minecraft.Vec3(vertexX, vertexY, vertexZ)) # draw the face # print("face count = " + str(faceCount) + " blockType = " + str(materials[faceCount][0]) + " blockData = " + str(materials[faceCount][1]) ) mcDrawing.drawFace(faceVertices, materials[faceCount][0], materials[faceCount][1]) faceCount = faceCount + 1
def __init__(self, mc, position=minecraft.Vec3(0, 0, 0)): # 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))
def clear_space(self): pos = self.mc.player.getPos() pos = minecraft.Vec3(int(pos.x), int(pos.y), int(pos.z)) self.mc.setBlocks(pos.x - 50, pos.y + 0, pos.z - 50, pos.x + 50, pos.y + 60, pos.z + 42, block.AIR) self.mc.setBlocks(pos.x - 50, pos.y - 1, pos.z - 50, pos.x + 50, pos.y - 2, pos.z + 50, block.SAND) self.chat('Space cleared by ' + self.ip)
def ZigZag(): #Nombre de funcion = contrasena coord = minecraft.Vec3( 346, 71, 774) #!!!! Coordenada para el teleporte de esta contrasena mc.postToChat("Your password has been accepted.") mc.player.setTilePos(coord) time.sleep(0.5) mc.postToChat("Welcome to the maze.") sys.exit() #Ya esta todo hecho. Quita el script
def House(): #Nombre de funcion = contrasena coord = minecraft.Vec3( 175, 65, 335) #!!!! Coordenada para el teleporte de esta contrasena mc.postToChat("Your password has been accepted.") mc.player.setTilePos(coord) time.sleep(0.5) mc.postToChat("Welcome home!") sys.exit() #Ya esta todo hecho. Quita el script
def ohSecret(): # Nombre de funcion = contrasena coord = minecraft.Vec3( 177, 62, 332) # Coordenada para el teleporte de esta contrasena mc.postToChat("Contraseña acceptada.") # Mensajes para el jugador mc.player.setTilePos(coord) time.sleep(0.5) mc.postToChat("Teleporte concluido. Has descubierto un secreto!") sys.exit() #Ya esta todo hecho. Quita el script
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)
def playerPosToChat(self, params): log.info('playerPos to chat') playerPos = mc.player.getPos() log.debug(playerPos) playerPos = minecraft.Vec3(int(playerPos.x), int(playerPos.y), int(playerPos.z)) log.debug(playerPos) posStr = ("x {0} y {1} z {2}".format(str(playerPos.x), str(playerPos.y), str(playerPos.z))) log.debug(posStr) mc.postToChat(urllib.unquote(posStr)) return ''
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)
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))
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 make_carpet(self, pos=None, coord=None, offset_x=2): point = minecraft.Vec3(pos.x + offset_x, pos.y, pos.z) self.log_to_console("clearing in front of") self.clear_area_in_front_of(point, length=len(coord), width=len(coord[0]), height=1) self.log_to_console("doing carpet...") for z in range(len(coord)): for x in range(len(coord[0])): self.mc.setBlock(point.x + x, point.y, point.z + z, block.WOOL.id, int(coord[z][x]))
class buffer: """ Double-buffer a voxel block for Minecraft. To improve performance, only changes are actually sent to Minecraft. """ anchor_position = minecraft.Vec3(0,0,0) offscreen = None onscreen = None def __init__(self, anchor_position): """ Set everything up to render the voxels into the world at the given position. """ self.anchor_position = anchor_position self.onscreen = Image.new("L", (32,32), color=0) def render(self): """ Get a picture of the clock. """ self.offscreen = draw_clock() def flip(self, client): """ Put the off-screen buffer onto the screen. Only send the differences. Remember the new screen for use during the next flip. """ if self.offscreen: width,height = self.offscreen.size draw = ImageDraw.Draw(self.onscreen) # So we can remember what we did for next time. for x in range(0, width - 1): for z in range(0, height - 1): dot = self.offscreen.getpixel((x,z)) if self.onscreen.getpixel((x,z)) != dot: # Change detected. draw.point((x,z), fill=dot) # Pick display items that suit the antialiasing. display = block.SNOW_BLOCK # Very white. if (dot >= colour_dark+16) and (dot < colour_medium + 16): display = block.WOOL # Light grey. elif (dot >= colour_medium + 16) and (dot < colour_light + 16): display = block.STONE # Medium grey. elif (dot >= colour_light + 16): display = block.OBSIDIAN # Blackish. client.setBlock(self.anchor_position.x + x, self.anchor_position.y, self.anchor_position.z + z, display)
def NextMove(current_position, last_position): print(f"Looking for next move - Cur {current_position}") for i, j in [(-1, 0), (1, 0), (0, -1), (0, 1)]: x = current_position.x + i z = current_position.z + j print(f"Checking {x},{z} --- Last {last_position.x},{last_position.z}") if (mc.getBlock(x, y - 1, z) == block.GOLD_BLOCK.id): print(f"{x},{z} --- Gold!") if (PositionMatches(minecraft.Vec3(x, y, z), last_position)): print(f"{x},{z} --- Failure - Position matches last") else: print(f"{x},{z} --- Success") return (x, y, z) else: print(f"{x},{z} --- Failure - No gold") return None
def make_picture(self, pos= None, coord=None, offset_x=2, offset_y=2): point = minecraft.Vec3(pos.x + offset_x, pos.y + offset_y, pos.z) self.log_to_console("clearing in front of") self.clear_area_in_front_of(point, length=len(coord), width=1, height=len(coord[0])) self.log_to_console("doing picture...") y = 0 for z in range(len(coord) - 1, -1, -1): for x in range(len(coord[0])): self.mc.setBlock(point.x + x, point.y + y, point.z, block.WOOL.id, int(coord[z][x])) y += 1
def make_sculpture(self, pos= None, coord=None, offset_x=2, offset_y=2): point = minecraft.Vec3(pos.x + offset_x, pos.y + offset_y, pos.z) self.log_to_console("clearing in front of") self.clear_area_in_front_of(point, length=len(coord), width=1, height=len(coord[0])) self.log_to_console("doing sculpture...") y = 0 for z in range(len(coord) - 1, -1, -1): for x in range(len(coord[0])): block_id = block.BEDROCK.id if int(coord[z][x]) > 0 else block.AIR.id self.mc.setBlock(point.x + x, point.y + y, point.z, block_id) y += 1
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)
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()
def theRiver(arenaPos, riverZPos): #create connection to minecraft mc = minecraft.Minecraft.create() #constants RIVERWIDTH = 4 BRIDGEWIDTH = 2 #create the river mc.setBlocks(arenaPos.x, arenaPos.y - 2, arenaPos.z + riverZPos, arenaPos.x + ARENAX, arenaPos.y, arenaPos.z + riverZPos + RIVERWIDTH - 1, block.AIR.id) #fill with water mc.setBlocks(arenaPos.x, arenaPos.y - 2, arenaPos.z + riverZPos, arenaPos.x + ARENAX, arenaPos.y - 2, arenaPos.z + riverZPos + RIVERWIDTH - 1, block.WATER.id) #create the bridge shape bridgePos = minecraft.Vec3(arenaPos.x, arenaPos.y, arenaPos.z + riverZPos + 1) bridgeShape = minecraftstuff.MinecraftShape(mc, bridgePos) bridgeShape.setBlocks( 0, 0, 0, BRIDGEWIDTH - 1, 0, RIVERWIDTH - 3, block.WOOD_PLANKS.id) #move the bridge left and right #how many steps are there between the left and right side of the arena steps = ARENAX - BRIDGEWIDTH + 1 while not gameOver: for left in range(0, steps): bridgeShape.moveBy(1,0,0) time.sleep(1) for right in range(0, steps): bridgeShape.moveBy(-1,0,0) time.sleep(1)
def theWall(arenaPos, wallZPos): mc = minecraft.Minecraft.create() # создаем подвижную стену wallPos = minecraft.Vec3(arenaPos.x, arenaPos.y + 1, arenaPos.z + wallZPos) wallBlocks = [] for x in range(0, ARENAX + 1): for y in range(1, ARENAY): wallBlocks.append( minecraftstuff.ShapeBlock(x, y, 0, block.BRICK_BLOCK.id)) wallShape = minecraftstuff.MinecraftShape(mc, wallPos, wallBlocks) # передвигаем стену вверх-вниз while not gameOver: wallShape.moveBy(0, 1, 0) time.sleep(1) wallShape.moveBy(0, -1, 0) time.sleep(1)
def pollEvents(self, params): global pollInc, pollLimit, prevPosStr pollInc += 1 log.debug('poll: {} {}'.format(pollInc, prevPosStr)) if (prevPosStr != "") and (pollInc % pollLimit != 0): log.debug("don't call mc") return prevPosStr log.debug("call mc") playerPos = mc.player.getPos() #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 # - the Vec3 object is part of the minecraft class library playerPos = minecraft.Vec3(int(playerPos.x), int(playerPos.y), int(playerPos.z)) posStr = ("playerPos/x {0}\r\nplayerPos/y {1}\r\nplayerPos/z {2}".format(str(playerPos.x), str(playerPos.y), str(playerPos.z))) prevPosStr = posStr return posStr