gomcbot

package module
v0.0.0-...-2f9bf8d Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

README

GoMCbot

This package has been moved to github.com/Tnze/go-mc/bot
注意,这个版本已经停止开发了,新版在github.com/Tnze/go-mc/bot,新版的代码更加整洁,而且支持1.14+

A golang minecraft robot package.

  • Current Version: 1.13.2 (1.14 version is comming)
  • Protocol Version: 404

GoDoc Go Report Card

What can it do

GoMCbot play a role in a Minecraft Client which has no graphy but you can control it by programing. These're what gomcbot can do and what can't do yet

  • Join online server
  • Join offline server
  • Parse chunk data
  • View inventory
  • Use item
  • Listening sound
  • Send chat message
  • Recive and parse chat message
  • Move around and look around
  • Swing hands
  • Mine blocks
  • Place blocks
  • Steer vehicle
  • Steer boat
  • Craft
  • Pick item
  • Use entity
  • Edit book
  • Enchant item
  • Record entity
  • Unload chunks

Talk to me if you want one of unrealized function.

Usage

There are some basic usage example. For more information, see Wiki.

To use gomcbot, simply run go get -u github.com/Tnze/gomcbot

Examples

See examples_test.go.

Documentation

Overview

Example (JoinOfflineServer)
package main

import (
	"fmt"
	bot "github.com/Tnze/gomcbot"
)

func main() {
	Auth := bot.Auth{
		Name: "Steve",
	}
	//Join server
	game, err := Auth.JoinServer("localhost", 25565)
	if err != nil {
		panic(err)
	}

	//Handle game
	events := game.GetEvents()
	go game.HandleGame()

	for e := range events { //Reciving events
		switch e.(type) {
		case bot.PlayerSpawnEvent:
			fmt.Println("Player is spawned!")
		}
	}
}
Output:

Example (JoinOnlineServer)
package main

import (
	"fmt"
	bot "github.com/Tnze/gomcbot"

	auth "github.com/Tnze/gomcbot/authenticate"
)

func main() {
	//Login

	// This is the basic authenticate function.
	// Maybe you could get more control of login process by using
	// https://github.com/JoshuaDoes/go-yggdrasil.
	resp, err := auth.Authenticate("email", "password")
	if err != nil {
		panic(err)
	}
	Auth := resp.ToAuth()

	//Join server
	game, err := Auth.JoinServer("localhost", 25565)
	if err != nil {
		panic(err)
	}

	//Handle game
	events := game.GetEvents()
	go game.HandleGame()

	for e := range events { //Reciving events
		switch e.(type) {
		case bot.PlayerSpawnEvent:
			fmt.Println("Player is spawned!")
		}
	}
}
Output:

Index

Examples

Constants

View Source
const (
	Jacket
	LeftSleeve
	RightSleeve
	LeftPantsLeg
	RightPantsLeg
	Hat
)

Used by Settings.DisplayedSkinParts. For each bits set if shows match part.

Variables

View Source
var DefaultSettings = Settings{
	Locale:             "zh_CN",
	ViewDistance:       15,
	ChatMode:           0,
	DisplayedSkinParts: Jacket | LeftSleeve | RightSleeve | LeftPantsLeg | RightPantsLeg | Hat,
	MainHand:           1,
	ReciveMap:          true,
}

DefaultSettings 定义了客户端的默认设置

Functions

func PingAndList

func PingAndList(addr string, port int) (string, error)

PingAndList chack server status and list online player

Example
package main

import (
	"fmt"
	bot "github.com/Tnze/gomcbot"
)

func main() {
	resp, err := bot.PingAndList("localhost", 25565)
	if err != nil {
		panic(err)
	}
	// see format of resp at https://wiki.vg/Server_List_Ping#Response
	fmt.Println(resp)
}
Output:

Types

type Auth

type Auth struct {
	Name string
	UUID string
	AsTk string
}

Auth includes a account

func (*Auth) JoinServer

func (p *Auth) JoinServer(addr string, port int) (g *Game, err error)

JoinServer connect a Minecraft server. Return a JSON string about server status. see JSON format at https://wiki.vg/Server_List_Ping#Response

type Block

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

Block is the base of world

func (Block) String

func (b Block) String() string

type BlockChangeEvent

type BlockChangeEvent struct{}

BlockChangeEvent sent when a block has been broken or placed

type ChatMessageEvent

type ChatMessageEvent struct {
	Msg ChatMsg
	Pos byte
}

ChatMessageEvent sent when chat message was recived. When Pos is 0, this message should be displayed at chat box. When it's 1, this is a system message and also at chat box, if 2, it's a game info which displayed above hotbar.

type ChatMsg

type ChatMsg jsonChat

ChatMsg is a message sent by other

func (ChatMsg) String

func (c ChatMsg) String() (s string)

String return the message with escape sequence for ansi color. On windows, you may want print this string using github.com/mattn/go-colorable.

type Chunk

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

Chunk store a 256*16*16 clolumn blocks

type DisconnectEvent

type DisconnectEvent ChatMsg

DisconnectEvent sent when server disconnect this client. The value is the reason.

type Entity

