Grab fallen saplings, fix bugs

This commit is contained in:
2020-10-15 01:37:47 -06:00
parent f328f3443a
commit 6c4aaf8d7d
5 changed files with 104 additions and 56 deletions
+79 -2
View File
@@ -1,6 +1,7 @@
import re
import time
import importlib
import random
from math import hypot
from panda3d.core import LPoint3f
@@ -626,8 +627,6 @@ class PlantTreeStates:
def idle(self):
return None
# TODO: maybe add a "plant deficit" so we know when to plant or not
def init(self):
if self.g.chopped_tree:
self.state = self.check_feet
@@ -731,6 +730,75 @@ class PlantTreeStates:
self.state()
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
saplings = w.find_objects(items.SAPLING_IDS)
if not saplings:
print('No saplings objects found, aborting')
self.state = self.cleanup
return
random.shuffle(saplings)
for s in saplings:
p = utils.pint(self.g.pos)
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
# slip 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 saplings, aborting')
self.state = self.cleanup
def going_to_sapling(self):
if utils.pint(self.g.pos) == self.sapling:
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.sapling = None
self.eid_blacklist = []
def run(self):
self.state()
class JobStates:
def idle(self):
return None
@@ -802,12 +870,14 @@ class JobStates:
s2 = self.plant_tree_states
s3 = self.sleep_with_bed_states
s4 = self.cache_items_states
s5 = self.grab_sapling_states
if s1.state == s1.idle:
s1.state = s1.init
s2.state = s2.init
s3.state = s3.init
s4.state = s4.init
s5.state = s5.init
elif s1.state == s1.done:
if s2.state != s2.done:
s2.run()
@@ -821,10 +891,15 @@ class JobStates:
s4.run()
return
if s5.state != s5.done:
s5.run()
return
s1.state = s1.init
s2.state = s2.init
s3.state = s3.init
s4.state = s4.init
s5.state = s5.init
return
s1.run()
@@ -836,6 +911,7 @@ class JobStates:
self.cache_items_states = CacheItemsStates(self.g)
self.find_gapple_states = FindGappleStates(self.g)
self.plant_tree_states = PlantTreeStates(self.g)
self.grab_sapling_states = GrabSaplingStates(self.g)
self.state = self.idle
def __init__(self, global_state):
@@ -849,6 +925,7 @@ class JobStates:
self.cache_items_states = CacheItemsStates(self.g)
self.find_gapple_states = FindGappleStates(self.g)
self.plant_tree_states = PlantTreeStates(self.g)
self.grab_sapling_states = GrabSaplingStates(self.g)
def tick(self):
self.state()