예제 #1
2
def flatten(size=50):
    """_mcp: flatten world around me.
    change one layer of blocks below me to sandstone,
    clear everything above.
    """
    mc = Minecraft.create()
    pos = mc.player.getTilePos()
    s = int(size)
    mc.setBlocks(pos.x - s, pos.y - 1, pos.z - s,
        pos.x + s, pos.y - 1, pos.z + s, 24)
    mc.setBlocks(pos.x - s, pos.y, pos.z - s,
        pos.x + s, pos.y + 64, pos.z + s, 0)
예제 #2
2
def buildHouse():
	
	from mcpi.minecraft import Minecraft
	mc = Minecraft.create()
	
	import random
	import time
	
	mc.setting("world_immutable", False)		### cannot break blocks

	### sets basic plain landscape

	mc.setBlocks(-127, -11, -127, 127, -11, 127, 2)
	mc.setBlocks(-127, -10, -127, 127, 100, 127, 0)


	### move to start location

	mc.player.setPos(-10, -3, 10)


	### build outer shell

	mc.setBlocks(5, -10, 5, 35, -5, 35, 4)
	mc.setBlocks(6, -9, 6, 34, -6, 34, 0)


	### nested for loops to build columns

	colx = list(range(8, 35, 3))
	coly = list(range(-9, -6, 1))
	colz = list(range(8, 35, 3))
	 
	for cy in coly:
		for cx in colx:
			for cz in colz:
				mc.setBlock(cx, cy, cz, 46,1) 


	### nested for loops to add glow block on top of column
	
	glowx = list(range(8, 35, 3))
	glowz = list(range(8, 35, 3))

	for glx in glowx:
		for glz in glowz:
			mc.setBlock(glx, -6, glz, 89)


	### entrance and steps

	mc.setBlocks(5, -10, 11, 5, -8, 12, 0)
	mc.setBlocks(5, -10, 11, 5, -10, 12, 109)


	### Generate available non column spaces for treasure to find

	xi=range(8,35)  	# all floor space inside the walls
	yi=range(8,35) 


	x=range(8,35,3) 	# floor spaces taken up by columns
	y=range(8,35,3) 

	floorSpace=[] 			# set up empty list for possible treasure spaces

	for ii in xi:
		for jj in yi:
			floorSpace.append([ii, -9, jj]) 	# add all spaces to dots list

	
	for i in x:
		for j in y:
			floorSpace.remove([i, -9, j]) 		# remove column coordinates

	
	### empty treasure loop

	global treasure
	treasure=[]
	
	qq = 0

	while qq < 10:								# repeat for ten random treasure cheats
		
		chest = random.choice(floorSpace)

		treasure.append(chest)					# add to treasure

		floorSpace.remove(chest)				# delete from floor space to avoid duplication

		
		for t in treasure:
			mc.setBlock((t),58)					# place treasure chests in building
			
		qq+=1
예제 #3
1
def instruct():

	from mcpi.minecraft import Minecraft
	mc = Minecraft.create()

	import time

	time.sleep(5)

	mc.postToChat("Strike the green block to begin")
	time.sleep(1)
	mc.postToChat(" ")
	time.sleep(1)
	mc.postToChat("Find all the treasure as quickly as possible")
	time.sleep(1)
	mc.postToChat(" ")
	time.sleep(1)
	mc.postToChat("The strike the red block to stop the clock")
	time.sleep(1)
	mc.postToChat(" ")
	time.sleep(1)
	mc.postToChat("Treasure to find: " + str(len(treasure)))
	mc.postToChat(" ")

	mc.setBlock(-5, -10, 8, 35,5)		# green start block
	mc.setBlock(-5, -10, 12, 35,14)		# red finish block
	mc.setBlocks(-5, -10, 6,  -5, -6,  6, 89)
	mc.setBlocks(-5, -10, 14, -5, -6, 14, 89)
	mc.setBlocks(-5,  -6,  6, -5, -6, 14, 89)
예제 #4
1
def blocky():
	
	from mcpi.minecraft import Minecraft
	mc = Minecraft.create()
	
	import time

	mc.postToChat("Blocks to find: " + str(len(treasure)))
	time.sleep(1)
	mc.postToChat("Go!!!!!!")
	
	
	while True:
		blockHits = mc.events.pollBlockHits()
		if blockHits:
				for blockHit in blockHits:
					x,y,z = blockHit.pos.x, blockHit.pos.y, blockHit.pos.z		# x,y,z = right click hit
										
				if [x,y,z] in treasure:
					treasure.remove([x,y,z])
					mc.setBlock(x, y, z, 0)
					
					if len(treasure) > 0:
						mc.postToChat("Blocks to find: " + str(len(treasure)))
					else:
						mc.postToChat("You have found all the treasure - find the exit")
