Last active
January 25, 2019 12:32
-
-
Save Tnze/c414ef6ec775eaa9ccc82ea8e952884e to your computer and use it in GitHub Desktop.
Minecraft auto-fish robot. 我的世界自动钓鱼机器人
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
bot "github.com/Tnze/gomcbot" | |
"github.com/Tnze/gomcbot/authenticate" | |
"log" | |
"time" | |
) | |
func main() { | |
log.Println("自动钓鱼机器人启动!") | |
log.Println("github.com/Tnze/gomcbot") | |
log.Println("作者: Tnze") | |
online := flag.Bool("online-mode", false, "If login server with online mode") | |
Name := flag.String("name", "Steve", "The player name in game. Only need for OFFLINE mode.") | |
UUID := flag.String("uuid", "", "Player's universally unique identifier. Only need for OFFLINE mode") | |
Email := flag.String("account", "", "Your Mojang account email. Only need for ONLINE mode") | |
Passwd := flag.String("password", "", "Your Mojang account password. Only need for ONLINE mode") | |
ServerIP := flag.String("ip", "localhost", "The server you want join") | |
Port := flag.Int("port", 25565, "The server's listening port") | |
flag.Parse() | |
var auth bot.Auth | |
if *online { //online mode | |
resp, err := authenticate.Authenticate(*Email, *Passwd) | |
if err != nil { | |
panic(fmt.Errorf("登录失败: %v", err)) | |
} | |
auth = resp.ToAuth() | |
log.Println("登录成功") | |
} else { //offline mode | |
auth = bot.Auth{ | |
Name: *Name, | |
UUID: *UUID, | |
} | |
} | |
g, err := auth.JoinServer(*ServerIP, *Port) | |
if err != nil { | |
panic(fmt.Errorf("加入服务器%s:%d失败: %v", *ServerIP, *Port, err)) | |
} | |
log.Println("成功加入服务器") | |
//Handle game | |
events := g.GetEvents() | |
go g.HandleGame() | |
//处理事件 | |
for e := range events { | |
switch e { | |
case bot.PlayerSpawnEvent: | |
log.Println("Player is spawn! 开始钓鱼") | |
go fish(g) | |
} | |
} | |
} | |
func fish(g *bot.Game) { | |
g.SetSoundCallBack(func(s int32, x, y, z float64, v, p float32) { | |
if s == 184 { // 184 是钓到鱼的声音! | |
log.Println("钓到物品") | |
g.UseItem(true) //收竿 | |
time.Sleep(time.Millisecond * 500) | |
g.UseItem(true) //下一次甩竿 | |
} | |
}) | |
g.UseItem(true) //甩竿 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment