How to use the mcpi.minecraft.Minecraft.create 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 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 whaleygeek / bitio / src / tilt_mc.py View on Github external
import mcpi.minecraft as minecraft
import microbit
import time

mc = minecraft.Minecraft.create()

while True:
    pos = mc.player.getTilePos()
    x = microbit.accelerometer.get_x()/300 # -ve=left/+ve=right
    y = microbit.accelerometer.get_y()/300 # -ve=forward/+ve=backward

    pos.x += x # east/west
    pos.z += y # north/south

    mc.player.setTilePos(pos.x, pos.y, pos.z)

    time.sleep(0.5)
github denosawr / mcpi-scratch / mcpi-scratch / mcpi-scratch-server.py View on Github external
It's meant for use with the MCPi-Scratch extension. You can get that extension here: https://github.denosawr/MCPi-Scratch.

Extension hanging or not working? There may be some pearls of wisdom in the stdout here.

Connecting to Minecraft: Pi Edition (make sure it's up and running)... """
	print(msg, end="")


BLOCK_IDS = {  # from https://www.stuffaboutcode.com/p/minecraft-api-reference.html
	"air": 0, "stone": 1, "grass": 2, "dirt": 3, "cobblestone": 4, "wood_planks": 5, "sapling": 6, "bedrock": 7, "water": 8, "lava": 10, "sand": 12, "gravel": 13, "gold_ore": 14, "iron_ore": 15, "coal_ore": 16, "wood": 17, "leaves": 18, "glass": 20, "lapis_lazuli_ore": 21, "lapis_lazuli_block": 22, "sandstone": 24, "bed": 26, "cobweb": 30, "grass_tall": 31, "wool": 35, "flower_yellow": 37, "flower_cyan": 38, "mushroom_brown": 39, "mushroom_red": 40, "gold_block": 41, "iron_block": 42, "stone_slab_double": 43, "stone_slab": 44, "brick_block": 45, "tnt": 46, "bookshelf": 47, "moss_stone": 48, "obsidian": 49, "torch": 50, "fire": 51, "stairs_wood": 53, "chest": 54, "diamond_ore": 56, "diamond_block": 57, "crafting_table": 58, "farmland": 60, "furnace_inactive": 61, "furnace_active": 62, "door_wood": 64, "ladder": 65, "stairs_cobblestone": 67, "door_iron": 71, "redstone_ore": 73, "snow": 78, "ice": 79, "snow_block": 80, "cactus": 81, "clay": 82, "sugar_cane": 83, "fence": 85, "glowstone_block": 89, "bedrock_invisible": 95, "stone_brick": 98, "glass_pane": 102, "melon": 103, "fence_gate": 107, "glowing_obsidian": 246, "nether_reactor_core": 247,
}

if __name__ == "__main__":
	startupBanner()

	mc = minecraft.Minecraft.create()
	server = SimpleWebSocketServer('', 9095, MCPiScratchServer)

	print("Done!\nStarting websocket server on Port 9095. Ctrl+C to cancel, or you can just close this Terminal window.\n")
	print("\rConnected: 0        ", end="")
	sys.stdout.flush()

	try:
		server.serveforever()
	except KeyboardInterrupt:
		print("\nClosing... Hope you had fun :)")
github jarvisteach / appJar / examples / mc / mc.py View on Github external
if btn == "LEFT" or btn == "":
        x -= 1
    elif btn == "RIGHT" or btn == "":
        x += 1
    elif btn == "FORWARD" or btn == "":
        z -= 1
    elif btn == "BACKWARD" or btn == "":
        z += 1
    elif btn == "JUMP" or btn == "":
        y += 1
        z -= 1 

    mc.player.setPos(x, y, z)

mc = Minecraft.create() # minecraft connection

# main GUI block
app = gui("Minecraft") # GUI
app.setLocation(300,650)

app.addLabelEntry("Chat", 0)
# put this in the main GUI block
app.setEntryFocus("Chat")
app.setEntrySubmitFunction("Chat", sendMsg)

app.addButton("Send", sendMsg, 0, 1)

# put this in the main GUI block
app.startLabelFrame("Move Me", colspan=2)
app.setSticky("EW")
app.setStretch("both")
github teachthenet / TeachCraft-Challenges / script.py View on Github external
import mcpi.minecraft as minecraft

#NOTE - replace "seanybob" below with your name
mc = minecraft.Minecraft.create(address="199.96.85.3", name="seanybob") 

x = 10
y = 110
z = 12

mc.player.setPos(x, y, z)
github koduj-z-klasa / python101 / docs / mcpi / algorytmy / mcpi-lpi.py View on Github external
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import random
from time import sleep
import mcpi.minecraft as minecraft  # import modułu minecraft
import mcpi.block as block  # import modułu block
import local.minecraftstuff as mcstuff

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

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


def plac(x, y, z, roz=10, gracz=False):
    """Funkcja wypełnia sześcienny obszar od podanej pozycji
    powietrzem i 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

    # kamienna podłoże
    mc.setBlocks(x, y - 1, z, x + roz, y - 1, z + roz, podloga)
github brooksc / mcpipy / stuffaboutcode_basics.py View on Github external
#import the minecraft.py module from the minecraft directory
import mcpi.minecraft as minecraft
#import minecraft block module
import mcpi.block as block
#import time, so delays can be used
import time
import server


if __name__ == "__main__":
    
    time.sleep(2)

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

    #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
github brooksc / mcpipy / daviewales_minesweeper.py View on Github external
def run(self):
        global running
        running = True
        mc = minecraft.Minecraft.create()
        while running:
            ### This is the winning condition... ###
            flagCount = 0
            correctFlagCount = 0

            for x in xrange(width):
                for y in xrange(height):
                    if mc.getBlock(x, y, 0-1) == 50:
                        flagCount += 1
                        if [x,y] in self.mineCoords:
                            correctFlagCount += 1

            if  (self.mineNumber == correctFlagCount) and (self.mineNumber == flagCount):
                for x in xrange(width):
                     for y in xrange(height):
                         mc.setBlock(x, y, self.z, 20)
github koduj-z-klasa / python101 / docs / mcpi / glife / mcpi-glife.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# import sys
import os
from random import randint
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 symulatorem


class GraWZycie(object):
    """
    Główna klasa gry, łączy wszystkie elementy.
    """

    def __init__(self, mc, szer, wys, ile=40):
        """
        Przygotowanie ustawień gry
        :param szer: szerokość planszy mierzona liczbą komórek
        :param wys: wysokość planszy mierzona liczbą komórek
        """
        self.mc = mc
        mc.postToChat('Gra o zycie')
        self.szer = szer