Improve trading villager selection based on profession
This commit is contained in:
parent
080895421d
commit
a87cc85eab
2
main.py
2
main.py
|
@ -71,7 +71,7 @@ def main():
|
|||
event_handler.on_any_event = reload_bot
|
||||
|
||||
observer = Observer()
|
||||
observer.schedule(event_handler, '.', recursive=True)
|
||||
observer.schedule(event_handler, 'mosfet', recursive=True)
|
||||
observer.start()
|
||||
|
||||
try:
|
||||
|
|
|
@ -393,6 +393,13 @@ class Game:
|
|||
obj.item_id = entry.value.item_id
|
||||
obj.item_count = entry.value.item_count
|
||||
|
||||
mob = self.g.mobs.get(packet.entity_id, None)
|
||||
if mob:
|
||||
for entry in packet.metadata:
|
||||
if mob.type == mobs.VILLAGER:
|
||||
if entry.index == 17:
|
||||
mob.profession = entry.value[1]
|
||||
|
||||
player = self.g.players.get(packet.entity_id, None)
|
||||
if player:
|
||||
return
|
||||
|
|
|
@ -103,6 +103,7 @@ WHEAT_ID = get_id('wheat')
|
|||
WHEAT_SEEDS_ID = get_id('wheat_seeds')
|
||||
BEETROOT_SEEDS_ID = get_id('beetroot_seeds')
|
||||
PUMPKIN_ID = get_id('pumpkin')
|
||||
BEETROOT_ID = get_id('beetroot')
|
||||
|
||||
EMERALD_ID = get_id('emerald')
|
||||
BERRIES_ID = get_id('sweet_berries')
|
||||
|
|
|
@ -1,8 +1,33 @@
|
|||
from mosfet.info import items
|
||||
import json
|
||||
|
||||
with open('minecraft_data/registries.json') as f:
|
||||
MOBS = json.load(f)['minecraft:entity_type']['entries']
|
||||
|
||||
VILLAGER = 93
|
||||
ARMORER = 1
|
||||
BUTCHER = 2
|
||||
CARTOGRAPHER = 3
|
||||
CLERIC = 4
|
||||
FARMER = 5
|
||||
FISHERMAN = 6
|
||||
FLETCHER = 7
|
||||
LEATHERWORKER = 8
|
||||
LIBRARIAN = 9
|
||||
MASON = 10
|
||||
NITWIT = 11
|
||||
SHEPHERD = 12
|
||||
TOOLSMITH = 13
|
||||
WEAPONSMITH = 14
|
||||
|
||||
TRADES = {
|
||||
ARMORER: [items.IRON_INGOT_ID],
|
||||
BUTCHER: [items.BERRIES_ID],
|
||||
FARMER: [items.PUMPKIN_ID, items.WHEAT_ID, items.POTATO_ID, items.CARROT_ID, items.BEETROOT_ID],
|
||||
TOOLSMITH: [items.IRON_INGOT_ID],
|
||||
WEAPONSMITH: [items.IRON_INGOT_ID],
|
||||
}
|
||||
|
||||
EVIL = [
|
||||
'blaze',
|
||||
'cave_spider',
|
||||
|
|
|
@ -235,6 +235,8 @@ class JobStates:
|
|||
tuple([items.IRON_INGOT_ID]): (64, 3),
|
||||
tuple([items.WHEAT_ID]): (64, 3),
|
||||
tuple([items.POTATO_ID]): (64, 3),
|
||||
tuple([items.CARROT_ID]): (64, 3),
|
||||
tuple([items.BEETROOT_ID]): (64, 3),
|
||||
}
|
||||
|
||||
items.set_needed(set([
|
||||
|
@ -243,6 +245,8 @@ class JobStates:
|
|||
items.IRON_INGOT_ID,
|
||||
items.WHEAT_ID,
|
||||
items.POTATO_ID,
|
||||
items.CARROT_ID,
|
||||
items.BEETROOT_ID,
|
||||
]))
|
||||
return machines
|
||||
|
||||
|
|
|
@ -102,6 +102,9 @@ class GrabSuppliesStates:
|
|||
print('No path, blacklisting barrel')
|
||||
time.sleep(0.1)
|
||||
self.bad_barrels.append(self.barrel)
|
||||
if len(self.bad_barrels) > 3:
|
||||
self.state = self.cleanup
|
||||
else:
|
||||
self.state = self.choose_barrel
|
||||
|
||||
def going_to_barrel(self):
|
||||
|
|
|
@ -31,7 +31,28 @@ class SellToVillagerStates:
|
|||
|
||||
for v in w.find_villagers(p, 100):
|
||||
print('Found villager:', v)
|
||||
if v not in self.bad_villagers and v not in self.spent_villagers:
|
||||
|
||||
if v in self.bad_villagers:
|
||||
print('In bad villager list')
|
||||
continue
|
||||
|
||||
if v in self.spent_villagers:
|
||||
print('In spent villager list')
|
||||
continue
|
||||
|
||||
if 'profession' not in v:
|
||||
print('Villager has unknown profession')
|
||||
continue
|
||||
|
||||
if v.profession not in mobs.TRADES:
|
||||
print('Villager doesnt sell stuff we collect')
|
||||
continue
|
||||
|
||||
trades = mobs.TRADES[v.profession]
|
||||
if not self.g.game.count_items(trades):
|
||||
print('We dont have anything to sell him')
|
||||
continue
|
||||
|
||||
break
|
||||
else: # for
|
||||
print('No good villagers left, aborting.')
|
||||
|
@ -59,7 +80,7 @@ class SellToVillagerStates:
|
|||
if self.villager not in self.good_villagers:
|
||||
self.bad_villagers.append(self.villager)
|
||||
print('Added to bad villager list')
|
||||
self.state = self.cleanup
|
||||
self.state = self.find_villager
|
||||
return
|
||||
|
||||
navpath = w.path_to_place(p, self.openings[0])
|
||||
|
@ -144,8 +165,7 @@ class SellToVillagerStates:
|
|||
print('Villager has been spent, aborting')
|
||||
self.g.game.close_window()
|
||||
self.spent_villagers.append(self.villager)
|
||||
self.state = self.wait
|
||||
self.wait_time = 10
|
||||
self.state = self.find_villager
|
||||
return
|
||||
|
||||
def click_trade(self):
|
||||
|
|
|
@ -304,7 +304,7 @@ class EntityMetadataPacket(Packet):
|
|||
self.metadata = []
|
||||
for _ in range(99):
|
||||
entry = Entry.read(file_object, self.context)
|
||||
if not entry: break
|
||||
if not entry: break # hit an unimplemented type, stops parsing
|
||||
self.metadata.append(entry)
|
||||
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ class Slot(Type):
|
|||
|
||||
|
||||
class Entry(Type):
|
||||
types = {
|
||||
simple_types = {
|
||||
0: Byte,
|
||||
1: VarInt,
|
||||
2: Float,
|
||||
|
@ -169,12 +169,19 @@ class Entry(Type):
|
|||
index = UnsignedByte.read(file_object)
|
||||
if index == 0xff: return None
|
||||
type = VarInt.read(file_object)
|
||||
|
||||
if type == 10: # optional position
|
||||
present = Boolean.read(file_object)
|
||||
value = Position.read_with_context(file_object, context) if present else None
|
||||
elif type == 16: # villager data
|
||||
value = (VarInt.read(file_object), VarInt.read(file_object), VarInt.read(file_object))
|
||||
else:
|
||||
try:
|
||||
value = Entry.types[type].read(file_object)
|
||||
value = Entry.simple_types[type].read(file_object)
|
||||
except TypeError:
|
||||
value = Entry.types[type].read_with_context(file_object, context)
|
||||
value = Entry.simple_types[type].read_with_context(file_object, context)
|
||||
except KeyError:
|
||||
return None
|
||||
return None # unimplemented data type, stops parsing entries
|
||||
return Entry(index, type, value)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user