Fix trading bugs
This commit is contained in:
parent
fcc74c7198
commit
2a3db71a7b
4
items.py
4
items.py
|
@ -110,6 +110,8 @@ BEETROOT_SEEDS_ID = get_id('beetroot_seeds')
|
|||
PUMPKIN_ID = get_id('pumpkin')
|
||||
|
||||
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])
|
||||
|
|
70
jobs.py
70
jobs.py
|
@ -954,8 +954,17 @@ class CacheItemsStates:
|
|||
|
||||
def move_items(self):
|
||||
if self.g.item_lock: return
|
||||
|
||||
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_inventory_slots = w_info.inventory
|
||||
|
||||
|
@ -1049,22 +1058,32 @@ class GrabSuppliesStates:
|
|||
self.state = self.cleanup
|
||||
|
||||
def check_supplies(self):
|
||||
|
||||
# TODO: only visit each barrel once
|
||||
# switch the supplies and barrels steps
|
||||
|
||||
for items, limits in self.supplies.items():
|
||||
minimum, maximum = limits
|
||||
print('Checking items:', items)
|
||||
num_items = self.g.game.count_items(items)
|
||||
print('Have:', num_items)
|
||||
|
||||
if num_items >= minimum:
|
||||
print('Skipping')
|
||||
if items in self.checked_supplies:
|
||||
print('Already checked, skipping')
|
||||
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')
|
||||
self.state = self.cleanup
|
||||
|
||||
|
@ -1085,7 +1104,7 @@ class GrabSuppliesStates:
|
|||
|
||||
if not len(self.barrels):
|
||||
print('No barrels')
|
||||
self.state = self.cleanup
|
||||
self.state = self.no_more_barrels
|
||||
return
|
||||
|
||||
barrel = self.barrels[0]
|
||||
|
@ -1126,8 +1145,17 @@ class GrabSuppliesStates:
|
|||
|
||||
def grab_items(self):
|
||||
if self.g.item_lock: return
|
||||
|
||||
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_container_slots = w_info.container
|
||||
|
||||
|
@ -1159,10 +1187,14 @@ class GrabSuppliesStates:
|
|||
def close_barrel(self):
|
||||
print('Closing barrel')
|
||||
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):
|
||||
self.g.look_at = None
|
||||
self.state = self.done
|
||||
|
||||
def done(self):
|
||||
|
@ -1173,8 +1205,8 @@ class GrabSuppliesStates:
|
|||
self.g = global_state
|
||||
self.state = self.idle
|
||||
|
||||
self.checked_supplies = []
|
||||
self.supplies = {}
|
||||
self.target_supplies = []
|
||||
self.barrels = []
|
||||
|
||||
self.target_items = None
|
||||
|
@ -1855,11 +1887,16 @@ class SellToVillagerStates:
|
|||
|
||||
def choose_trade(self):
|
||||
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')
|
||||
self.state = self.cleanup
|
||||
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):
|
||||
in_id = trade.input_item_1.item_id
|
||||
|
@ -1869,6 +1906,7 @@ class SellToVillagerStates:
|
|||
price = in_num \
|
||||
+ floor(in_num * trade.price_multiplier * trade.demand) \
|
||||
+ trade.special_price
|
||||
if price < 1: price = 1
|
||||
|
||||
if g.count_items([in_id]) < price:
|
||||
continue
|
||||
|
@ -2125,6 +2163,8 @@ class JobStates:
|
|||
self.cache_items_states.silent = True
|
||||
self.grab_supplies_states.supplies = {
|
||||
tuple([items.PUMPKIN_ID]): (64, 9),
|
||||
tuple([items.BERRIES_ID]): (64, 9),
|
||||
tuple([items.IRON_INGOT_ID]): (64, 9),
|
||||
}
|
||||
return machines
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user