예제 #5
1
def instruct(): ### next enter name and write time to txt file to keep hire score table
	
	from mcpi.minecraft import Minecraft
	mc = Minecraft.create()
	
	import time
	
	time.sleep(5)
	
	mc.postToChat("Strike the green block to begin")
	time.sleep(1)
	mc.postToChat(" ")
	time.sleep(1)
	mc.postToChat("Find all the treasure as quickly as possible")
	time.sleep(1)
	mc.postToChat(" ")
	time.sleep(1)
	mc.postToChat("The strike the red block to stop the clock")
	time.sleep(1)
	mc.postToChat(" ")
	time.sleep(1)
	mc.postToChat("Treasure to find: " + str(len(treasure)))
	mc.postToChat(" ")
	
	mc.setBlock(-5, -10, 8, 35,5)		# green start block
	mc.setBlock(-5, -10, 12, 35,14)		# red finish block
예제 #6
1
def cube(size=5, typeId=1):
    "_mcp: create a cube"
    mc = Minecraft.create()
    pos = mc.player.getTilePos()
    s = int(size)
    t = int(typeId)
    mc.setBlocks(pos.x + 1, pos.y, pos.z,
        pos.x + s, pos.y + s - 1, pos.z + s - 1, t)
예제 #7
1
    def __init__(self, pos, width, height, length):
        self.mc = Minecraft.create()
        
        self.pos = pos
        self.width = width
        self.height = height
        self.length = length

        self._draw()
 def __init__(self): #??? Uses mc instance.
     # create minecraft object
     print ("\nFUNCTION: MinecraftGenerator __init__")
     print ("Opening connection to Minecraft Pi")
     try:
         self.mc=Minecraft.create()
     except:
         #print("There was an error connecting to Minecraft.")
         sys.exit("There was an error connecting to Minecraft.")
예제 #9
1
def hunt():
	
	from mcpi.minecraft import Minecraft
	mc = Minecraft.create()
	
	import time
		
	timer = 0
	
	while True:		
	
		blockHits = mc.events.pollBlockHits()
		if blockHits:
			
			for blockHit in blockHits:
				x,y,z = blockHit.pos.x, blockHit.pos.y, blockHit.pos.z		# x,y,z = right click hit
				
			if [x,y,z] == [-5, -10, 8] and mc.getBlock(-5, -10, 8) == 35:	#check for green block strike
				mc.setBlock(-5, -10, 8, 0)									#red block still in place
				mc.postToChat("Go!!!!!!")
				mc.postToChat(" ")
				
				
			if [x,y,z] == [-5, -10, 12] and mc.getBlock(-5, -10, 12) == 35 and mc.getBlock(-5, -10, 8) == 0 and len(treasure) == 0:
				mc.setBlock(-5, -10, 12, 0)
				mc.postToChat("Mission Complete!!!!")					#if red block hit and green hit and no treasure left
				mc.postToChat(" ")
				mc.postToChat("Your score is " + str(5000 - timer))
				break
				
				
			if mc.getBlock(-5, -10, 8) == 0:
									
				if [x,y,z] in treasure:
					treasure.remove([x,y,z])
					mc.setBlock(x, y, z, 0)
					
					if len(treasure) > 0:
						mc.postToChat("Blocks to find: " + str(len(treasure)))
						
					elif len(treasure) == 0:
						mc.postToChat("You have found all the treaure")
						mc.postToChat(" ")
						mc.postToChat("Head for the exit!!")
						
										
		if mc.getBlock(-5, -10, 8) == 0 and mc.getBlock(-5, -10, 12) == 35:
			timer +=1
			time.sleep(0.05)
예제 #10
1
def falling_block():
    """_mcp
    A gold block is falling from the sky
    """
    mc = Minecraft.create()
    pos = mc.player.getTilePos()
    y = pos.y + 40
    for i in range(40):
        time.sleep(0.5)
        # if the block below is anything other than air
        # stop falling
        if mc.getBlock(pos.x, y-i-1, pos.z) != 0:
            break
        mc.setBlock(pos.x, y-i, pos.z, 0)
        mc.setBlock(pos.x, y-i-1, pos.z, 41)
예제 #11
1
def rainbow():
    """_mcp
    create a rainbow.
    The code is from:
    http://dev.bukkit.org/bukkit-plugins/raspberryjuice/
    """
    mc = Minecraft.create()
    pos = mc.player.getTilePos()
    colors = [14, 1, 4, 5, 3, 11, 10]
    height = 60
    mc.setBlocks(pos.x-64,0,0,pos.x+64,height + len(colors),0,0)
    for x in range(0, 128):
        for colourindex in range(0, len(colors)):
            y = sin((x / 128.0) * pi) * height + colourindex
            mc.setBlock(pos.x+x - 64, pos.y+y, pos.z,
                35, colors[len(colors) - 1 - colourindex])
