本文整理汇总了Python中connection.Connection.sendReceive_flat方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.sendReceive_flat方法的具体用法?Python Connection.sendReceive_flat怎么用?Python Connection.sendReceive_flat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.sendReceive_flat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import sendReceive_flat [as 别名]
class Minecraft:
"""The main class to interact with a running instance of Minecraft Pi."""
def __init__(self, connection=None, autoId=True):
if connection:
self.conn = connection
else:
self.conn = Connection()
self.camera = CmdCamera(self.conn)
self.entity = CmdEntity(self.conn)
if autoId:
try:
playerId = int(environ['MINECRAFT_PLAYER_ID'])
self.player = CmdPlayer(self.conn,playerId=playerId)
except:
self.player = CmdPlayer(self.conn)
else:
self.player = CmdPlayer(self.conn)
self.events = CmdEvents(self.conn)
self.enabledNBT = False
def spawnEntity(self, *args):
"""Spawn entity (type,x,y,z,tags) and get its id => id:int"""
return int(self.conn.sendReceive("world.spawnEntity", args))
def removeEntity(self, *args):
"""Remove entity (id)"""
self.conn.send("world.removeEntity", args)
def getBlock(self, *args):
"""Get block (x,y,z) => id:int"""
return int(self.conn.sendReceive_flat("world.getBlock", floorFlatten(args)))
def getBlockWithData(self, *args):
"""Get block with data (x,y,z) => Block"""
ans = self.conn.sendReceive_flat("world.getBlockWithData", floorFlatten(args))
return Block(*map(int, ans.split(",")[:2]))
def getBlockWithNBT(self, *args):
"""
Get block with data and nbt (x,y,z) => Block (if no NBT) or (Block,nbt)
For this to work, you first need to do setting("include_nbt_with_data",1)
"""
if not self.enabledNBT:
self.setting("include_nbt_with_data",1)
self.enabledNBT = True
try:
ans = self.conn.sendReceive_flat("world.getBlockWithData", floorFlatten(args))
except RequestError:
# retry in case we had a Fail from the setting
ans = self.conn.receive()
else:
ans = self.conn.sendReceive_flat("world.getBlockWithData", floorFlatten(args))
id,data = (map(int, ans.split(",")[:2]))
commas = 0
for i in range(0,len(ans)):
if ans[i] == ',':
commas += 1
if commas == 2:
if '{' in ans[i+1:]:
return Block(id,data,ans[i+1:])
else:
break
return Block(id,data)
"""
@TODO
"""
# must have no NBT tags in any Block instances
def getBlocks(self, *args):
"""Get a cuboid of blocks (x0,y0,z0,x1,y1,z1) => [id:int]"""
return int(self.conn.sendReceive_flat("world.getBlocks", floorFlatten(args)))
# must have no NBT tags in Block instance
def setBlock(self, *args):
"""Set block (x,y,z,id,[data])"""
self.conn.send_flat("world.setBlock", floorFlatten(args))
def setBlockWithNBT(self, *args):
"""Set block (x,y,z,id,data,nbt)"""
data = list(flatten(args))
self.conn.send_flat("world.setBlock", list(floorFlatten(data[:5]))+data[5:])
# must have no NBT tags in Block instance
def setBlocks(self, *args):
"""Set a cuboid of blocks (x0,y0,z0,x1,y1,z1,id,[data])"""
self.conn.send_flat("world.setBlocks", floorFlatten(args))
def setBlocksWithNBT(self, *args):
"""Set a cuboid of blocks (x0,y0,z0,x1,y1,z1,id,data,nbt)"""
data = list(flatten(args))
self.conn.send_flat("world.setBlocks", list(floorFlatten(data[:8]))+data[8:])
def getHeight(self, *args):
"""Get the height of the world (x,z) => int"""
return int(self.conn.sendReceive_flat("world.getHeight", floorFlatten(args)))
def getPlayerId(self, *args):
"""Get the id of the current player"""
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import sendReceive_flat [as 别名]
class Minecraft:
"""The main class to interact with a running instance of Minecraft Pi."""
def __init__(self, connection=None, autoId=True):
if connection:
self.conn = connection
else:
self.conn = Connection()
if security.AUTHENTICATION_USERNAME and security.AUTHENTICATION_PASSWORD:
self.conn.authenticate(security.AUTHENTICATION_USERNAME, security.AUTHENTICATION_PASSWORD)
self.camera = CmdCamera(self.conn)
self.entity = CmdEntity(self.conn)
self.playerId = None
if autoId:
try:
self.playerId = int(environ['MINECRAFT_PLAYER_ID'])
self.player = CmdPlayer(self.conn,playerId=self.playerId)
except:
try:
self.playerId = self.getPlayerId(environ['MINECRAFT_PLAYER_NAME'])
self.player = CmdPlayer(self.conn,playerId=self.playerId)
except:
if security.AUTHENTICATION_USERNAME:
try:
self.playerId = self.getPlayerId(security.AUTHENTICATION_USERNAME)
self.player = CmdPlayer(self.conn,playerId=self.playerId)
except:
self.player = CmdPlayer(self.conn)
else:
self.player = CmdPlayer(self.conn)
else:
self.player = CmdPlayer(self.conn)
self.events = CmdEvents(self.conn)
self.enabledNBT = False
def spawnEntity(self, *args):
"""Spawn entity (type,x,y,z,tags) and get its id => id:int"""
return int(self.conn.sendReceive("world.spawnEntity", args))
def removeEntity(self, *args):
"""Remove entity (id)"""
self.conn.send("world.removeEntity", args)
def getBlock(self, *args):
"""Get block (x,y,z) => id:int"""
return int(self.conn.sendReceive_flat("world.getBlock", floorFlatten(args)))
def getBlockWithData(self, *args):
"""Get block with data (x,y,z) => Block"""
ans = self.conn.sendReceive_flat("world.getBlockWithData", floorFlatten(args))
return Block(*map(int, ans.split(",")[:2]))
def getBlockWithNBT(self, *args):
"""
Get block with data and nbt (x,y,z) => Block (if no NBT) or (Block,nbt)
For this to work, you first need to do setting("include_nbt_with_data",1)
"""
if not self.enabledNBT:
self.setting("include_nbt_with_data",1)
self.enabledNBT = True
try:
ans = self.conn.sendReceive_flat("world.getBlockWithData", floorFlatten(args))
except RequestError:
# retry in case we had a Fail from the setting
ans = self.conn.receive()
else:
ans = self.conn.sendReceive_flat("world.getBlockWithData", floorFlatten(args))
return stringToBlockWithNBT(ans)
"""
@TODO
"""
def fallbackGetCuboid(self, getBlock, *args):
(x0,y0,z0,x1,y1,z1) = map(lambda x:int(math.floor(float(x))), flatten(args))
out = []
for y in range(min(y0,y1),max(y0,y1)+1):
for x in range(min(x0,x1),max(x0,x1)+1):
for z in range(min(z0,z1),max(z0,z1)+1):
out.append(getBlock(x,y,z))
return out
def fallbackGetBlocksWithData(self, *args):
return self.fallbackGetCuboid(self.getBlockWithData, args)
def fallbackGetBlocks(self, *args):
return self.fallbackGetCuboid(self.getBlock, args)
def fallbackGetBlocksWithNBT(self, *args):
return self.fallbackGetCuboid(self.getBlockWithNBT, args)
def getBlocks(self, *args):
"""
Get a cuboid of blocks (x0,y0,z0,x1,y1,z1) => [id:int]
Packed with a y-loop, x-loop, z-loop, in this order.
#.........这里部分代码省略.........