Begin villager trading job
This commit is contained in:
@@ -309,6 +309,40 @@ class MCWorld:
|
||||
result.append(mob)
|
||||
return result
|
||||
|
||||
def find_villagers(self, center, distance):
|
||||
# finds villagers within distance
|
||||
result = []
|
||||
for eid, mob in copy(self.g.mobs).items():
|
||||
type_name = mobs.MOB_NAMES[mob.type]
|
||||
if type_name != 'villager' : continue
|
||||
pos = utils.pint((mob.x, mob.y, mob.z))
|
||||
if utils.phyp(center, pos) > distance:
|
||||
continue
|
||||
result.append(mob)
|
||||
return result
|
||||
|
||||
def find_villager_openings(self, villager):
|
||||
# returns coords in a cardinal direction where we can stand by a villager
|
||||
maze_solver = path.Pathfinder(self.g.chunks)
|
||||
result = []
|
||||
|
||||
for distance in range(3):
|
||||
for direction in path.CHECK_DIRECTIONS:
|
||||
offset = utils.pmul(direction, distance+1)
|
||||
|
||||
if not maze_solver.check_traverse(villager, offset):
|
||||
continue
|
||||
|
||||
# check for line of sight
|
||||
for check in range(distance+1):
|
||||
offset2 = utils.pmul(direction, check+1)
|
||||
offset2 = utils.padd(offset2, path.BLOCK_ABOVE)
|
||||
check = utils.padd(villager, offset2)
|
||||
if self.block_at(*check) not in blocks.NON_SOLID_IDS:
|
||||
break
|
||||
else: # for
|
||||
result.append(utils.padd(villager, offset))
|
||||
return result
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -642,7 +676,12 @@ class Game:
|
||||
self.g.job.state = self.g.job.loiter
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'trade':
|
||||
self.g.job.state = self.g.job.trade
|
||||
reply = 'ok'
|
||||
|
||||
if command == 'stop':
|
||||
self.close_window()
|
||||
bot.init(self.g)
|
||||
reply = 'ok'
|
||||
|
||||
@@ -773,7 +812,8 @@ class Game:
|
||||
|
||||
if command == 'test':
|
||||
reply = 'ok'
|
||||
self.select_next_item()
|
||||
r = self.g.world.find_villager_openings((615, 78, 493))
|
||||
print(r)
|
||||
|
||||
################# Authorized commands ##########################
|
||||
if authed:
|
||||
@@ -965,10 +1005,11 @@ class Game:
|
||||
w.count += 1
|
||||
|
||||
def close_window(self):
|
||||
packet = CloseWindowPacket()
|
||||
packet.window_id = self.g.window.data.window_id
|
||||
self.g.connection.write_packet(packet)
|
||||
self.g.window = None
|
||||
if self.g.window:
|
||||
packet = CloseWindowPacket()
|
||||
packet.window_id = self.g.window.data.window_id
|
||||
self.g.connection.write_packet(packet)
|
||||
self.g.window = None
|
||||
|
||||
def handle_window_confirmation(self, packet):
|
||||
print(packet)
|
||||
@@ -1143,6 +1184,7 @@ class Game:
|
||||
|
||||
def handle_trade_list(self, packet):
|
||||
print(packet)
|
||||
self.g.trades = packet.trades
|
||||
|
||||
def tick(self):
|
||||
if self.g.breaking:
|
||||
|
||||
Reference in New Issue
Block a user