예제 #12
1
def Image(ImageName,X0,Y0,Z0):
    from PIL import Image
    import math
    mc = Minecraft.create()
    white = [221,221,221,0]#rgb, id
    orange = [219,125,62,1]#rgb, id
    magneta = [179,80,188,2]#rgb, id
    lightBlue = [107,138,201,3]#rgb, id
    yellow = [177,166,39,4]#rgb, id
    lime = [65,174,56,5]#rgb, id
    pink = [208,132,153,6]#rgb, id
    gray = [64,64,64,7]#rgb, id
    lightGray = [154,161,161,8]#rgb, id
    cyan = [46,110,137,9]#rgb, id
    purple = [126,61,181,10]#rgb, id
    blue = [46,56,141,11]#rgb, id
    brown = [79,50,31,12]#rgb, id
    green = [53,70,27,13]#rgb, id
    red = [150,52,48,14]#rgb, id
    black = [25,22,22,15]#rgb, id
    colors = [white,orange,magneta,lightBlue,yellow,lime,pink,gray,lightGray,cyan,purple,blue,brown,green,red,black]
    #enter your data here:
    img = Image.open(ImageName)#image
    #place
    if img.width*img.height > 500*500:
        mc.postToChat("the Image is too big!")
    else:
        data = img.load()
        x = 0
        while x < img.width:
            y = 0
            while y < img.height:
                res = 255*3
                pixel = data[x,y]
                for color in colors:
                    r = pixel[0]-color[0]
                    g = pixel[1]-color[1]
                    b = pixel[2]-color[2]
                    if math.fabs(r)+math.fabs(g)+math.fabs(b) < res:
                        res = math.fabs(r)+math.fabs(g)+math.fabs(b)
                        block = 35,color[3]
                mc.setBlock(X0+x,Y0,Z0+y,block)
                y = y + 1
            mc.postToChat(str(int(x / img.width * 100))+"%")
            x = x + 1
        mc.postToChat("done.")
예제 #13
1
def banner(txt, size=24, type1=41, type2=0):
    """_mcp
    Display a word banner made of blocks
    must have word2banner.py and word2banner.ini in the 
    same directory.
    see word2banner at github.com/wensheng/word2banner
    """
    mc = Minecraft.create()
    pos = mc.player.getTilePos()
    import pplugins.word2banner
    size = int(size)
    type1 = int(type1)
    type2 = int(type2)
    w2b = pplugins.word2banner.word2banner(txt, 1, size)
    y = pos.y + size
    for r in w2b:
        z = pos.z + 1
        for c in r:
            if c:
                mc.setBlock(pos.x, y, z, type1)
            else:
                mc.setBlock(pos.x, y, z, type2)
            z += 1
        y -= 1
예제 #14
1
from mcpi.minecraft import Minecraft #carga las funciones del API

mc = Minecraft.create() #crea la conexion con Minecraft

mc.postToChat("Hola, ya estoy dentro")  #escribe en la barra de chat


예제 #15
1
파일: dance1.py 프로젝트: csprimary/raspi
def buttongreenpressed(channel, event):
    mcg = Minecraft.create()
    blockingreencol = mcg.getBlock(pos.x-1, pos.y, pos.z + 10)
    if blockingreencol == block.WOOL.id:
	    mc.postToChat("Well Done!")
	    mcg.setBlock(pos.x-1, pos.y, pos.z + 10,block.WOOL.id,0)
예제 #16
1
파일: dance1.py 프로젝트: csprimary/raspi
def buttonredpressed(channel, event):
	mcr = Minecraft.create()
	blockinredcol = mcr.getBlock(pos.x+1, pos.y, pos.z + 10)
	if blockinredcol == block.WOOL.id:
		mc.postToChat("Excellent!!")
		mcr.setBlock(pos.x+1, pos.y, pos.z + 10,block.WOOL.id,0)
예제 #17
1
from mcpi.minecraft import Minecraft #mcpi.minecraft api에서 Minecraft를 임포트합니다. 관련 함수를 사용할 수 있게됩니다.
import math #math 관련 함수를 사용할 수 있게 임포트합니다.
import time #time 관련 함수를 사용할 수 있게 임포트합니다.
import random #time 관련 함수를 사용할 수 있게 임포트합니다.
mc = Minecraft.create() #Minecraft의 create 함수를 호출하고 결과를 mc 변수에 담습니다.

destX = random.randint(-127, 127) #-127에서 127사이의 정수를 랜덤으로 뽑아  destX 변수에 담습니다.
destZ = random.randint(-127, 127) #-127에서 127사이의 정수를 랜덤으로 뽑아  destZ 변수에 담습니다.
destY = mc.getHeight(destX, destZ) #destX와 destZ를 인자로 mc.getHeight 함수를 호출합니다. 그 결과값을 destY에 담습니다.

