func chop(client *mcclient.Client, p xyz) { for { block, _, _, _, _, _ := client.GetBlock(p.x, p.y, p.z) if block == 17 { moveTo(client, p) ansi.Printf(ansi.Green, "Breaking block at (%d, %d, %d)\n", p.x, p.y, p.z) die(client.SendPacket(0x0E, int8(0), int32(p.x), int8(p.y), int32(p.z), int8(5))) die(client.SendPacket(0x0E, int8(2), int32(p.x), int8(p.y), int32(p.z), int8(5))) time.Sleep(time.Second * 3) p.y++ } else { break } } }
func findNearestTree(client *mcclient.Client) (p xyz, ok bool) { p = xyz{int(client.PlayerX), int(client.PlayerY), int(client.PlayerZ)} radius := 1 x := -radius z := -radius p.x -= radius p.z -= radius dir := 1 mainloop: for { //fmt.Scanln() block, _, _, _, _, ok := client.GetBlock(p.x, p.y, p.z) if !ok { ansi.Printf(ansi.RedBold, "No log found!\n") return p, false } //println(p.x, p.y, p.z, block) if block == 0 { under, _, _, _, _, _ := client.GetBlock(p.x, p.y-1, p.z) if under == 0 { p.y-- } else { if (dir > 0 && x == radius) || (dir < 0 && x == -radius) { if (dir > 0 && z == radius) || (dir < 0 && z == -radius) { if dir < 0 { radius++ x = -radius z = -radius p.x -= 1 p.z -= 1 } dir = -dir } else { z += dir p.z += dir } } else { x += dir p.x += dir } } } else if block == 17 { // We found log! n := p for { n.y++ block, _, _, _, _, ok = client.GetBlock(n.x, n.y, n.z) if block == 17 { // Log continue } else if block == 18 { // Leaves, always found above a tree break } else { // Not a log continue mainloop } } for { block, _, _, _, _, ok = client.GetBlock(p.x, p.y-1, p.z) if block == 17 { p.y-- continue } else { // Bottom block of trunk return p, true } } } else { p.y++ } } return p, false }