• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python minecraft.Minecraft类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16:

#!/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)
开发者ID:williamhbell,项目名称:MinecraftPython,代码行数:13,代码来源:addBlockOnce.py


示例17: input

from mcpi.minecraft import Minecraft
mc = Minecraft.create('192.168.0.4')
userName = input('What is your Minecraft username?')
mc.postToChat(userName + ': Hello')
开发者ID:MilanKankanwadi,项目名称:minecraft,代码行数:4,代码来源:HelloServer.py


示例18: buildHouse

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


示例19: mulMat

x180 = mulMat(x90,x90)

if __name__ == "__main__":
    def copy(v,airOnly=False):
        b = mc.getBlockWithNBT(v)
        if airOnly and b.id != block.AIR.id:
            return
        v1 = addVec(v,(0.5,0.5,0.5))
        for t in transforms:
            mc.setBlockWithNBT(t(v1),b)

    def err():
        mc.postToChat("Invalid symmetry specification. See symmetry.py comments.")
        exit()

    mc = Minecraft()

    playerPos = mc.player.getPos()

    matrices = set()
    translations = []

    if len(sys.argv) <= 1:
        matrices.add(xn)
        matrices.add(xe)

    i = 1
    while i < len(sys.argv):
        opt = sys.argv[i]
        i += 1
        if opt == 't':
开发者ID:Michaelangel007,项目名称:raspberryjammod,代码行数:31,代码来源:symmetry.py


示例20: sleep

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)
开发者ID:rebekahorth,项目名称:minecraft-mcpi,代码行数:11,代码来源:flowers.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mcplatform.platform_open函数代码示例发布时间:2022-05-27
下一篇:
Python log.error函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap