Set sand origin when command is given
This commit is contained in:
parent
a5642409d2
commit
4026b410f4
2
main.py
2
main.py
|
@ -20,6 +20,7 @@ g.name = None
|
||||||
g.mcdata = False
|
g.mcdata = False
|
||||||
g.pos = False
|
g.pos = False
|
||||||
g.dimension = None
|
g.dimension = None
|
||||||
|
g.item_lock = False
|
||||||
g.inv = {}
|
g.inv = {}
|
||||||
g.objects = {}
|
g.objects = {}
|
||||||
g.mobs = {}
|
g.mobs = {}
|
||||||
|
@ -32,6 +33,7 @@ g.holding = 0
|
||||||
g.afk = False
|
g.afk = False
|
||||||
g.health = 20
|
g.health = 20
|
||||||
g.food = 20
|
g.food = 20
|
||||||
|
g.sand_origin = None
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def hello_world():
|
def hello_world():
|
||||||
|
|
|
@ -268,6 +268,8 @@ class Commands:
|
||||||
self.g.job.state = self.g.job.gather_wood
|
self.g.job.state = self.g.job.gather_wood
|
||||||
reply = 'ok'
|
reply = 'ok'
|
||||||
elif data == 'sand':
|
elif data == 'sand':
|
||||||
|
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.g.job.state = self.g.job.gather_sand
|
self.g.job.state = self.g.job.gather_sand
|
||||||
reply = 'ok'
|
reply = 'ok'
|
||||||
|
|
||||||
|
@ -288,6 +290,8 @@ class Commands:
|
||||||
self.g.job.state = self.g.job.farm_wood
|
self.g.job.state = self.g.job.farm_wood
|
||||||
reply = 'ok'
|
reply = 'ok'
|
||||||
elif data == 'sand':
|
elif data == 'sand':
|
||||||
|
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.g.job.state = self.g.job.farm_sand
|
self.g.job.state = self.g.job.farm_sand
|
||||||
reply = 'ok'
|
reply = 'ok'
|
||||||
elif data == 'wart':
|
elif data == 'wart':
|
||||||
|
|
|
@ -27,6 +27,9 @@ class GatherSandStates:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def init(self):
|
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
|
self.state = self.select_shovel
|
||||||
|
|
||||||
def select_shovel(self):
|
def select_shovel(self):
|
||||||
|
@ -36,10 +39,11 @@ class GatherSandStates:
|
||||||
def find_new_slice(self):
|
def find_new_slice(self):
|
||||||
print('Finding new slice...')
|
print('Finding new slice...')
|
||||||
w = self.g.world
|
w = self.g.world
|
||||||
|
origin = self.g.sand_origin
|
||||||
|
|
||||||
print('using origin', self.origin)
|
print('using origin', self.g.sand_origin)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
self.prev_layer, s = w.find_sand_slice(self.origin, 200, 10, self.bad_slices, self.prev_layer)
|
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')
|
print('Found slice:', s, 'in', time.time() - start, 'seconds')
|
||||||
|
|
||||||
if s:
|
if s:
|
||||||
|
@ -117,8 +121,6 @@ class GatherSandStates:
|
||||||
self.g = global_state
|
self.g = global_state
|
||||||
self.state = self.idle
|
self.state = self.idle
|
||||||
|
|
||||||
self.origin = utils.pint(self.g.pos)
|
|
||||||
self.origin = (2019, 64, 238)
|
|
||||||
self.slice = None
|
self.slice = None
|
||||||
self.bad_slices = []
|
self.bad_slices = []
|
||||||
self.prev_layer = 0
|
self.prev_layer = 0
|
||||||
|
|
|
@ -38,7 +38,7 @@ class SleepWithBedStates:
|
||||||
w = self.g.world
|
w = self.g.world
|
||||||
p = utils.pint(self.g.pos)
|
p = utils.pint(self.g.pos)
|
||||||
|
|
||||||
result = w.find_blocks_indexed(p, blocks.BED_IDS)
|
result = w.find_blocks_indexed(p, blocks.BED_IDS, 80)
|
||||||
|
|
||||||
self.beds = []
|
self.beds = []
|
||||||
for bed in result:
|
for bed in result:
|
||||||
|
|
|
@ -116,7 +116,7 @@ class ChunksManager:
|
||||||
if not c: return None
|
if not c: return None
|
||||||
c.set_block_at(x%16, y%16, z%16, block)
|
c.set_block_at(x%16, y%16, z%16, block)
|
||||||
|
|
||||||
def check_loaded(self, position, steps):
|
def check_loaded(self, position, steps=1):
|
||||||
x, y, z = utils.pint(position)
|
x, y, z = utils.pint(position)
|
||||||
player_chunk = (x//16, 1, z//16)
|
player_chunk = (x//16, 1, z//16)
|
||||||
for i in range(steps): # TODO: base off render_distance?
|
for i in range(steps): # TODO: base off render_distance?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user