fix: there isn't a scheduler yet when registering

This commit is contained in:
əlemi 2023-03-16 16:31:03 +01:00
parent ef8ffac391
commit 8655c5ebde
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -18,11 +18,14 @@ class GameWorld(Scaffold):
vehicle_id : Optional[int] vehicle_id : Optional[int]
world : World world : World
_last_steer_vehicle : float
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.position = BlockPos(0, 0, 0) self.position = BlockPos(0, 0, 0)
self.vehicle_id = None self.vehicle_id = None
self._last_steer_vehicle = time()
@self.on_packet(PacketSetPassengers) @self.on_packet(PacketSetPassengers)
async def player_enters_vehicle_cb(packet:PacketSetPassengers): async def player_enters_vehicle_cb(packet:PacketSetPassengers):
@ -58,23 +61,19 @@ class GameWorld(Scaffold):
self.position.y + packet.dY, self.position.y + packet.dY,
self.position.z + packet.dZ self.position.z + packet.dZ
) )
self.logger.info( self.logger.debug(
"Position synchronized : (x:%.0f,y:%.0f,z:%.0f) (relMove vehicle)", "Position synchronized : (x:%.0f,y:%.0f,z:%.0f) (relMove vehicle)",
self.position.x, self.position.y, self.position.z self.position.x, self.position.y, self.position.z
) )
if time() - self._last_steer_vehicle >= 5:
@self.scheduler.scheduled_job('interval', seconds=5, name='send steer vehicle if riding a vehicle') await self.dispatcher.write(
async def steer_vehicle_cb(): PacketSteerVehicle(
if self.vehicle_id is None: self.dispatcher.proto,
return forward=0,
await self.dispatcher.write( sideways=0,
PacketSteerVehicle( jump=0
self.dispatcher.proto, )
forward=0,
sideways=0,
jump=0
) )
)
@self.on_packet(PacketPosition) @self.on_packet(PacketPosition)
async def player_rubberband_cb(packet:PacketPosition): async def player_rubberband_cb(packet:PacketPosition):