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