minecraft pythonapl_Minecraft API

This is a reference of Minecraft Python API Library, which is supported on Minecraft: Pi edition and the PC version using the RaspberryJuice plugin.

似乎缺少生物相关的api?难道生物也是block?

pip install mcpi

一、代码结构

minecraft.py

Class Minecraft - main class for connecting and interacting with the game

Class camera - changing camera angle and postion

Class player - getting and changing the players position and setting

Class entity - getting and changing entities position and setting

Class events - retreiving events which have occured in the game

block.py

Class Block - definition of a block, specifically its type

event.py

Class BlockEvent - definition of a block event, specifically what event, what block and what player

vec3.py

Class Vec3 - generic class for managing a 3 dimension vector (i.e. x,y,z)

connection.py - internal module used by the api

util.py - internal module used by the api

Compatability

Not all functions and block types are available on all version of the api, by each function you will see a logo which shows whether that function is available:

二、API 明细

import mcpi.minecraft as minecraft

import mcpi.block as block

1.Minecraft

"Main class for interacting with the Minecraft world, includes functions for creating a connection, modifying players and blocks and capturing events"

.create(address = "localhost", port = 4711)

"Create connection to Minecraft (address, port) => Minecraft object"

mc = minecraft.Minecraft.create() #use default address and port

mc = minecraft.Minecraft.create("192.168.1.1", 4711) #specify ip address and port

.getBlock(x,y,z)

"Get block (x,y,z) => id:int"

blockType = mc.getBlock(0,0,0) #retrieves the block type for the block at 0,0,0

.getBlocks(x0,y0,z0,x1,y1,z1)

"Get a cuboid of blocks (x0,y0,z0,x1,y1,z1) => [id:int]"

blocks = mc.getBlocks(-1,-1,-1,1,1,1) #get the block id's in a cuboid

for block in blocks:

print block

.getBlockWithData(x,y,z)

"Get block with data (x,y,z) => Block"

blockObj = mc.getBlockWithData(0,0,0) #retrieves a block object for the block at 0,0,0

.setBlock(x,y,z)

"Set block (x,y,z,id,[data])"

mc.setBlock(0,0,0,block.DIRT.id) #sets a block at an x, y, z co-ordinate to a particular type

mc.setblock(0,0,0,block.WOOD.id, 1) #sets a block to a particular type and 'subtype'

.setBlocks(x0,y0,z0,x1,y1,z1,blockType, blockData)

"Set a cuboid of blocks (x0,y0,z0,x1,y1,z1,id,[data])"

mc.setBlocks(-1, -1, -1, 1, 1, 1, block.STONE.id) #sets many blocks at a time, filling the gap between 2 sets of x, y, z co-ordinates

.getHeight(x,z)

"Get the height of the world (x,z) => int"

y = mc.getHeight(0,0) #find the y (vertical) of an x, z co-ordinate which represents the 'highest' (non-air) block

.getPlayerEntityIds()

"Get the entity ids of the connected players => [id:int]"

entityIds = mc.getPlayerEntityIds() #get the entity id's of the players connected to the game

for entityId in entityIds:

print entityId

.getPlayerEntityId(playerName)

"Get the entity id for a named player => [id:int]

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值