type Entity interface {
	EntityID() int32
}

Entity 表示一个实体

type Event

type Event interface{}

Event happends in game and you can recive it from what Game.GetEvent() returns

type Face

type Face byte

Face is a face of a block

const (
	Bottom Face = iota
	Top
	North
	South
	West
	East
)

All six faces in a block

type Game

type Game struct {
	Info PlayerInfo
	// contains filtered or unexported fields
}

Game is the Object used to access Minecraft server

func (*Game) Chat

func (g *Game) Chat(msg string) error

Chat send chat message to server such as player send message in chat box msg can not longger than 256

func (*Game) Dig

func (g *Game) Dig(x, y, z int) error

Dig a block in the position and wait for it's breaked

func (*Game) GetBlock

func (g *Game) GetBlock(x, y, z int) Block

GetBlock return the block at (x, y, z)

func (*Game) GetEvents

func (g *Game) GetEvents() <-chan Event

GetEvents returns a int type channal. When event happends, a event ID was be sended into this chan Note that HandleGame will block if you don't recive from Events

func (*Game) GetPlayer

func (g *Game) GetPlayer() Player

GetPlayer return the player

func (*Game) HandleGame

func (g *Game) HandleGame() error

HandleGame recive server packet and response them correctly. Note that HandleGame will block if you don't recive from Events.

func (*Game) LookAt

func (g *Game) LookAt(x, y, z float64)

LookAt method turn player's hand and make it look at a point.

func (*Game) LookYawPitch

func (g *Game) LookYawPitch(yaw, pitch float32)

LookYawPitch set player's hand to the direct by yaw and pitch. yaw can be [0, 360) and pitch can be (-180, 180). if |pitch|>90 the player's hand will be very strange.

func (*Game) SetPosition

func (g *Game) SetPosition(x, y, z float64, onGround bool)

SetPosition method move your character around. Server will ignore this if changes too much.

func (*Game) Settings

func (g *Game) Settings(set Settings)

Settings set a Settings to Game

func (*Game) SwingHand

func (g *Game) SwingHand(hand bool)

SwingHand sent when the player's arm swings. if hand is true, swing the main hand

func (*Game) UseItem

func (g *Game) UseItem(hand bool)

UseItem use the item in hand. if hand is true, swing the main hand

type InventoryChangeEvent

type InventoryChangeEvent int16

InventoryChangeEvent sent when player's inventory is changed. The value is the changed slot id. -1 means the cursor (the item currently dragged with the mouse) and -2 if the server update all of the slots.

type Player

type Player struct {
	UUID [2]int64 //128bit UUID

	X, Y, Z    float64
	Yaw, Pitch float32
	OnGround   bool

	HeldItem  int //拿着的物品栏位
	Inventory []Solt

	Health         float32 //血量
	Food           int32   //饱食度
	FoodSaturation float32 //食物饱和度
	// contains filtered or unexported fields
}

Player includes the player's status.

func (*Player) EntityID

func (p *Player) EntityID() int32

EntityID get player's entity ID.

func (*Player) GetBlockPos

func (p *Player) GetBlockPos() (x, y, z int)

GetBlockPos return the position of the Block at player's feet

func (*Player) GetPosition

func (p *Player) GetPosition() (x, y, z float64)

GetPosition return the player's position

type PlayerAbilities

type PlayerAbilities struct {
	Flags               int8
	FlyingSpeed         float32
	FieldofViewModifier float32
}

PlayerAbilities defines what player can do.

type PlayerDeadEvent

type PlayerDeadEvent struct{}

PlayerDeadEvent sent when player is dead

type PlayerInfo

type PlayerInfo struct {
	EntityID         int      //实体ID
	Gamemode         int      //游戏模式
	Hardcore         bool     //是否是极限模式
	Dimension        int      //维度
	Difficulty       int      //难度
	LevelType        string   //地图类型
	ReducedDebugInfo bool     //减少调试信息
	SpawnPosition    Position //主世界出生点
}

PlayerInfo content player info in server.

type PlayerSpawnEvent

type PlayerSpawnEvent struct{}

PlayerSpawnEvent sent when this client is ready to playing.

type Position

type Position struct {
	X, Y, Z int
}

Position is a 3D vector.

type Section

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

Section store a 16*16*16 cube blocks

type Settings

type Settings struct {
	Locale             string //地区
	ViewDistance       int    //视距
	ChatMode           int    //聊天模式
	ChatColors         bool   //聊天颜色
	DisplayedSkinParts uint8  //皮肤显示
	MainHand           int    //主手
	ReciveMap          bool   //接收地图数据
}

Settings 客户端设置

type Solt

type Solt struct {
	ID    int
	Count byte
}

Solt 表示物品栏的一格

func (Solt) String

func (s Solt) String() string

type SoundEffectEvent

type SoundEffectEvent struct {
	Sound         int32
	Category      int32
	X, Y, Z       float64
	Volume, Pitch float32
}

SoundEffectEvent sent when a sound should be played for sound id, check: https://pokechu22.github.io/Burger/1.13.2.html#sounds x, y, z is the position the sound played volume is the volume of the sound pitch is the direction of the sound

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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