|
|
@ -19,7 +19,6 @@ importlib.reload(blocks) |
|
|
|
class MCWorld: |
|
|
|
class MCWorld: |
|
|
|
def __init__(self, global_state): |
|
|
|
def __init__(self, global_state): |
|
|
|
self.g = global_state |
|
|
|
self.g = global_state |
|
|
|
self.l = self.g.local_state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def block_at(self, x, y, z): |
|
|
|
def block_at(self, x, y, z): |
|
|
|
return self.g.chunks.get_block_at(x, y, z) |
|
|
|
return self.g.chunks.get_block_at(x, y, z) |
|
|
@ -164,7 +163,6 @@ class MCWorld: |
|
|
|
class Game: |
|
|
|
class Game: |
|
|
|
def __init__(self, global_state): |
|
|
|
def __init__(self, global_state): |
|
|
|
self.g = global_state |
|
|
|
self.g = global_state |
|
|
|
self.l = self.g.local_state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
register = self.g.connection.register_packet_listener |
|
|
|
register = self.g.connection.register_packet_listener |
|
|
|
register(self.handle_block_change, clientbound.play.BlockChangePacket) |
|
|
|
register(self.handle_block_change, clientbound.play.BlockChangePacket) |
|
|
@ -184,19 +182,17 @@ class Game: |
|
|
|
self.g.eid = packet.entity_id |
|
|
|
self.g.eid = packet.entity_id |
|
|
|
|
|
|
|
|
|
|
|
def handle_block_change(self, packet): |
|
|
|
def handle_block_change(self, packet): |
|
|
|
l = self.g.local_state |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if packet.block_state_id == blocks.SOUL_TORCH: |
|
|
|
if packet.block_state_id == blocks.SOUL_TORCH: |
|
|
|
try: |
|
|
|
try: |
|
|
|
l.goal = LPoint3f(x=packet.location[0], y=packet.location[1], z=packet.location[2]) |
|
|
|
self.g.goal = LPoint3f(x=packet.location[0], y=packet.location[1], z=packet.location[2]) |
|
|
|
print('new waypoint:', l.goal) |
|
|
|
print('new waypoint:', self.g.goal) |
|
|
|
|
|
|
|
|
|
|
|
start = time.time() |
|
|
|
start = time.time() |
|
|
|
solution = path.Pathfinder(self.g.chunks).astar(utils.pint(self.g.pos), utils.pint(l.goal)) |
|
|
|
solution = path.Pathfinder(self.g.chunks).astar(utils.pint(self.g.pos), utils.pint(g.goal)) |
|
|
|
if solution: |
|
|
|
if solution: |
|
|
|
solution = list(solution) |
|
|
|
solution = list(solution) |
|
|
|
l.path = solution |
|
|
|
self.g.path = solution |
|
|
|
#l.jobstate.state = l.jobstate.stop |
|
|
|
#g.jobstate.state = self.g.jobstate.stop |
|
|
|
print(len(solution)) |
|
|
|
print(len(solution)) |
|
|
|
print(solution) |
|
|
|
print(solution) |
|
|
|
print(round(time.time() - start, 3), 'seconds') |
|
|
|
print(round(time.time() - start, 3), 'seconds') |
|
|
@ -204,8 +200,8 @@ class Game: |
|
|
|
print('No path found') |
|
|
|
print('No path found') |
|
|
|
#say(connection, 'No path found') |
|
|
|
#say(connection, 'No path found') |
|
|
|
|
|
|
|
|
|
|
|
#l.y_v = 10.0 |
|
|
|
#g.y_v = 10.0 |
|
|
|
#l.y_a = -36.0 |
|
|
|
#g.y_a = -36.0 |
|
|
|
except BaseException as e: |
|
|
|
except BaseException as e: |
|
|
|
import traceback |
|
|
|
import traceback |
|
|
|
print(traceback.format_exc()) |
|
|
|
print(traceback.format_exc()) |
|
|
@ -270,8 +266,7 @@ class Game: |
|
|
|
self.g.chat.send(reply) |
|
|
|
self.g.chat.send(reply) |
|
|
|
|
|
|
|
|
|
|
|
def handle_time_update(self, packet): |
|
|
|
def handle_time_update(self, packet): |
|
|
|
l = self.g.local_state |
|
|
|
self.g.time = packet.time_of_day % 24000 |
|
|
|
l.time = packet.time_of_day % 24000 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_set_slot(self, packet): |
|
|
|
def handle_set_slot(self, packet): |
|
|
|
print(packet) |
|
|
|
print(packet) |
|
|
@ -287,16 +282,16 @@ class Game: |
|
|
|
packet.face = 1 |
|
|
|
packet.face = 1 |
|
|
|
self.g.connection.write_packet(packet) |
|
|
|
self.g.connection.write_packet(packet) |
|
|
|
|
|
|
|
|
|
|
|
self.l.breaking = location |
|
|
|
self.g.breaking = location |
|
|
|
self.l.break_time = time.time() + utils.break_time(bid) |
|
|
|
self.g.break_time = time.time() + utils.break_time(bid) |
|
|
|
|
|
|
|
|
|
|
|
def break_finish(self): |
|
|
|
def break_finish(self): |
|
|
|
packet = PlayerDiggingPacket() |
|
|
|
packet = PlayerDiggingPacket() |
|
|
|
packet.status = 2 |
|
|
|
packet.status = 2 |
|
|
|
packet.location = self.l.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.l.breaking = None |
|
|
|
self.g.breaking = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_break_animation(self, packet): |
|
|
|
def handle_break_animation(self, packet): |
|
|
@ -322,8 +317,8 @@ class Game: |
|
|
|
self.g.connection.write_packet(packet) |
|
|
|
self.g.connection.write_packet(packet) |
|
|
|
|
|
|
|
|
|
|
|
def tick(self): |
|
|
|
def tick(self): |
|
|
|
if self.l.breaking: |
|
|
|
if self.g.breaking: |
|
|
|
self.animate() |
|
|
|
self.animate() |
|
|
|
|
|
|
|
|
|
|
|
if time.time() >= self.l.break_time - 2*utils.TICK: |
|
|
|
if time.time() >= self.g.break_time - 2*utils.TICK: |
|
|
|
self.break_finish() |
|
|
|
self.break_finish() |
|
|
|