124 lines
3.1 KiB
Python
124 lines
3.1 KiB
Python
|
import re
|
||
|
import time
|
||
|
import importlib
|
||
|
import random
|
||
|
from itertools import count
|
||
|
from math import hypot, floor
|
||
|
|
||
|
from minecraft.networking.types import BlockFace
|
||
|
|
||
|
from protocol.managers import ChunkNotLoadedException
|
||
|
|
||
|
import utils
|
||
|
importlib.reload(utils)
|
||
|
import path
|
||
|
importlib.reload(path)
|
||
|
import blocks
|
||
|
importlib.reload(blocks)
|
||
|
import items
|
||
|
importlib.reload(items)
|
||
|
import mcdata
|
||
|
importlib.reload(mcdata)
|
||
|
import mobs
|
||
|
importlib.reload(mobs)
|
||
|
|
||
|
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 = (self.coord[0], 50, self.coord[2])
|
||
|
|
||
|
print('count:', self.count, 'teleporting to:', self.coord)
|
||
|
self.g.chat.send('/tp {} {} {}'.format(*self.coord))
|
||
|
|
||
|
self.g.command_lock = True
|
||
|
self.state = self.wait_for_load
|
||
|
|
||
|
def wait_for_load(self):
|
||
|
if self.g.command_lock:
|
||
|
return
|
||
|
|
||
|
if self.g.chunks.check_loaded(self.g.pos, 169):
|
||
|
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:
|
||
|
# slow but simple
|
||
|
continue
|
||
|
|
||
|
if utils.phyp_king(self.coord, chest) > 96:
|
||
|
# skip because we can't detect item drops
|
||
|
continue
|
||
|
|
||
|
self.current_chest = chest
|
||
|
self.checked_chests.append(self.current_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.item_lock = True
|
||
|
self.g.chat.send('/setblock {} {} {} air destroy'.format(*self.current_chest))
|
||
|
|
||
|
self.wait_time = 0.5
|
||
|
self.state = self.wait_for_items
|
||
|
|
||
|
def wait_for_items(self):
|
||
|
# wait for command to execute
|
||
|
if self.g.command_lock:
|
||
|
return
|
||
|
|
||
|
# wait for items to drop
|
||
|
if self.wait_time > 0:
|
||
|
self.wait_time -= utils.TICK
|
||
|
else:
|
||
|
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 = []
|
||
|
self.wait_time = 0
|
||
|
|
||
|
def run(self):
|
||
|
self.state()
|
||
|
|
||
|
|