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!")
}
}
}
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!")
}
}
}
Index ¶
- Constants
- Variables
- func PingAndList(addr string, port int) (string, error)
- type Auth
- type Block
- type BlockChangeEvent
- type ChatMessageEvent
- type ChatMsg
- type Chunk
- type DisconnectEvent
- type Entity
- type Event
- type Face
- type Game
- func (g *Game) Chat(msg string) error
- func (g *Game) Dig(x, y, z int) error
- func (g *Game) GetBlock(x, y, z int) Block
- func (g *Game) GetEvents() <-chan Event
- func (g *Game) GetPlayer() Player
- func (g *Game) HandleGame() error
- func (g *Game) LookAt(x, y, z float64)
- func (g *Game) LookYawPitch(yaw, pitch float32)
- func (g *Game) SetPosition(x, y, z float64, onGround bool)
- func (g *Game) Settings(set Settings)
- func (g *Game) SwingHand(hand bool)
- func (g *Game) UseItem(hand bool)
- type InventoryChangeEvent
- type Player
- type PlayerAbilities
- type PlayerDeadEvent
- type PlayerInfo
- type PlayerSpawnEvent
- type Position
- type Section
- type Settings
- type Solt
- type SoundEffectEvent
Examples ¶
Constants ¶
const ( Jacket LeftSleeve RightSleeve LeftPantsLeg RightPantsLeg Hat )
Used by Settings.DisplayedSkinParts. For each bits set if shows match part.
Variables ¶
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 ¶
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)
}
Types ¶
type Auth ¶
Auth includes a account
func (*Auth) JoinServer ¶
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
type BlockChangeEvent ¶
type BlockChangeEvent struct{}
BlockChangeEvent sent when a block has been broken or placed
type ChatMessageEvent ¶
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 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 Event ¶
type Event interface{}
Event happends in game and you can recive it from what Game.GetEvent() returns
type Game ¶
type Game struct {
Info PlayerInfo
// contains filtered or unexported fields
}
Game is the Object used to access Minecraft server
func (*Game) Chat ¶
Chat send chat message to server such as player send message in chat box msg can not longger than 256
func (*Game) GetEvents ¶
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) HandleGame ¶
HandleGame recive server packet and response them correctly. Note that HandleGame will block if you don't recive from Events.
func (*Game) LookYawPitch ¶
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 ¶
SetPosition method move your character around. Server will ignore this if changes too much.
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) GetBlockPos ¶
GetBlockPos return the position of the Block at player's feet
func (*Player) GetPosition ¶
GetPosition return the player's position
type PlayerAbilities ¶
PlayerAbilities defines what player can do.
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 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 SoundEffectEvent ¶
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