mcpiapi

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

go-mcpi-api

GoDoc

This library 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.

中文版本README: 用go語言翻轉Minecraft - go-mcpi-api

Also see FrozenKP's version.

FAQ

What is MCPI ?

MCPI is an API which can let you control Minecraft with code.

It's original edition was written with python; you can learn it here.

Can I using it with a normal edition Minecraft ?

Yes, you can. You can refer to this project.

Example

var c mcpiapi.Connection
c.Open("192.168.1.115", "player1")
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)
}

Pocket Edition Information

Block types are 0-108. 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.

The library includes some utility functions for shapes - more may be added over time.

NOTE: Events have not been tested.

Installation

go get github.com/ancientlore/go-mcpi-api

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

View Source
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

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

func DegToRad(degrees float64) float64

DegToRad converts degrees to radians.

func IsAir

func IsAir(blockTypeId int) bool

IsAir returns true if the given block type is air.

func IsFire

func IsFire(blockTypeId int) bool

IsFire returns true if the given block type is fire.

func IsLava

func IsLava(blockTypeId int) bool

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

func IsSlab

func IsSlab(blockTypeId int) bool

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

func IsStairs

func IsStairs(blockTypeId int) bool

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

func IsWater

func IsWater(blockTypeId int) bool

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

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 Block

type Block object

Block provides methods for getting block events.

func (Block) Hits

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

Hits returns the current block events as a slice.

type Camera

type Camera object

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

func (Camera) Mode

func (obj Camera) Mode() Mode

Mode returns the mode object for the camera

type Chat

type Chat object

Chat provides methods to post messages to the user.

func (Chat) Post

func (obj Chat) Post(text string) error

Post displays the given text 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) Chat

func (obj *Connection) Chat() Chat

Chat returns the chat 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.

func (*Connection) World

func (obj *Connection) World() World

World returns the world object.

type Events

type Events object

Events provides methods for getting events.

func (Events) Block

func (obj Events) Block() Block

Block returns the block object.

func (Events) Clear

func (obj Events) Clear() error

Clear clears the event queue.

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

func (obj Mode) SetFixed() error

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

func (Mode) SetNormal

func (obj Mode) SetNormal() error

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

func (Mode) SetPos

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

SetPos moves the camera to the given coordinate.

func (Mode) SetThirdPerson

func (obj Mode) SetThirdPerson() error

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

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

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

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

func (Player) SetPos

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

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

SetTile moves the player the given world coordinates.

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

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

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

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

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL