Improve searching for crops

master
Tanner Collin 3 years ago
parent 9874e23aa6
commit 23891066c0
  1. 3
      mosfet/bot.py
  2. 6
      mosfet/jobs/gather_crop.py
  3. 14
      mosfet/jobs/gather_wart.py
  4. 75
      mosfet/utils.py
  5. 25
      mosfet/world.py

@ -26,7 +26,6 @@ from munch import Munch
from mosfet import blocks from mosfet import blocks
from mosfet import game from mosfet import game
from mosfet import world
from mosfet import items from mosfet import items
from mosfet import job from mosfet import job
from mosfet import mcdata from mosfet import mcdata
@ -35,6 +34,7 @@ from mosfet import path
from mosfet import print_help from mosfet import print_help
from mosfet import utils from mosfet import utils
from mosfet import vector from mosfet import vector
from mosfet import world
for module in [ for module in [
blocks, blocks,
@ -47,6 +47,7 @@ for module in [
print_help, print_help,
utils, utils,
vector, vector,
world,
]: ]:
importlib.reload(module) importlib.reload(module)

@ -35,8 +35,7 @@ class GatherCropStates:
blocks.MATURE_BEETROOT_ID, blocks.MATURE_BEETROOT_ID,
] ]
for crop in w.find_blocks_3d(p, mature_crops, 50, 20): for crop in w.find_blocks_3d(p, mature_crops, 50, 20, True):
print('Found crop:', crop)
if crop not in self.bad_crops: if crop not in self.bad_crops:
break break
else: # for else: # for
@ -44,6 +43,7 @@ class GatherCropStates:
self.state = self.cleanup self.state = self.cleanup
return return
print('Found crop:', crop)
self.crop = crop self.crop = crop
self.type_id = w.block_at(*crop) self.type_id = w.block_at(*crop)
self.state = self.nav_to_crop self.state = self.nav_to_crop
@ -55,10 +55,12 @@ class GatherCropStates:
navpath = w.path_to_place(p, self.crop) navpath = w.path_to_place(p, self.crop)
if navpath: if navpath:
print('Going to crop', self.crop)
self.g.path = navpath self.g.path = navpath
self.g.look_at = utils.padd(self.crop, path.BLOCK_BELOW) self.g.look_at = utils.padd(self.crop, path.BLOCK_BELOW)
self.state = self.going_to_crop self.state = self.going_to_crop
else: else:
print('Cant get to it, blacklisting')
self.bad_crops.append(self.crop) self.bad_crops.append(self.crop)
self.wait_time = 0.5 self.wait_time = 0.5
self.state = self.wait_to_restart self.state = self.wait_to_restart

@ -29,8 +29,7 @@ class GatherWartStates:
p = utils.pint(self.g.pos) p = utils.pint(self.g.pos)
mature_wart = max(blocks.NETHERWART_IDS) mature_wart = max(blocks.NETHERWART_IDS)
for wart in w.find_blocks_3d(p, [mature_wart], 50, 20): for wart in w.find_blocks_3d(p, [mature_wart], 50, 20, True):
print('Found wart:', wart)
if wart not in self.bad_warts: if wart not in self.bad_warts:
break break
else: # for else: # for
@ -38,6 +37,7 @@ class GatherWartStates:
self.state = self.cleanup self.state = self.cleanup
return return
print('Found wart:', wart)
self.wart = wart self.wart = wart
self.state = self.nav_to_wart self.state = self.nav_to_wart
@ -48,11 +48,21 @@ class GatherWartStates:
navpath = w.path_to_place(p, self.wart) navpath = w.path_to_place(p, self.wart)
if navpath: if navpath:
print('Going to wart', self.crop)
self.g.path = navpath self.g.path = navpath
self.g.look_at = utils.padd(self.wart, path.BLOCK_BELOW) self.g.look_at = utils.padd(self.wart, path.BLOCK_BELOW)
self.state = self.going_to_wart self.state = self.going_to_wart
else: else:
print('Cant get to it, blacklisting')
self.bad_warts.append(wart) self.bad_warts.append(wart)
self.wait_time = 0.5
self.state = self.wait_to_restart
def wait_to_restart(self):
# prevent timeouts
if self.wait_time > 0:
self.wait_time -= utils.TICK
else:
self.state = self.find_new_wart self.state = self.find_new_wart
def going_to_wart(self): def going_to_wart(self):

@ -133,49 +133,32 @@ def search_2d(distance=0):
visited.add(cur) visited.add(cur)
yield cur yield cur
def search_3d(distance=0, y_limit=0): def get_neighbors_3d(x,y,z):
def get_neighbors(x,y,z): return [
return [ #(x+1, y+1, z+0),
(x+1, y+1, z+0), #(x+1, y-1, z+0),
(x+1, y-1, z+0), #(x+1, y+1, z+1),
(x+1, y+1, z+1), #(x+1, y+0, z+1),
(x+1, y+0, z+1), #(x+1, y-1, z+1),
(x+1, y-1, z+1), #(x+1, y+1, z-1),
(x+1, y+1, z-1), #(x+1, y+0, z-1),
(x+1, y+0, z-1), #(x+1, y-1, z-1),
(x+1, y-1, z-1), (x+1, y+0, z+0),
(x+1, y+0, z+0), (x+0, y+1, z+0),
(x+0, y+1, z+0), (x+0, y-1, z+0),
(x+0, y-1, z+0), #(x+0, y+1, z+1),
(x+0, y+1, z+1), (x+0, y+0, z+1),
(x+0, y+0, z+1), #(x+0, y-1, z+1),
(x+0, y-1, z+1), #(x+0, y+1, z-1),
(x+0, y+1, z-1), (x+0, y+0, z-1),
(x+0, y+0, z-1), #(x+0, y-1, z-1),
(x+0, y-1, z-1), #(x-1, y+1, z+0),
(x-1, y+1, z+0), #(x-1, y-1, z+0),
(x-1, y-1, z+0), #(x-1, y+1, z+1),
(x-1, y+1, z+1), #(x-1, y+0, z+1),
(x-1, y+0, z+1), #(x-1, y-1, z+1),
(x-1, y-1, z+1), #(x-1, y+1, z-1),
(x-1, y+1, z-1), #(x-1, y+0, z-1),
(x-1, y+0, z-1), #(x-1, y-1, z-1),
(x-1, y-1, z-1), (x-1, y+0, z+0),
(x-1, y+0, z+0), ]
]
to_visit = collections.deque([(0, 0, 0)])
visited = set()
while to_visit:
cur = to_visit.pop()
if cur in visited:
continue
if y_limit and abs(cur[1]) > y_limit:
continue
if distance and hypot(*cur) > distance:
continue
for neighbor in get_neighbors(*cur):
to_visit.appendleft(neighbor)
visited.add(cur)
yield cur

@ -1,3 +1,4 @@
import collections
import re import re
import time import time
import random import random
@ -24,9 +25,27 @@ class World:
return False return False
return True return True
def find_blocks_3d(self, center, block_ids, distance=0, y_limit=0): def find_blocks_3d(self, center, block_ids, distance=0, y_limit=0, thru_air=False):
for offset in utils.search_3d(distance, y_limit): to_visit = collections.deque([(0, 0, 0)])
check = utils.padd(center, offset) visited = set()
while to_visit:
cur = to_visit.pop()
if cur in visited:
continue
if y_limit and abs(cur[1]) > y_limit:
continue
if distance and hypot(*cur) > distance:
continue
check = utils.padd(center, cur)
if not thru_air or self.block_at(*check) in blocks.NON_SOLID_IDS:
for neighbor in utils.get_neighbors_3d(*cur):
to_visit.appendleft(neighbor)
visited.add(cur)
if self.block_at(*check) in block_ids: if self.block_at(*check) in block_ids:
yield check yield check

Loading…
Cancel
Save