print(destX, destY, destZ) #위의 변수들을 출력합니다.

block = 57 #block 변수에 57숫자를 저장합니다.
mc.setBlock(destX, destY, destZ, block) #mc.setBlock으로 destX, destY, destZ, block 변수들을 인자로 넘기고 블록을 셋팅합니다.
mc.postToChat("Block set") #mc.postToChat함수로 "Block set"을 마인크래프트로 채팅합니다.

while True: #다음 코드를 영원히 반복합니다.
    pos = mc.player.getPos() #pos변수에 mc.player.getPos() 리턴값, 플레이어의 위치를 저장합니다.
    distance = math.sqrt((pos.x - destX) ** 2 + (pos.z - destZ) ** 2)
    #pos.x에서 destX만큼을 빼고 2을 재곱한뒤 pos.z에서 destZ를 빼고 2제곱한 만큼의 값을 더한뒤 그의 제곱근을 구해 distance변수에 담습니다.

    if distance == 0: #distance가 0이 되면 반복문에서 빠져나옵니다.
        break

    if distance > 100: #distance가 100이상이 되면 mc.postToChat로 다음을 출력합니다. ("Freezing")
        mc.postToChat("Freezing")
    elif distance > 50: #distance가 50이상이 되면 mc.postToChat를 다음을 출력합니다. ("Cold")
        mc.postToChat("Cold")
    elif distance > 25: #distance가 25이상이 되면 mc.postToChat를 다음을 출력합니다. ("Warm")
        mc.postToChat("Warm")
    elif distance > 12: #distance가 12이상이 되면 mc.postToChat를 다음을 출력합니다. ("Boiling")
예제 #18
1
from mcpi.minecraft import Minecraft
from time import sleep
import server
mc = Minecraft.create(server.address)

flower = 38

while True:
    x, y, z = mc.player.getPos()
    mc.setBlock(x, y, z, flower)
    sleep(0.1)
예제 #19
1
#!/usr/bin/env python3
#
# Import needed libraries
from mcpi.minecraft import Minecraft
import mcpi.block as block
mc = Minecraft.create()  # Connect to Minecraft, running on the local PC
pos = mc.player.getPos() # Get the player position
x = pos.x # Assign the value of the x coordinate to x
y = pos.y # Assign the value of the y coordinate to y
z = pos.z # Assing the value of the x coordinate to z

# Set the block where the player is to be Spruce 
mc.setBlock(x, y, z, block.WOOD.id, 1)
예제 #20
1
파일: dance1.py 프로젝트: csprimary/raspi
def buttonyellowpressed(channel, event):
	mcy = Minecraft.create()
	blockinyellowcol = mcy.getBlock(pos.x, pos.y, pos.z + 10)
	if blockinyellowcol == block.WOOL.id:
		mc.postToChat("You're doing great!")
		mcy.setBlock(pos.x, pos.y, pos.z + 10,block.WOOL.id,0)
예제 #21
1
from mcpi.minecraft import Minecraft
mc = Minecraft.create('192.168.0.4')
userName = input('What is your Minecraft username?')
mc.postToChat(userName + ': Hello')
예제 #22
1
    def run(self):
        #open the file
        self.running = True
        self.stopped = False

        try:
            #open astro pi data file
            apr = AstroPiDataReader(self.filename)
            self.apr = apr
            #are there any rows?
            if apr.rowcount > 0:
                
                #create connection to minecraft
                mc = Minecraft.create()

                mc.postToChat("Playback {} Started".format(self.filename))

                #find the position of where to put the ISS tower display
                pos = mc.player.getTilePos()
                pos.z -= 10
                pos.y = mc.getHeight(pos.x, pos.z)

                try:
                    #create the iss tower display
                    isstowerdisplay = ISSTowerMinecraftDisplay(mc, pos)

                    #loop until its stopped
                    found_row = True
                    while self.stopped == False and found_row == True:
                        #get the time started
                        real_time_start = time()
                        last_row_time = apr.get_time()
                        
                        #update the ISS dispay with the data
                        isstowerdisplay.update(
                            apr.get_time(),
                            apr.get_cpu_temperature(),
                            apr.get_temperature(),
                            apr.get_humidity(),
                            apr.get_pressure(),
                            apr.get_orientation(),
                            apr.get_joystick())
                        
                        #move onto the next row
                        found_row = apr.next()

                        #wait until the next row time
                        if found_row:
                            #wait until the time in the real world is greater than the time between the rows
                            while (time() - real_time_start) < ((apr.get_time() - last_row_time) / self.speed) :
                                sleep(0.001)
                finally:
                    isstowerdisplay.clear()
                    mc.postToChat("Playback {} finished".format(self.filename))
                    
            else:
                print("Error - {} contained no data".format(self.filename))

        #catch failed to open file error
        except IOError:
            print("Failed to open file '{}'.".format(self.filename))
            print(sys.exc_info()[1])

        #catch any other error
        except:
            print(sys.exc_info()[0])
            print(sys.exc_info()[1])
                        
        finally:
            self.running = False
            self.stopped = True
