Reverse order slices are found, fix bugs
This commit is contained in:
parent
b7295b4beb
commit
00846538e8
18
game.py
18
game.py
|
@ -211,19 +211,17 @@ class MCWorld:
|
|||
|
||||
return False
|
||||
|
||||
def find_sand_slice(self, center, distance, skip_to=(0, 0)):
|
||||
def find_sand_slice(self, center, distance, bad_slices=[]):
|
||||
# returns the centre coord of the next 5x5x1 slice that still has
|
||||
# diggable sand in it. lower slices are only valid if there's an
|
||||
# adjacent slice farther at the same level. this should ensure an
|
||||
# upside down pyramid gets excavated so the edges are still climbable
|
||||
skip_vertical, skip_spiral = skip_to
|
||||
|
||||
for v in count(skip_vertical):
|
||||
for v in count():
|
||||
peak = utils.padd(center, (0, 20-v, 0))
|
||||
|
||||
slices = []
|
||||
layer = 0
|
||||
start_step = skip_spiral if v == skip_vertical else 0
|
||||
for step in count(start_step):
|
||||
for step in count():
|
||||
offset = utils.spiral(step)
|
||||
layer = max(layer, *offset)
|
||||
offset = utils.pmul(offset, 3)
|
||||
|
@ -233,10 +231,12 @@ class MCWorld:
|
|||
if utils.phyp(center, check) >= distance:
|
||||
break
|
||||
|
||||
if self.check_sand_slice(check):
|
||||
return (v-1, step+1), check
|
||||
if self.check_sand_slice(check) and check not in bad_slices:
|
||||
slices.append(check)
|
||||
|
||||
if v > 40:
|
||||
if len(slices):
|
||||
return slices[-1]
|
||||
elif v > 40:
|
||||
return None, None
|
||||
|
||||
|
||||
|
|
37
jobs.py
37
jobs.py
|
@ -305,13 +305,13 @@ class GatherSandStates:
|
|||
print('Finding new slice...')
|
||||
w = self.g.world
|
||||
|
||||
#o = utils.padd(self.origin, (0, 10, 0))
|
||||
print('using origin', self.origin)
|
||||
self.skip, s = w.find_sand_slice(self.origin, 50)
|
||||
print('Found slice:', s, 'skip:', self.skip)
|
||||
s = w.find_sand_slice(self.origin, 50, self.bad_slices)
|
||||
print('Found slice:', s)
|
||||
|
||||
if s:
|
||||
self.slice = s
|
||||
#self.bad_slices.append(s)
|
||||
self.state = self.find_new_sand
|
||||
else:
|
||||
print('No slices remaining.')
|
||||
|
@ -385,8 +385,8 @@ class GatherSandStates:
|
|||
self.state = self.idle
|
||||
|
||||
self.origin = utils.pint(self.g.pos)
|
||||
self.skip = (0, 0)
|
||||
self.slice = None
|
||||
self.bad_slices = []
|
||||
self.sand = None
|
||||
self.bad_sand = []
|
||||
self.wait_time = 0
|
||||
|
@ -422,11 +422,13 @@ class GrabSandStates:
|
|||
|
||||
if utils.phyp(p, s_pos) > 6:
|
||||
continue
|
||||
if s.entity_id in self.eid_blacklist:
|
||||
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)
|
||||
|
||||
|
@ -434,16 +436,17 @@ class GrabSandStates:
|
|||
self.g.path = navpath
|
||||
self.state = self.going_to_sand
|
||||
self.sand = s_pos
|
||||
self.eid_blacklist.append(s.entity_id)
|
||||
print('Going to sand', self.sand)
|
||||
return
|
||||
else:
|
||||
print('Cant get to sand', self.sand)
|
||||
|
||||
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.find_sand
|
||||
self.state = self.cleanup
|
||||
|
||||
def cleanup(self):
|
||||
self.g.look_at = None
|
||||
|
@ -607,7 +610,7 @@ class CacheItemsStates:
|
|||
|
||||
if not len(self.trapped_chests):
|
||||
print('No trapped chests')
|
||||
self.state = self.find_cache_spot
|
||||
self.state = self.select_chest
|
||||
return
|
||||
|
||||
chest = self.trapped_chests[0]
|
||||
|
@ -634,6 +637,14 @@ class CacheItemsStates:
|
|||
self.state = self.open_chest
|
||||
|
||||
|
||||
def select_chest(self):
|
||||
if self.g.game.select_item(items.CHEST_ID):
|
||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||
self.state = self.find_cache_spot
|
||||
else:
|
||||
print('No chest, aborting')
|
||||
self.state = self.cleanup
|
||||
|
||||
def find_cache_spot(self):
|
||||
print('Finding a chest spot...')
|
||||
w = self.g.world
|
||||
|
@ -667,15 +678,7 @@ class CacheItemsStates:
|
|||
def going_to_area(self):
|
||||
if utils.pint(self.g.pos) == self.opening:
|
||||
self.g.look_at = self.area
|
||||
self.state = self.select_chest
|
||||
|
||||
def select_chest(self):
|
||||
if self.g.game.select_item(items.CHEST_ID):
|
||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||
self.state = self.place_chest
|
||||
else:
|
||||
print('No chest, aborting')
|
||||
self.state = self.cleanup
|
||||
|
||||
def place_chest(self):
|
||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||
|
|
Loading…
Reference in New Issue
Block a user