How to use the mcpi.minecraft.Minecraft function in mcpi

To help you get started, we’ve selected a few mcpi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arpruss / raspberryjammod-minetest / raspberryjammod / mcpipy / helloworld.py View on Github external
import mcpi.minecraft as minecraft
import mcpi.block as block
import server
import sys
mc = minecraft.Minecraft()
mc.postToChat("Hello world!")
playerPos = mc.player.getPos()
mc.setBlock(playerPos.x,playerPos.y-1,playerPos.z,block.DIAMOND_ORE)
github brooksc / mcpipy / daviewales_minesweeper.py View on Github external
mc.setBlock(x, y, z, 0) # (If you hit a mine it clears the board.)
                    mc.postToChat("You Lose!")
                    running = False
                    sys.exit()

                if newBoard[cursorX][cursorY] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
                    #visibleScreen[x][y] = newBoard[x][y]
                    mc.setBlock(cursorX, cursorY, cursorZ, 0) # We just remove the top layer.

                if newBoard[cursorX][cursorY] == " ":
                    explore(cursorX, cursorY, cursorZ)

#def main():
global running
running = True
mc = minecraft.Minecraft.create(server.address)
board = board()
newBoard = board.create()
visibleScreen = board.visibleScreen()

for x in xrange(width):
    for y in xrange(height):
        mc.setBlock(x,y,-1,0)

z = 0 # For now... We can make this dynamic later.
for y in xrange(height):
   for x in xrange(width):
       # This bit of code's dodgy, because it relies on the 
       # creation of "visibleScreen" external to the function...
       minecraftAddBlock(x, y, z, "dirt")

WinningCheck = WinningCheckThread(board.mineCoords, board.mineNumber, z)
github koduj-z-klasa / python101 / docs / mcpi / rgame / mcpi-rg01.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import json
from time import sleep
import mcpi.minecraft as minecraft  # import modułu minecraft
import mcpi.block as block  # import modułu block

os.environ["USERNAME"] = "Steve"  # nazwa użytkownika
os.environ["COMPUTERNAME"] = "mykomp"  # nazwa komputera

mc = minecraft.Minecraft.create("192.168.1.10")  # połączenie z MCPi


class GraRobotow(object):
    """Główna klasa gry"""

    obstacle = [(0,0),(1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0),(9,0),
        (10,0),(11,0),(12,0),(13,0),(14,0),(15,0),(16,0),(17,0),(18,0),(0,1),
        (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(12,1),(13,1),(14,1),(15,1),
        (16,1),(17,1),(18,1),(0,2),(1,2),(2,2),(3,2),(4,2),(14,2),(15,2),
        (16,2),(17,2),(18,2),(0,3),(1,3),(2,3),(16,3),(17,3),(18,3),(0,4),
        (1,4),(2,4),(16,4),(17,4),(18,4),(0,5),(1,5),(17,5),(18,5),(0,6),
        (1,6),(17,6),(18,6),(0,7),(18,7),(0,8),(18,8),(0,9),(18,9),(0,10),
        (18,10),(0,11),(18,11),(0,12),(1,12),(17,12),(18,12),(0,13),(1,13),
        (17,13),(18,13),(0,14),(1,14),(2,14),(16,14),(17,14),(18,14),(0,15),
        (1,15),(2,15),(16,15),(17,15),(18,15),(0,16),(1,16),(2,16),(3,16),
        (4,16),(14,16),(15,16),(16,16),(17,16),(18,16),(0,17),(1,17),(2,17),
github brooksc / mcpipy / brooksc_teleport_pad.py View on Github external
# as shared on mcpipy.com

import mcpi.minecraft as minecraft
import mcpi.block as block
import time
import server


# If you are running this script with the bukkit mod, then use a diamond block as the magic center block for teleporting
# comment/uncomment below as appropriate
magic_block = block.DIAMOND_BLOCK # for bukkit server
#magic_block = block.NETHER_REACTOR_CORE # for raspberry pi

if __name__ == "__main__": # The script
    mc = minecraft.Minecraft.create(server.address)
    loc = mc.player.getPos()
    x = loc.x
    y = loc.y - 1
    z = loc.z
    for z_z in range (int(z-1), int(z+2)):
        for x_x in range(int(x-1), int(x+2)):
            mc.setBlock(x_x,y,z_z, block.COBBLESTONE)
            mc.setBlock(x_x,y+1,z_z, block.AIR)

mc.setBlock(x,y,z, magic_block)
github bennuttall / sense-hat-examples / python / minecraft_map.py View on Github external
block = mc.getBlock(dx, y+0, dz)
                known_blocks[b] = block
            blocks.append(block)

    return blocks

def lookup_colour(block):
    if block in colours:
        return colours[block]
    else:
        return white

def map_blocks_to_colours(blocks):
    return [lookup_colour(block) for block in blocks]

mc = minecraft.Minecraft.create()
sense = SenseHat()

known_blocks = {}

# blocks
air = 0
grass = 2
water = 9
sand = 12

# colours
white = (150, 150, 150)
green = (0, 150, 0)
blue = (0, 0, 150)
yellow = (150, 150, 0)
black = (0, 0, 0)
github martinohanlon / mcpi / mcpi / minecraft.py View on Github external
def removeEntity(self, id):
        """Remove entity by id (entityId:int) => (removedEntitiesCount:int)"""
        return int(self.conn.sendReceive(b"world.removeEntity", int(id)))

    def removeEntities(self, typeId=-1):
        """Remove entities all currently loaded Entities by type (typeId:int) => (removedEntitiesCount:int)"""
        return int(self.conn.sendReceive(b"world.removeEntities", typeId))

    @staticmethod
    def create(address = "localhost", port = 4711):
        return Minecraft(Connection(address, port))


if __name__ == "__main__":
    mc = Minecraft.create()
    mc.postToChat("Hello, Minecraft!")
github koduj-z-klasa / python101 / docs / mcpi / funkcje / mcpi-funkcje05.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import numpy as np  # import biblioteki do obliczeń naukowych
import matplotlib.pyplot as plt  # import biblioteki do tworzenia wykresów
import mcpi.minecraft as minecraft  # import modułu minecraft
import mcpi.block as block  # import modułu block

os.environ["USERNAME"] = "Steve"  # wpisz dowolną nazwę użytkownika
os.environ["COMPUTERNAME"] = "mykomp"  # wpisz dowolną nazwę komputera

mc = minecraft.Minecraft.create("192.168.1.10")  # połaczenie z mc


def plac(x, y, z, roz=10, gracz=False):
    """
    Funkcja tworzy podłoże i wypełnia sześcienny obszar od podanej pozycji,
    opcjonalnie umieszcza gracza w środku.
    Parametry: x, y, z - współrzędne pozycji początkowej,
    roz - rozmiar wypełnianej przestrzeni,
    gracz - czy umieścić gracza w środku
    Wymaga: globalnych obiektów mc i block.
    """

    podloga = block.STONE
    wypelniacz = block.AIR

    # podloga i czyszczenie
github brooksc / mcpipy / mcpi / examples / brooksc_template.py View on Github external
def main():
    mc = minecraft.Minecraft.create(server.address)
    # write the rest of your code here...
    mc.postToChat("Hello MCPIPY World!")