diff --git a/blocks.py b/blocks.py index a28330e..b6b3cc7 100644 --- a/blocks.py +++ b/blocks.py @@ -24,6 +24,10 @@ SOUL_TORCH = 4008 TEST_BLOCK = (616, 78, 496) +WATER = [ + 'water', +] + AVOID = [ 'lava', 'water', @@ -253,6 +257,11 @@ for block_name in AVOID: for state in JSON_BLOCKS['minecraft:' + block_name]['states']: AVOID_IDS.add(state['id']) +WATER_IDS = set() +for block_name in WATER: + for state in JSON_BLOCKS['minecraft:' + block_name]['states']: + WATER_IDS.add(state['id']) + LOG_IDS = set() for block_name in LOGS: for state in JSON_BLOCKS['minecraft:' + block_name]['states']: diff --git a/bot.py b/bot.py index 10d5532..0f23e7d 100644 --- a/bot.py +++ b/bot.py @@ -130,9 +130,12 @@ def tick(global_state): block_below = g.chunks.get_block_at(floor(p.x), ceil(p.y-1), floor(p.z)) in_void = p.y < 0 in_air = block_below in blocks.NON_SOLID_IDS or in_void + in_water = block_below in blocks.WATER_IDS if in_air: g.y_a = -36.0 + elif in_water: + g.y_a = -16.0 else: p.y = ceil(p.y) g.y_v = 0 diff --git a/game.py b/game.py index 096e95e..e887976 100644 --- a/game.py +++ b/game.py @@ -431,6 +431,7 @@ class Game: if command == 'stop': self.g.job.state = self.g.job.stop + self.g.path = [] reply = 'ok' if command == 'inv': @@ -514,7 +515,7 @@ class Game: if command == 'sand_slice': try: - _, result = self.g.world.find_sand_slice(utils.pint(self.g.pos), 50) + result = self.g.world.find_sand_slice(utils.pint(self.g.pos), 50) reply = str(result) except: import traceback @@ -553,7 +554,7 @@ class Game: self.g.connection.write_packet(packet) self.g.breaking = location - self.g.break_time = time.time() + utils.break_time(bid) + self.g.break_time = time.time() + utils.break_time(bid, self.g.holding) def break_finish(self): packet = PlayerDiggingPacket() @@ -622,6 +623,7 @@ class Game: for slot, item in inv_items: if item.item_id in items: self.g.game.choose_slot(slot) + self.g.holding = item.item_id return True else: #for return False diff --git a/items.py b/items.py index 195486e..9a23f6a 100644 --- a/items.py +++ b/items.py @@ -22,6 +22,15 @@ BEDS = [ 'black_bed', ] +SHOVELS = [ + 'wooden_shovel', + 'stone_shovel', + 'golden_shovel', + 'iron_shovel', + 'diamond_shovel', + 'netherite_shovel', +] + SAPLINGS = [ 'oak_sapling', 'spruce_sapling', @@ -35,6 +44,10 @@ BED_IDS = set() for item_name in BEDS: BED_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id']) +SHOVEL_IDS = set() +for item_name in SHOVELS: + SHOVEL_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id']) + SAPLING_IDS = set() for item_name in SAPLINGS: SAPLING_IDS.add(ITEMS['minecraft:'+item_name]['protocol_id']) diff --git a/jobs.py b/jobs.py index 6dfc743..66bfefc 100644 --- a/jobs.py +++ b/jobs.py @@ -299,6 +299,10 @@ class GatherSandStates: return None def init(self): + self.state = self.select_shovel + + def select_shovel(self): + self.g.game.select_item(items.SHOVEL_IDS) self.state = self.find_new_slice def find_new_slice(self): @@ -566,7 +570,7 @@ class SleepWithBedStates: self.g = global_state self.state = self.idle - self.silent = True + self.silent = False self.area = None self.opening = None diff --git a/main.py b/main.py index b07af94..a59ea59 100644 --- a/main.py +++ b/main.py @@ -23,6 +23,7 @@ g.objects = {} g.window = None g.job = None g.correction_count = 0 +g.holding = 0 @app.route('/') def hello_world(): diff --git a/utils.py b/utils.py index 05e5b77..e9b7b5b 100644 --- a/utils.py +++ b/utils.py @@ -71,6 +71,7 @@ def diffrange(n): def break_time(block_id, held_item=0, in_water=False, on_ground=True, enchantments=[], effects={}): # from PrismarineJS/prismarine-block + held_item = str(held_item) block_data = blocks.get(block_id) can_harvest = 'harvestTools' not in block_data or str(held_item) in block_data['harvestTools']