예제 #23
0
파일: utils.py 프로젝트: braingineer/mctk
def clear_by_player(size):
    mc = Minecraft.create()
    x,y,z = mc.player.getPos()
    clear_region(x,y,z,size)    
예제 #24
0
파일: utils.py 프로젝트: braingineer/mctk
def clear_region(x,y,z, size):
    '''will clear a cube with sides = size'''
    mc = Minecraft.create()
    mc.setBlocks(x-size/2,y-size/2, z-size/2, x+size/2, y+size/2, z+size/2, 0)
예제 #25
0
from mcpi.minecraft import Minecraft  #引入Minecraft
mc = Minecraft.create()  #縮寫為mc
mc.player.setpos(0.5, 20, 0.5)  #穿梭去的座標,注意 setPos 要大寫的部份
예제 #26
0
def init():
    mc = Minecraft.create("127.0.0.1", 4711)
    x, y, z = mc.player.getPos()
    return mc
예제 #27
0
class Dungeon:
    _mc = Minecraft.create()
    _rooms = {}
    _MIN_X = -10
    _MIN_Y = -30
    _MIN_Z = -80
    _MAX_X = 120
    _MAX_Y = -12
    _MAX_Z = 80
    _ROOM_WIDTH = 10
    _ROOM_LENGTH = 10
    _ROOM_HEIGHT = 4

    ###########################################################
    #
    # Construct a room with the given dimensions. Place torches
    # around the walls, optionally put a random piece of
    # treasure in the room.
    #
    ###########################################################
    def MakeRoom(self, x1, y1, z1, x2, y2, z2):
        # Plot the room itself
        self._mc.setBlocks(x1, y1, z1, x2, y2, z2, block.AIR.id)

        # Determine height of torch
        th = min([y1, y2]) + 2

        # Place torches along each wall.
        for i in range(x1 + 1, x2 - 1):
            if i % 6 == 0 and (self._mc.getBlock(i, th, z1 - 1) != block.AIR):
                self._mc.setBlock(i, th, z1, block.TORCH)
            if i % 6 == 0 and (self._mc.getBlock(i, th, z2 + 1) != block.AIR):
                self._mc.setBlock(i, th, z2, block.TORCH)
        for i in range(z1 + 1, z2 - 1):
            if i % 6 == 0 and (self._mc.getBlock(x1 - 1, th, i) != block.AIR):
                self._mc.setBlock(x1, th, i, block.TORCH)
            if i % 6 == 0 and (self._mc.getBlock(x2 + 1, th, i) != block.AIR):
                self._mc.setBlock(x2, th, i, block.TORCH)

    ###########################################################
    #
    # Construct a flight of steps going downwards. The steps
    # must go through water so must include walls and ceiling.
    #
    ############################################################
    def MakeSteps(self, x, y, z, l):
        for step in range(l + 1):
            # Floor steps
            self._mc.setBlock(x + step, y - step, z - 1,
                              block.STAIRS_COBBLESTONE.id, 1)
            self._mc.setBlock(x + step, y - step, z,
                              block.STAIRS_COBBLESTONE.id, 1)
            self._mc.setBlock(x + step, y - step, z + 1,
                              block.STAIRS_COBBLESTONE.id, 1)
            # Ceiling steps
            self._mc.setBlock(x + step, y - step + 4, z - 1,
                              block.STAIRS_COBBLESTONE.id, 4)
            self._mc.setBlock(x + step, y - step + 4, z,
                              block.STAIRS_COBBLESTONE.id, 4)
            self._mc.setBlock(x + step, y - step + 4, z + 1,
                              block.STAIRS_COBBLESTONE.id, 4)
            # Sidewalls
            self._mc.setBlocks(x + step, y - step, z - 2, x + step,
                               y - step + self._ROOM_HEIGHT, z - 2,
                               block.STONE)
            self._mc.setBlocks(x + step, y - step, z + 2, x + step,
                               y - step + self._ROOM_HEIGHT, z + 2,
                               block.STONE)
            # Ensure that nothing is in the void.
            self._mc.setBlocks(x + step, y - step + 1, z - 1, x + step,
                               y - step + 3, z + 1, block.AIR)

    ###########################################################
    #
    # Construct a flight of steps going downwards to join rooms.
    #
    ############################################################
    def StepsDown(self, x, y, z):
        self._mc.setBlocks(x + 3, y, z - 1, x + self._ROOM_HEIGHT + 4, y,
                           z - 1, block.FENCE)
        self._mc.setBlocks(x + 3, y, z + 1, x + self._ROOM_HEIGHT + 4, y,
                           z + 1, block.FENCE)
        self._mc.setBlocks(x + self._ROOM_HEIGHT + 4, y, z - 1,
                           x + self._ROOM_HEIGHT + 4, y, z + 1, block.FENCE)
        for step in range(1, self._ROOM_HEIGHT + 3):
            # Floor steps
            self._mc.setBlock(x + step, y - step, z,
                              block.STAIRS_COBBLESTONE.id, 1)
            # Space to walk
            self._mc.setBlocks(x + step + 1, y - step, z,
                               x + self._ROOM_HEIGHT + 3, y - step, z,
                               block.AIR)

    ############################################################
    #
    # Construct a new room.
    #
    ############################################################
    def newRoom(self, start, direction):
        handle = len(self._rooms)
        if direction.upper() not in ["N", "S", "E", "W", "U", "D"]:
            raise DungeonError.DirectionError(
                "Direction must be: \"N\", \"S\", \"E\", \"W\", \"U\" or \"D\""
            )
        else:
            if start not in self._rooms:
                raise DungeonError.RoomError("Unknown room: " + str(start))
            else:
                x, y, z = self._rooms[start]
                if (direction.upper() == "N"):
                    x += self._ROOM_LENGTH + 2
                elif (direction.upper() == "S"):
                    x -= self._ROOM_LENGTH + 2
                elif (direction.upper() == "E"):
                    z += self._ROOM_WIDTH + 2
                elif (direction.upper() == "W"):
                    z -= self._ROOM_WIDTH + 2
                elif (direction.upper() == "U"):
                    y += self._ROOM_HEIGHT + 2
                else:
                    y -= self._ROOM_HEIGHT + 2
                if (x > self._MAX_X - self._ROOM_LENGTH or x < self._MIN_X
                        or z < self._MIN_Z
                        or x > self._MAX_Z - self._ROOM_WIDTH
                        or y > self._MAX_Y or y < self._MIN_Y):
                    raise DungeonError.RoomError(
                        "Not enough space in direction \"" + direction +
                        "\" from room " + str(start))
                else:
                    if (self._mc.getBlock(x + 1, y, z + 2) == block.AIR.id):
                        raise DungeonError.RoomError(
                            "There is already a room in direction \"" +
                            direction + "\" from room " + str(start))
                    else:
                        self.MakeRoom(x, y, z, x + self._ROOM_LENGTH,
                                      y + self._ROOM_HEIGHT,
                                      z + self._ROOM_WIDTH)
                        self._rooms[handle] = [x, y, z]
                        # Create the ajoining corridore or steps
                        if (direction.upper() == "N"):
                            self._mc.setBlocks(x - 2, y,
                                               z + self._ROOM_WIDTH / 2, x,
                                               y + 1, z + self._ROOM_WIDTH / 2,
                                               block.AIR)
                        elif (direction.upper() == "S"):
                            self._mc.setBlocks(x + self._ROOM_LENGTH, y,
                                               z + self._ROOM_WIDTH / 2,
                                               x + self._ROOM_LENGTH + 2,
                                               y + 1, z + self._ROOM_WIDTH / 2,
                                               block.AIR)
                        elif (direction.upper() == "E"):
                            self._mc.setBlocks(x + self._ROOM_LENGTH / 2, y,
                                               z - 2,
                                               x + self._ROOM_LENGTH / 2,
                                               y + 1, z, block.AIR)
                        elif (direction.upper() == "W"):
                            self._mc.setBlocks(x + self._ROOM_LENGTH / 2, y,
                                               z + self._ROOM_WIDTH,
                                               x + self._ROOM_LENGTH / 2,
                                               y + 1, z + self._ROOM_WIDTH + 2,
                                               block.AIR)
                        elif (direction.upper() == "U"):
                            self.StepsDown(x + 1, y, z + 2)
                        else:
                            self.StepsDown(x + 1, y + self._ROOM_HEIGHT + 2,
                                           z + 2)
        return handle

    def __init__(self):
        # Create a large underwater block of stone for the dungeon.
        self._mc.setBlocks(self._MIN_X, -4, self._MIN_Z, self._MAX_X, -30,
                           self._MAX_Z, block.STONE)
        self._mc.setBlocks(self._MIN_X - 2, 0, self._MIN_Z - 2,
                           self._MAX_X + 2, -3, self._MAX_Z + 2,
                           block.WATER_STATIONARY)
        self._mc.setBlocks(self._MIN_X - 4, 0, self._MIN_Z - 4,
                           self._MAX_X + 4, 30, self._MAX_Z + 4, block.AIR)

        # Create external plinth for player to stand on
        self._mc.setBlocks(-6, 0, -5, 0, -3, 5, block.STONE)

    def create(self):
        # Create a dungeon as the start point
        self.MakeRoom(10, -12, -5, 20, -8, 5)
        self._rooms[0] = [10, -12, -5]

        # Place some steps down into the dungeon.
        self.MakeSteps(1, 0, 0, 12)

        # Put the playr near the dungeon entrance.
        self._mc.player.setPos(-2, 1, 0)
        self._mc.setting("world_immutable", True)
        return 0
