Documentation ¶
Overview ¶
Package mcpiapi enables you to use the Minecraft Pi Edition API from Go. Each connection uses a single socket and commands are sent over channels, making it safe to use the API from different goroutines.
Example:
var c mcpiapi.Connection c.Open("192.168.1.115") defer c.Close() go func() { c.Chat().Post("Hello, World!") }() go func() { c.Chat().Post("Hello again!") }() err = c.World().SetBlock(0, 0, 0, mcpiapi.GOLD_BLOCK, 0) if err != nil { log.Print(err) }
Block types are 0-255. See the Minecraft Wiki for information on block values.
Block data is 0-15, and is used to specify extra characteristics like wool color.
Regarding the coordinate system, (0,0,0) is where the world was spawned and is sea level. (X,Z) represents the ground plane while Y points to the sky.
Be sure and read the Minecraft Pi Edition API speificication which is included in the installation at:
mcpi/api/spec/mcpi_protocol_spec.txt
See also:
http://pi.minecraft.net/ http://www.minecraftwiki.net/wiki/Data_values_(Pocket_Edition) http://golang.org/
Index ¶
- Constants
- func Arc(c Connection, x, y, z, r int, xzStartRads, xyStartRads, xzRads, xyRads float64, ...) error
- func BaseMaterial(blockTypeId int) int
- func DegToRad(degrees float64) float64
- func IsAir(blockTypeId int) bool
- func IsFire(blockTypeId int) bool
- func IsLava(blockTypeId int) bool
- func IsSlab(blockTypeId int) bool
- func IsStairs(blockTypeId int) bool
- func IsWater(blockTypeId int) bool
- func Pyramid(c Connection, x, y, z, height, blockTypeId, blockData int, ...) error
- func PyramidHere(c Connection, height int) error
- func Sphere(c Connection, x, y, z, r, blockTypeId, blockData int) error
- type Block
- type Camera
- type Chat
- type Checkpoint
- type Connection
- type Events
- type Hit
- type Mode
- type Player
- type PyramidSettings
- type World
- func (obj World) Checkpoint() Checkpoint
- func (obj World) GetBlock(x, y, z int) (blockTypeId int, err error)
- func (obj World) GetHeight(x, z int) (y int, err error)
- func (obj World) SetBlock(x, y, z, blockTypeId, blockData int) error
- func (obj World) SetBlocks(x1, y1, z1, x2, y2, z2, blockTypeId, blockData int) error
- func (obj World) Setting(key string, enable bool) error
Constants ¶
const ( AIR = 0 STONE = 1 GRASS = 2 DIRT = 3 COBBLESTONE = 4 WOOD_PLANKS = 5 SAPLING = 6 BEDROCK = 7 WATER_FLOWING = 8 WATER = WATER_FLOWING WATER_STATIONARY = 9 LAVA_FLOWING = 10 LAVA = LAVA_FLOWING LAVA_STATIONARY = 11 SAND = 12 GRAVEL = 13 GOLD_ORE = 14 IRON_ORE = 15 COAL_ORE = 16 WOOD = 17 LEAVES = 18 SPONGE = 19 // added GLASS = 20 LAPIS_LAZULI_ORE = 21 LAPIS_LAZULI_BLOCK = 22 SANDSTONE = 24 BED = 26 POWERED_RAIL = 27 // added COBWEB = 30 GRASS_TALL = 31 DEAD_BUSH = 32 // adeed WOOL = 35 FLOWER_YELLOW = 37 FLOWER_CYAN = 38 MUSHROOM_BROWN = 39 MUSHROOM_RED = 40 GOLD_BLOCK = 41 IRON_BLOCK = 42 STONE_SLAB_DOUBLE = 43 STONE_SLAB = 44 BRICK_BLOCK = 45 TNT = 46 BOOKSHELF = 47 MOSS_STONE = 48 OBSIDIAN = 49 TORCH = 50 FIRE = 51 STAIRS_WOOD = 53 CHEST = 54 DIAMOND_ORE = 56 DIAMOND_BLOCK = 57 CRAFTING_TABLE = 58 SEEDS = 59 // added FARMLAND = 60 FURNACE_INACTIVE = 61 FURNACE_ACTIVE = 62 SIGN_POST = 63 // added DOOR_WOOD = 64 LADDER = 65 RAIL = 66 // added STAIRS_COBBLESTONE = 67 WALL_SIGN = 68 // added DOOR_IRON = 71 REDSTONE_ORE = 73 GLOWING_REDSTONE_ORE = 74 // added SNOW = 78 ICE = 79 SNOW_BLOCK = 80 CACTUS = 81 CLAY = 82 SUGAR_CANE = 83 FENCE = 85 PUMPKIN = 86 // adeed NETHERRACK = 87 // added GLOWSTONE_BLOCK = 89 JACK_O_LANTERN = 91 // added CAKE_BLOCK = 92 // added BEDROCK_INVISIBLE = 95 TRAP_DOOR = 96 // added STONE_BRICK = 98 IRON_BARS = 101 GLASS_PANE = 102 MELON = 103 PUMPKIN_STEM = 104 // added MELON_STEM = 105 // added FENCE_GATE = 107 BRICK_STAIRS = 108 // added STONE_BRICK_STAIRS = 109 // added NETHER_BRICK = 112 // added NETHER_BRICK_STAIRS = 114 // added SANDSTONE_STAIRS = 128 // added EMERALD_ORE = 129 // added SPRUCE_WOOD_STAIRS = 134 // added BIRCH_WOOD_STAIRS = 135 // added JUNGLE_WOOD_STAIRS = 136 // added COBBLESTONE_WALL = 139 // added CARROTS = 141 // added POTATO = 142 // added QUARTZ_BLOCK = 155 // added QUARTZ_STAIRS = 156 // added WOODEN_DOUBLE_SLAB = 157 // added WOODEN_SLAB = 158 // added HAY_BLOCK = 170 // added CARPET = 171 // added BLOCK_OF_COAL = 173 // added BEETROOT = 244 // added STONE_CUTTER = 245 // added GLOWING_OBSIDIAN = 246 NETHER_REACTOR_CORE = 247 UPDATE_GAME_BLOCK_1 = 248 // added UPDATE_GAME_BLOCK_2 = 249 // added LAST = 255 // added )
Block types
Variables ¶
This section is empty.
Functions ¶
func Arc ¶
func Arc(c Connection, x, y, z, r int, xzStartRads, xyStartRads, xzRads, xyRads float64, blockTypeId, blockData int) error
Arc draws an arc of radius r centered at (x, y, z) within the angles specified.
func BaseMaterial ¶
BaseMaterial returns a block ID of the base material for the given type. The intent of the function is to determine the base type of stairs and other manufactured objects.
func IsSlab ¶
IsSlab returns true if the given block type is any kind of slab, which is half-height.
func Pyramid ¶
func Pyramid(c Connection, x, y, z, height, blockTypeId, blockData int, settings *PyramidSettings) error
Pyramid draws a pyramid of the given height at the specified location using the block type and settings provided.
func PyramidHere ¶
func PyramidHere(c Connection, height int) error
PyramidHere draws a pyramid of the given height at the player's current location.
func Sphere ¶
func Sphere(c Connection, x, y, z, r, blockTypeId, blockData int) error
Sphere draws a sphere of the given radius r around the coordinates (x, y, z).
Types ¶
type Camera ¶
type Camera object
Camera has methods for manipulating the scene displayed to the user.
type Checkpoint ¶
type Checkpoint object
Checkpoint has methods for managing saving and restoring the world's state.
func (Checkpoint) Restore ¶
func (obj Checkpoint) Restore() error
Restore restores the world's state to that of the last checkpoint.
func (Checkpoint) Save ¶
func (obj Checkpoint) Save() error
Save saves the world's current state so that it can be restored later.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection provides access to the Minecraft API.
func (*Connection) Camera ¶
func (obj *Connection) Camera() Camera
Camera returns the camera object.
func (*Connection) Close ¶
func (obj *Connection) Close() error
Close closes the connection to the host.
func (*Connection) Events ¶
func (obj *Connection) Events() Events
Events returns the events object.
func (*Connection) Open ¶
func (obj *Connection) Open(host string, name string) error
Open establishes a connection to the given host over port 4711 with player name.
func (*Connection) Player ¶
func (obj *Connection) Player() Player
Player returns the player object.
type Hit ¶
type Hit struct { PositionX int PositionY int PositionZ int SurfaceX int SurfaceY int SurfaceZ int BlockTypeId int }
Hit contains the information for a block event.
type Mode ¶
type Mode object
Mode has methods for manipulating the camera mode.
func (Mode) SetThirdPerson ¶
SetThirdPerson sets the camera to the third-person view.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
Player provides methods to manipulate the player you typed.
func (Player) GetPos ¶
GetPos returns the player's position. Note the the player position is more granular than a world position.
type PyramidSettings ¶
type PyramidSettings struct { Floor bool // Draws a floor under the pyramid FloorBlockTypeId int // Block ID to use for the floor FloorBlockData int // Block data to use for the floor ClearInside bool // whether to clear the blocks from the inside of the pyramid }
PyramidSettings is used to specify additional information controlling rendering a pyramid.
type World ¶
type World object
World has methods for manipulating the Minecraft world.
func (World) Checkpoint ¶
func (obj World) Checkpoint() Checkpoint
Checkpoint provides access to the checkpoint object for this world.
func (World) GetBlock ¶
GetBlock returns the block type at the given coordinates. Block types can be 0-108.
func (World) SetBlock ¶
SetBlock sets the block type and block data at the given coordinate. Block types are 0-255 and block data can be 0-15. Block data represents extra attributes like the wool color.