想在拥有完整功能版的 Minecraft 中尝试使用 Minecraft Pi API 进行编程吗?RaspberryJuice 为 Bukkit 服务器实现了 Minecraft Pi 模组开发 API。
该插件监听端口 4711,并支持大多数 Minecraft Pi 命令,这些命令的文档详见 。
该插件支持 Pi 版本附带的大多数 API 功能,大部分示例代码均可正常运行。
Minecraft Forums 讨论帖
目前已实现的命令:
world.getBlock
world.getBlockWithData
world.setBlock
world.setBlocks
world.getPlayerIds
chat.post
events.clear
events.block.hits
player.getTile
player.setTile
player.getPos
player.setPos
world.getHeight
entity.getTile
entity.setTile
entity.getPos
entity.setPos
额外功能(^):
已实现 getBlocks(x1,y1,z1,x2,y2,z2)
getDirection、getRotation、getPitch 函数 —— 获取玩家和实体所朝向的方向
getPlayerId(playerName) —— 通过名称获取玩家的实体信息
pollChatPosts() —— 获取发送到聊天栏的事件反馈
配置(位于 config.yml):
- port: 4711 - 默认 TCP 端口可在 config.yml 中修改
- location: RELATIVE - 确定位置是相对于出生点(默认行为,与 Pi 版一致)还是绝对坐标(ABSOLUTE)
- hitclick: RIGHT - 确定命中事件是由左键点击、右键点击还是两者同时触发
^ 要使用额外功能,需要使用由 Mojang 随 Pi 版提供的原始 Java 和 Python 库的修改版,https:github.com/zhuowei/RaspberryJuice/tree/master/src/main/resources/mcpi。你只需在需要使用额外功能时才需要这些修改版的库;原始库仍然可以正常工作,只是无法使用额外功能。
示例:
此 Python 脚本会在出生点附近建造一道彩虹。将此示例放入 Minecraft Pi 预发布版的 api/python 目录中,在同一台计算机上启动服务器,然后运行 python name.py(将 name.py 替换为脚本的实际文件名)即可运行。
import mcpi.minecraft as minecraft
import mcpi.block as block
from math import *
colors = [14, 1, 4, 5, 3, 11, 10]
mc = minecraft.Minecraft.create()
height = 60
mc.setBlocks(-64,0,0,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(x - 64, y, 0, block.WOOL.id, colors[len(colors) - 1 - colourindex])
结果:
更多示例请参阅 http:www.stuffaboutcode.com/p/minecraft.html
Want to try to program with the Minecraft Pi API but with the full version of Minecraft? RaspberryJuice implements the Minecraft Pi modding API for Bukkit servers.
The plugin listens on port 4711, and accept most of the Minecraft Pi commands, which are documented at .
The plugin supports the majority of the api's supplied with the Pi edition and most examples will work.
Minecraft Forums thread
Currently implemented commands:
world.getBlock
world.getBlockWithData
world.setBlock
world.setBlocks
world.getPlayerIds
chat.post
events.clear
events.block.hits
player.getTile
player.setTile
player.getPos
player.setPos
world.getHeight
entity.getTile
entity.setTile
entity.getPos
entity.setPos
Extra features(^):
getBlocks(x1,y1,z1,x2,y2,z2) has been implemented
getDirection, getRotation, getPitch functions - get the 'direction' players and entities are facing
getPlayerId(playerName) - get the entity of a player by name
pollChatPosts() - get events back for posts to the chat
Config (in config.yml):
- port: 4711 - the default tcp port can be changed in config.yml
- location: RELATIVE - determine whether locations are RELATIVE to the spawn point (default like pi) or ABSOLUTE
- hitclick: RIGHT - determine whether hit events are triggered by LEFT clicks, RIGHT clicks or BOTH
^ to use the extra features an modded version of the java and python libraries that were originally supplied by Mojang with the Pi is required, https:github.com/zhuowei/RaspberryJuice/tree/master/src/main/resources/mcpi. You only need the modded libraries to use the extra features, the original libraries still work, you just wont be able to use the extra features
Example:
This Python script builds a rainbow near the spawn. Place this example in the api/python directory of the Minecraft Pi prerelease, start the server on the same computer, and run python name.py to run, replacing name.py with the actual name of the script.
import mcpi.minecraft as minecraft
import mcpi.block as block
from math import *
colors = [14, 1, 4, 5, 3, 11, 10]
mc = minecraft.Minecraft.create()
height = 60
mc.setBlocks(-64,0,0,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(x - 64, y, 0, block.WOOL.id, colors[len(colors) - 1 - colourindex])
Result:
Further examples can be found at http:www.stuffaboutcode.com/p/minecraft.html
评论 0
登录后参与评分
还没有评论,来抢沙发吧