How to use mcpi - 10 common examples

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 koduj-z-klasa / python101 / docs / mcpi / funkcje / mcpi-funkcje06.py View on Github external
print x1, "\n", y1

    x2 = range(0, 361, 10)  # lista argumentów x
    y2 = [None if i == 90 or i == 270 else np.tan(i * np.pi / 180) for i in x2]
    x2 = [i // 10 for i in x2]
    y2 = [round(i * 3, 2) if i is not None else None for i in y2]
    print x2, "\n", y2
    wykres(x1, y1, "Funkcje sinus i tangens", x2, y2)

    del x2[9]  # usuń 10 element listy
    del y2[9]  # usuń 10 element listy
    del x2[x2.index(27)]  # usuń element o wartości 27
    del y2[y2.index(None)]  # usuń element None
    print x2, "\n", y2
    rysuj(x1, [1], y1, block.GOLD_BLOCK)
    rysuj(x2, y2, [1], block.OBSIDIAN)
github arpruss / raspberryjam-pe / p2 / scripts / import.py View on Github external
def importSchematic(mc,path,x0,y0,z0,centerX=False,centerY=False,centerZ=False,clear=False,movePlayer=True):
    mc.postToChat("Reading "+path);
    schematic = nbt.NBTFile(path, "rb")
    sizeX = schematic["Width"].value
    sizeY = schematic["Height"].value
    sizeZ = schematic["Length"].value

    def offset(x,y,z):
        return x + (y*sizeZ + z)*sizeX

    px,pz = x0,z0

    if centerX:
        x0 -= sizeX // 2
    if centerY:
        y0 -= sizeY // 2
    if centerZ:
        z0 -= sizeZ // 2
github arpruss / raspberryjam-pe / p3 / scripts / import.py View on Github external
def importSchematic(mc,path,x0,y0,z0,centerX=False,centerY=False,centerZ=False,clear=False,movePlayer=True):
    mc.postToChat("Reading "+path);
    schematic = nbt.NBTFile(path, "rb")
    sizeX = schematic["Width"].value
    sizeY = schematic["Height"].value
    sizeZ = schematic["Length"].value

    def offset(x,y,z):
        return x + (y*sizeZ + z)*sizeX

    px,pz = x0,z0

    if centerX:
        x0 -= sizeX // 2
    if centerY:
        y0 -= sizeY // 2
    if centerZ:
        z0 -= sizeZ // 2
github arpruss / raspberryjammod-minetest / raspberryjammod / mcpipy / console.py View on Github external
while True:
        chats = mc.events.pollChatPosts()
        for c in chats:
            if c.entityId == playerId:
                print c.message
                if c.message == 'quit':
                    return 'quit()'
                elif c.message == ' ':
                    return ''
                elif "__" in c.message:
                    sys.exit();
                else:
                    return c.message
        time.sleep(0.2)

mc = minecraft.Minecraft()
playerPos = mc.player.getPos()
playerId = mc.getPlayerId()

mc.postToChat("Enter python code into chat, type 'quit' to quit.")
i = code.interact(banner="Minecraft Python ready", readfunc=inputLine, local=locals())
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 arpruss / raspberryjammod-minetest / raspberryjammod / mcpipy / render.py View on Github external
self.controlFileLines.append("swapyz 0\n")
                self.controlFileLines.append("#credits Mesh by ..., copyright (c) ...\n")
                self.controlFileLines.append("yaw 0\n")
                self.controlFileLines.append("pitch 0\n")
                self.controlFileLines.append("roll 0\n")
                self.controlFileLines.append("size " + str(self.size) + "\n")
                self.controlFileLines.append("default STONE\n")
                self.controlFileLines.append("#order material position\n")
                self.controlFileLines.append("materials\n")
                self.haveMaterialArea = True
                self.endLineIndex = len(self.controlFileLines)
                self.controlFileLines.append("end\n\n")
                self.controlFileLines.append("[Insert any detailed licensing information here]")
                for line in self.controlFileLines:
                    f.write(line)
         if settings.isPE:
             self.size /= 2
github arpruss / raspberryjammod-minetest / raspberryjammod / mcpipy / sierpinski3d.py View on Github external
for p in bottom:
        yield (level+1,height/2.,average(apex,p))

def sierpinski(height, x,y,z, level):
    tetrahedra = [(0,height,(x,y,z))]
    for i in range(level):
        out = []
        for tet in tetrahedra:
            out += transform(tet)
        tetrahedra = out
    return tetrahedra

mc = Minecraft()
d = drawing.Drawing(mc)
pos = mc.player.getPos()
height = 240 if not settings.isPE else 128
levels = 7
mc.player.setPos(tetrahedronBottom(height,(pos.x,pos.y+height,pos.z))[0])
tetrahedra = sierpinski(height,pos.x,pos.y+height,pos.z,levels)
mc.postToChat("Drawing")
if len(argv) >= 2 and '__' not in argv[1]:
    specifiedBlock = parseBlock(argv[1])
    block = lambda level : specifiedBlock
else:
    block = lambda level : RAINBOW[level % len(RAINBOW)]
for tet in tetrahedra:
    drawTetrahedron(tet[1],tet[2],block(tet[0]))
github kbsriram / mcpiapi / mcpimods / python / clear.py View on Github external
def asCardinalDirection(yaw):
    while yaw < 0:
        yaw = yaw + 360
    while yaw > 360:
        yaw = yaw - 360

    if (yaw < 45) or (yaw > 315):
        return 0 # South
    elif yaw < 135:
        return 1 # West
    elif yaw < 225:
        return 2 # North
    else:
        return 3 # East

mc = minecraft.Minecraft.create()
if len(sys.argv) != 4:
    mc.postToChat('Usage: /py clear   ')
    exit(0)
try:
    x = int(sys.argv[1])
    y = int(sys.argv[2])
    z = int(sys.argv[3])
except ValueError:
    mc.postToChat('Usage: /py clear   ')
    exit(0)

ppos = mc.player.getTilePos()

# Where is the player looking (to the closest cardinal direction)
direction = asCardinalDirection(mc.player.getRotation())
print "direction", direction
github scratch2mcpi / scratch2mcpi / scratchx2mcpi.py View on Github external
self.send_response(200)
        self.end_headers()
        command_path = parsed_path[2].split('/')
        handler = commands[command_path[1]]
        result = handler(command_path[2:])
        self.wfile.write(result)
        return

if __name__ == '__main__':
    print "================="
    print "SratchX2MCPI %s" % VERSION
    print "================="
    print ""

    try:
        mc = minecraft.Minecraft.create()
    except:
        e = sys.exc_info()[0]
        log.exception('Unable to connect to Minecraft Pi.')
        traceback.print_exc(file=sys.stdout)
        sys.exit(0)

    server = HTTPServer(('localhost', 8080), ScratchX2MCPIServer)
    log.info('Starting ScratchX2MCPIServer, use  to stop.')
    server.serve_forever()
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)