Fix trading bugs

This commit is contained in:
Tanner Collin 2021-02-28 23:33:31 +00:00
parent fcc74c7198
commit 2a3db71a7b
2 changed files with 58 additions and 16 deletions

View File

@ -110,6 +110,8 @@ BEETROOT_SEEDS_ID = get_id('beetroot_seeds')
PUMPKIN_ID = get_id('pumpkin') PUMPKIN_ID = get_id('pumpkin')
EMERALD_ID = get_id('emerald') EMERALD_ID = get_id('emerald')
BERRIES_ID = get_id('sweet_berries')
IRON_INGOT_ID = get_id('iron_ingot')
NEEDED_ITEMS = BED_IDS | SHOVEL_IDS | AXE_IDS | FOOD_IDS | set([CHEST_ID, PUMPKIN_ID]) NEEDED_ITEMS = BED_IDS | SHOVEL_IDS | AXE_IDS | FOOD_IDS | set([CHEST_ID, PUMPKIN_ID, BERRIES_ID, IRON_INGOT_ID])
WANTED_ITEMS = SAPLING_IDS | set([NETHERWART_ID, CARROT_ID, POTATO_ID, WHEAT_SEEDS_ID, BEETROOT_SEEDS_ID]) WANTED_ITEMS = SAPLING_IDS | set([NETHERWART_ID, CARROT_ID, POTATO_ID, WHEAT_SEEDS_ID, BEETROOT_SEEDS_ID])

70
jobs.py
View File

@ -954,8 +954,17 @@ class CacheItemsStates:
def move_items(self): def move_items(self):
if self.g.item_lock: return if self.g.item_lock: return
w = self.g.window w = self.g.window
if not w:
print('Didnt get a window, aborting')
self.state = self.cleanup
return
if w.data.window_type != mcdata.SINGLE_CHEST:
print('Got wrong window, aborting')
self.state = self.cleanup
return
w_info = mcdata.WINDOWS[w.data.window_type] w_info = mcdata.WINDOWS[w.data.window_type]
w_inventory_slots = w_info.inventory w_inventory_slots = w_info.inventory
@ -1049,22 +1058,32 @@ class GrabSuppliesStates:
self.state = self.cleanup self.state = self.cleanup
def check_supplies(self): def check_supplies(self):
# TODO: only visit each barrel once
# switch the supplies and barrels steps
for items, limits in self.supplies.items(): for items, limits in self.supplies.items():
minimum, maximum = limits minimum, maximum = limits
print('Checking items:', items) print('Checking items:', items)
num_items = self.g.game.count_items(items) num_items = self.g.game.count_items(items)
print('Have:', num_items) print('Have:', num_items)
if num_items >= minimum: if items in self.checked_supplies:
print('Skipping') print('Already checked, skipping')
continue continue
else:
self.target_items = items
self.maximum_items = maximum
self.count = 0
self.state = self.find_barrels
return
if num_items >= minimum:
print('Have enough, skipping')
continue
self.target_items = items
self.checked_supplies.append(items)
self.maximum_items = maximum
self.count = 0
self.state = self.find_barrels
return
self.checked_supplies = []
print('Aborting, don\'t need any more supplies') print('Aborting, don\'t need any more supplies')
self.state = self.cleanup self.state = self.cleanup
@ -1085,7 +1104,7 @@ class GrabSuppliesStates:
if not len(self.barrels): if not len(self.barrels):
print('No barrels') print('No barrels')
self.state = self.cleanup self.state = self.no_more_barrels
return return
barrel = self.barrels[0] barrel = self.barrels[0]
@ -1126,8 +1145,17 @@ class GrabSuppliesStates:
def grab_items(self): def grab_items(self):
if self.g.item_lock: return if self.g.item_lock: return
w = self.g.window w = self.g.window
if not w:
print('Didnt get a window, aborting')
self.state = self.cleanup
return
if w.data.window_type != mcdata.SINGLE_CHEST:
print('Got wrong window, aborting')
self.state = self.cleanup
return
w_info = mcdata.WINDOWS[w.data.window_type] w_info = mcdata.WINDOWS[w.data.window_type]
w_container_slots = w_info.container w_container_slots = w_info.container
@ -1159,10 +1187,14 @@ class GrabSuppliesStates:
def close_barrel(self): def close_barrel(self):
print('Closing barrel') print('Closing barrel')
self.g.game.close_window() self.g.game.close_window()
self.state = self.cleanup self.g.look_at = None
self.barrels.pop(0)
self.state = self.choose_barrel
def no_more_barrels(self):
self.state = self.check_supplies
def cleanup(self): def cleanup(self):
self.g.look_at = None
self.state = self.done self.state = self.done
def done(self): def done(self):
@ -1173,8 +1205,8 @@ class GrabSuppliesStates:
self.g = global_state self.g = global_state
self.state = self.idle self.state = self.idle
self.checked_supplies = []
self.supplies = {} self.supplies = {}
self.target_supplies = []
self.barrels = [] self.barrels = []
self.target_items = None self.target_items = None
@ -1855,11 +1887,16 @@ class SellToVillagerStates:
def choose_trade(self): def choose_trade(self):
g = self.g.game g = self.g.game
w = self.g.window
if not self.g.window or not self.g.trades: if not w or not self.g.trades:
print('Didnt get a trade window, aborting') print('Didnt get a trade window, aborting')
self.state = self.cleanup self.state = self.cleanup
return return
if w.data.window_type != mcdata.VILLAGER_TRADE:
print('Got wrong window, aborting')
self.state = self.cleanup
return
for trade_num, trade in enumerate(self.g.trades): for trade_num, trade in enumerate(self.g.trades):
in_id = trade.input_item_1.item_id in_id = trade.input_item_1.item_id
@ -1869,6 +1906,7 @@ class SellToVillagerStates:
price = in_num \ price = in_num \
+ floor(in_num * trade.price_multiplier * trade.demand) \ + floor(in_num * trade.price_multiplier * trade.demand) \
+ trade.special_price + trade.special_price
if price < 1: price = 1
if g.count_items([in_id]) < price: if g.count_items([in_id]) < price:
continue continue
@ -2125,6 +2163,8 @@ class JobStates:
self.cache_items_states.silent = True self.cache_items_states.silent = True
self.grab_supplies_states.supplies = { self.grab_supplies_states.supplies = {
tuple([items.PUMPKIN_ID]): (64, 9), tuple([items.PUMPKIN_ID]): (64, 9),
tuple([items.BERRIES_ID]): (64, 9),
tuple([items.IRON_INGOT_ID]): (64, 9),
} }
return machines return machines