132 lines
3.5 KiB
Python
132 lines
3.5 KiB
Python
import re
|
|
import time
|
|
import importlib
|
|
import random
|
|
from itertools import count
|
|
from math import hypot, floor
|
|
|
|
from minecraft.networking.types import BlockFace
|
|
|
|
from mosfet.protocol.managers import ChunkNotLoadedException
|
|
|
|
from mosfet import utils
|
|
from mosfet import path
|
|
from mosfet.info import blocks
|
|
from mosfet.info import items
|
|
from mosfet.info import mcdata
|
|
from mosfet.info import mobs
|
|
|
|
class GatherSandStates:
|
|
def bair(self, p):
|
|
return self.g.chunks.get_block_at(*p) in blocks.NON_SOLID_IDS
|
|
|
|
def bsand(self, p):
|
|
return self.g.chunks.get_block_at(*p) == blocks.SAND
|
|
|
|
def idle(self):
|
|
return None
|
|
|
|
def init(self):
|
|
if not self.g.sand_origin or not self.g.chunks.check_loaded(self.g.sand_origin):
|
|
self.g.sand_origin = utils.pint(self.g.pos)
|
|
|
|
self.state = self.select_shovel
|
|
|
|
def select_shovel(self):
|
|
self.g.game.select_item(items.SHOVEL_IDS)
|
|
self.state = self.find_new_slice
|
|
|
|
def find_new_slice(self):
|
|
print('Finding new slice...')
|
|
w = self.g.world
|
|
origin = self.g.sand_origin
|
|
|
|
print('using origin', self.g.sand_origin)
|
|
start = time.time()
|
|
self.prev_layer, s = w.find_sand_slice(self.g.sand_origin, 200, 10, self.bad_slices, self.prev_layer)
|
|
print('Found slice:', s, 'in', time.time() - start, 'seconds')
|
|
|
|
if s:
|
|
self.slice = s
|
|
self.bad_slices.append(s)
|
|
self.state = self.find_new_sand
|
|
else:
|
|
print('No slices remaining.')
|
|
self.state = self.cleanup
|
|
|
|
def find_new_sand(self):
|
|
print('Finding new sand...')
|
|
w = self.g.world
|
|
p = utils.pint(self.g.pos)
|
|
head = utils.padd(p, path.BLOCK_ABOVE)
|
|
|
|
for sand in w.find_sand(self.slice, 2, p):
|
|
if sand not in self.bad_sand:
|
|
print('Found sand:', sand)
|
|
break
|
|
else: # for
|
|
print('No good sands left, aborting.')
|
|
self.state = self.cleanup
|
|
return
|
|
|
|
self.sand = sand
|
|
|
|
if utils.phyp(head, self.sand) < blocks.BREAK_DISTANCE:
|
|
self.state = self.dig_sand
|
|
else:
|
|
self.state = self.nav_to_sand
|
|
|
|
def nav_to_sand(self):
|
|
w = self.g.world
|
|
p = utils.pint(self.g.pos)
|
|
c = self.g.chunks
|
|
|
|
navpath = w.path_to_place_faked(p, self.sand)
|
|
print('navpath:', navpath)
|
|
|
|
if navpath:
|
|
self.g.path = navpath[:-1]
|
|
self.state = self.going_to_sand
|
|
else:
|
|
print('Cant get to that sand')
|
|
time.sleep(0.1)
|
|
self.bad_sand.append(self.sand)
|
|
self.state = self.find_new_sand
|
|
|
|
def going_to_sand(self):
|
|
if not len(self.g.path):
|
|
self.g.look_at = self.sand
|
|
self.state = self.dig_sand
|
|
|
|
def dig_sand(self):
|
|
if not self.g.breaking:
|
|
if self.bsand(self.sand):
|
|
self.g.look_at = self.sand
|
|
self.g.game.break_block(self.sand)
|
|
print('digging sand')
|
|
else:
|
|
self.state = self.find_new_sand
|
|
|
|
def cleanup(self):
|
|
self.g.look_at = None
|
|
self.state = self.done
|
|
|
|
def done(self):
|
|
# never gets ran, placeholder
|
|
return None
|
|
|
|
|
|
def __init__(self, global_state):
|
|
self.g = global_state
|
|
self.state = self.idle
|
|
|
|
self.slice = None
|
|
self.bad_slices = []
|
|
self.prev_layer = 0
|
|
self.sand = None
|
|
self.bad_sand = []
|
|
self.wait_time = 0
|
|
|
|
def run(self):
|
|
self.state()
|