2021-04-19 01:34:54 +00:00
|
|
|
import re
|
|
|
|
import time
|
|
|
|
import importlib
|
|
|
|
import random
|
|
|
|
from itertools import count
|
2021-04-28 07:12:30 +00:00
|
|
|
from math import floor
|
2021-04-19 01:34:54 +00:00
|
|
|
|
|
|
|
from minecraft.networking.types import BlockFace
|
|
|
|
|
2021-04-22 00:46:54 +00:00
|
|
|
from mosfet.protocol.managers import ChunkNotLoadedException
|
|
|
|
|
|
|
|
from mosfet import utils
|
|
|
|
from mosfet import path
|
2021-04-23 01:41:01 +00:00
|
|
|
from mosfet.info import blocks
|
|
|
|
from mosfet.info import items
|
|
|
|
from mosfet.info import mcdata
|
|
|
|
from mosfet.info import mobs
|
2021-04-19 01:34:54 +00:00
|
|
|
|
|
|
|
class GrabSandStates:
|
|
|
|
def idle(self):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
self.state = self.find_sand
|
|
|
|
print('Trying to grab sand')
|
|
|
|
|
|
|
|
def find_sand(self):
|
|
|
|
w = self.g.world
|
|
|
|
p = utils.pint(self.g.pos)
|
|
|
|
|
|
|
|
sand = w.find_objects([items.SAND_ID])
|
|
|
|
|
|
|
|
if not sand:
|
|
|
|
print('No sand objects found, aborting')
|
|
|
|
self.state = self.cleanup
|
|
|
|
return
|
|
|
|
|
|
|
|
sand.sort(key=lambda s: utils.phyp(p, (s.x, s.y, s.z)))
|
|
|
|
|
|
|
|
for s in sand:
|
|
|
|
s_pos = utils.pint((s.x, s.y, s.z))
|
|
|
|
check = utils.padd(s_pos, path.BLOCK_BELOW)
|
|
|
|
|
|
|
|
if utils.phyp(p, s_pos) > 6:
|
|
|
|
continue
|
|
|
|
# skip if the sand is floating
|
|
|
|
if self.g.chunks.get_block_at(*check) in {0}:
|
|
|
|
continue
|
|
|
|
if s.entity_id in self.eid_blacklist:
|
|
|
|
continue
|
|
|
|
|
|
|
|
self.eid_blacklist.append(s.entity_id)
|
|
|
|
|
|
|
|
navpath = w.path_to_place(p, s_pos)
|
|
|
|
|
|
|
|
if navpath:
|
|
|
|
self.g.path = navpath
|
|
|
|
self.state = self.going_to_sand
|
|
|
|
self.sand = s_pos
|
|
|
|
print('Going to sand', self.sand)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
print('Cant get to sand', self.sand)
|
2021-04-25 23:39:57 +00:00
|
|
|
time.sleep(0.1)
|
2021-04-19 01:34:54 +00:00
|
|
|
|
|
|
|
print('Cant get to any more sand, aborting')
|
|
|
|
self.state = self.cleanup
|
|
|
|
|
|
|
|
def going_to_sand(self):
|
|
|
|
if utils.pint(self.g.pos) == self.sand:
|
|
|
|
self.state = self.cleanup
|
|
|
|
|
|
|
|
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.sand = None
|
|
|
|
self.eid_blacklist = []
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.state()
|