You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.1 KiB
85 lines
2.1 KiB
import re |
|
import time |
|
import importlib |
|
import random |
|
from itertools import count |
|
from math import floor |
|
|
|
from minecraft.networking.types import BlockFace |
|
|
|
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 |
|
|
|
class GrabSaplingStates: |
|
def idle(self): |
|
return None |
|
|
|
def init(self): |
|
self.state = self.find_saplings |
|
print('Trying to grab a sapling') |
|
|
|
def find_saplings(self): |
|
w = self.g.world |
|
p = utils.pint(self.g.pos) |
|
|
|
saplings = w.find_objects(items.SAPLING_IDS) |
|
|
|
if not saplings: |
|
print('No sapling objects found, aborting') |
|
self.state = self.cleanup |
|
return |
|
|
|
saplings.sort(key=lambda s: utils.phyp(p, (s.x, s.y, s.z))) |
|
|
|
for s in saplings: |
|
s_pos = utils.pint((s.x, s.y, s.z)) |
|
|
|
check = utils.padd(s_pos, path.BLOCK_BELOW) |
|
|
|
if s.entity_id in self.eid_blacklist: |
|
continue |
|
|
|
# skip if the sapling is floating |
|
if self.g.chunks.get_block_at(*check) in blocks.LEAF_IDS | {0}: |
|
continue |
|
|
|
navpath = w.path_to_place(p, s_pos) |
|
|
|
if navpath: |
|
self.g.path = navpath |
|
self.state = self.going_to_sapling |
|
self.sapling = s_pos |
|
self.eid_blacklist.append(s.entity_id) |
|
print('Going to sapling', self.sapling) |
|
return |
|
|
|
print('Cant get to any more saplings, aborting') |
|
self.state = self.cleanup |
|
|
|
def going_to_sapling(self): |
|
if utils.pint(self.g.pos) == self.sapling: |
|
self.state = self.find_saplings |
|
|
|
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.sapling = None |
|
self.eid_blacklist = [] |
|
|
|
def run(self): |
|
self.state()
|
|
|