How to use the mcpi.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 / 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 brooksc / mcpipy / sleepyoz_digitalclock.py View on Github external
line_offset = 0 # Start at the top line.
    for line in dots: # For each line of each digit.
        dot_offset = 0 # Start at the left-most voxel.
        for dot in line: # For each voxel in the line.
            if dot == '0': # If voxel should be drawn.
                client.setBlock(position.x+dot_offset+x_offset, position.y-line_offset, position.z, block.ICE)
            else: # Voxel should be cleared.
                client.setBlock(position.x+dot_offset+x_offset, position.y-line_offset, position.z, block.AIR)
            dot_offset += 1 # Move over to the next voxel.

        # Each digit is 5 wide, but not all 5 voxels need to be supplied in the digit_dots, so blank out any that were not given.
        for blank in range(dot_offset, 5):
            client.setBlock(position.x+blank+x_offset, position.y-line_offset, position.z, block.AIR)
        line_offset += 1 # Next line.

client=minecraft.Minecraft.create(server.address) # Connect to Minecraft.
place=client.player.getPos() # Start near the player.
place.y += 9 # Above the player's ground level.

while True: # Repeat forever.
    timestr = time.strftime("%H:%M:%S") # Format time nicely.
    digit_offset = 0 # Start with the first digit.
    for letter in timestr: # For each symbol in the time.
        map = digit_dots[letter] # Get the dot map for the current digit.
        output_digit(client, place, digit_offset, map) # Draw the digit.
        digit_offset += 1 # Next digit.
    time.sleep(0.5) # Rest a while before drawing again.
github brooksc / mcpipy / burnaron_bunkermatic2.py View on Github external
#!/usr/bin/env python

# mcpipy.com retrieved from URL below, written by burnaron
# http://www.minecraftforum.net/topic/1689199-my-first-script-bunkermaticpy/

import mcpi.minecraft as minecraft
import mcpi.block as block
from math import *
import server

mc = minecraft.Minecraft.create(server.address)
x1 = -4
y1 = 3
z1 = 9
long_tun = 10
long_arc_ch = 8
long_ch = 26
long_m_ch = long_ch - 2 * long_arc_ch
deepness = 60
high_c_ch = 3

# FASE 1: cleaning zone
mc.setBlocks(x1-2,y1,z1-2,x1+2,y1+20,z1+2,0)
mc.setBlocks(x1-(long_tun+long_ch+1),y1-(deepness+1),z1-(long_tun+long_ch+1),x1+long_tun+long_ch+1,y1-(deepness-long_arc_ch-2-1),z1+long_tun+long_ch+1,1)

# FASE 2: establishing access
mc.setBlocks(x1-1.5,y1+2,z1-1.5,x1+1.5,y1-deepness,z1+1.5,1)
github brooksc / mcpipy / stuffaboutcode_bridge.py View on Github external
#import time, so delays can be used
import time
import server


#function to round players float position to integer position
def roundVec3(vec3):
    return minecraft.Vec3(int(vec3.x), int(vec3.y), int(vec3.z))

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 - Auto Bridge Active")
    mc.postToChat("www.stuffaboutcode.com")

    #Get the players position
    lastPlayerPos = mc.player.getPos()

    while (True):

        #Get the players position
        playerPos = mc.player.getPos()

        #Find the difference between the player's position and the last position
        movementX = lastPlayerPos.x - playerPos.x
        movementZ = lastPlayerPos.z - playerPos.z
github martinohanlon / minecraft-turtle / examples / example_pattern.py View on Github external
# Minecraft Turtle Example - Crazy Pattern
from mcturtle import minecraftturtle
from mcpi import minecraft
from mcpi import block

# create connection to minecraft
mc = minecraft.Minecraft.create()

# get players position
pos = mc.player.getPos()

# create minecraft turtle
steve = minecraftturtle.MinecraftTurtle(mc, pos)

steve.penblock(block.WOOL.id, 11)
steve.speed(10)

for step in range(0, 50):
    steve.forward(50)
    steve.right(123)
github koduj-z-klasa / python101 / docs / mcpi / funkcje / mcpi-funkcje03.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 adafruit / Adafruit_Python_PN532 / examples / mcpi_listen.py View on Github external
subtype_id = data[6]
    # Find the block name (it's ugly to search for it, but there are less than 100).
    for block in mcpi_data.BLOCKS:
        if block[1] == block_id:
            block_name = block[0]
            break
    print('Found block!')
    print('Type: {0}'.format(block_name))
    if has_subtype:
        subtype_name = mcpi_data.SUBTYPES[block_name][subtype_id]
        print('Subtype: {0}'.format(subtype_name))
    # Try to create the block in Minecraft.
    # First check if connected to Minecraft world.
    try:
        if mc is None:
            mc = minecraft.Minecraft.create()
        create_block(mc, block_id, subtype_id if has_subtype else None)
        time.sleep(MAX_UPDATE_SEC)
    except socket.error:
        # Socket error, Minecraft probably isn't running.
        print('Could not connect to Minecraft, is the game running in a world?')
        continue
github jbaragry / mcpi-scratch / mcpi-scratch.py View on Github external
# nasty stuff to slow down the polling that comes from scratch.
    # from the docs, sratch is polling at 30 times per second
    # updating the player pos that often is causing the app to choke.
    # use these vars to only make the call to MC every pollMax times - 15
    # maybe change this to a cmd-line switch
    pollInc = 0
    pollLimit = 15
    prevPosStr = ""


    host = args.host or "localhost"
    connected = False
    while (not connected):
        try:
            mc = minecraft.Minecraft.create(host)
            connected = True
        except:
            print("Timed out connecting to a Minecraft MCPI server (" + host + ":4711). Retrying in "+ str(MCPI_CONNECT_TIMEOUT) +" secs ... Press CTRL-C to exit.")
            time.sleep( MCPI_CONNECT_TIMEOUT )

    from BaseHTTPServer import HTTPServer
    server = HTTPServer(('localhost', 4715), GetHandler)
    log.info('Starting server, use  to stop')
    server.serve_forever()
github brooksc / mcpipy / gf_helloworld.py View on Github external
#! /usr/bin/python
import mcpi.minecraft as minecraft
import server

""" hello world test app

    @author: goldfish"""

mc = minecraft.Minecraft.create( server.address )
mc.postToChat("Hello, Minecraft!")
github martinohanlon / minecraft-stuff / minecraftstuff / minecraftstuff.py View on Github external
def _roundVec3(position):
        return minecraft.vec3(int(position.x), int(position.y), int(position.z))