minecraft-bot/mosfet/jobs/gather_wart.py

127 lines
3.2 KiB
Python
Raw Normal View History

2021-04-19 01:34:54 +00:00
import re
import time
import importlib
import random
from itertools import count
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
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 GatherWartStates:
def idle(self):
return None
def init(self):
self.state = self.find_new_wart
def find_new_wart(self):
print('Finding new wart...')
w = self.g.world
p = utils.pint(self.g.pos)
mature_wart = max(blocks.NETHERWART_IDS)
2021-04-23 01:25:44 +00:00
for wart in w.find_blocks_3d(p, [mature_wart], 50, 20, True):
2021-04-19 01:34:54 +00:00
if wart not in self.bad_warts:
break
else: # for
print('No good warts left, aborting.')
self.state = self.cleanup
return
2021-04-23 01:25:44 +00:00
print('Found wart:', wart)
2021-04-19 01:34:54 +00:00
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:
print('Going to wart', self.wart)
2021-04-19 01:34:54 +00:00
self.g.path = navpath
self.g.look_at = utils.padd(self.wart, path.BLOCK_BELOW)
self.state = self.going_to_wart
else:
2021-04-23 01:25:44 +00:00
print('Cant get to it, blacklisting')
time.sleep(0.1)
2021-04-19 01:34:54 +00:00
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()