当前位置: 首页>>代码示例>>Python>>正文


Python minecraft.Minecraft类代码示例

本文整理汇总了Python中mcpi.minecraft.Minecraft的典型用法代码示例。如果您正苦于以下问题:Python Minecraft类的具体用法?Python Minecraft怎么用?Python Minecraft使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Minecraft类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: instruct

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)
开发者ID:joolsbamford,项目名称:pisync,代码行数:29,代码来源:rjamgame.py

示例2: instruct

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
开发者ID:joolsbamford,项目名称:pisync,代码行数:26,代码来源:houseBuild.py

示例3: blocky

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")
开发者ID:joolsbamford,项目名称:pisync,代码行数:26,代码来源:housebuild_notimer.py

示例4: __init__

 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)
开发者ID:jrmhaig,项目名称:rube-mc-pi,代码行数:7,代码来源:minecraft.py

示例5: cube

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)
开发者ID:wensheng,项目名称:JuicyRaspberryPie,代码行数:8,代码来源:examples.py

示例6: __init__

 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.")
开发者ID:sbyrne1,项目名称:Python-Minecraft,代码行数:9,代码来源:MinecraftGenerator.py

示例7: __init__

    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()
开发者ID:NP-Games,项目名称:minecraft-starwars,代码行数:9,代码来源:trench.py

示例8: flatten

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)
开发者ID:wensheng,项目名称:JuicyRaspberryPie,代码行数:12,代码来源:examples.py

示例9: hunt

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)
开发者ID:joolsbamford,项目名称:pisync,代码行数:49,代码来源:houseBuild.py

示例10: falling_block

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)
开发者ID:wensheng,项目名称:JuicyRaspberryPie,代码行数:15,代码来源:examples.py

示例11: rainbow

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])
开发者ID:wensheng,项目名称:JuicyRaspberryPie,代码行数:16,代码来源:examples.py

示例12: Image

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.")
开发者ID:matkavt,项目名称:python-minecraft-lib,代码行数:46,代码来源:obj.py

示例13: banner

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
开发者ID:wensheng,项目名称:JuicyRaspberryPie,代码行数:24,代码来源:examples.py

示例14:

import config
import platform
from mcpi.minecraft import Minecraft

mc = Minecraft.create(config.server_address)

mc.postToChat("Hello " + platform.platform())
开发者ID:makotokw,项目名称:minecraft-pi-samples,代码行数:7,代码来源:hello.py

示例15: run

    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
开发者ID:astro-pi,项目名称:SpaceCRAFT,代码行数:71,代码来源:mcastroplayback.py


注:本文中的mcpi.minecraft.Minecraft类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。