예제 #28
0
파일: Ship.py 프로젝트: S3thBr0wn/Python-3
def init():
	mc = Minecraft.create("192.168.3.5", 4711)
	x,y,z = mc.player.getPos()
	return mc
예제 #29
0
import RPi.GPIO as GPIO
import time
from mcpi.minecraft import Minecraft

mc = Minecraft.create() # create Minecraft Object

buzzer_pin = 12 # store the GPIO pin number

GPIO.setmode(GPIO.BOARD) # change GPIO mode to BOARD
GPIO.setup(buzzer_pin, GPIO.OUT) # setup the pin to OUTPUT

# repeat indefinitely
while True:
    # get player position
    x, y, z = mc.player.getPos()
    # look at every block until block 15
    for i in range(15):
        if mc.getBlock(x, y - i, z) == 46:
            GPIO.output(buzzer_pin, True) # buzz the buzzer on
            time.sleep(0.5) # wait
            GPIO.output(buzzer_pin, False) # turn the buzzer off
            time.sleep(0.5) # wait
예제 #30
0
from mcpi.minecraft import Minecraft
from lekcje.helpers import clear_world
mc = Minecraft.create("minecraft-py.lasyk.info", 4711)



clear_world(mc)

mc.player.setPos(0, 100, 0)
예제 #31
0
from mcpi.minecraft import Minecraft
import mcpi.block as block
mc = Minecraft.create("192.168.1.6") # add server ip
import time
players = mc.getPlayerEntityIds()
counter = -500
x = 60
y= 60
cubesize = 5
airsize = cubesize -1
for i in players:
  mc.entity.setPos(i,x,y, counter)
  p = mc.entity.getPos(i)
  
  print(i)
  mc.setBlocks(p.x-cubesize,p.y-cubesize,p.z-cubesize,p.x+cubesize,p.y+cubesize,p.z+cubesize, block.OBSIDIAN.id)
  mc.setBlocks(p.x-airsize,p.y-airsize,p.z-airsize,p.x+airsize,p.y+airsize,p.z+airsize, block.AIR.id)
  time.sleep(1)
  mc.postToChat("lol")
  mc.entity.setPos(i,x,y,counter)

  counter =+ 20

