go-mcpi-api: github.com/ancientlore/go-mcpi-api Index | Files

package mcpiapi

import "github.com/ancientlore/go-mcpi-api"

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

Package Files

blocks.go camera.go chat.go connection.go doc.go events.go player.go utils.go world.go

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

func Arc Uses

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 Uses

func BaseMaterial(blockTypeId int) int

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 DegToRad Uses

func DegToRad(degrees float64) float64

DegToRad converts degrees to radians.

func IsAir Uses

func IsAir(blockTypeId int) bool

IsAir returns true if the given block type is air.

func IsFire Uses

func IsFire(blockTypeId int) bool

IsFire returns true if the given block type is fire.

func IsLava Uses

func IsLava(blockTypeId int) bool

IsLava returns true if the given block type is any kind of lava.

func IsSlab Uses

func IsSlab(blockTypeId int) bool

IsSlab returns true if the given block type is any kind of slab, which is half-height.

func IsStairs Uses

func IsStairs(blockTypeId int) bool

IsStairs returns true if the given block type is any kind of stairs.

func IsWater Uses

func IsWater(blockTypeId int) bool

IsWater returns true if the given block type is any kind of water.

func Pyramid Uses

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 Uses

func PyramidHere(c Connection, height int) error

PyramidHere draws a pyramid of the given height at the player's current location.

func Sphere Uses

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).

type Block Uses

type Block object

Block provides methods for getting block events.

func (Block) Hits Uses

func (obj Block) Hits() (hits []Hit, err error)

Hits returns the current block events as a slice.

type Camera Uses

type Camera object

Camera has methods for manipulating the scene displayed to the user.

func (Camera) Mode Uses

func (obj Camera) Mode() Mode

Mode returns the mode object for the camera

type Chat Uses

type Chat object

Chat provides methods to post messages to the user.

func (Chat) Post Uses

func (obj Chat) Post(text string) error

Post displays the given text to the user.

type Checkpoint Uses

type Checkpoint object

Checkpoint has methods for managing saving and restoring the world's state.

func (Checkpoint) Restore Uses

func (obj Checkpoint) Restore() error

Restore restores the world's state to that of the last checkpoint.

func (Checkpoint) Save Uses

func (obj Checkpoint) Save() error

Save saves the world's current state so that it can be restored later.

type Connection Uses

type Connection struct {
    // contains filtered or unexported fields
}

Connection provides access to the Minecraft API.

func (*Connection) Camera Uses

func (obj *Connection) Camera() Camera

Camera returns the camera object.

func (*Connection) Chat Uses

func (obj *Connection) Chat() Chat

Chat returns the chat object.

func (*Connection) Close Uses

func (obj *Connection) Close() error

Close closes the connection to the host.

func (*Connection) Events Uses

func (obj *Connection) Events() Events

Events returns the events object.

func (*Connection) Open Uses

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 Uses

func (obj *Connection) Player() Player

Player returns the player object.

func (*Connection) World Uses

func (obj *Connection) World() World

World returns the world object.

type Events Uses

type Events object

Events provides methods for getting events.

func (Events) Block Uses

func (obj Events) Block() Block

Block returns the block object.

func (Events) Clear Uses

func (obj Events) Clear() error

Clear clears the event queue.

type Hit Uses

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 Uses

type Mode object

Mode has methods for manipulating the camera mode.

func (Mode) SetFixed Uses

func (obj Mode) SetFixed() error

SetFixed sets the camera to a fixed view. Use SetPos to move it around.

func (Mode) SetNormal Uses

func (obj Mode) SetNormal() error

SetNormal sets the camera mode to the normal first-person view.

func (Mode) SetPos Uses

func (obj Mode) SetPos(x, y, z int) error

SetPos moves the camera to the given coordinate.

func (Mode) SetThirdPerson Uses

func (obj Mode) SetThirdPerson() error

SetThirdPerson sets the camera to the third-person view.

type Player Uses

type Player struct {
    // contains filtered or unexported fields
}

Player provides methods to manipulate the player you typed.

func (Player) GetPos Uses

func (obj Player) GetPos() (xf, yf, zf float64, err error)

GetPos returns the player's position. Note the the player position is more granular than a world position.

func (Player) GetTile Uses

func (obj Player) GetTile() (x, y, z int, err error)

GetTile returns the world coordinates of the player's location.

func (Player) SetPos Uses

func (obj Player) SetPos(xf, yf, zf float64) error

SetPos sets the player's position. Note that the player position is more granular than a world position.

func (Player) SetTile Uses

func (obj Player) SetTile(x, y, z int) error

SetTile moves the player the given world coordinates.

type PyramidSettings Uses

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 Uses

type World object

World has methods for manipulating the Minecraft world.

func (World) Checkpoint Uses

func (obj World) Checkpoint() Checkpoint

Checkpoint provides access to the checkpoint object for this world.

func (World) GetBlock Uses

func (obj World) GetBlock(x, y, z int) (blockTypeId int, err error)

GetBlock returns the block type at the given coordinates. Block types can be 0-108.

func (World) GetHeight Uses

func (obj World) GetHeight(x, z int) (y int, err error)

GetHeight returns the height of the ground at the given coordinate.

func (World) SetBlock Uses

func (obj World) SetBlock(x, y, z, blockTypeId, blockData int) error

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.

func (World) SetBlocks Uses

func (obj World) SetBlocks(x1, y1, z1, x2, y2, z2, blockTypeId, blockData int) error

SetBlocks sets a range of blocks to the block type and block data provided. Block types are 0-255 and block data can be 0-15. Block data represents extra attributes like the wool color. Note: Setting a huge number of blocks can cause lag in the Minecraft game.

func (World) Setting Uses

func (obj World) Setting(key string, enable bool) error

Setting is used to enable or disable various Minecraft world settings.

Package mcpiapi imports 7 packages (graph). Updated 2019-08-21. Refresh now. Tools for package owners.