Add a job for farming nether wart
This commit is contained in:
parent
6c0688b759
commit
6c9f228862
|
@ -279,6 +279,11 @@ for block_name in ['trapped_chest']:
|
||||||
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
||||||
TRAPPED_CHEST_IDS.add(state['id'])
|
TRAPPED_CHEST_IDS.add(state['id'])
|
||||||
|
|
||||||
|
NETHERWART_IDS = set()
|
||||||
|
for block_name in ['nether_wart']:
|
||||||
|
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
||||||
|
NETHERWART_IDS.add(state['id'])
|
||||||
|
|
||||||
INDEXED_IDS = set()
|
INDEXED_IDS = set()
|
||||||
for block_name in INDEXED:
|
for block_name in INDEXED:
|
||||||
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
|
||||||
|
|
3
game.py
3
game.py
|
@ -639,6 +639,9 @@ class Game:
|
||||||
elif data == 'sand':
|
elif data == 'sand':
|
||||||
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':
|
||||||
|
self.g.job.state = self.g.job.farm_wart
|
||||||
|
reply = 'ok'
|
||||||
|
|
||||||
if reply:
|
if reply:
|
||||||
for i in self.g.inv.values():
|
for i in self.g.inv.values():
|
||||||
|
|
4
items.py
4
items.py
|
@ -62,5 +62,7 @@ GAPPLE_ID = set([ITEMS['minecraft:enchanted_golden_apple']['protocol_id']])
|
||||||
|
|
||||||
SAND_ID = set([ITEMS['minecraft:sand']['protocol_id']])
|
SAND_ID = set([ITEMS['minecraft:sand']['protocol_id']])
|
||||||
|
|
||||||
|
NETHERWART_ID = set([ITEMS['minecraft:nether_wart']['protocol_id']])
|
||||||
|
|
||||||
NEEDED_ITEMS = BED_IDS | CHEST_ID
|
NEEDED_ITEMS = BED_IDS | CHEST_ID
|
||||||
WANTED_ITEMS = SAPLING_IDS
|
WANTED_ITEMS = SAPLING_IDS | NETHERWART_ID
|
||||||
|
|
118
jobs.py
118
jobs.py
|
@ -124,6 +124,113 @@ class FindGappleStates:
|
||||||
self.state()
|
self.state()
|
||||||
|
|
||||||
|
|
||||||
|
class GatherWartStates:
|
||||||
|
def idle(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.g.chopped_tree = False
|
||||||
|
self.state = self.find_new_wart
|
||||||
|
|
||||||
|
def find_new_wart(self):
|
||||||
|
print('Finding new tree...')
|
||||||
|
w = self.g.world
|
||||||
|
p = utils.pint(self.g.pos)
|
||||||
|
|
||||||
|
mature_wart = max(blocks.NETHERWART_IDS)
|
||||||
|
for wart in w.find_blocks_3d(p, [mature_wart], 100):
|
||||||
|
print('Found wart:', wart)
|
||||||
|
if wart not in self.bad_warts:
|
||||||
|
break
|
||||||
|
else: # for
|
||||||
|
print('No good warts left, aborting.')
|
||||||
|
self.state = self.cleanup
|
||||||
|
return
|
||||||
|
|
||||||
|
self.wart = wart
|
||||||
|
self.state = self.nav_to_wart
|
||||||
|
|
||||||
|
def nav_to_wart(self):
|
||||||
|
w = self.g.world
|
||||||
|
p = utils.pint(self.g.pos)
|
||||||
|
|
||||||
|
navpath = w.path_to_place(p, self.wart)
|
||||||
|
|
||||||
|
if navpath:
|
||||||
|
self.g.path = navpath
|
||||||
|
self.g.look_at = utils.padd(self.wart, path.BLOCK_BELOW)
|
||||||
|
self.state = self.going_to_wart
|
||||||
|
else:
|
||||||
|
self.bad_warts.append(wart)
|
||||||
|
self.state = self.find_new_wart
|
||||||
|
|
||||||
|
def going_to_wart(self):
|
||||||
|
if utils.pint(self.g.pos) == self.wart:
|
||||||
|
print('At the wart')
|
||||||
|
self.state = self.break_wart
|
||||||
|
|
||||||
|
def break_wart(self):
|
||||||
|
self.g.game.break_block(self.wart)
|
||||||
|
self.wait_time = 0.5
|
||||||
|
self.state = self.wait
|
||||||
|
|
||||||
|
def wait(self):
|
||||||
|
# wait for the item
|
||||||
|
if self.wait_time > 0:
|
||||||
|
self.wait_time -= utils.TICK
|
||||||
|
else:
|
||||||
|
self.state = self.select_wart
|
||||||
|
|
||||||
|
def select_wart(self):
|
||||||
|
p = utils.pint(self.g.pos)
|
||||||
|
|
||||||
|
if self.g.game.select_item(items.NETHERWART_ID):
|
||||||
|
self.state = self.wait_select
|
||||||
|
self.wait_time = 0.5
|
||||||
|
else:
|
||||||
|
print('Aborting planting, no wart')
|
||||||
|
self.state = self.cleanup
|
||||||
|
|
||||||
|
def wait_select(self):
|
||||||
|
# wait a bit to select
|
||||||
|
if self.wait_time > 0:
|
||||||
|
self.wait_time -= utils.TICK
|
||||||
|
else:
|
||||||
|
self.state = self.place_wart
|
||||||
|
|
||||||
|
def place_wart(self):
|
||||||
|
p = utils.pint(self.g.pos)
|
||||||
|
self.g.game.place_block(p, BlockFace.TOP)
|
||||||
|
print('Placed wart')
|
||||||
|
self.state = self.wait_place
|
||||||
|
self.wait_time = 0.5
|
||||||
|
|
||||||
|
def wait_place(self):
|
||||||
|
# wait a bit for chunk data to update
|
||||||
|
if self.wait_time > 0:
|
||||||
|
self.wait_time -= utils.TICK
|
||||||
|
else:
|
||||||
|
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.wart = None
|
||||||
|
self.bad_warts = []
|
||||||
|
self.wait_time = 0
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.state()
|
||||||
|
|
||||||
class GatherWoodStates:
|
class GatherWoodStates:
|
||||||
def bair(self, p):
|
def bair(self, p):
|
||||||
return self.g.chunks.get_block_at(*p) in blocks.NON_SOLID_IDS
|
return self.g.chunks.get_block_at(*p) in blocks.NON_SOLID_IDS
|
||||||
|
@ -1325,6 +1432,7 @@ class JobStates:
|
||||||
self.grab_sand_states = GrabSandStates(self.g)
|
self.grab_sand_states = GrabSandStates(self.g)
|
||||||
self.fill_blocks_states = FillBlocksStates(self.g)
|
self.fill_blocks_states = FillBlocksStates(self.g)
|
||||||
self.check_threats_states = CheckThreatsStates(self.g)
|
self.check_threats_states = CheckThreatsStates(self.g)
|
||||||
|
self.gather_wart_states = GatherWartStates(self.g)
|
||||||
|
|
||||||
def run_machines(self, machines):
|
def run_machines(self, machines):
|
||||||
for m in machines:
|
for m in machines:
|
||||||
|
@ -1393,6 +1501,16 @@ class JobStates:
|
||||||
self.cache_items_states.silent = True
|
self.cache_items_states.silent = True
|
||||||
return machines
|
return machines
|
||||||
|
|
||||||
|
def farm_wart(self):
|
||||||
|
machines = [
|
||||||
|
self.gather_wart_states,
|
||||||
|
self.sleep_with_bed_states,
|
||||||
|
self.cache_items_states,
|
||||||
|
]
|
||||||
|
self.sleep_with_bed_states.silent = True
|
||||||
|
self.cache_items_states.silent = True
|
||||||
|
return machines
|
||||||
|
|
||||||
def fill_blocks(self):
|
def fill_blocks(self):
|
||||||
machines = [
|
machines = [
|
||||||
self.fill_blocks_states,
|
self.fill_blocks_states,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user