mc.postToChat("you need to teleport out")
예제 #32
0
from mcpi.minecraft import Minecraft, ChatEvent
from mcpi.minecraftstuff import MinecraftDrawing, MinecraftTurtle
from mcpi import block, entity

name = "JeremyTsui"
# connect to minecraft
address = "localhost"
mc = Minecraft.create(address)
md = MinecraftDrawing(mc)
turtle = MinecraftTurtle(mc)

# get the x,y,z (position)
entity_id = mc.getPlayerEntityId(name)
position = mc.entity.getPos(entity_id)
x, y, z = int(position.x), int(position.y), int(position.z)

ada = MinecraftTurtle(mc)
ada.setposition(x, y, z)
예제 #33
0
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 21 16:08:27 2018

@author: Sam
"""
from mcpi.minecraft import Minecraft

sam = Minecraft.create()
x, y, z = sam.player.getTilePos()
name = input("請輸入姓名")
s = input("請輸入想說的話")
sam.postToChat("<" + name + ">")
예제 #34
0
from mcpi.minecraft import Minecraft
mc = Minecraft.create()

import time

time.sleep(60)

hits = mc.events.pollBlockHits()
block = 103

for hit in hits:
    x, y, z = hit.pos.x, hit.pos.y, hit.pos.z
    mc.setBlock = 103
예제 #35
0
##
##逆さまのピラミッドをつくるプログラム
##
from mcpi.minecraft import Minecraft  #Minecraftクラスの呼び出し
from mcpi.block import *

mc = Minecraft.create()  #Minecraftとの接続を作成

pos = mc.player.getTilePos()  #自分のいる位置を取得
#そこを基準にしてピラミッドを作成
height = 51  #ピラミッドの高さ
length = height * 2 - 1  #一番上のブロックの数(正方形の一辺の長さ)
#上からピラミッドを作っていく
for i in range(height):
    mc.setBlocks(pos.x + i, pos.y + (height - i), pos.z + i,
                 pos.x + (length - i + 1), pos.y + (height - i),
                 pos.z + (length - i + 1), STONE)
예제 #36
0
from mcpi.minecraft import Minecraft as mcs
mc = mcs.create()
x, y, z = mc.player.getPos()


def planttree(x, y, z, mc):
    mc.setBlocks(x + 1, y + 5, z + 1, x - 1, y + 3, z - 1, 35, 5)
    mc.setBlocks(x, y + 4, z, x, y, z, 17)


for i in range(0, 10):
    for h in range(0, 10):
        planttree(x + i * 5, y + i * h, z, mc)
예제 #37
0
 def __init__(self):
     # create minecraft object
     self.mc=Minecraft.create()
예제 #38
0
# Adventure 3: buildHouse.py

# From the book: "Adventures in Minecraft"
# written by David Whale and Martin O'Hanlon, Wiley, 2014
# http://eu.wiley.com/WileyCDA/WileyTitle/productCd-111894691X.html
#
# This program builds a single house, with a doorway, windows,
# a roof, and a carpet.

# Import necessary modules
from mcpi.minecraft import Minecraft
import mcpi.block as block

# Connect to Minecraft
mc = Minecraft.create("47.100.46.95", 4783)

# A constant, that sets the size of your house
SIZE = 20

# Get the players position
pos = mc.player.getTilePos()

# Decide where to start building the house, slightly away from player
x = pos.x + 2
y = pos.y
z = pos.z

# Calculate the midpoints of the front face of the house
midx = x + SIZE / 2
midy = y + SIZE / 2
from mcpi.minecraft import Minecraft
import time
import random
mc = Minecraft.create()

while True:
    chat = ["Message 1", "Message 2", "Message 3"]
    thing = random.randint (0,2)
    mc.postToChat (chat[thing])
    time.sleep(3)
예제 #40
0
            else:
                mc.setBlock(x+2+ii, i+1-ii, z+14, QUARTZ_BLOCK)
"""

