Add a job to find enchanted golden apples
This commit is contained in:
@@ -7,6 +7,8 @@ from panda3d.core import LPoint3f
|
||||
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
from protocol.managers import ChunkNotLoadedException
|
||||
|
||||
import utils
|
||||
importlib.reload(utils)
|
||||
import path
|
||||
@@ -19,6 +21,85 @@ import data
|
||||
importlib.reload(data)
|
||||
|
||||
|
||||
class FindGappleStates:
|
||||
def idle(self):
|
||||
return None
|
||||
|
||||
def init(self):
|
||||
self.state = self.go_spectator
|
||||
|
||||
def go_spectator(self):
|
||||
print('Going spectator...')
|
||||
self.g.chat.send('/gamemode spectator')
|
||||
|
||||
self.state = self.tp_to_coord
|
||||
|
||||
def tp_to_coord(self):
|
||||
step = utils.spiral(self.count)
|
||||
step_scaled = utils.pmul(step, 192)
|
||||
self.coord = utils.padd(self.origin, step_scaled)
|
||||
self.coord = utils.padd(self.coord, (0, 50, 0))
|
||||
|
||||
print('count:', self.count, 'teleporting to:', self.coord)
|
||||
self.g.chat.send('/tp {} {} {}'.format(*self.coord))
|
||||
|
||||
self.state = self.wait_for_load
|
||||
|
||||
def wait_for_load(self):
|
||||
if self.g.chunks.check_loaded(self.g.pos):
|
||||
print('chunks have been loaded')
|
||||
self.state = self.pick_chest
|
||||
|
||||
def pick_chest(self):
|
||||
chest_list = []
|
||||
for chest_id in blocks.CHEST_IDS:
|
||||
chest_list.extend(self.g.chunks.index.get(chest_id, []))
|
||||
|
||||
for chest in chest_list:
|
||||
if chest in self.checked_chests: continue
|
||||
|
||||
self.current_chest = chest
|
||||
self.state = self.break_chest
|
||||
break
|
||||
else: # for
|
||||
print('exhausted chest list')
|
||||
self.state = self.cleanup
|
||||
|
||||
def break_chest(self):
|
||||
print('Breaking chest', self.current_chest)
|
||||
self.g.command_lock = True
|
||||
self.g.chat.send('/setblock {} {} {} air destroy'.format(*self.current_chest))
|
||||
self.checked_chests.append(self.current_chest)
|
||||
|
||||
self.state = self.wait_for_items
|
||||
|
||||
def wait_for_items(self):
|
||||
if not self.g.command_lock:
|
||||
print('done waiting for items')
|
||||
self.state = self.pick_chest
|
||||
|
||||
def cleanup(self):
|
||||
self.count += 1
|
||||
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.origin = utils.pint(self.g.pos)
|
||||
self.count = 0
|
||||
self.coord = None
|
||||
self.current_chest = None
|
||||
self.checked_chests = []
|
||||
|
||||
def run(self):
|
||||
self.state()
|
||||
|
||||
|
||||
class LumberjackStates:
|
||||
def bair(self, p):
|
||||
return self.g.chunks.get_block_at(*p) in blocks.NON_SOLID_IDS
|
||||
@@ -515,6 +596,16 @@ class JobStates:
|
||||
def idle(self):
|
||||
return None
|
||||
|
||||
def find_gapple(self):
|
||||
s1 = self.find_gapple_states
|
||||
|
||||
if s1.state == s1.idle:
|
||||
s1.state = s1.init
|
||||
elif s1.state == s1.done:
|
||||
s1.state = s1.init
|
||||
|
||||
s1.run()
|
||||
|
||||
def gather_sand(self):
|
||||
s1 = self.gather_sand_states
|
||||
s2 = self.sleep_with_bed_states
|
||||
@@ -570,6 +661,7 @@ class JobStates:
|
||||
self.gather_sand_states = GatherSandStates(self.g)
|
||||
self.sleep_with_bed_states = SleepWithBedStates(self.g)
|
||||
self.cache_items_states = CacheItemsStates(self.g)
|
||||
self.find_gapple_states = FindGappleStates(self.g)
|
||||
self.state = self.idle
|
||||
|
||||
def __init__(self, global_state):
|
||||
@@ -581,6 +673,7 @@ class JobStates:
|
||||
self.gather_sand_states = GatherSandStates(self.g)
|
||||
self.sleep_with_bed_states = SleepWithBedStates(self.g)
|
||||
self.cache_items_states = CacheItemsStates(self.g)
|
||||
self.find_gapple_states = FindGappleStates(self.g)
|
||||
|
||||
def tick(self):
|
||||
self.state()
|
||||
|
||||
Reference in New Issue
Block a user