Cache items into trapped chests

This commit is contained in:
Tanner Collin 2020-12-01 00:48:02 +00:00
parent efcefc8192
commit eabb0a04d1
5 changed files with 93 additions and 16 deletions

View File

@ -233,8 +233,13 @@ CHESTS = [
'chest', 'chest',
] ]
TRAPPED_CHESTS = [
'trapped_chest',
]
INDEXED = [ INDEXED = [
'chest', 'chest',
'trapped_chest',
] ]
@ -263,6 +268,11 @@ for block_name in CHESTS:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']: for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
CHEST_IDS.add(state['id']) CHEST_IDS.add(state['id'])
TRAPPED_CHEST_IDS = set()
for block_name in TRAPPED_CHESTS:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']:
TRAPPED_CHEST_IDS.add(state['id'])
INDEXED_IDS = set() INDEXED_IDS = set()
for block_name in INDEXED: for block_name in INDEXED:
for state in JSON_BLOCKS['minecraft:' + block_name]['states']: for state in JSON_BLOCKS['minecraft:' + block_name]['states']:

3
bot.py
View File

@ -128,7 +128,8 @@ def tick(global_state):
g.y_v += g.y_a * utils.TICK g.y_v += g.y_a * utils.TICK
block_below = g.chunks.get_block_at(floor(p.x), ceil(p.y-1), floor(p.z)) block_below = g.chunks.get_block_at(floor(p.x), ceil(p.y-1), floor(p.z))
in_air = block_below in blocks.NON_SOLID_IDS in_void = p.y < 0
in_air = block_below in blocks.NON_SOLID_IDS or in_void
if in_air: if in_air:
g.y_a = -36.0 g.y_a = -36.0

View File

@ -1,5 +1,5 @@
import json import json
from bunch import Bunch from munch import Munch
import minecraft_data import minecraft_data
@ -12,12 +12,12 @@ SINGLE_CHEST = 2
DOUBLE_CHEST = 5 DOUBLE_CHEST = 5
WINDOWS = { WINDOWS = {
SINGLE_CHEST: Bunch( SINGLE_CHEST: Munch(
container=list(range(0, 27)), container=list(range(0, 27)),
inventory=list(range(27, 63)), inventory=list(range(27, 63)),
slot_diff=18, slot_diff=18,
), ),
DOUBLE_CHEST: Bunch( DOUBLE_CHEST: Munch(
container=list(range(0, 54)), container=list(range(0, 54)),
inventory=list(range(54, 90)), inventory=list(range(54, 90)),
slot_diff=45, slot_diff=45,

25
game.py
View File

@ -47,6 +47,25 @@ class MCWorld:
if self.block_at(*check) in block_ids: if self.block_at(*check) in block_ids:
yield check yield check
def find_blocks_indexed(self, center, block_ids, distance=0):
print('finding', block_ids)
index = []
for bid in block_ids:
index.extend(self.g.chunks.index.get(bid, []))
print('index', index)
result = []
for block in index:
if self.block_at(*block) not in block_ids:
continue
if distance and utils.phyp(center, block) > distance:
continue
result.append(block)
result.sort(key=lambda x: utils.phyp(center, x))
return result
def find_blocks(self, center, distance, block_ids, limit=0): def find_blocks(self, center, distance, block_ids, limit=0):
# search in a spiral from center to all blocks with ID # search in a spiral from center to all blocks with ID
result = [] result = []
@ -477,8 +496,10 @@ class Game:
packet.location = self.g.breaking packet.location = self.g.breaking
packet.face = 1 packet.face = 1
self.g.connection.write_packet(packet) self.g.connection.write_packet(packet)
self.g.chunks.set_block_at(*self.g.breaking, 0) #self.g.chunks.set_block_at(*self.g.breaking, 0)
self.g.breaking = None
if self.g.chunks.get_block_at(*self.g.breaking) == 0:
self.g.breaking = None
def handle_break_animation(self, packet): def handle_break_animation(self, packet):
print(packet) print(packet)

65
jobs.py
View File

@ -388,11 +388,19 @@ class SleepWithBedStates:
def init(self): def init(self):
if self.g.time >= 12000: if self.g.time >= 12000:
self.state = self.find_bed_spot self.state = self.select_bed
else: else:
print('Aborting sleep, not night') print('Aborting sleep, not night')
self.state = self.cleanup self.state = self.cleanup
def select_bed(self):
if self.g.game.select_item(items.BED_IDS):
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
self.state = self.find_bed_spot
else:
print('No bed, aborting.')
self.state = self.cleanup
def find_bed_spot(self): def find_bed_spot(self):
print('Finding a bed spot...') print('Finding a bed spot...')
w = self.g.world w = self.g.world
@ -426,15 +434,7 @@ class SleepWithBedStates:
def going_to_area(self): def going_to_area(self):
if utils.pint(self.g.pos) == self.opening: if utils.pint(self.g.pos) == self.opening:
self.g.look_at = self.area self.g.look_at = self.area
self.state = self.select_bed
def select_bed(self):
if self.g.game.select_item(items.BED_IDS):
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
self.state = self.place_bed self.state = self.place_bed
else:
print('No bed, aborting.')
self.state = self.cleanup
def place_bed(self): def place_bed(self):
self.g.game.place_block(self.area, BlockFace.TOP) self.g.game.place_block(self.area, BlockFace.TOP)
@ -504,11 +504,55 @@ class CacheItemsStates:
num_stacks = len([x for x in self.g.inv.values() if x.present]) num_stacks = len([x for x in self.g.inv.values() if x.present])
print('Inventory amount:', num_stacks) print('Inventory amount:', num_stacks)
if num_stacks >= 27: if num_stacks >= 27:
self.state = self.find_cache_spot self.state = self.find_trapped_chests
else: else:
print('Aborting caching, not full') print('Aborting caching, not full')
self.state = self.cleanup self.state = self.cleanup
def find_trapped_chests(self):
print('Finding trapped chests...')
w = self.g.world
p = utils.pint(self.g.pos)
self.trapped_chests = w.find_blocks_indexed(p, blocks.TRAPPED_CHEST_IDS, 100)
print('Found:', self.trapped_chests)
self.state = self.choose_trapped_chest
def choose_trapped_chest(self):
print('Choosing a trapped chest...')
w = self.g.world
p = utils.pint(self.g.pos)
c = self.g.chunks
if not len(self.trapped_chests):
print('No trapped chests')
self.state = self.find_cache_spot
return
chest = self.trapped_chests[0]
tmp = c.get_block_at(*chest)
c.set_block_at(*chest, blocks.AIR)
navpath = w.path_to_place(p, chest)
c.set_block_at(*chest, tmp)
print('navpath:', navpath)
if navpath:
self.g.path = navpath[:-1]
self.opening = self.g.path[-1]
self.area = chest
self.state = self.going_to_trapped_chest
return
else:
self.trapped_chests.pop(0)
def going_to_trapped_chest(self):
if utils.pint(self.g.pos) == self.opening:
self.g.look_at = self.area
self.state = self.open_chest
def find_cache_spot(self): def find_cache_spot(self):
print('Finding a chest spot...') print('Finding a chest spot...')
w = self.g.world w = self.g.world
@ -644,6 +688,7 @@ class CacheItemsStates:
self.area = None self.area = None
self.opening = None self.opening = None
self.trapped_chests = []
self.bad_areas = [] self.bad_areas = []
self.wait_time = 0 self.wait_time = 0