"""1. 모듈 불러오기"""
# 마인크래프트 서버 불러오기
from mcpi.minecraft import Minecraft

# 내가 만든 필수 함수 불러오기
from minecraftProj.minecraftPyModules import *

# 일정량의 시간을 비우기 위해
import time

"""2. 서버에 접속"""
minecraftPy = Minecraft.create() # 서버 접속

essentialModule_selfMade.connectSever() # 서버와 연결이 됐는지 확인

"""3. 사용자 위치 확인 및 좌표 변수 등록"""
gotPlayerPos = essentialModule_selfMade.getMyPos()

playerX = gotPlayerPos.x
playerY = gotPlayerPos.y
playerZ = gotPlayerPos.z

blockX = gotPlayerPos.x + 1
blockY = gotPlayerPos.y
blockZ = gotPlayerPos.z + 1

"""4. 해당 위치의 좌표에 블럭이 있는지 확인"""
예제 #41
0
def specified_pos():
    while True:
        for event in world.events.pollBlockHits():
            return event.pos


def get_args():
    parser = ArgumentParser("image2blocks")
    parser.add_argument("image", help="250 <= height && 4 >= width / height")
    return parser.parse_args()


def main():
    args = get_args()
    img = Image.open(args.image).convert("RGB")
    img.thumbnail((1000, 191))
    print("Please specify a block ...")
    pos = specified_pos()
    # pos = Vec3(0, 0, 0)
    world.postToChat("pos:{} size:{}".format(pos, img.size))
    with open("1.8.8.json") as file:
        blocks = dict(map(desirialize, load(file)))
    similar_blocks = map(blocks.__getitem__, quantized(img, palette(list(blocks.keys()))))
    for vec, block in reversed(list(zip(drawing_area(pos, img), similar_blocks))):
        world.setBlock(vec, block)


if __name__ == "__main__":
    world = Minecraft.create()
    main()
예제 #42
0
파일: dance1.py 프로젝트: csprimary/raspi
def buttonbluepressed(channel, event):
	mcb = Minecraft.create()
	blockinbluecol = mcb.getBlock(pos.x+2, pos.y, pos.z + 10)
	if blockinbluecol == block.WOOL.id:
		mc.postToChat("Super work!")
		mcb.setBlock(pos.x+2, pos.y, pos.z + 10,block.WOOL.id,0)
예제 #43
-7
 def __init__(self, attribs):
     self.server_address = attribs["server_address"]
     self.server_port = attribs.get("server_port", 4711)
     self.coords_x = attribs["coords_x"]
     self.coords_y = attribs["coords_y"]
     self.coords_z = attribs["coords_z"]
     self.world_connection = Minecraft.create(self.server_address, self.server_port)
예제 #44
-14
import config
import platform
from mcpi.minecraft import Minecraft

mc = Minecraft.create(config.server_address)

mc.postToChat("Hello " + platform.platform())